You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2008/05/31 16:19:35 UTC
svn commit: r662030 - in
/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client:
DefaultClientRequestDirector.java RequestWrapper.java
Author: olegk
Date: Sat May 31 07:19:35 2008
New Revision: 662030
URL: http://svn.apache.org/viewvc?rev=662030&view=rev
Log:
* 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
Modified:
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java?rev=662030&r1=662029&r2=662030&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java Sat May 31 07:19:35 2008
@@ -347,9 +347,8 @@
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 @@
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");
+ }
+ 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;
}
- LOG.info("Retrying request");
- continue;
+
+ // 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
Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java?rev=662030&r1=662029&r2=662030&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java Sat May 31 07:19:35 2008
@@ -71,8 +71,6 @@
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 @@
return this.original;
}
- public void clearHeaders() {
+ public void resetHeaders() {
+ // Make a copy of original headers
this.headergroup.clear();
+ setHeaders(this.original.getAllHeaders());
}
}