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.services.s3.internal;
 
 import java.util.Map;
 import java.util.Set;
 
 
Abstract HTTP response handler for Amazon S3 responses. Provides common utilities that other specialized S3 response handlers need to share such as pulling common response metadata (ex: request IDs) out of headers.

Parameters:
<T> The output type resulting from handling a response.
 
 public abstract class AbstractS3ResponseHandler<T>
         implements HttpResponseHandler<AmazonWebServiceResponse<T>> {

    
Shared logger
 
     private static final Log log = LogFactory.getLog(S3MetadataResponseHandler.class);

    
The set of response headers that aren't part of the object's metadata
 
     private static final Set<StringignoredHeaders;
 
     static {
          = new HashSet<String>();
         .add(.);
         .add(.);
     }

    
The majority of S3 response handlers read the complete response while handling it, and don't need to manually manage the underlying HTTP connection.

 
     public boolean needsConnectionLeftOpen() {
         return false;
     }

    
Parses the S3 response metadata (ex: AWS request ID) from the specified response, and returns a AmazonWebServiceResponse<T> object ready for the result to be plugged in.

Parameters:
response The response containing the response metadata to pull out.
Returns:
A new, populated AmazonWebServiceResponse<T> object, ready for the result to be plugged in.
 
     protected AmazonWebServiceResponse<T> parseResponseMetadata(HttpResponse response) {
         AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
         String awsRequestId = response.getHeaders().get(.);
         String hostId = response.getHeaders().get(.);
 
         Map<StringStringmetadataMap = new HashMap<StringString>();
         metadataMap.put(.awsRequestId);
         metadataMap.put(.hostId);
         awsResponse.setResponseMetadata(new S3ResponseMetadata(metadataMap));
 
         return awsResponse;
     }

    
Populates the specified S3ObjectMetadata object with all object metadata pulled from the headers in the specified response.

Parameters:
response The HTTP response containing the object metadata within the headers.
metadata The metadata object to populate from the response's headers.
    protected void populateObjectMetadata(HttpResponse responseObjectMetadata metadata) {
        for (Entry<StringStringheader : response.getHeaders().entrySet()) {
            String key = header.getKey();
            if (key.startsWith(.)) {
                key = key.substring(..length());
                metadata.addUserMetadata(keyheader.getValue());
            } else if (.contains(key)) {
                // ignore...
            } else if (key.equals(.)) {
                try {
                    metadata.setHeader(key, ServiceUtils.parseRfc822Date(header.getValue()));
                } catch (Exception pe) {
                    .warn("Unable to parse last modified date: " + header.getValue(), pe);
                }
            } else if (key.equals(.)) {
                try {
                    metadata.setHeader(key, Long.parseLong(header.getValue()));
                } catch (NumberFormatException nfe) {
                    .warn("Unable to parse content length: " + header.getValue(), nfe);
                }
            } else if (key.equals(.)) {
                metadata.setHeader(key, ServiceUtils.removeQuotes(header.getValue()));
            } else if (key.equals(.)) {
                try {
                    metadata.setHttpExpiresDate(DateUtils.parseRFC822Date(header.getValue()));
                } catch (Exception pe) {
                    .warn("Unable to parse http expiration date: " + header.getValue(), pe);
                }
            } else if (key.equals(.)) {
                new ObjectExpirationHeaderHandler<ObjectMetadata>().handle(metadataresponse);
            } else if (key.equals(.)) {
                new ObjectRestoreHeaderHandler<ObjectRestoreResult>().handle(metadataresponse);
            } else {
                metadata.setHeader(keyheader.getValue());
            }
        }
    }
New to GrepCode? Check out our FAQ X