HTTPCLIENT-1448: Add context information to NoHttpResponseException

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1559999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2014-01-21 12:50:22 +00:00
parent a718eee61c
commit b7291b4c32
2 changed files with 34 additions and 8 deletions

View File

@ -42,6 +42,7 @@ import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.NoHttpResponseException;
import org.apache.http.ProtocolException;
import org.apache.http.ProtocolVersion;
import org.apache.http.annotation.NotThreadSafe;
@ -621,12 +622,14 @@ public class DefaultRequestDirector implements RequestDirector {
if (retryHandler.retryRequest(ex, connectCount, context)) {
if (this.log.isInfoEnabled()) {
this.log.info("I/O exception ("+ ex.getClass().getName() +
") caught when connecting to the target host: "
") caught when connecting to "
+ route +
": "
+ ex.getMessage());
if (this.log.isDebugEnabled()) {
this.log.debug(ex.getMessage(), ex);
}
this.log.info("Retrying connect");
this.log.info("Retrying connect to " + route);
}
} else {
throw ex;
@ -691,16 +694,27 @@ public class DefaultRequestDirector implements RequestDirector {
if (retryHandler.retryRequest(ex, wrapper.getExecCount(), context)) {
if (this.log.isInfoEnabled()) {
this.log.info("I/O exception ("+ ex.getClass().getName() +
") caught when processing request: "
") caught when processing request to "
+ route +
": "
+ ex.getMessage());
}
if (this.log.isDebugEnabled()) {
this.log.debug(ex.getMessage(), ex);
}
this.log.info("Retrying request");
if (this.log.isInfoEnabled()) {
this.log.info("Retrying request to " + route);
}
retryReason = ex;
} else {
throw ex;
if (ex instanceof NoHttpResponseException) {
final NoHttpResponseException updatedex = new NoHttpResponseException(
route.getTargetHost().toHostString() + " failed to respond");
updatedex.setStackTrace(ex.getStackTrace());
throw updatedex;
} else {
throw ex;
}
}
}
}

View File

@ -33,6 +33,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.NoHttpResponseException;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.HttpRequestRetryHandler;
import org.apache.http.client.NonRepeatableRequestException;
@ -91,7 +92,9 @@ public class RetryExec implements ClientExecChain {
if (retryHandler.retryRequest(ex, execCount, context)) {
if (this.log.isInfoEnabled()) {
this.log.info("I/O exception ("+ ex.getClass().getName() +
") caught when processing request: "
") caught when processing request to "
+ route +
": "
+ ex.getMessage());
}
if (this.log.isDebugEnabled()) {
@ -103,9 +106,18 @@ public class RetryExec implements ClientExecChain {
"with a non-repeatable request entity", ex);
}
request.setHeaders(origheaders);
this.log.info("Retrying request");
if (this.log.isInfoEnabled()) {
this.log.info("Retrying request to " + route);
}
} else {
throw ex;
if (ex instanceof NoHttpResponseException) {
final NoHttpResponseException updatedex = new NoHttpResponseException(
route.getTargetHost().toHostString() + " failed to respond");
updatedex.setStackTrace(ex.getStackTrace());
throw updatedex;
} else {
throw ex;
}
}
}
}