* Fixed bug introduced by my previous patch

* Optimized the way requests are re-tried. If a request is submitted over a direct connection, there is no need to regenerate the request wrapper and re-run protocol interceptors on it 


git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@662030 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2008-05-31 14:19:35 +00:00
parent 650a04c734
commit c4fd46d1f8
2 changed files with 41 additions and 26 deletions

View File

@ -347,9 +347,8 @@ public class DefaultClientRequestDirector
break;
}
// Clear autogenerated headers if case the request is being
// retried
wrapper.clearHeaders();
// Reset headers on the request wrapper
wrapper.resetHeaders();
// Re-write request URI if needed
rewriteRequestURI(wrapper, route);
@ -382,29 +381,45 @@ public class DefaultClientRequestDirector
context.setAttribute(ExecutionContext.HTTP_REQUEST,
wrapper);
execCount++;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Attempt " + execCount + " to execute request");
}
response = requestExec.execute(wrapper, managedConn, context);
} catch (IOException ex) {
LOG.debug("Closing the connection.");
managedConn.close();
if (retryHandler.retryRequest(ex, execCount, context)) {
if (LOG.isInfoEnabled()) {
LOG.info("I/O exception ("+ ex.getClass().getName() +
") caught when processing request: "
+ ex.getMessage());
}
boolean retrying = true;
while (retrying) {
execCount++;
try {
if (LOG.isDebugEnabled()) {
LOG.debug(ex.getMessage(), ex);
LOG.debug("Attempt " + execCount + " to execute request");
}
LOG.info("Retrying request");
continue;
response = requestExec.execute(wrapper, managedConn, context);
retrying = false;
} catch (IOException ex) {
LOG.debug("Closing the connection.");
managedConn.close();
if (retryHandler.retryRequest(ex, execCount, context)) {
if (LOG.isInfoEnabled()) {
LOG.info("I/O exception ("+ ex.getClass().getName() +
") caught when processing request: "
+ ex.getMessage());
}
if (LOG.isDebugEnabled()) {
LOG.debug(ex.getMessage(), ex);
}
LOG.info("Retrying request");
} else {
throw ex;
}
// If we have a direct route to the target host
// just re-open connection and re-try the request
if (route.getHopCount() == 1) {
LOG.debug("Reopening the direct connection.");
managedConn.open(route, context, params);
} else {
// otherwise give up
retrying = false;
}
}
throw ex;
}
// Run response protocol interceptors

View File

@ -71,8 +71,6 @@ class RequestWrapper extends AbstractHttpMessage implements HttpUriRequest {
throw new IllegalArgumentException("HTTP request may not be null");
}
this.original = request;
// Make a copy of original headers
setHeaders(request.getAllHeaders());
setParams(request.getParams());
// Make a copy of the original URI
if (request instanceof HttpUriRequest) {
@ -149,8 +147,10 @@ class RequestWrapper extends AbstractHttpMessage implements HttpUriRequest {
return this.original;
}
public void clearHeaders() {
public void resetHeaders() {
// Make a copy of original headers
this.headergroup.clear();
setHeaders(this.original.getAllHeaders());
}
}