Java 类com.amazonaws.AmazonWebServiceResponse 实例源码

项目:ibm-cos-sdk-java    文件:AmazonHttpClient.java   
/**
 * Executes the request and returns the result.
 *
 * @param request              The AmazonWebServices request to send to the remote server
 * @param responseHandler      A response handler to accept a successful response from the
 *                             remote server
 * @param errorResponseHandler A response handler to accept an unsuccessful response from the
 *                             remote server
 * @param executionContext     Additional information about the context of this web service
 *                             call
 * @deprecated Use {@link #requestExecutionBuilder()} to configure and execute a HTTP request.
 */
@Deprecated
public <T> Response<T> execute(Request<?> request,
                               HttpResponseHandler<AmazonWebServiceResponse<T>> responseHandler,
                               HttpResponseHandler<AmazonServiceException> errorResponseHandler,
                               ExecutionContext executionContext) {
    HttpResponseHandler<T> adaptedRespHandler = new AwsResponseHandlerAdapter<T>(
            getNonNullResponseHandler(responseHandler),
            request,
            executionContext.getAwsRequestMetrics(),
            responseMetadataCache);
    return requestExecutionBuilder()
            .request(request)
            .requestConfig(new AmazonWebServiceRequestAdapter(request.getOriginalRequest()))
            .errorResponseHandler(new AwsErrorResponseHandler(errorResponseHandler, executionContext.getAwsRequestMetrics()))
            .executionContext(executionContext)
            .execute(adaptedRespHandler);
}
项目:ibm-cos-sdk-java    文件:HttpResponseHandlers.java   
public static <T> HttpResponseHandler<AmazonWebServiceResponse<T>> responseHandler(final FunctionWithException<HttpResponse, T> handle) {
    return new HttpResponseHandler<AmazonWebServiceResponse<T>>() {

        @Override
        public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
            AmazonWebServiceResponse<T> resp = new AmazonWebServiceResponse<T>();
            resp.setResult(handle.apply(response));
            return resp;
        }

        @Override
        public boolean needsConnectionLeftOpen() {
            return false;
        }
    };
}
项目:ibm-cos-sdk-java    文件:HeadBucketResultHandler.java   
@Override
public AmazonWebServiceResponse<HeadBucketResult> handle(HttpResponse response)
        throws Exception {
    final AmazonWebServiceResponse<HeadBucketResult> awsResponse = new AmazonWebServiceResponse<HeadBucketResult>();
    final HeadBucketResult result = new HeadBucketResult();
    result.setBucketRegion(response.getHeaders().get(Headers.S3_BUCKET_REGION));

    if (!StringUtils.isNullOrEmpty(response.getHeaders().get(Headers.IBM_SSE_KP_ENABLED))){
        result.setIBMSSEKPEnabled(Boolean.parseBoolean(response.getHeaders().get(Headers.IBM_SSE_KP_ENABLED)));
    }
    if (!StringUtils.isNullOrEmpty(response.getHeaders().get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN))){
        result.setIBMSSEKPCrk(response.getHeaders().get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN));
    }
    awsResponse.setResult(result);

    return awsResponse;
}
项目:ibm-cos-sdk-java    文件:S3XmlResponseHandler.java   
/**
 * @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
 */
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
    AmazonWebServiceResponse<T> awsResponse = parseResponseMetadata(response);
    responseHeaders = response.getHeaders();

    if (responseUnmarshaller != null) {
        log.trace("Beginning to parse service response XML");
        T result = responseUnmarshaller.unmarshall(response.getContent());
        log.trace("Done parsing service response XML");
        awsResponse.setResult(result);

        if (result instanceof ObjectListing) {
            if (!StringUtils.isNullOrEmpty(responseHeaders.get(Headers.IBM_SSE_KP_ENABLED))){
                ((ObjectListing) result).setIBMSSEKPEnabled(Boolean.parseBoolean(responseHeaders.get(Headers.IBM_SSE_KP_ENABLED)));
            }
            if (!StringUtils.isNullOrEmpty(responseHeaders.get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN))) {
                ((ObjectListing) result).setIBMSSEKPCrk(responseHeaders.get(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN));
            } 
        }
    }

    return awsResponse;
}
项目:ibm-cos-sdk-java    文件:S3XmlResponseHandlerTest.java   
/**
 * Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK are set in the ObjectLIsting
 * response object
 * @throws Exception 
 * 
 */ 
