HTTPCLIENT-713: remove RoutedRequest from ClientRequestDirector interface

git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@603956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Roland Weber 2007-12-13 17:10:22 +00:00
parent baf3239aec
commit be0227d72a
3 changed files with 27 additions and 15 deletions

View File

@ -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 <code>HttpMethodDirector</code>
* 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
;

View File

@ -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.

View File

@ -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 {