List of usage examples for com.amazonaws Request setResourcePath
void setResourcePath(String path);
From source file:com.comcast.cmb.common.controller.AdminServletBase.java
License:Apache License
protected String httpPOST(String baseUrl, String urlString, AWSCredentials awsCredentials) { URL url;/*from w ww . ja va2 s .c om*/ HttpURLConnection conn; BufferedReader br; String line; String doc = ""; try { String urlPost = urlString.substring(0, urlString.indexOf("?")); url = new URL(urlPost); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); CreateQueueRequest createQueueRequest = new CreateQueueRequest("test"); Request<CreateQueueRequest> request = new CreateQueueRequestMarshaller().marshall(createQueueRequest); //set parameters from url String parameterString = urlString.substring(urlString.indexOf("?") + 1); String[] parameterArray = parameterString.split("&"); Map<String, String> requestParameters = new HashMap<String, String>(); for (int i = 0; i < parameterArray.length; i++) { requestParameters.put(parameterArray[i].substring(0, parameterArray[i].indexOf("=")), parameterArray[i].substring(parameterArray[i].indexOf("=") + 1)); } request.setParameters(requestParameters); //get endpoint from url URI uri = new URI(baseUrl); request.setEndpoint(uri); String resourcePath = urlString.substring(baseUrl.length(), urlString.indexOf("?")); request.setResourcePath(resourcePath); AWS4Signer aws4Signer = new AWS4Signer(); String host = uri.getHost(); aws4Signer.setServiceName(host); aws4Signer.sign(request, awsCredentials); //set headers for real request for (Entry<String, String> entry : request.getHeaders().entrySet()) { conn.setRequestProperty(entry.getKey(), entry.getValue()); } // Send post request conn.setDoOutput(true); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); StringBuffer bodyStringBuffer = new StringBuffer(); for (Entry<String, String> entry : requestParameters.entrySet()) { bodyStringBuffer.append(entry.getKey() + "=" + entry.getValue() + "&"); } String bodyString = ""; if (bodyStringBuffer.length() > 0) { bodyString = bodyStringBuffer.substring(0, bodyStringBuffer.length() - 1); } wr.writeBytes(bodyString); wr.flush(); wr.close(); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); while ((line = br.readLine()) != null) { doc += line; } br.close(); logger.info("event=http_get url=" + urlString); } catch (Exception ex) { logger.error("event=http_get url=" + urlString, ex); } return doc; }
From source file:com.erudika.para.rest.Signer.java
License:Apache License
private Request<?> buildAWSRequest(String httpMethod, String endpoint, String resourcePath, Map<String, String> headers, Map<String, String> params, InputStream entity) { Request<?> r = new DefaultRequest<AmazonWebServiceRequest>(Config.PARA); if (!StringUtils.isBlank(httpMethod)) { r.setHttpMethod(HttpMethodName.valueOf(httpMethod)); }//from w w w . j a va 2 s . com if (!StringUtils.isBlank(endpoint)) { if (!endpoint.startsWith("http")) { endpoint = "https://" + endpoint; } r.setEndpoint(URI.create(endpoint)); } if (!StringUtils.isBlank(resourcePath)) { r.setResourcePath(SdkHttpUtils.urlEncode(resourcePath, true)); } if (headers != null) { if (headers.containsKey("x-amz-date")) { overriddenDate = parseAWSDate(headers.get("x-amz-date")); } // we don't need these here, added by default headers.remove("host"); headers.remove("x-amz-date"); r.setHeaders(headers); } if (params != null) { for (Map.Entry<String, String> param : params.entrySet()) { r.addParameter(param.getKey(), param.getValue()); } } if (entity != null) { r.setContent(entity); } return r; }
From source file:com.ivona.services.tts.model.transform.createspeech.CreateSpeechGetRequestMarshaller.java
License:Open Source License
public Request<CreateSpeechRequest> marshall(CreateSpeechRequest createSpeechRequest) { if (createSpeechRequest == null) { throw new AmazonClientException("null createSpeechRequest passed to marshall(...)"); }//from ww w .j ava 2 s . c o m Request<CreateSpeechRequest> request = new DefaultRequest<CreateSpeechRequest>(createSpeechRequest, IvonaSpeechCloudClient.SERVICE_NAME); setRequestParameters(request, createSpeechRequest); request.setHttpMethod(HttpMethodName.GET); request.setResourcePath(RESOURCE_PATH); return request; }
From source file:com.ivona.services.tts.model.transform.createspeech.CreateSpeechPostRequestMarshaller.java
License:Open Source License
public Request<CreateSpeechRequest> marshall(CreateSpeechRequest createSpeechRequest) { if (createSpeechRequest == null) { throw new AmazonClientException("null createSpeechRequest passed to marshall(...)"); }//from w w w. j a v a 2s . c o m Request<CreateSpeechRequest> request = new DefaultRequest<CreateSpeechRequest>(createSpeechRequest, IvonaSpeechCloudClient.SERVICE_NAME); request.setHttpMethod(HttpMethodName.POST); setRequestPayload(request, createSpeechRequest); request.setResourcePath(RESOURCE_PATH); return request; }
From source file:com.ivona.services.tts.model.transform.lexicons.DeleteLexiconPostRequestMarshaller.java
License:Open Source License
public Request<DeleteLexiconRequest> marshall(DeleteLexiconRequest deleteLexiconRequest) { if (deleteLexiconRequest == null) { throw new AmazonClientException("null deleteLexiconRequest passed to marshall(...)"); }//ww w . j av a 2 s . c o m Request<DeleteLexiconRequest> request = new DefaultRequest<DeleteLexiconRequest>(deleteLexiconRequest, IvonaSpeechCloudClient.SERVICE_NAME); request.setHttpMethod(HttpMethodName.POST); setRequestPayload(request, deleteLexiconRequest); request.setResourcePath(RESOURCE_PATH); return request; }
From source file:com.ivona.services.tts.model.transform.lexicons.GetLexiconPostRequestMarshaller.java
License:Open Source License
public Request<GetLexiconRequest> marshall(GetLexiconRequest getLexiconRequest) { if (getLexiconRequest == null) { throw new AmazonClientException("null getLexiconRequest passed to marshall(...)"); }//from ww w .ja v a 2s. c o m Request<GetLexiconRequest> request = new DefaultRequest<GetLexiconRequest>(getLexiconRequest, IvonaSpeechCloudClient.SERVICE_NAME); request.setHttpMethod(HttpMethodName.POST); setRequestPayload(request, getLexiconRequest); request.setResourcePath(RESOURCE_PATH); return request; }
From source file:com.ivona.services.tts.model.transform.lexicons.ListLexiconsPostRequestMarshaller.java
License:Open Source License
public Request<ListLexiconsRequest> marshall(ListLexiconsRequest listLexiconsRequest) { if (listLexiconsRequest == null) { throw new AmazonClientException("null listLexiconsRequest passed to marshall(...)"); }/* ww w . ja va 2 s . c om*/ Request<ListLexiconsRequest> request = new DefaultRequest<ListLexiconsRequest>(listLexiconsRequest, IvonaSpeechCloudClient.SERVICE_NAME); request.setHttpMethod(HttpMethodName.POST); setRequestPayload(request, listLexiconsRequest); request.setResourcePath(RESOURCE_PATH); return request; }
From source file:com.ivona.services.tts.model.transform.lexicons.PutLexiconPostRequestMarshaller.java
License:Open Source License
public Request<PutLexiconRequest> marshall(PutLexiconRequest putLexiconRequest) { if (putLexiconRequest == null) { throw new AmazonClientException("null putLexiconRequest passed to marshall(...)"); }//from ww w.ja va 2 s . c o m Request<PutLexiconRequest> request = new DefaultRequest<PutLexiconRequest>(putLexiconRequest, IvonaSpeechCloudClient.SERVICE_NAME); request.setHttpMethod(HttpMethodName.POST); setRequestPayload(request, putLexiconRequest); request.setResourcePath(RESOURCE_PATH); return request; }
From source file:com.ivona.services.tts.model.transform.listvoices.ListVoicesGetRequestMarshaller.java
License:Open Source License
public Request<ListVoicesRequest> marshall(ListVoicesRequest listVoicesRequest) { if (listVoicesRequest == null) { throw new AmazonClientException("null listVoicesRequest passed to marshall(...)"); }/*from w w w. ja va 2s . c om*/ Request<ListVoicesRequest> request = new DefaultRequest<ListVoicesRequest>(listVoicesRequest, IvonaSpeechCloudClient.SERVICE_NAME); request.setHttpMethod(HttpMethodName.GET); request.setResourcePath(RESOURCE_PATH); setRequestParameters(request, listVoicesRequest); return request; }
From source file:com.ivona.services.tts.model.transform.listvoices.ListVoicesPostRequestMarshaller.java
License:Open Source License
public Request<ListVoicesRequest> marshall(ListVoicesRequest listVoicesRequest) { if (listVoicesRequest == null) { throw new AmazonClientException("null listVoicesRequest passed to marshall(...)"); }/* w w w . j a va2 s. c o m*/ Request<ListVoicesRequest> request = new DefaultRequest<ListVoicesRequest>(listVoicesRequest, IvonaSpeechCloudClient.SERVICE_NAME); request.setHttpMethod(HttpMethodName.POST); request.setResourcePath(RESOURCE_PATH); setRequestPayload(request, listVoicesRequest); return request; }