本文整理了Java中com.amazonaws.http.HttpResponse.getStatusCode()
方法的一些代码示例,展示了HttpResponse.getStatusCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getStatusCode()
方法的具体详情如下:
包路径:com.amazonaws.http.HttpResponse
类名称:HttpResponse
方法名:getStatusCode
[英]Returns the HTTP status code (ex: 200, 404, etc) associated with this response.
[中]返回与此响应关联的HTTP状态代码(例如:200、404等)。
代码示例来源:origin: aws/aws-sdk-java
/**
* Static factory to create an {@link SdkHttpMetadata} from the details in a {@link
* HttpResponse}.
*/
public static SdkHttpMetadata from(HttpResponse httpResponse) {
return new SdkHttpMetadata(httpResponse.getHeaders(), httpResponse.getStatusCode());
}
代码示例来源:origin: aws/aws-sdk-java
public InvokeAsyncResult unmarshall(JsonUnmarshallerContext context) throws Exception {
InvokeAsyncResult invokeAsyncResult = new InvokeAsyncResult();
invokeAsyncResult.setStatus(context.getHttpResponse().getStatusCode());
return invokeAsyncResult;
}
代码示例来源: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 errorResponse) throws Exception {
AmazonServiceException ase = createAse(errorResponse);
if (ase == null) {
throw new SdkClientException("Unable to unmarshall error response from service");
}
ase.setHttpHeaders(errorResponse.getHeaders());
if (StringUtils.isNullOrEmpty(ase.getErrorCode())) {
ase.setErrorCode(errorResponse.getStatusCode() + " " + errorResponse.getStatusText());
}
return ase;
}
代码示例来源: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
private AmazonS3Exception createExceptionFromHeaders(
HttpResponse errorResponse, String errorResponseXml) {
final Map<String, String> headers = errorResponse.getHeaders();
final int statusCode = errorResponse.getStatusCode();
final AmazonS3ExceptionBuilder exceptionBuilder = new AmazonS3ExceptionBuilder();
exceptionBuilder.setErrorMessage(errorResponse.getStatusText());
exceptionBuilder.setErrorResponseXml(errorResponseXml);
exceptionBuilder.setStatusCode(statusCode);
exceptionBuilder
.setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID));
exceptionBuilder.setRequestId(headers.get(Headers.REQUEST_ID));
exceptionBuilder.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID));
exceptionBuilder
.setErrorCode(statusCode + " " + errorResponse.getStatusText());
exceptionBuilder.addAdditionalDetail(Headers.S3_BUCKET_REGION,
errorResponse.getHeaders().get(Headers.S3_BUCKET_REGION));
return exceptionBuilder.build();
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public SdkBaseException handle(HttpResponse response) throws Exception {
JsonContent jsonContent = JsonContent.createJsonContent(response, jsonFactory);
BaseException exception = createException(response.getStatusCode(), jsonContent);
exception.sdkHttpMetadata(new SdkErrorHttpMetadata(SdkHttpMetadata.from(response), jsonContent.getRawContent()));
exception.setMessage(messageParser.parseErrorMessage(jsonContent.getJsonNode()));
// Wrap in ASE, will be unwrapped when caught in the service client.
return (SdkBaseException) exception;
}
代码示例来源: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
public InvokeResult unmarshall(JsonUnmarshallerContext context) throws Exception {
InvokeResult invokeResult = new InvokeResult();
if (context.isStartOfDocument()) {
if (context.getHeader("X-Amz-Function-Error") != null) {
context.setCurrentHeader("X-Amz-Function-Error");
invokeResult.setFunctionError(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("X-Amz-Log-Result") != null) {
context.setCurrentHeader("X-Amz-Log-Result");
invokeResult.setLogResult(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("X-Amz-Executed-Version") != null) {
context.setCurrentHeader("X-Amz-Executed-Version");
invokeResult.setExecutedVersion(context.getUnmarshaller(String.class).unmarshall(context));
}
}
invokeResult.setStatusCode(context.getHttpResponse().getStatusCode());
java.io.InputStream is = context.getHttpResponse().getContent();
if (is != null) {
try {
invokeResult.setPayload(java.nio.ByteBuffer.wrap(com.amazonaws.util.IOUtils.toByteArray(is)));
} finally {
com.amazonaws.util.IOUtils.closeQuietly(is, null);
}
}
return invokeResult;
}
代码示例来源:origin: aws/aws-sdk-java
public DeleteUserResult unmarshall(JsonUnmarshallerContext context) throws Exception {
DeleteUserResult deleteUserResult = new DeleteUserResult();
deleteUserResult.setStatus(context.getHttpResponse().getStatusCode());
int originalDepth = context.getCurrentDepth();
String currentParentElement = context.getCurrentParentElement();
int targetDepth = originalDepth + 1;
JsonToken token = context.getCurrentToken();
if (token == null)
token = context.nextToken();
if (token == VALUE_NULL) {
return deleteUserResult;
}
while (true) {
if (token == null)
break;
if (token == FIELD_NAME || token == START_OBJECT) {
if (context.testExpression("RequestId", targetDepth)) {
context.nextToken();
deleteUserResult.setRequestId(context.getUnmarshaller(String.class).unmarshall(context));
}
} else if (token == END_ARRAY || token == END_OBJECT) {
if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) {
if (context.getCurrentDepth() <= originalDepth)
break;
}
}
token = context.nextToken();
}
return deleteUserResult;
}
代码示例来源:origin: aws/aws-sdk-java
public DeleteGroupMembershipResult unmarshall(JsonUnmarshallerContext context) throws Exception {
DeleteGroupMembershipResult deleteGroupMembershipResult = new DeleteGroupMembershipResult();
deleteGroupMembershipResult.setStatus(context.getHttpResponse().getStatusCode());
int originalDepth = context.getCurrentDepth();
String currentParentElement = context.getCurrentParentElement();
int targetDepth = originalDepth + 1;
JsonToken token = context.getCurrentToken();
if (token == null)
token = context.nextToken();
if (token == VALUE_NULL) {
return deleteGroupMembershipResult;
}
while (true) {
if (token == null)
break;
if (token == FIELD_NAME || token == START_OBJECT) {
if (context.testExpression("RequestId", targetDepth)) {
context.nextToken();
deleteGroupMembershipResult.setRequestId(context.getUnmarshaller(String.class).unmarshall(context));
}
} else if (token == END_ARRAY || token == END_OBJECT) {
if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) {
if (context.getCurrentDepth() <= originalDepth)
break;
}
}
token = context.nextToken();
}
return deleteGroupMembershipResult;
}
代码示例来源:origin: aws/aws-sdk-java
public DeleteGroupResult unmarshall(JsonUnmarshallerContext context) throws Exception {
DeleteGroupResult deleteGroupResult = new DeleteGroupResult();
deleteGroupResult.setStatus(context.getHttpResponse().getStatusCode());
int originalDepth = context.getCurrentDepth();
String currentParentElement = context.getCurrentParentElement();
int targetDepth = originalDepth + 1;
JsonToken token = context.getCurrentToken();
if (token == null)
token = context.nextToken();
if (token == VALUE_NULL) {
return deleteGroupResult;
}
while (true) {
if (token == null)
break;
if (token == FIELD_NAME || token == START_OBJECT) {
if (context.testExpression("RequestId", targetDepth)) {
context.nextToken();
deleteGroupResult.setRequestId(context.getUnmarshaller(String.class).unmarshall(context));
}
} else if (token == END_ARRAY || token == END_OBJECT) {
if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) {
if (context.getCurrentDepth() <= originalDepth)
break;
}
}
token = context.nextToken();
}
return deleteGroupResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetJobOutputResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetJobOutputResult getJobOutputResult = new GetJobOutputResult();
if (context.isStartOfDocument()) {
if (context.getHeader("x-amz-sha256-tree-hash") != null) {
context.setCurrentHeader("x-amz-sha256-tree-hash");
getJobOutputResult.setChecksum(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Content-Range") != null) {
context.setCurrentHeader("Content-Range");
getJobOutputResult.setContentRange(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Accept-Ranges") != null) {
context.setCurrentHeader("Accept-Ranges");
getJobOutputResult.setAcceptRanges(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("Content-Type") != null) {
context.setCurrentHeader("Content-Type");
getJobOutputResult.setContentType(context.getUnmarshaller(String.class).unmarshall(context));
}
if (context.getHeader("x-amz-archive-description") != null) {
context.setCurrentHeader("x-amz-archive-description");
getJobOutputResult.setArchiveDescription(context.getUnmarshaller(String.class).unmarshall(context));
}
}
getJobOutputResult.setStatus(context.getHttpResponse().getStatusCode());
getJobOutputResult.setBody(context.getHttpResponse().getContent());
return getJobOutputResult;
}
代码示例来源:origin: aws/aws-sdk-java
public GetDashboardEmbedUrlResult unmarshall(JsonUnmarshallerContext context) throws Exception {
GetDashboardEmbedUrlResult getDashboardEmbedUrlResult = new GetDashboardEmbedUrlResult();
getDashboardEmbedUrlResult.setStatus(context.getHttpResponse().getStatusCode());
代码示例来源: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: aws/aws-sdk-java
getObjectResult.setStatusCode(context.getHttpResponse().getStatusCode());
代码示例来源:origin: aws/aws-sdk-java
public DescribeGroupResult unmarshall(JsonUnmarshallerContext context) throws Exception {
DescribeGroupResult describeGroupResult = new DescribeGroupResult();
describeGroupResult.setStatus(context.getHttpResponse().getStatusCode());
代码示例来源:origin: aws/aws-sdk-java
public CreateGroupMembershipResult unmarshall(JsonUnmarshallerContext context) throws Exception {
CreateGroupMembershipResult createGroupMembershipResult = new CreateGroupMembershipResult();
createGroupMembershipResult.setStatus(context.getHttpResponse().getStatusCode());
代码示例来源:origin: aws/aws-sdk-java
public CreateGroupResult unmarshall(JsonUnmarshallerContext context) throws Exception {
CreateGroupResult createGroupResult = new CreateGroupResult();
createGroupResult.setStatus(context.getHttpResponse().getStatusCode());
代码示例来源: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;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!