Search in sources :

Example 1 with S3ResponseMetadata

use of com.amazonaws.services.s3.S3ResponseMetadata in project aws-sdk-android by aws-amplify.

the class AbstractS3ResponseHandler method parseResponseMetadata.

/**
 * 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.
 *
 * @param response The response containing the response metadata to pull
 *            out.
 * @return A new, populated AmazonWebServiceResponse<T> object, ready for
 *         the result to be plugged in.
 */
protected AmazonWebServiceResponse<T> parseResponseMetadata(HttpResponse response) {
    final AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
    final String awsRequestId = response.getHeaders().get(Headers.REQUEST_ID);
    final String hostId = response.getHeaders().get(Headers.EXTENDED_REQUEST_ID);
    final String cloudFrontId = response.getHeaders().get(Headers.CLOUD_FRONT_ID);
    final Map<String, String> metadataMap = new HashMap<String, String>();
    metadataMap.put(ResponseMetadata.AWS_REQUEST_ID, awsRequestId);
    metadataMap.put(S3ResponseMetadata.HOST_ID, hostId);
    metadataMap.put(S3ResponseMetadata.CLOUD_FRONT_ID, cloudFrontId);
    awsResponse.setResponseMetadata(new S3ResponseMetadata(metadataMap));
    return awsResponse;
}
Also used : S3ResponseMetadata(com.amazonaws.services.s3.S3ResponseMetadata) HashMap(java.util.HashMap) AmazonWebServiceResponse(com.amazonaws.AmazonWebServiceResponse)

Example 2 with S3ResponseMetadata

use of com.amazonaws.services.s3.S3ResponseMetadata in project aws-sdk-android by aws-amplify.

the class S3MetadataResponseHandlerTest method testHandle.

@Test
public void testHandle() throws Exception {
    HttpResponse response = new HttpResponse.Builder().header(Headers.REQUEST_ID, "testId").header(Headers.EXTENDED_REQUEST_ID, "extendedId").header(Headers.S3_USER_METADATA_PREFIX + "userKey", "userValue").header(Headers.LAST_MODIFIED, "Sun, 1 Jan 2006 12:00:00 GMT").header(Headers.CONTENT_LENGTH, "5").header(Headers.ETAG, "Etag").header(Headers.EXPIRES, "Sun, 1 Jan 2006 12:00:00 GMT").header(Headers.EXPIRATION, "expiry-date=\"Fri, 21 Dec 2012 00:00:00 GMT\", rule-id=\"Rule for testfile.txt\"").header(Headers.RESTORE, "ongoing-request=\"false\", expiry-date=\"Wed, 07 Nov 2012 00:00:00 GMT\"").header("UndefinedKey", "UndefinedValue").header(Headers.STORAGE_CLASS, "STANDARD_IA").build();
    S3MetadataResponseHandler handler = new S3MetadataResponseHandler();
    AmazonWebServiceResponse<ObjectMetadata> awsr = handler.handle(response);
    assertEquals(awsr.getResponseMetadata().getRequestId(), "testId");
    assertEquals(((S3ResponseMetadata) awsr.getResponseMetadata()).getHostId(), "extendedId");
    ObjectMetadata om = awsr.getResult();
    assertEquals(om.getRawMetadataValue(Headers.REQUEST_ID), null);
    assertEquals(om.getRawMetadataValue(Headers.EXTENDED_REQUEST_ID), null);
    assertEquals(om.getUserMetaDataOf("userKey"), "userValue");
    assertEquals(1136116800000L, om.getLastModified().getTime());
    assertEquals(om.getContentLength(), 5);
    assertEquals(om.getETag(), "Etag");
    assertEquals(1356048000000L, om.getExpirationTime().getTime());
    assertEquals(1136116800000L, om.getHttpExpiresDate().getTime());
    assertEquals("Rule for testfile.txt", om.getExpirationTimeRuleId());
    assertEquals(1352246400000L, om.getRestoreExpirationTime().getTime());
    assertFalse(om.getOngoingRestore());
    assertEquals(om.getStorageClass(), StorageClass.StandardInfrequentAccess.toString());
}
Also used : HttpResponse(com.amazonaws.http.HttpResponse) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Aggregations

AmazonWebServiceResponse (com.amazonaws.AmazonWebServiceResponse)1 HttpResponse (com.amazonaws.http.HttpResponse)1 S3ResponseMetadata (com.amazonaws.services.s3.S3ResponseMetadata)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1