diff --git a/module-client/src/main/java/org/apache/http/client/ClientRequestDirector.java b/module-client/src/main/java/org/apache/http/client/ClientRequestDirector.java index 52434ee5d..ed537d7af 100644 --- a/module-client/src/main/java/org/apache/http/client/ClientRequestDirector.java +++ b/module-client/src/main/java/org/apache/http/client/ClientRequestDirector.java @@ -33,9 +33,11 @@ package org.apache.http.client; import java.io.IOException; +import org.apache.http.HttpRequest; import org.apache.http.HttpResponse; import org.apache.http.HttpException; import org.apache.http.protocol.HttpContext; +import org.apache.http.conn.HttpRoute; //@@@ replace by HttpTarget import org.apache.http.conn.ManagedClientConnection; @@ -78,7 +80,8 @@ public interface ClientRequestDirector { * This is the same behavior as for HttpMethodDirector * in HttpClient 3. * - * @param roureq the route and request to execute + * @param request the request to execute + * @param route the route to the target of the request * @param context the context for executing the request * * @return the final response to the request. @@ -88,7 +91,8 @@ public interface ClientRequestDirector { * @throws IOException in case of an IO problem * @throws InterruptedException in case of an interrupt */ - HttpResponse execute(RoutedRequest roureq, HttpContext context) + HttpResponse execute(HttpRequest request, HttpRoute route, + HttpContext context) throws HttpException, IOException, InterruptedException ; diff --git a/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java b/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java index 5f03137a4..9ac29b524 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java +++ b/module-client/src/main/java/org/apache/http/impl/client/AbstractHttpClient.java @@ -508,7 +508,8 @@ public abstract class AbstractHttpClient implements HttpClient { determineParams(roureq.getRequest())); } - HttpResponse response = director.execute(roureq, context); + HttpResponse response = director.execute(roureq.getRequest(), + roureq.getRoute(), context); // If the response depends on the connection, the director // will have set up an auto-release input stream. diff --git a/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java b/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java index eb4d2ae33..11c19750e 100644 --- a/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java +++ b/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java @@ -258,10 +258,13 @@ public class DefaultClientRequestDirector // non-javadoc, see interface ClientRequestDirector - public HttpResponse execute(RoutedRequest roureq, HttpContext context) + public HttpResponse execute(HttpRequest request, HttpRoute route, + HttpContext context) throws HttpException, IOException, InterruptedException { - HttpRequest orig = roureq.getRequest(); + RoutedRequest roureq = new RoutedRequest.Impl(request, route); + + final HttpRequest orig = request; long timeout = HttpClientParams.getConnectionManagerTimeout(params); @@ -271,8 +274,12 @@ public class DefaultClientRequestDirector boolean done = false; try { while (!done) { + // In this loop, the RoutedRequest may be replaced by a + // followup request and route. The request and route passed + // in the method arguments will be replaced. The original + // request is still available in 'orig'. - HttpRoute route = roureq.getRoute(); + route = roureq.getRoute(); // Allocate connection if needed if (managedConn == null) { @@ -303,15 +310,15 @@ public class DefaultClientRequestDirector } } - // Wrap the original request - RequestWrapper request = wrapRequest(roureq.getRequest()); - request.setParams(this.params); + // Wrap the request to be sent, original or followup. + RequestWrapper reqwrap = wrapRequest(roureq.getRequest()); + reqwrap.setParams(this.params); // Re-write request URI if needed - rewriteRequestURI(request, route); + rewriteRequestURI(reqwrap, route); // Use virtual host if set - HttpHost target = (HttpHost) request.getParams().getParameter( + HttpHost target = (HttpHost) reqwrap.getParams().getParameter( ClientPNames.VIRTUAL_HOST); if (target == null) { @@ -331,21 +338,21 @@ public class DefaultClientRequestDirector targetAuthState); context.setAttribute(ClientContext.PROXY_AUTH_STATE, proxyAuthState); - requestExec.preProcess(request, httpProcessor, context); + requestExec.preProcess(reqwrap, httpProcessor, context); if (orig instanceof AbortableHttpRequest) { ((AbortableHttpRequest) orig).setReleaseTrigger(managedConn); } context.setAttribute(ExecutionContext.HTTP_REQUEST, - request); + reqwrap); execCount++; try { if (LOG.isDebugEnabled()) { LOG.debug("Attempt " + execCount + " to execute request"); } - response = requestExec.execute(request, managedConn, context); + response = requestExec.execute(reqwrap, managedConn, context); } catch (IOException ex) { LOG.debug("Closing the connection."); @@ -369,7 +376,7 @@ public class DefaultClientRequestDirector requestExec.postProcess(response, httpProcessor, context); RoutedRequest followup = - handleResponse(roureq, request, response, context); + handleResponse(roureq, reqwrap, response, context); if (followup == null) { done = true; } else {