@Override public AmazonServiceException handle(HttpResponse httpResponse) throws XMLStreamException { final AmazonServiceException exception = createException(httpResponse); exception.setHttpHeaders(httpResponse.getHeaders()); return exception; }
return createExceptionFromHeaders(httpResponse, null); if (log.isDebugEnabled()) log.debug("Failed in parsing the error response : ", ioe); return createExceptionFromHeaders(httpResponse, null); if (targetDepth == 1 && !S3ErrorTags.Error.toString().equals(tagName)) return createExceptionFromHeaders(httpResponse, "Unable to parse error response. Error XML Not in proper format." + content); targetDepth--; if (!(hasErrorTagVisited) || targetDepth > 1) { return createExceptionFromHeaders(httpResponse, "Unable to parse error response. Error XML Not in proper format." + content); e); return createExceptionFromHeaders(httpResponse, content);
return newAmazonS3Exception(errorResponse.getStatusText(), errorResponse); log.debug("Failed in reading the error response", ex); return newAmazonS3Exception(errorResponse.getStatusText(), errorResponse); final int statusCode = errorResponse.getStatusCode(); ase.setStatusCode(statusCode); ase.setErrorType(errorTypeOf(statusCode)); ase.setErrorCode(errorCode); ase.setRequestId(requestId); log.debug("Failed in parsing the response as XML: " + content, ex); return newAmazonS3Exception(content, errorResponse);
@Test public void testErrorResponseFromUnparsableXML() throws IOException { String response = "<Error>" + "<Message>testError"; ByteArrayInputStream content = new ByteArrayInputStream(response.getBytes(StringUtils.UTF8)); HttpResponse errorResponse = new HttpResponse.Builder() .statusCode(200) .content(content) .statusText("testError").build(); S3ErrorResponseHandler handler = new S3ErrorResponseHandler(); AmazonS3Exception ase = (AmazonS3Exception) handler.handle(errorResponse); assertEquals(ase.getStatusCode(), 200); assertEquals(ase.getErrorType(), ErrorType.Client); assertEquals(ase.getErrorCode(), "200 testError"); }
/** * Used to create an {@link AmazonS3Exception} when we failed to read the * error response or parsed the error response as XML. */ private AmazonS3Exception newAmazonS3Exception(String errmsg, HttpResponse httpResponse) { final AmazonS3Exception ase = new AmazonS3Exception(errmsg); final int statusCode = httpResponse.getStatusCode(); ase.setErrorCode(statusCode + " " + httpResponse.getStatusText()); ase.setStatusCode(statusCode); ase.setErrorType(errorTypeOf(statusCode)); final Map<String, String> headers = httpResponse.getHeaders(); ase.setRequestId(headers.get(Headers.REQUEST_ID)); ase.setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID)); ase.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID)); final Map<String, String> additionalDetails = new HashMap<String, String>(); additionalDetails.put(Headers.S3_BUCKET_REGION, headers.get(Headers.S3_BUCKET_REGION)); ase.setAdditionalDetails(additionalDetails); return ase; }
return newAmazonS3Exception(errorResponse.getStatusText(), errorResponse); log.debug("Failed in reading the error response", ex); return newAmazonS3Exception(errorResponse.getStatusText(), errorResponse); final int statusCode = errorResponse.getStatusCode(); ase.setStatusCode(statusCode); ase.setErrorType(errorTypeOf(statusCode)); ase.setErrorCode(errorCode); ase.setRequestId(requestId); log.debug("Failed in parsing the response as XML: " + content, ex); return newAmazonS3Exception(content, errorResponse);
@Test public void testHandleErrorResponse() throws IOException { String response = "<Error>" + "<Message>testError</Message>" + "<Code>testCode</Code>" + "<RequestId>testId</RequestId>" + "<HostId>testHost</HostId>" + "</Error>"; ByteArrayInputStream content = new ByteArrayInputStream(response.getBytes(StringUtils.UTF8)); HttpResponse errorResponse = new HttpResponse.Builder() .statusCode(200) .content(content) .statusText("testError").build(); S3ErrorResponseHandler handler = new S3ErrorResponseHandler(); AmazonS3Exception ase = (AmazonS3Exception) handler.handle(errorResponse); assertEquals(ase.getErrorMessage(), "testError"); assertEquals(ase.getErrorType(), ErrorType.Client); assertEquals(ase.getRequestId(), "testId"); assertEquals(ase.getExtendedRequestId(), "testHost"); assertEquals(ase.getStatusCode(), 200); assertEquals(ase.getErrorCode(), "testCode"); }
/** * Used to create an {@link AmazonS3Exception} when we failed to read the * error response or parsed the error response as XML. */ private AmazonS3Exception newAmazonS3Exception(String errmsg, HttpResponse httpResponse) { final AmazonS3Exception ase = new AmazonS3Exception(errmsg); final int statusCode = httpResponse.getStatusCode(); ase.setErrorCode(statusCode + " " + httpResponse.getStatusText()); ase.setStatusCode(statusCode); ase.setErrorType(errorTypeOf(statusCode)); final Map<String, String> headers = httpResponse.getHeaders(); ase.setRequestId(headers.get(Headers.REQUEST_ID)); ase.setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID)); ase.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID)); final Map<String, String> additionalDetails = new HashMap<String, String>(); additionalDetails.put(Headers.S3_BUCKET_REGION, headers.get(Headers.S3_BUCKET_REGION)); ase.setAdditionalDetails(additionalDetails); return ase; }
@Test public void testHandleErrorResponseWithNoBody() throws IOException { HttpResponse errorResponse = new HttpResponse.Builder() .statusCode(500) .content(null) .statusText("testError") .header(Headers.REQUEST_ID, "testId") .header(Headers.EXTENDED_REQUEST_ID, "extendedId").build(); S3ErrorResponseHandler handler = new S3ErrorResponseHandler(); AmazonS3Exception ase = (AmazonS3Exception) handler.handle(errorResponse); assertEquals(ase.getErrorMessage(), "testError"); assertEquals(ase.getErrorType(), ErrorType.Service); assertEquals(ase.getRequestId(), "testId"); assertEquals(ase.getExtendedRequestId(), "extendedId"); assertEquals(ase.getStatusCode(), 500); }
@Override public AmazonServiceException handle(HttpResponse httpResponse) throws XMLStreamException { final AmazonServiceException exception = createException(httpResponse); exception.setHttpHeaders(httpResponse.getHeaders()); return exception; }
return createExceptionFromHeaders(httpResponse, null); if (log.isDebugEnabled()) log.debug("Failed in parsing the error response : ", ioe); return createExceptionFromHeaders(httpResponse, null); if (targetDepth == 1 && !S3ErrorTags.Error.toString().equals(tagName)) return createExceptionFromHeaders(httpResponse, "Unable to parse error response. Error XML Not in proper format." + content); targetDepth--; if (!(hasErrorTagVisited) || targetDepth > 1) { return createExceptionFromHeaders(httpResponse, "Unable to parse error response. Error XML Not in proper format." + content); e); return createExceptionFromHeaders(httpResponse, content);