@Test
public void testHeadersAddedToObjectListing() throws Exception {

    Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
    S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
    HttpResponse httpResponse = new HttpResponse(null, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, "True");
    httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, "123456");

    InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
    httpResponse.setContent(is);

    AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);

    assertEquals(objectListing.getResult().getIBMSSEKPCrk(), "123456");
    assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), true);
}
项目:ibm-cos-sdk-java    文件:S3XmlResponseHandlerTest.java   
/**
 * Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK null headers are handled
 * 
 * @throws Exception 
 * 
 */ 
@Test
public void testNullKPHeadersAreHandled() throws Exception {

    Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
    S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
    HttpResponse httpResponse = new HttpResponse(null, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_CRK, null);

    InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
    httpResponse.setContent(is);

    AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);

    assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
    assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
项目:ibm-cos-sdk-java    文件:S3XmlResponseHandlerTest.java   
/**
 * Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK empty headers are handled
 * 
 * @throws Exception 
 * 
 */ 
@Test
public void testEmptyKPHeadersAreHandled() throws Exception {

    Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
    S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
    HttpResponse httpResponse = new HttpResponse(null, null);

    InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
    httpResponse.setContent(is);

    AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);

    assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
    assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
项目:ibm-cos-sdk-java    文件:S3XmlResponseHandlerTest.java   
/**
 * Test the IBM_SSE_KP_CRK empty header is handled
 * 
 * @throws Exception 
 * 
 */ 
@Test
public void testOnlyKPEnabledHeaderIsSet() throws Exception {

    Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
    S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
    HttpResponse httpResponse = new HttpResponse(null, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, "True");

    InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
    httpResponse.setContent(is);

    AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);

    assertEquals(objectListing.getResult().getIBMSSEKPCrk(), null);
    assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), true);
}
项目:ibm-cos-sdk-java    文件:S3XmlResponseHandlerTest.java   
/**
 * Test the IBM_SSE_KP_CRK empty header is handled
 * 
 * @throws Exception 
 * 
 */ 
@Test
public void testOnlyCRKHeaderIsSet() throws Exception {

    Unmarshaller<ObjectListing, InputStream> unmarshaller = new Unmarshallers.ListObjectsUnmarshaller(false);
    S3XmlResponseHandler xmlResponseHandler = new S3XmlResponseHandler<ObjectListing>(unmarshaller);
    HttpResponse httpResponse = new HttpResponse(null, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, "34567");

    InputStream is = new ByteArrayInputStream(getXmlContent().getBytes());;
    httpResponse.setContent(is);

    AmazonWebServiceResponse<ObjectListing> objectListing = xmlResponseHandler.handle(httpResponse);

    assertEquals(objectListing.getResult().getIBMSSEKPCrk(), "34567");
    assertEquals(objectListing.getResult().getIBMSSEKPEnabled(), false);
}
项目:aws-hal-client-java    文件:HalClient.java   
private <T> T invoke(HttpMethodName httpMethodName, String resourcePath, Object representation,
                     HttpResponseHandler<AmazonWebServiceResponse<T>> responseHandler)
        throws AmazonClientException {
    ExecutionContext executionContext = createExecutionContext();
    AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics();

    awsRequestMetrics.startEvent(AWSRequestMetrics.Field.RequestMarshallTime.name());
    Request request = buildRequest(httpMethodName, resourcePath, representation);
    awsRequestMetrics.endEvent(AWSRequestMetrics.Field.RequestMarshallTime.name());

    awsRequestMetrics.startEvent(AWSRequestMetrics.Field.CredentialsRequestTime.name());
    AWSCredentials credentials = awsCredentialsProvider.getCredentials();
    awsRequestMetrics.endEvent(AWSRequestMetrics.Field.CredentialsRequestTime.name());

    executionContext.setCredentials(credentials);

    awsRequestMetrics.startEvent(AWSRequestMetrics.Field.ClientExecuteTime.name());
    Response<T> response = client.execute(request, responseHandler, errorResponseHandler, executionContext);
    awsRequestMetrics.endEvent(AWSRequestMetrics.Field.ClientExecuteTime.name());

    awsRequestMetrics.log();

    return response.getAwsResponse();
}
项目:async-sqs    文件:SqsAwsSdkAction.java   
@Override
public ResponseT parseHttpResponse(Response response) throws Exception {
    HttpResponse httpResponse = responseConverter.apply(response, awsHttpRequest);
    int statusCode = httpResponse.getStatusCode();
    if (HTTP_STATUS_RANGE_SUCCESS.contains(statusCode)) {
        AmazonWebServiceResponse<ResponseT> awsResponse = staxResponseHandler.handle(httpResponse);
        return awsResponse.getResult();
    } else {
        throw errorResponseHandler.handle(httpResponse);
    }
}
项目:ibm-cos-sdk-java    文件:AwsResponseHandlerAdapter.java   
/**
 * @param delegate          Response handler to delegate to and unwrap
 * @param request           Marshalled request
 * @param awsRequestMetrics Request metrics
 */
