Example usage for com.amazonaws.services.sqs.model.transform CreateQueueRequestMarshaller CreateQueueRequestMarshaller

List of usage examples for com.amazonaws.services.sqs.model.transform CreateQueueRequestMarshaller CreateQueueRequestMarshaller

Introduction

In this page you can find the example usage for com.amazonaws.services.sqs.model.transform CreateQueueRequestMarshaller CreateQueueRequestMarshaller.

Prototype

CreateQueueRequestMarshaller

Source Link

Usage

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  www  .  j  a v  a 2  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;
}