Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws;
 
 import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
 
Default implementation of the Request interface.

This class is only intended for internal use inside the AWS client libraries. Callers shouldn't ever interact directly with objects of this class.

 
 public class DefaultRequest<T> implements Request<T> {

    
The resource path being requested
 
     private String resourcePath;

    
Map of the parameters being sent as part of this request.

Note that a LinkedHashMap is used, since we want to preserve the insertion order so that members of a list parameter will still be ordered by their indices when they are marshalled into the query string.

 
     private Map<StringList<String>> parameters = new LinkedHashMap<StringList<String>>();

    
Map of the headers included in this request
 
     private Map<StringStringheaders = new HashMap<StringString>();

    
The service endpoint to which this request should be sent
 
     private URI endpoint;

    
The name of the service to which this request is being sent
 
     private String serviceName;

    
The original, user facing request object which this internal request object is representing
 
     private final AmazonWebServiceRequest originalRequest;

    
The HTTP method to use when sending this request.
 
     private HttpMethodName httpMethod = .;

    
An optional stream from which to read the request payload.
 
     private InputStream content;

    
An optional time offset to account for clock skew
 
     private int timeOffset;

    
All AWS Request metrics are collected into this object.
 
     private AWSRequestMetrics metrics;

    
Constructs a new DefaultRequest with the specified service name and the original, user facing request object.

Parameters:
serviceName The name of the service to which this request is being sent.
originalRequest The original, user facing, AWS request being represented by this internal request object.
 
     public DefaultRequest(AmazonWebServiceRequest originalRequestString serviceName) {
         this. = serviceName;
         this. = originalRequest == null
                 ? .
                 : originalRequest;
     }

    
Constructs a new DefaultRequest with the specified service name and no specified original, user facing request object.

Parameters:
serviceName The name of the service to which this request is being sent.
    public DefaultRequest(String serviceName) {
        this(nullserviceName);
    }


    
Returns the original, user facing request object which this internal request object is representing.

Returns:
The original, user facing request object which this request object is representing.
        return ;
    }

    
    public void addHeader(String nameString value) {
        .put(namevalue);
    }

    
    public Map<StringStringgetHeaders() {
        return ;
    }

    
    public void setResourcePath(String resourcePath) {
        this. = resourcePath;
    }

    
    public String getResourcePath() {
        return ;
    }

    
    public void addParameter(String nameString value) {
        List<StringparamList = .get(name);
        if (paramList == null) {
            paramList = new ArrayList<String>();
            .put(nameparamList);
        }
        paramList.add(value);
    }

    
    public Map<StringList<String>> getParameters() {
        return ;
    }

    
    public Request<T> withParameter(String nameString value) {
        addParameter(namevalue);
        return this;
    }

    
    public HttpMethodName getHttpMethod() {
        return ;
    }

    
    public void setHttpMethod(HttpMethodName httpMethod) {
        this. = httpMethod;
    }

    
    public void setEndpoint(URI endpoint) {
        this. = endpoint;
    }

    
    public URI getEndpoint() {
        return ;
    }

    
    public String getServiceName() {
        return ;
    }

    
    public InputStream getContent() {
        return ;
    }

    
    public void setContent(InputStream content) {
        this. = content;
    }

    
    public void setHeaders(Map<StringStringheaders) {
        this..clear();
        this..putAll(headers);
    }

    
    public void setParameters(Map<StringList<String>> parameters) {
        this..clear();
        this..putAll(parameters);
    }

    
    public int getTimeOffset() {
        return ;
    }

    
    public void setTimeOffset(int timeOffset) {
        this. = timeOffset;
    }

    
    public Request<T> withTimeOffset(int timeOffset) {
        setTimeOffset(timeOffset);
        return this;
    }
    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder();
        builder.append(getHttpMethod()).append(" ");
        builder.append(getEndpoint()).append(" ");
        String resourcePath = getResourcePath();
        if (resourcePath == null) {
            builder.append("/");
        }
        else {
            if (!resourcePath.startsWith("/")) {
                builder.append("/");
            }
            builder.append(resourcePath);
        }
        builder.append(" ");
        if (!getParameters().isEmpty()) {
            builder.append("Parameters: (")
                   .append(Jackson.toJsonString());
        }
        if (!getHeaders().isEmpty()) {
            builder.append("Headers: (");
            for (String key : getHeaders().keySet()) {
                String value = getHeaders().get(key);
                builder.append(key).append(": ").append(value).append(", ");
            }
            builder.append(") ");
        }
        return builder.toString();
    }
    @Override
        return ;
    }
    @Override
    public void setAWSRequestMetrics(AWSRequestMetrics metrics) {
        if (this. == null) {
            this. = metrics;
        } else {
            throw new IllegalStateException("AWSRequestMetrics has already been set on this request");
        }
    }
    @SuppressWarnings("resource")
    @Override
    public InputStream getContentUnwrapped() {
        InputStream is = getContent();
        if (is == null)
            return null;
        // We want to disable the progress reporting when the stream is
        // consumed for signing purpose.
        while (is instanceof ProgressInputStream) {
            ProgressInputStream pris = (ProgressInputStream)is;
            is = pris.getWrappedInputStream();
        }
        return is;
    }
    @Override
    public ReadLimitInfo getReadLimitInfo() {
        return ;
    }
    @Override
    public Object getOriginalRequestObject() {
        return ;
    }
New to GrepCode? Check out our FAQ X