forked from aws/aws-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messages when using proxy server.
If using a proxy server and the AWS exception does not contain a request ID, then that's a potential sign that the request was rejected at the proxy server, because the request ID is assigned at the AWS server side. This patch helps users troubleshoot this by including the proxy host in the exception message.
- Loading branch information
Showing
9 changed files
with
243 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
aws-java-sdk-core/src/test/java/com/amazonaws/http/AwsErrorResponseHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
package com.amazonaws.http; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
import org.apache.http.HttpStatus; | ||
|
||
import org.junit.Test; | ||
|
||
import com.amazonaws.AmazonServiceException; | ||
import com.amazonaws.ClientConfiguration; | ||
import com.amazonaws.DefaultRequest; | ||
import com.amazonaws.util.AWSRequestMetrics; | ||
import com.amazonaws.util.StringInputStream; | ||
|
||
public class AwsErrorResponseHandlerTest { | ||
|
||
private static final String ERROR_MESSAGE = "someErrorMessage"; | ||
private static final String PROXY_HOST = "someHost"; | ||
private static final String REQUEST_ID = "1234"; | ||
private static final String SERVICE_NAME = "someService"; | ||
|
||
@Test | ||
public void handle_withProxy_withRequestId() throws Exception { | ||
HttpResponseHandler<AmazonServiceException> delegate = mock(HttpResponseHandler.class); | ||
AmazonServiceException ase = new AmazonServiceException(ERROR_MESSAGE); | ||
ase.setRequestId(REQUEST_ID); | ||
when(delegate.handle(any(HttpResponse.class))).thenReturn(ase); | ||
AWSRequestMetrics awsRequestMetrics = mock(AWSRequestMetrics.class); | ||
ClientConfiguration conf = new ClientConfiguration(); | ||
conf.setProxyHost(PROXY_HOST); | ||
AwsErrorResponseHandler responseHandler = new AwsErrorResponseHandler(delegate, awsRequestMetrics, conf); | ||
HttpResponse httpResponse = new HttpResponse(new DefaultRequest<String>(SERVICE_NAME), null); | ||
httpResponse.setStatusCode(HttpStatus.SC_FORBIDDEN); | ||
AmazonServiceException e = responseHandler.handle(httpResponse); | ||
assertNotNull(e); | ||
assertEquals(PROXY_HOST, e.getProxyHost()); | ||
assertNotNull(e.getMessage()); | ||
assertFalse(e.getMessage().contains(PROXY_HOST)); | ||
} | ||
|
||
@Test | ||
public void handle_withProxy_withoutRequestId() throws Exception { | ||
HttpResponseHandler<AmazonServiceException> delegate = mock(HttpResponseHandler.class); | ||
AmazonServiceException ase = new AmazonServiceException(ERROR_MESSAGE); | ||
when(delegate.handle(any(HttpResponse.class))).thenReturn(ase); | ||
AWSRequestMetrics awsRequestMetrics = mock(AWSRequestMetrics.class); | ||
ClientConfiguration conf = new ClientConfiguration(); | ||
conf.setProxyHost(PROXY_HOST); | ||
AwsErrorResponseHandler responseHandler = new AwsErrorResponseHandler(delegate, awsRequestMetrics, conf); | ||
HttpResponse httpResponse = new HttpResponse(new DefaultRequest<String>(SERVICE_NAME), null); | ||
httpResponse.setStatusCode(HttpStatus.SC_FORBIDDEN); | ||
AmazonServiceException e = responseHandler.handle(httpResponse); | ||
assertNotNull(e); | ||
assertEquals(PROXY_HOST, e.getProxyHost()); | ||
assertNotNull(e.getMessage()); | ||
assertTrue(e.getMessage().contains(PROXY_HOST)); | ||
} | ||
|
||
@Test | ||
public void handle_withoutProxy() throws Exception { | ||
HttpResponseHandler<AmazonServiceException> delegate = mock(HttpResponseHandler.class); | ||
AmazonServiceException ase = new AmazonServiceException(ERROR_MESSAGE); | ||
when(delegate.handle(any(HttpResponse.class))).thenReturn(ase); | ||
AWSRequestMetrics awsRequestMetrics = mock(AWSRequestMetrics.class); | ||
ClientConfiguration conf = new ClientConfiguration(); | ||
AwsErrorResponseHandler responseHandler = new AwsErrorResponseHandler(delegate, awsRequestMetrics, conf); | ||
HttpResponse httpResponse = new HttpResponse(new DefaultRequest<String>(SERVICE_NAME), null); | ||
httpResponse.setStatusCode(HttpStatus.SC_FORBIDDEN); | ||
AmazonServiceException e = responseHandler.handle(httpResponse); | ||
assertNotNull(e); | ||
assertNull(e.getProxyHost()); | ||
assertNotNull(e.getMessage()); | ||
assertFalse(e.getMessage().contains(PROXY_HOST)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...a-sdk-s3/src/test/java/com/amazonaws/services/s3/internal/S3ErrorResponseHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
package com.amazonaws.services.s3.internal; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.apache.http.HttpStatus; | ||
|
||
import org.junit.Test; | ||
|
||
import com.amazonaws.AmazonServiceException; | ||
import com.amazonaws.ClientConfiguration; | ||
import com.amazonaws.DefaultRequest; | ||
import com.amazonaws.http.HttpResponse; | ||
import com.amazonaws.util.StringInputStream; | ||
|
||
public class S3ErrorResponseHandlerTest { | ||
|
||
private static final String PROXY_HOST = "someHost"; | ||
private static final String SERVICE_NAME = "someService"; | ||
|
||
@Test | ||
public void handle_withProxy_withRequestId() throws Exception { | ||
ClientConfiguration conf = new ClientConfiguration(); | ||
conf.setProxyHost(PROXY_HOST); | ||
S3ErrorResponseHandler responseHandler = new S3ErrorResponseHandler(conf); | ||
HttpResponse httpResponse = new HttpResponse(new DefaultRequest<String>(SERVICE_NAME), null); | ||
httpResponse.setStatusCode(HttpStatus.SC_FORBIDDEN); | ||
httpResponse.setContent(new StringInputStream( | ||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | ||
+ "<Error>" | ||
+ " <RequestId>1234</RequestId>" | ||
+ "</Error>")); | ||
AmazonServiceException e = responseHandler.handle(httpResponse); | ||
assertNotNull(e); | ||
assertEquals(PROXY_HOST, e.getProxyHost()); | ||
assertNotNull(e.getMessage()); | ||
assertFalse(e.getMessage().contains(PROXY_HOST)); | ||
} | ||
|
||
@Test | ||
public void handle_withProxy_withoutRequestId() throws Exception { | ||
ClientConfiguration conf = new ClientConfiguration(); | ||
conf.setProxyHost(PROXY_HOST); | ||
S3ErrorResponseHandler responseHandler = new S3ErrorResponseHandler(conf); | ||
HttpResponse httpResponse = new HttpResponse(new DefaultRequest<String>(SERVICE_NAME), null); | ||
httpResponse.setStatusCode(HttpStatus.SC_FORBIDDEN); | ||
AmazonServiceException e = responseHandler.handle(httpResponse); | ||
assertNotNull(e); | ||
assertEquals(PROXY_HOST, e.getProxyHost()); | ||
assertNotNull(e.getMessage()); | ||
assertTrue(e.getMessage().contains(PROXY_HOST)); | ||
} | ||
|
||
@Test | ||
public void handle_withoutProxy() throws Exception { | ||
ClientConfiguration conf = new ClientConfiguration(); | ||
S3ErrorResponseHandler responseHandler = new S3ErrorResponseHandler(conf); | ||
HttpResponse httpResponse = new HttpResponse(new DefaultRequest<String>(SERVICE_NAME), null); | ||
httpResponse.setStatusCode(HttpStatus.SC_FORBIDDEN); | ||
AmazonServiceException e = responseHandler.handle(httpResponse); | ||
assertNotNull(e); | ||
assertNull(e.getProxyHost()); | ||
assertNotNull(e.getMessage()); | ||
assertFalse(e.getMessage().contains(PROXY_HOST)); | ||
} | ||
} |