com.amazonaws.http.HttpResponseHandler.handle()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(108)

本文整理了Java中com.amazonaws.http.HttpResponseHandler.handle()方法的一些代码示例,展示了HttpResponseHandler.handle()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponseHandler.handle()方法的具体详情如下:
包路径:com.amazonaws.http.HttpResponseHandler
类名称:HttpResponseHandler
方法名:handle

HttpResponseHandler.handle介绍

[英]Accepts an HTTP response object, and returns an object of type T. Individual implementations may choose to handle the response however they need to, and return any type that they need to.
[中]接受HTTP响应对象,并返回类型为T的对象。各个实现可以选择以任何方式处理响应,并返回任何需要的类型。

代码示例

代码示例来源:origin: aws/aws-sdk-java

/**
 * We've received all the error content so send it off to the error response handler to produce the service exception.
 */
private AmazonServiceException unmarshallError() throws Exception {
  errorResponse.setContent(new ByteArrayInputStream(BinaryUtils.copyBytesFrom(cumulation.nioBuffer())));
  return errorResponseHandler.handle(errorResponse);
}

代码示例来源:origin: aws/aws-sdk-java

SdkBaseException exception;
try {
  exception = errorResponseHandler.handle(response);
  if (requestLog.isDebugEnabled()) {
    requestLog.debug("Received error response: " + exception);

代码示例来源:origin: aws/aws-sdk-java

@Override
public T handle(HttpResponse httpResponse) throws Exception {
  T result = delegate.handle(httpResponse).getResult();
  result.sdkResponseMetadata(new SdkResponseMetadata(SdkHttpMetadata.from(httpResponse)));
  return result;
}

代码示例来源:origin: aws/aws-sdk-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);
}

代码示例来源:origin: aws/aws-sdk-java

try {
  awsResponse = responseHandler
      .handle(beforeUnmarshalling(httpResponse));
} finally {
  awsRequestMetrics.endEvent(Field.ResponseProcessingTime);

代码示例来源:origin: aws/aws-sdk-java

private AmazonServiceException handleAse(HttpResponse response) throws Exception {
  final int statusCode = response.getStatusCode();
  try {
    return delegate.handle(response);
  } catch(InterruptedException e) {
    throw e;
  } catch (Exception e) {
    // If the errorResponseHandler doesn't work, then check for error responses that don't have any content
    if (statusCode == 413) {
      AmazonServiceException exception = new AmazonServiceException("Request entity too large");
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Client);
      exception.setErrorCode("Request entity too large");
      return exception;
    } else if (statusCode >= 500 && statusCode < 600) {
      AmazonServiceException exception = new AmazonServiceException(response.getStatusText());
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Service);
      exception.setErrorCode(response.getStatusText());
      return exception;
    } else {
      throw e;
    }
  }
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

SdkBaseException exception;
try {
  exception = errorResponseHandler.handle(response);
  if (requestLog.isDebugEnabled()) {
    requestLog.debug("Received error response: " + exception);

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

@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);
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

try {
  awsResponse = responseHandler
      .handle(beforeUnmarshalling(httpResponse));
} finally {
  awsRequestMetrics.endEvent(Field.ResponseProcessingTime);

代码示例来源:origin: aws-amplify/aws-sdk-android

awsRequestMetrics.startEvent(Field.ResponseProcessingTime);
try {
  awsResponse = responseHandler.handle(response);
} finally {
  awsRequestMetrics.endEvent(Field.ResponseProcessingTime);

代码示例来源:origin: aws-amplify/aws-sdk-android

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

代码示例来源:origin: aws-amplify/aws-sdk-android

exception = errorResponseHandler.handle(response);
  REQUEST_LOG.debug("Received error response: " + exception.toString());
} catch (final Exception e) {

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

private AmazonServiceException handleAse(HttpResponse response) throws Exception {
  final int statusCode = response.getStatusCode();
  try {
    return delegate.handle(response);
  } catch(InterruptedException e) {
    throw e;
  } catch (Exception e) {
    // If the errorResponseHandler doesn't work, then check for error responses that don't have any content
    if (statusCode == 413) {
      AmazonServiceException exception = new AmazonServiceException("Request entity too large");
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Client);
      exception.setErrorCode("Request entity too large");
      return exception;
    } else if (statusCode >= 500 && statusCode < 600) {
      AmazonServiceException exception = new AmazonServiceException(response.getStatusText());
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Service);
      exception.setErrorCode(response.getStatusText());
      return exception;
    } else {
      throw e;
    }
  }
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-kinesisvideo

/**
 * We've received all the error content so send it off to the error response handler to produce the service exception.
 */
private AmazonServiceException unmarshallError() throws Exception {
  errorResponse.setContent(new ByteArrayInputStream(BinaryUtils.copyBytesFrom(cumulation.nioBuffer())));
  return errorResponseHandler.handle(errorResponse);
}

代码示例来源:origin: Nextdoor/bender

SdkBaseException exception;
try {
  exception = errorResponseHandler.handle(response);
  if (requestLog.isDebugEnabled()) {
    requestLog.debug("Received error response: " + exception);

代码示例来源:origin: aws/aws-sdk-java-v2

@Benchmark
public Object getItem(GetItemState s) {
  HttpResponse resp = new HttpResponse(null, null);
  resp.setContent(new ByteArrayInputStream(s.testItem.utf8()));
  try {
    return getItemJsonResponseHandler().handle(resp);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: Nextdoor/bender

@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);
}

代码示例来源:origin: com.gluonhq/aws-java-sdk-core

exception = errorResponseHandler.handle(response);
  REQUEST_LOG.debug("Received error response: " + exception.toString());
} catch (final Exception e) {

代码示例来源:origin: com.amazonaws/aws-android-sdk-core

exception = errorResponseHandler.handle(response);
  REQUEST_LOG.debug("Received error response: " + exception.toString());
} catch (final Exception e) {

代码示例来源:origin: Nextdoor/bender

private AmazonServiceException handleAse(HttpResponse response) throws Exception {
  final int statusCode = response.getStatusCode();
  try {
    return delegate.handle(response);
  } catch(InterruptedException e) {
    throw e;
  } catch (Exception e) {
    // If the errorResponseHandler doesn't work, then check for error responses that don't have any content
    if (statusCode == 413) {
      AmazonServiceException exception = new AmazonServiceException("Request entity too large");
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Client);
      exception.setErrorCode("Request entity too large");
      return exception;
    } else if (statusCode >= 500 && statusCode < 600) {
      AmazonServiceException exception = new AmazonServiceException(response.getStatusText());
      exception.setServiceName(response.getRequest().getServiceName());
      exception.setStatusCode(statusCode);
      exception.setErrorType(AmazonServiceException.ErrorType.Service);
      exception.setErrorCode(response.getStatusText());
      return exception;
    } else {
      throw e;
    }
  }
}

相关文章

微信公众号

最新文章

更多