I am having a strange problem when org.apache.http.NoHttpResponseExceptionit is thrown as an exception, even if it is an exception thrown as it extends java.io.IOException... As you can see from the next published stacktrace, I get an exception that should be checked at compile time as a runtime exception.
The stacktrace element of the exception that I get looks like this (my classes are in the package:) com.example.staticsite:
org.apache.http.NoHttpResponseException: sqs.eu-west-1.amazonaws.com failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:260)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:251)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:197)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:271)
at com.amazonaws.http.protocol.SdkHttpRequestExecutor.doReceiveResponse(SdkHttpRequestExecutor.java:66)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:685)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:487)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:728)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:489)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:310)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2419)
at com.amazonaws.services.sqs.AmazonSQSClient.receiveMessage(AmazonSQSClient.java:1130)
at com.example.staticsite.aws.SqsReceiverImpl.receiveReceipt(SqsReceiverImpl.java:57)
at com.example.staticsite.core.processsite.ProcessSiteImpl.runOneTime(ProcessSiteImpl.java:59)
at com.example.staticsite.core.processsite.ProcessSiteImpl.run(ProcessSiteImpl.java:44)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
at java.lang.Thread.run(Thread.java:748)
Method that throws an exception inside my code:
public class SqsReceiverImpl implements SqsReceiver {
private AmazonSQS client;
private String queueUrl;
@Inject
public SqsReceiverImpl(AmazonSQS client,@Assisted String queueUrl) {
this.client = client;
this.queueUrl = queueUrl;
}
public List<String> receiveReceipt() throws SqsReceiverException {
if(queueUrl == null)
throw new SqsReceiverException(SqsReceiverException.MESSAGE_NO_QUEURURL);
ReceiveMessageRequest request = new ReceiveMessageRequest();
request.setMaxNumberOfMessages(10);
request.setQueueUrl(queueUrl);
request.setWaitTimeSeconds(20);
ReceiveMessageResult results = null;
try {
results = client.receiveMessage(request);
}
catch(OverLimitException oe){
throw new SqsReceiverException("OverLimitException thrown");
}
catch(AmazonServiceException oe){
throw new SqsReceiverException("AmazonServiceException thrown");
}
catch(AmazonClientException oe){
throw new SqsReceiverException("AmazonClientException thrown");
}
SqsReceiverException defined as follows:
public class SqsReceiverException extends Exception{
public SqsReceiverException(String messageNoQueururl) {
super(messageNoQueururl);
}
public static final String MESSAGE_NO_QUEURURL = "Queue url not found. Se the queue url";
}
The pom file dependencies are declared as follows:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<version>1.10.12</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
Result:

, , ?
- ?
, , Amazon.
Update
downtrace AmazonHttpClient, , `IOException ':
catch (IOException ioe) {
if (log.isInfoEnabled()) {
log.info("Unable to execute HTTP request: " + ioe.getMessage(), ioe);
}
captureExceptionMetrics(ioe, awsRequestMetrics);
awsRequestMetrics.addProperty(AWSRequestID, null);
AmazonClientException ace = new AmazonClientException(
"Unable to execute HTTP request: " + ioe.getMessage(),
ioe);
if (!shouldRetry(request.getOriginalRequest(),
p.apacheRequest,
ace,
p.requestCount,
config.getRetryPolicy())) {
throw lastReset(ace, request);
}
p.retriedException = ace;
}
lastReset , , , - org.apache.http.NoHttpResponseException...
stacktrace :
2017-09-15 07:41:39 INFO AmazonHttpClient:496 - Unable to execute HTTP request: sqs.eu-west-1.amazonaws.com failed to respond