本文整理了Java中com.amazonaws.AmazonServiceException.setStatusCode()
方法的一些代码示例,展示了AmazonServiceException.setStatusCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AmazonServiceException.setStatusCode()
方法的具体详情如下:
包路径:com.amazonaws.AmazonServiceException
类名称:AmazonServiceException
方法名:setStatusCode
[英]Sets the HTTP status code that was returned with this service exception.
[中]设置与此服务异常一起返回的HTTP状态代码。
代码示例来源:origin: aws/aws-sdk-java
private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
String errorCode = null;
// Parse the error stream returned from the service.
if(errorStream != null) {
String errorResponse = IOUtils.toString(errorStream);
try {
JsonNode node = Jackson.jsonNodeOf(errorResponse);
JsonNode code = node.get("code");
JsonNode message = node.get("message");
if (code != null && message != null) {
errorCode = code.asText();
responseMessage = message.asText();
}
} catch (Exception exception) {
LOG.debug("Unable to parse error stream");
}
}
AmazonServiceException ase = new AmazonServiceException(responseMessage);
ase.setStatusCode(statusCode);
ase.setErrorCode(errorCode);
throw ase;
}
}
代码示例来源:origin: aws/aws-sdk-java
private AmazonServiceException createAse(HttpResponse errorResponse) throws Exception {
// Try to parse the error response as XML
final Document document = documentFromContent(errorResponse.getContent(), idString(errorResponse));
/*
* We need to select which exception unmarshaller is the correct one to
* use from all the possible exceptions this operation can throw.
* Currently we rely on the unmarshallers to return null if they can't
* unmarshall the response, but we might need something a little more
* sophisticated in the future.
*/
for (Unmarshaller<AmazonServiceException, Node> unmarshaller : unmarshallerList) {
AmazonServiceException ase = unmarshaller.unmarshall(document);
if (ase != null) {
ase.setStatusCode(errorResponse.getStatusCode());
return ase;
}
}
return null;
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public AmazonServiceException handle(HttpResponse response) throws Exception {
final AmazonServiceException ase = handleAse(response);
ase.setStatusCode(response.getStatusCode());
ase.setServiceName(response.getRequest().getServiceName());
awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId())
.addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode())
.addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode());
return ase;
}
代码示例来源: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: aws/aws-sdk-java
@Override
public AmazonServiceException handle(HttpResponse response) throws Exception {
JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory);
String errorCode = errorCodeParser.parseErrorCode(response, jsonContent);
AmazonServiceException ase = createException(errorCode, jsonContent);
// Jackson has special-casing for 'message' values when deserializing
// Throwables, but sometimes the service passes the error message in
// other JSON fields - handle it here.
if (ase.getErrorMessage() == null) {
ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode()));
}
ase.setErrorCode(errorCode);
ase.setServiceName(response.getRequest().getServiceName());
ase.setStatusCode(response.getStatusCode());
ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode()));
ase.setRawResponse(jsonContent.getRawContent());
String requestId = getRequestIdFromHeaders(response.getHeaders());
if (requestId != null) {
ase.setRequestId(requestId);
}
ase.setHttpHeaders(response.getHeaders());
return ase;
}
代码示例来源:origin: com.amazonaws/aws-java-sdk-core
private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
String errorCode = null;
// Parse the error stream returned from the service.
if(errorStream != null) {
String errorResponse = IOUtils.toString(errorStream);
try {
JsonNode node = Jackson.jsonNodeOf(errorResponse);
JsonNode code = node.get("code");
JsonNode message = node.get("message");
if (code != null && message != null) {
errorCode = code.asText();
responseMessage = message.asText();
}
} catch (Exception exception) {
LOG.debug("Unable to parse error stream");
}
}
AmazonServiceException ase = new AmazonServiceException(responseMessage);
ase.setStatusCode(statusCode);
ase.setErrorCode(errorCode);
throw ase;
}
}
代码示例来源:origin: com.amazonaws/aws-java-sdk-core
private AmazonServiceException createAse(HttpResponse errorResponse) throws Exception {
// Try to parse the error response as XML
final Document document = documentFromContent(errorResponse.getContent(), idString(errorResponse));
/*
* We need to select which exception unmarshaller is the correct one to
* use from all the possible exceptions this operation can throw.
* Currently we rely on the unmarshallers to return null if they can't
* unmarshall the response, but we might need something a little more
* sophisticated in the future.
*/
for (Unmarshaller<AmazonServiceException, Node> unmarshaller : unmarshallerList) {
AmazonServiceException ase = unmarshaller.unmarshall(document);
if (ase != null) {
ase.setStatusCode(errorResponse.getStatusCode());
return ase;
}
}
return null;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
/**
* Used to create an {@link newAmazonServiceException} when we failed to
* read the error response or parsed the error response as XML.
*/
private AmazonServiceException newAmazonServiceException(String errmsg,
HttpResponse httpResponse, Exception readFailure) {
AmazonServiceException exception = new AmazonServiceException(errmsg, readFailure);
final int statusCode = httpResponse.getStatusCode();
exception.setErrorCode(statusCode + " " + httpResponse.getStatusText());
exception.setErrorType(AmazonServiceException.ErrorType.Unknown);
exception.setStatusCode(statusCode);
return exception;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
@Override
public AmazonServiceException handle(HttpResponse response) throws Exception {
JsonErrorResponse error;
try {
error = JsonErrorResponse.fromResponse(response);
} catch (IOException e) {
throw new AmazonClientException("Unable to parse error response", e);
}
AmazonServiceException ase = runErrorUnmarshallers(error);
if (ase == null)
return null;
ase.setStatusCode(response.getStatusCode());
if (response.getStatusCode() < HTTP_STATUS_INTERNAL_SERVER_ERROR) {
ase.setErrorType(ErrorType.Client);
} else {
ase.setErrorType(ErrorType.Service);
}
ase.setErrorCode(error.getErrorCode());
for (Entry<String, String> headerEntry : response.getHeaders().entrySet()) {
if ("X-Amzn-RequestId".equalsIgnoreCase(headerEntry.getKey())) {
ase.setRequestId(headerEntry.getValue());
}
}
return ase;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
AmazonServiceException ase = unmarshaller.unmarshall(document);
if (ase != null) {
ase.setStatusCode(errorResponse.getStatusCode());
return ase;
代码示例来源:origin: aws-amplify/aws-sdk-android
@Override
public AmazonServiceException handle(
com.amazonaws.http.HttpResponse response) throws Exception {
AmazonServiceException ase = new AmazonServiceException("Fake service exception.");
ase.setStatusCode(response.getStatusCode());
ase.setErrorCode(response.getStatusText());
return ase;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
exception = new AmazonServiceException("Request entity too large");
exception.setServiceName(request.getServiceName());
exception.setStatusCode(HTTP_STATUS_REQ_TOO_LONG);
exception.setErrorType(ErrorType.Client);
exception.setErrorCode("Request entity too large");
exception = new AmazonServiceException("Service unavailable");
exception.setServiceName(request.getServiceName());
exception.setStatusCode(HTTP_STATUS_SERVICE_UNAVAILABLE);
exception.setErrorType(ErrorType.Service);
exception.setErrorCode("Service unavailable");
exception.setStatusCode(status);
exception.setServiceName(request.getServiceName());
exception.fillInStackTrace();
代码示例来源:origin: com.amazonaws/aws-java-sdk-core
@Override
public AmazonServiceException handle(HttpResponse response) throws Exception {
final AmazonServiceException ase = handleAse(response);
ase.setStatusCode(response.getStatusCode());
ase.setServiceName(response.getRequest().getServiceName());
awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId())
.addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode())
.addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode());
return ase;
}
代码示例来源: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: aws-amplify/aws-sdk-android
@Override
public AmazonServiceException handle(HttpResponse response) throws Exception {
assertSame(response, httpResponse);
AmazonServiceException ase = new AmazonServiceException("Test");
ase.setErrorCode("TestError");
ase.setErrorType(ErrorType.Service);
ase.setServiceName(request.getServiceName());
ase.setStatusCode(response.getStatusCode());
return ase;
}
代码示例来源:origin: com.amazonaws/aws-java-sdk-core
@Override
public AmazonServiceException handle(HttpResponse response) throws Exception {
JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory);
String errorCode = errorCodeParser.parseErrorCode(response, jsonContent);
AmazonServiceException ase = createException(errorCode, jsonContent);
// Jackson has special-casing for 'message' values when deserializing
// Throwables, but sometimes the service passes the error message in
// other JSON fields - handle it here.
if (ase.getErrorMessage() == null) {
ase.setErrorMessage(errorMessageParser.parseErrorMessage(response, jsonContent.getJsonNode()));
}
ase.setErrorCode(errorCode);
ase.setServiceName(response.getRequest().getServiceName());
ase.setStatusCode(response.getStatusCode());
ase.setErrorType(getErrorTypeFromStatusCode(response.getStatusCode()));
ase.setRawResponse(jsonContent.getRawContent());
String requestId = getRequestIdFromHeaders(response.getHeaders());
if (requestId != null) {
ase.setRequestId(requestId);
}
ase.setHttpHeaders(response.getHeaders());
return ase;
}
代码示例来源:origin: com.netflix.spinnaker.kork/kork-core
static AmazonServiceException amazonServiceException(Exception exception, String serviceName, int statusCode) {
if (exception instanceof AmazonServiceException) {
return (AmazonServiceException) exception;
}
final AmazonServiceException ase = new AmazonServiceException(exception.getMessage(), exception);
ase.setStatusCode(statusCode);
ase.setErrorCode(DEFAULT_UNKNOWN);
ase.setServiceName(serviceName);
ase.setErrorType(AmazonServiceException.ErrorType.Unknown);
return ase;
}
}
代码示例来源:origin: awslabs/emr-dynamodb-connector
@Test(expected = RuntimeException.class)
public void testNonRetryableASEException() throws Exception {
AmazonServiceException ase = new AmazonServiceException("Test");
ase.setErrorCode("ArbitNonRetryableException");
ase.setStatusCode(400);
when(call.call()).thenThrow(ase);
DynamoDBFibonacciRetryer retryer = new DynamoDBFibonacciRetryer(Duration.standardSeconds(10));
try {
retryer.runWithRetry(call, null, null);
} finally {
verify(call).call();
}
}
代码示例来源:origin: embulk/embulk-input-s3
@Test(expected = AmazonServiceException.class)
public void listS3FileByPrefix_on_retry_gave_up_should_throw_the_original_exception_in_methodnotallow_code()
{
AmazonServiceException exception = new AmazonServiceException("method not allow exception");
exception.setStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);
exception.setErrorType(AmazonServiceException.ErrorType.Client);
doThrow(exception).doReturn(new ObjectListing())
.when(client).listObjects(any(ListObjectsRequest.class));
FileList.Builder builder = new FileList.Builder();
dummyS3Plugin().listS3FilesByPrefix(
builder, client, "some_bucket", "some_prefix", Optional.of("last_path"), true,
retryExecutor().withRetryLimit(1));
}
代码示例来源:origin: Nextdoor/bender
@Override
public AmazonServiceException handle(HttpResponse response) throws Exception {
final AmazonServiceException ase = handleAse(response);
ase.setStatusCode(response.getStatusCode());
ase.setServiceName(response.getRequest().getServiceName());
awsRequestMetrics.addPropertyWith(AWSRequestMetrics.Field.AWSRequestID, ase.getRequestId())
.addPropertyWith(AWSRequestMetrics.Field.AWSErrorCode, ase.getErrorCode())
.addPropertyWith(AWSRequestMetrics.Field.StatusCode, ase.getStatusCode());
return ase;
}
内容来源于网络,如有侵权,请联系作者删除!