Java 类com.amazonaws.http.HttpResponseHandler 实例源码

项目:ibm-cos-sdk-java    文件:AwsResponseHandlerAdapter.java   
/**
 * Used to log the "x-amzn-RequestId" header at DEBUG level, if any, from the response. This
 * method assumes the apache httpClientSettings request/response has just been successfully
 * executed. The request id is logged using the "com.amazonaws.requestId" logger if it was
 * enabled at DEBUG level; otherwise, it is logged at DEBUG level using the
 * "com.amazonaws.request" logger.
 *
 * @return true if the AWS request id is available from the httpClientSettings header; false
 * otherwise.
 */
private boolean logHeaderRequestId(final HttpResponse response) {
    final String reqIdHeader = response.getHeaders()
            .get(HttpResponseHandler.X_AMZN_REQUEST_ID_HEADER);
    final boolean isHeaderReqIdAvail = reqIdHeader != null;

    if (requestIdLog.isDebugEnabled() || requestLog.isDebugEnabled()) {
        final String msg = HttpResponseHandler.X_AMZN_REQUEST_ID_HEADER + ": "
                           + (isHeaderReqIdAvail ? reqIdHeader : "not available");
        if (requestIdLog.isDebugEnabled()) {
            requestIdLog.debug(msg);
        } else {
            requestLog.debug(msg);
        }
    }
    return isHeaderReqIdAvail;
}
项目: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;
        }
    };
}
项目:charles-rest    文件:EsHttpRequest.java   
/**
 * Ctor.
 * @param esEdp ElasticSearch URL.
 * @param uri REST path to the desired ElasticSearch endpoint.
 * @param respHandler Response handler.
 * @param errHandle Error handler.
 */
public EsHttpRequest(
    EsEndPoint esEdp,
    String uri,
    HttpResponseHandler<T> respHandler,
    HttpResponseHandler<AmazonServiceException> errHandler
){
    this.request = new DefaultRequest<Void>("es");
    String esEndpoint = esEdp.read();
    if(esEndpoint == null || esEndpoint.isEmpty()) {
        throw new IllegalStateException("ElasticSearch endpoint needs to be specified!");
    }
    if(esEndpoint.endsWith("/")) {
        esEndpoint += uri;
    } else {
        esEndpoint += "/" + uri;
    }
    this.request.setEndpoint(URI.create(esEndpoint));


    this.respHandler = respHandler;
    this.errHandler = errHandler;
}
项目: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();
}
项目: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    文件:ClientHandlerImpl.java   
/**
 * Normal invoke with authentication. Credentials are required and may be overriden at the
 * request level.
 **/
private <Output, Input> Response<Output> invoke(Request<Input> request,
                                                RequestConfig requestConfig,
                                                ExecutionContext executionContext,
                                                HttpResponseHandler<Output> responseHandler,
                                                HttpResponseHandler<? extends SdkBaseException> errorResponseHandler) {

    executionContext.setCredentialsProvider(CredentialUtils.getCredentialsProvider(
            requestConfig, awsCredentialsProvider));

    return doInvoke(request, requestConfig, executionContext, responseHandler,
                    errorResponseHandler);
}
项目:ibm-cos-sdk-java    文件:ClientHandlerImpl.java   
/**
 * Invoke the request using the http client. Assumes credentials (or lack thereof) have been
 * configured in the ExecutionContext beforehand.
 **/
private <Output, Input> Response<Output> doInvoke(Request<Input> request,
                                                  RequestConfig requestConfig,
                                                  ExecutionContext executionContext,
                                                  HttpResponseHandler<Output> responseHandler,
                                                  HttpResponseHandler<? extends SdkBaseException> errorResponseHandler) {
    request.setEndpoint(endpoint);
    return client.requestExecutionBuilder()
            .request(request)
            .requestConfig(requestConfig)
            .executionContext(executionContext)
            .errorResponseHandler(errorResponseHandler)
            .execute(responseHandler);
}
项目: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());
        }
    });
}
项目:aws-hal-client-java    文件:HalService.java   
public HalService(String endpoint, String serviceName, String regionId, Class<T> rootClass, String rootPath,
                  HttpResponseHandler<AmazonServiceException> errorResponseHandler) {
    this.endpoint = endpoint;
    this.serviceName = serviceName;
    this.regionId = regionId;
    this.rootClass = rootClass;
    this.rootPath = rootPath;
    this.errorResponseHandler = errorResponseHandler;
}
项目:aws-hal-client-java    文件:HalClient.java   
public HalClient(ClientConfiguration clientConfiguration, String endpoint, String serviceName,
                 AWSCredentialsProvider awsCredentialsProvider, Map<String, Object> resourceCache,
                 HttpResponseHandler<AmazonServiceException> errorResponseHandler) {
    super(clientConfiguration);

    this.setServiceNameIntern(serviceName);
    this.setEndpoint(endpoint);
    this.awsCredentialsProvider = awsCredentialsProvider;
    this.resourceCache = resourceCache;
    this.errorResponseHandler = errorResponseHandler;
    this.addRequestHandler(new AcceptHalJsonRequestHandler());
}
项目: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    文件:SdkJsonProtocolFactory.java   
/**
 * Creates a response handler for handling a error response (non 2xx response).
 */
public HttpResponseHandler<AmazonServiceException> createErrorResponseHandler(
        JsonErrorResponseMetadata errorResponsMetadata) {
    return getSdkFactory().createErrorResponseHandler(errorUnmarshallers, errorResponsMetadata
            .getCustomErrorCodeFieldName());
}
项目:ibm-cos-sdk-java    文件:ClientExecutionParams.java   
public HttpResponseHandler<Output> getResponseHandler() {
    return responseHandler;
}
项目:ibm-cos-sdk-java    文件:ClientExecutionParams.java   
public ClientExecutionParams<Input, Output> withResponseHandler(
        HttpResponseHandler<Output> responseHandler) {
    this.responseHandler = responseHandler;
    return this;
}
项目:ibm-cos-sdk-java    文件:ClientExecutionParams.java   
public HttpResponseHandler<? extends SdkBaseException> getErrorResponseHandler() {
    return errorResponseHandler;
}
项目:ibm-cos-sdk-java    文件:ClientExecutionParams.java   
public ClientExecutionParams<Input, Output> withErrorResponseHandler(
        HttpResponseHandler<? extends SdkBaseException> errorResponseHandler) {
    this.errorResponseHandler = errorResponseHandler;
    return this;
}
项目:ibm-cos-sdk-java    文件:WireMockTestBase.java   
protected HttpResponseHandler<AmazonServiceException> stubErrorHandler() throws Exception {
    HttpResponseHandler<AmazonServiceException> errorHandler = mock(JsonErrorResponseHandler.class);
    when(errorHandler.handle(any(HttpResponse.class))).thenReturn(mockException());
    return errorHandler;
}
项目: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;
}
项目:aws-hal-client-java    文件:HalService.java   
public HalService(String endpoint, String serviceName, String regionId, Class<T> rootClass,
                  HttpResponseHandler<AmazonServiceException> errorResponseHandler) {
    this(endpoint, serviceName, regionId, rootClass, DEFAULT_ROOT_PATH, errorResponseHandler);
}