* 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; break;
} }
// Clear autogenerated headers if case the request is being // Reset headers on the request wrapper
// retried wrapper.resetHeaders();
wrapper.clearHeaders();
// Re-write request URI if needed // Re-write request URI if needed
rewriteRequestURI(wrapper, route); rewriteRequestURI(wrapper, route);
@ -382,12 +381,15 @@ public class DefaultClientRequestDirector
context.setAttribute(ExecutionContext.HTTP_REQUEST, context.setAttribute(ExecutionContext.HTTP_REQUEST,
wrapper); wrapper);
boolean retrying = true;
while (retrying) {
execCount++; execCount++;
try { try {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("Attempt " + execCount + " to execute request"); LOG.debug("Attempt " + execCount + " to execute request");
} }
response = requestExec.execute(wrapper, managedConn, context); response = requestExec.execute(wrapper, managedConn, context);
retrying = false;
} catch (IOException ex) { } catch (IOException ex) {
LOG.debug("Closing the connection."); LOG.debug("Closing the connection.");
@ -402,11 +404,24 @@ public class DefaultClientRequestDirector
LOG.debug(ex.getMessage(), ex); LOG.debug(ex.getMessage(), ex);
} }
LOG.info("Retrying request"); LOG.info("Retrying request");
continue; } else {
}
throw ex; 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;
}
}
}
// Run response protocol interceptors // Run response protocol interceptors
response.setParams(params); response.setParams(params);
requestExec.postProcess(response, httpProcessor, context); requestExec.postProcess(response, httpProcessor, context);

View File

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