public AwsResponseHandlerAdapter(HttpResponseHandler<AmazonWebServiceResponse<T>> delegate,
                                 Request<?> request,
                                 AWSRequestMetrics awsRequestMetrics,
                                 MetadataCache responseMetadataCache) {
    this.delegate = delegate;
    this.request = request;
    this.awsRequestMetrics = awsRequestMetrics;
    this.responseMetadataCache = responseMetadataCache;
}
项目:ibm-cos-sdk-java    文件:AwsResponseHandlerAdapter.java   
@Override
public T handle(HttpResponse response) throws Exception {
    final AmazonWebServiceResponse<T> awsResponse = delegate.handle(response);

    if (awsResponse == null) {
        throw new RuntimeException("Unable to unmarshall response metadata. Response Code: "
                                   + response.getStatusCode() + ", Response Text: " +
                                   response.getStatusText());
    }

    AmazonWebServiceRequest userRequest = request.getOriginalRequest();
    if (userRequest.getCloneRoot() != null) {
        userRequest = userRequest.getCloneRoot();
    }
    responseMetadataCache.add(userRequest, awsResponse.getResponseMetadata());
    final String awsRequestId = awsResponse.getRequestId();

    if (requestLog.isDebugEnabled()) {
        requestLog
                .debug("Received successful response: " + response.getStatusCode() +
                       ", AWS Request ID: " + awsRequestId);
    }

    if (!logHeaderRequestId(response)) {
        // Logs the AWS request ID extracted from the payload if
        // it is not available from the response header.
        logResponseRequestId(awsRequestId);
    }
    awsRequestMetrics.addProperty(AWSRequestMetrics.Field.AWSRequestID, awsRequestId);
    return fillInResponseMetadata(awsResponse, response);
}
项目:ibm-cos-sdk-java    文件:AwsResponseHandlerAdapter.java   
@SuppressWarnings("unchecked")
private <T> T fillInResponseMetadata(AmazonWebServiceResponse<T> awsResponse,
                                     HttpResponse httpResponse) {
    final T result = awsResponse.getResult();
    if (result instanceof AmazonWebServiceResult<?>) {
        ((AmazonWebServiceResult) result)
                .setSdkResponseMetadata(awsResponse.getResponseMetadata())
                .setSdkHttpMetadata(SdkHttpMetadata.from(httpResponse));
    }
    return result;
}
项目:ibm-cos-sdk-java    文件:HttpResponseHandlers.java   
public static HttpResponseHandler<AmazonWebServiceResponse<String>> stringResponseHandler() {
    return responseHandler(new FunctionWithException<HttpResponse, String>() {
        @Override
        public String apply(HttpResponse in) throws Exception {
            return IOUtils.toString(in.getContent());
        }
    });
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
@Test
public void testUserAgentPrefixAndSuffixAreAdded() throws Exception {
    String prefix = "somePrefix", suffix = "someSuffix";
    Request<?> request = mockRequest(SERVER_NAME, HttpMethodName.PUT, URI_NAME, true);

    HttpResponseHandler<AmazonWebServiceResponse<Object>> handler = createStubResponseHandler();
    EasyMock.replay(handler);
    ClientConfiguration config =
            new ClientConfiguration().withUserAgentPrefix(prefix).withUserAgentSuffix(suffix);

    Capture<HttpRequestBase> capturedRequest = new Capture<HttpRequestBase>();

    EasyMock.reset(httpClient);
    EasyMock
            .expect(httpClient.execute(
                    EasyMock.capture(capturedRequest), EasyMock.<HttpContext>anyObject()))
            .andReturn(createBasicHttpResponse())
            .once();
    EasyMock.replay(httpClient);

    AmazonHttpClient client = new AmazonHttpClient(config, httpClient, null);

    client.requestExecutionBuilder().request(request).execute(handler);

    String userAgent = capturedRequest.getValue().getFirstHeader("User-Agent").getValue();
    Assert.assertTrue(userAgent.startsWith(prefix));
    Assert.assertTrue(userAgent.endsWith(suffix));
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
@Test
public void testCredentialsSetInRequestContext() throws Exception {
    EasyMock.reset(httpClient);
    EasyMock
            .expect(httpClient.execute(EasyMock.<HttpRequestBase>anyObject(), EasyMock.<HttpContext>anyObject()))
            .andReturn(createBasicHttpResponse())
            .once();
    EasyMock.replay(httpClient);

    AmazonHttpClient client = new AmazonHttpClient(new ClientConfiguration(), httpClient, null);

    final BasicAWSCredentials credentials = new BasicAWSCredentials("foo", "bar");

    AWSCredentialsProvider credentialsProvider = EasyMock.createMock(AWSCredentialsProvider.class);
    EasyMock.expect(credentialsProvider.getCredentials())
            .andReturn(credentials)
            .anyTimes();
    EasyMock.replay(credentialsProvider);

    ExecutionContext executionContext = new ExecutionContext();
    executionContext.setCredentialsProvider(credentialsProvider);

    Request<?> request = mockRequest(SERVER_NAME, HttpMethodName.PUT, URI_NAME, true);

    HttpResponseHandler<AmazonWebServiceResponse<Object>> handler = createStubResponseHandler();
    EasyMock.replay(handler);

    client.execute(request, handler, null, executionContext);

    assertEquals(credentials, request.getHandlerContext(HandlerContextKey.AWS_CREDENTIALS));
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
private HttpResponseHandler<AmazonWebServiceResponse<Object>> createStubResponseHandler() throws Exception {
    HttpResponseHandler<AmazonWebServiceResponse<Object>> handler =
            EasyMock.createMock(HttpResponseHandler.class);
    AmazonWebServiceResponse<Object> response = new AmazonWebServiceResponse<Object>();
    EasyMock
            .expect(handler.needsConnectionLeftOpen())
            .andReturn(false)
            .anyTimes();

    EasyMock
            .expect(handler.handle(EasyMock.<HttpResponse>anyObject()))
            .andReturn(response)
            .anyTimes();
    return handler;
}
项目:ibm-cos-sdk-java    文件:ResponseHeaderHandlerChain.java   
@Override
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
    AmazonWebServiceResponse<T> awsResponse = super.handle(response);

    T result = awsResponse.getResult();
    if (result != null) {
        for (HeaderHandler<T> handler : headerHandlers) {
            handler.handle(result, response);
        }
    }

    return awsResponse;
}
项目:ibm-cos-sdk-java    文件:AbstractS3ResponseHandler.java   
/**
 * 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) {
    AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
    String awsRequestId = response.getHeaders().get(Headers.REQUEST_ID);
    String hostId = response.getHeaders().get(Headers.EXTENDED_REQUEST_ID);
    String cloudFrontId = response.getHeaders().get(Headers.CLOUD_FRONT_ID);

    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;
}
项目:ibm-cos-sdk-java    文件:S3StringResponseHandler.java   
public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception {
    AmazonWebServiceResponse<String> awsResponse = parseResponseMetadata(response);

    int bytesRead;
    byte[] buffer = new byte[1024];
    StringBuilder builder = new StringBuilder();
    InputStream content = response.getContent();
    while ((bytesRead = content.read(buffer)) > 0) {
        builder.append(new String(buffer, 0, bytesRead, StringUtils.UTF8));
    }
    awsResponse.setResult(builder.toString());

    return awsResponse;
}
项目:ibm-cos-sdk-java    文件:S3MetadataResponseHandler.java   
/**
 * @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
 */
public AmazonWebServiceResponse<ObjectMetadata> handle(HttpResponse response) throws Exception {
    ObjectMetadata metadata = new ObjectMetadata();
    populateObjectMetadata(response, metadata);

    AmazonWebServiceResponse<ObjectMetadata> awsResponse = parseResponseMetadata(response);
    awsResponse.setResult(metadata);
    return awsResponse;
}
项目:ibm-cos-sdk-java    文件:S3ObjectResponseHandler.java   
/**
 * @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
 */
public AmazonWebServiceResponse<S3Object> handle(HttpResponse response) throws Exception {
    /*
     * TODO: It'd be nice to set the bucket name and key here, but the information isn't easy to
     * pull out of the response/request currently.
     */
    S3Object object = new S3Object();
    AmazonWebServiceResponse<S3Object> awsResponse = parseResponseMetadata(response);
    if (response.getHeaders().get(Headers.REDIRECT_LOCATION) != null) {
        object.setRedirectLocation(response.getHeaders().get(Headers.REDIRECT_LOCATION));
    }
    // If the requester is charged when downloading a object from an
    // Requester Pays bucket, then this header is set.
    if (response.getHeaders().get(Headers.REQUESTER_CHARGED_HEADER) != null) {
        object.setRequesterCharged(true);
    }

    if (response.getHeaders().get(Headers.S3_TAGGING_COUNT) != null) {
        object.setTaggingCount(Integer.parseInt(response.getHeaders().get(Headers.S3_TAGGING_COUNT)));
    }

    ObjectMetadata metadata = object.getObjectMetadata();
    populateObjectMetadata(response, metadata);

    object.setObjectContent(new S3ObjectInputStream(abortableIs(response), response.getHttpRequest()));

    awsResponse.setResult(object);
    return awsResponse;
}
项目:ibm-cos-sdk-java    文件:HeadBucketResultHandlerTest.java   
/**
 * Test the IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK are set in the HeadResult object
 * @throws Exception 
 * 
 */ 
@Test
public void testHeadResultIsSetCorrect() throws Exception {

    HttpResponse httpResponse = new HttpResponse(null, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, "True");
    httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, "123456");

    HeadBucketResultHandler handler = new HeadBucketResultHandler();
    AmazonWebServiceResponse<HeadBucketResult> result = handler.handle(httpResponse);

    assertEquals(result.getResult().getIBMSSEKPCrk(), "123456");
    assertEquals(result.getResult().getIBMSSEKPEnabled(), true);
}
项目:ibm-cos-sdk-java    文件:HeadBucketResultHandlerTest.java   
/**
 * Test null IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK headers are handled
 * @throws Exception 
 * 
 */ 
@Test
public void testNullHeadersAreHandled() throws Exception {

    HttpResponse httpResponse = new HttpResponse(null, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, null);

    HeadBucketResultHandler handler = new HeadBucketResultHandler();
    AmazonWebServiceResponse<HeadBucketResult> result = handler.handle(httpResponse);

    assertEquals(result.getResult().getIBMSSEKPCrk(), null);
    assertEquals(result.getResult().getIBMSSEKPEnabled(), false);
}
项目:ibm-cos-sdk-java    文件:HeadBucketResultHandlerTest.java   
/**
 * Test empty IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK headers are handled
 * @throws Exception 
 * 
 */ 
@Test
public void testEmptyHeadersAreHandled() throws Exception {

    HttpResponse httpResponse = new HttpResponse(null, null);

    HeadBucketResultHandler handler = new HeadBucketResultHandler();
    AmazonWebServiceResponse<HeadBucketResult> result = handler.handle(httpResponse);

    assertEquals(result.getResult().getIBMSSEKPCrk(), null);
    assertEquals(result.getResult().getIBMSSEKPEnabled(), false);
}
项目:ibm-cos-sdk-java    文件:HeadBucketResultHandlerTest.java   
/**
 * Test empty IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK headers are handled
 * @throws Exception 
 * 
 */ 
@Test
public void testOnlyKPEnabledHeaderIsSet() throws Exception {

    HttpResponse httpResponse = new HttpResponse(null, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_ENABLED, "True");

    HeadBucketResultHandler handler = new HeadBucketResultHandler();
    AmazonWebServiceResponse<HeadBucketResult> result = handler.handle(httpResponse);

    assertEquals(result.getResult().getIBMSSEKPCrk(), null);
    assertEquals(result.getResult().getIBMSSEKPEnabled(), true);
}
项目:ibm-cos-sdk-java    文件:HeadBucketResultHandlerTest.java   
/**
 * Test empty IBM_SSE_KP_ENABLED & IBM_SSE_KP_CRK headers are handled
 * @throws Exception 
 * 
 */ 
@Test
public void testOnlyCRKHeaderIsSet() throws Exception {

    HttpResponse httpResponse = new HttpResponse(null, null);
    httpResponse.addHeader(Headers.IBM_SSE_KP_CUSTOMER_ROOT_KEY_CRN, "12345");

    HeadBucketResultHandler handler = new HeadBucketResultHandler();
    AmazonWebServiceResponse<HeadBucketResult> result = handler.handle(httpResponse);

    assertEquals(result.getResult().getIBMSSEKPCrk(), "12345");
    assertEquals(result.getResult().getIBMSSEKPEnabled(), false);
}
项目:ivona-speechcloud-sdk-java    文件:StreamResponseHandler.java   
@Override
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
    AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
    T result = responseUnmarshaller.unmarshall(response);
    awsResponse.setResult(result);
    return awsResponse;
}
项目:ibm-cos-sdk-java    文件:SdkJsonProtocolFactory.java   
/**
 * Returns the response handler to be used for handling a successful response.
 *
 * @param operationMetadata Additional context information about an operation to create the appropriate response handler.
 */
