Example usage for com.amazonaws Request setParameters

List of usage examples for com.amazonaws Request setParameters

Introduction

In this page you can find the example usage for com.amazonaws Request setParameters.

Prototype

void setParameters(Map<String, List<String>> parameters);

Source Link

Document

Sets all parameters, clearing any existing values.

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 av a 2s  .  co  m
    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.ivona.services.tts.model.transform.createspeech.CreateSpeechGetRequestMarshaller.java

License:Open Source License

private void setRequestParameters(Request<CreateSpeechRequest> request,
        CreateSpeechRequest createSpeechRequest) {
    Map<String, List<String>> parameters = new HashMap<String, List<String>>();

    MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_INPUT_DATA,
            createSpeechRequest.getInput().getData());
    MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_INPUT_TYPE,
            createSpeechRequest.getInput().getType());

    if (createSpeechRequest.getOutputFormat() != null) {
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_OUTPUT_FORMAT_CODEC,
                createSpeechRequest.getOutputFormat().getCodec());
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_OUTPUT_FORMAT_SAMPLE_RATE,
                createSpeechRequest.getOutputFormat().getSampleRate());

        SpeechMarks speechMarks = createSpeechRequest.getOutputFormat().getSpeechMarks();
        if (speechMarks != null) {
            MarshallerHelper.putToMapIfTrue(parameters, GET_PARAM_OUTPUT_FORMAT_SPEECH_MARKS_SENTENCE,
                    speechMarks.isSentence());
            MarshallerHelper.putToMapIfTrue(parameters, GET_PARAM_OUTPUT_FORMAT_SPEECH_MARKS_SSML,
                    speechMarks.isSsml());
            MarshallerHelper.putToMapIfTrue(parameters, GET_PARAM_OUTPUT_FORMAT_SPEECH_MARKS_VISEME,
                    speechMarks.isViseme());
            MarshallerHelper.putToMapIfTrue(parameters, GET_PARAM_OUTPUT_FORMAT_SPEECH_MARKS_WORD,
                    speechMarks.isWord());
        }//from  ww  w  .  j  a v  a2  s.c om
    }

    if (createSpeechRequest.getParameters() != null) {
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_RATE,
                createSpeechRequest.getParameters().getRate());
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_VOLUME,
                createSpeechRequest.getParameters().getVolume());
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_PARAGRAPH_BREAK,
                createSpeechRequest.getParameters().getParagraphBreak());
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_PARAMETERS_SENTENCE_BREAK,
                createSpeechRequest.getParameters().getSentenceBreak());
    }

    if (createSpeechRequest.getLexiconNames() != null) {
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_LEXICONS,
                createSpeechRequest.getLexiconNames());
    }

    if (createSpeechRequest.getVoice() != null) {
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_NAME,
                createSpeechRequest.getVoice().getName());
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_LANGUAGE,
                createSpeechRequest.getVoice().getLanguage());
        MarshallerHelper.putToMapIfNotNull(parameters, GET_PARAM_VOICE_GENDER,
                createSpeechRequest.getVoice().getGender());
    }

    request.setParameters(parameters);
}

From source file:com.ivona.services.tts.model.transform.listvoices.ListVoicesGetRequestMarshaller.java

License:Open Source License

protected void setRequestParameters(Request<ListVoicesRequest> request, ListVoicesRequest listVoicesRequest) {
    Map<String, List<String>> parameters = new HashMap<String, List<String>>();

    if (listVoicesRequest.getVoice() != null) {
        MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_NAME,
                listVoicesRequest.getVoice().getName());
        MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_LANGUAGE,
                listVoicesRequest.getVoice().getLanguage());
        MarshallerHelper.putToMapIfNotNull(parameters, PARAM_VOICE_GENDER,
                listVoicesRequest.getVoice().getGender());
    }//from   w  w w  .j  av  a2 s .c o m

    request.setParameters(parameters);
}