Example usage for com.amazonaws.util SdkHttpUtils urlEncode

List of usage examples for com.amazonaws.util SdkHttpUtils urlEncode

Introduction

In this page you can find the example usage for com.amazonaws.util SdkHttpUtils urlEncode.

Prototype

public static String urlEncode(final String value, final boolean path) 

Source Link

Document

Encode a string for use in the path of a URL; uses URLEncoder.encode, (which encodes a string for use in the query portion of a URL), then applies some postfilters to fix things up per the RFC.

Usage

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));
    }/* w w  w . j  av  a2  s.  c o  m*/
    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;
}