public <T> HttpResponseHandler<AmazonWebServiceResponse<T>> createResponseHandler(
        JsonOperationMetadata operationMetadata,
        Unmarshaller<T, JsonUnmarshallerContext> responseUnmarshaller) {
    return getSdkFactory().createResponseHandler(operationMetadata, responseUnmarshaller);
}
项目:ibm-cos-sdk-java    文件:JsonResponseHandler.java   
/**
 * @see HttpResponseHandler#handle(HttpResponse)
 */
public AmazonWebServiceResponse<T> handle(HttpResponse response) throws Exception {
    log.trace("Parsing service response JSON");

    String CRC32Checksum = response.getHeaders().get("x-amz-crc32");

    JsonParser jsonParser = null;

    if (shouldParsePayloadAsJson()) {
        jsonParser = jsonFactory.createParser(response.getContent());
    }

    try {
        AmazonWebServiceResponse<T> awsResponse = new AmazonWebServiceResponse<T>();
        JsonUnmarshallerContext unmarshallerContext = new JsonUnmarshallerContextImpl(
                jsonParser, simpleTypeUnmarshallers, customTypeMarshallers, response);
        registerAdditionalMetadataExpressions(unmarshallerContext);

        T result = responseUnmarshaller.unmarshall(unmarshallerContext);

        // Make sure we read all the data to get an accurate CRC32 calculation.
        // See https://github.com/aws/aws-sdk-java/issues/1018
        if (shouldParsePayloadAsJson() && response.getContent() != null) {
            IOUtils.drainInputStream(response.getContent());
        }

        if (CRC32Checksum != null) {
            long serverSideCRC = Long.parseLong(CRC32Checksum);
            long clientSideCRC = response.getCRC32Checksum();
            if (clientSideCRC != serverSideCRC) {
                throw new CRC32MismatchException(
                        "Client calculated crc32 checksum didn't match that calculated by server side");
            }
        }

        awsResponse.setResult(result);

        Map<String, String> metadata = unmarshallerContext.getMetadata();
        metadata.put(ResponseMetadata.AWS_REQUEST_ID,
                     response.getHeaders().get(X_AMZN_REQUEST_ID_HEADER));
        awsResponse.setResponseMetadata(new ResponseMetadata(metadata));

        log.trace("Done parsing service response");
        return awsResponse;
    } finally {
        if (shouldParsePayloadAsJson()) {
            try {
                jsonParser.close();
            } catch (IOException e) {
                log.warn("Error closing json parser", e);
            }
        }
    }
}
项目:ibm-cos-sdk-java    文件:DummyResponseHandler.java   
@Override
public AmazonWebServiceResponse<String> handle(HttpResponse response) throws Exception {
    return new AmazonWebServiceResponse<String>() {
    };
}
项目:ibm-cos-sdk-java    文件:EmptyAWSResponseHandler.java   
@Override
public AmazonWebServiceResponse<Object> handle(HttpResponse response)
        throws Exception {
    return new AmazonWebServiceResponse<Object>();
}
项目:ibm-cos-sdk-java    文件:UnresponsiveResponseHandler.java   
@Override
public AmazonWebServiceResponse<Object> handle(HttpResponse response) throws Exception {
    Thread.sleep(Long.MAX_VALUE);
    return null;
}
项目:ibm-cos-sdk-java    文件:NullResponseHandler.java   
@Override
public AmazonWebServiceResponse<Object> handle(HttpResponse response) throws Exception {
    return null;
}
项目:ibm-cos-sdk-java    文件:ErrorDuringUnmarshallingResponseHandler.java   
@Override
public AmazonWebServiceResponse<Object> handle(HttpResponse response) throws Exception {
    throw new RuntimeException("Unable to unmarshall response");
}
项目:ibm-cos-sdk-java    文件:AmazonHttpClientTest.java   
@Test
public void testRetryIOExceptionFromHandler() throws Exception {
    final IOException exception = new IOException("BOOM");

    HttpResponseHandler<AmazonWebServiceResponse<Object>> handler =
            EasyMock.createMock(HttpResponseHandler.class);

    EasyMock
        .expect(handler.needsConnectionLeftOpen())
        .andReturn(false)
        .anyTimes();

    EasyMock
        .expect(handler.handle(EasyMock.<HttpResponse>anyObject()))
        .andThrow(exception)
        .times(4);

    EasyMock.replay(handler);

    BasicHttpResponse response = createBasicHttpResponse();

    EasyMock.reset(httpClient);

    EasyMock
        .expect(httpClient.getConnectionManager())
        .andReturn(null)
        .anyTimes();

    EasyMock
        .expect(httpClient.execute(EasyMock.<HttpUriRequest>anyObject(),
                                   EasyMock.<HttpContext>anyObject()))
        .andReturn(response)
        .times(4);

    EasyMock.replay(httpClient);

    ExecutionContext context = new ExecutionContext();

    Request<?> request = new DefaultRequest<Object>(null, "testsvc");
    request.setEndpoint(java.net.URI.create(
            "http://testsvc.region.amazonaws.com"));
    request.setContent(new java.io.ByteArrayInputStream(new byte[0]));

    try {

        client.requestExecutionBuilder().request(request).executionContext(context).execute(handler);
        Assert.fail("No exception when request repeatedly fails!");

    } catch (AmazonClientException e) {
        Assert.assertSame(exception, e.getCause());
    }

    // Verify that we called execute 4 times.
    EasyMock.verify(httpClient);
}
项目:ibm-cos-sdk-java    文件:AmazonS3Client.java   
private <X, Y extends AmazonWebServiceRequest> X invoke(Request<Y> request,
                                                        HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler,
                                                        String bucket, String key) {
    return invoke(request, responseHandler, bucket, key, false);
}
项目:ivona-speechcloud-sdk-java    文件:IvonaSpeechCloudClient.java   
private <X, Y extends AmazonWebServiceRequest> Response<X> invoke(
        Request<Y> request,
        HttpResponseHandler<AmazonWebServiceResponse<X>> responseHandler,
        ExecutionContext executionContext) {

    JsonErrorResponseHandler errorResponseHandler = new JsonErrorResponseHandler(exceptionUnmarshallers);

    Response<X> result = client.execute(
            prepareRequest(request, executionContext),
            responseHandler,
            errorResponseHandler,
            executionContext);

    return result;
}