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:
parent
baf3239aec
commit
be0227d72a
|
@ -33,9 +33,11 @@ package org.apache.http.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.http.HttpRequest;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpException;
|
import org.apache.http.HttpException;
|
||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
|
import org.apache.http.conn.HttpRoute; //@@@ replace by HttpTarget
|
||||||
import org.apache.http.conn.ManagedClientConnection;
|
import org.apache.http.conn.ManagedClientConnection;
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,7 +80,8 @@ public interface ClientRequestDirector {
|
||||||
* This is the same behavior as for <code>HttpMethodDirector</code>
|
* This is the same behavior as for <code>HttpMethodDirector</code>
|
||||||
* in HttpClient 3.
|
* 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
|
* @param context the context for executing the request
|
||||||
*
|
*
|
||||||
* @return the final response to 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 IOException in case of an IO problem
|
||||||
* @throws InterruptedException in case of an interrupt
|
* @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
|
throws HttpException, IOException, InterruptedException
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -508,7 +508,8 @@ public abstract class AbstractHttpClient implements HttpClient {
|
||||||
determineParams(roureq.getRequest()));
|
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
|
// If the response depends on the connection, the director
|
||||||
// will have set up an auto-release input stream.
|
// will have set up an auto-release input stream.
|
||||||
|
|
||||||
|
|
|
@ -258,10 +258,13 @@ public class DefaultClientRequestDirector
|
||||||
|
|
||||||
|
|
||||||
// non-javadoc, see interface ClientRequestDirector
|
// 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 {
|
throws HttpException, IOException, InterruptedException {
|
||||||
|
|
||||||
HttpRequest orig = roureq.getRequest();
|
RoutedRequest roureq = new RoutedRequest.Impl(request, route);
|
||||||
|
|
||||||
|
final HttpRequest orig = request;
|
||||||
|
|
||||||
long timeout = HttpClientParams.getConnectionManagerTimeout(params);
|
long timeout = HttpClientParams.getConnectionManagerTimeout(params);
|
||||||
|
|
||||||
|
@ -271,8 +274,12 @@ public class DefaultClientRequestDirector
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
try {
|
try {
|
||||||
while (!done) {
|
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
|
// Allocate connection if needed
|
||||||
if (managedConn == null) {
|
if (managedConn == null) {
|
||||||
|
@ -303,15 +310,15 @@ public class DefaultClientRequestDirector
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrap the original request
|
// Wrap the request to be sent, original or followup.
|
||||||
RequestWrapper request = wrapRequest(roureq.getRequest());
|
RequestWrapper reqwrap = wrapRequest(roureq.getRequest());
|
||||||
request.setParams(this.params);
|
reqwrap.setParams(this.params);
|
||||||
|
|
||||||
// Re-write request URI if needed
|
// Re-write request URI if needed
|
||||||
rewriteRequestURI(request, route);
|
rewriteRequestURI(reqwrap, route);
|
||||||
|
|
||||||
// Use virtual host if set
|
// Use virtual host if set
|
||||||
HttpHost target = (HttpHost) request.getParams().getParameter(
|
HttpHost target = (HttpHost) reqwrap.getParams().getParameter(
|
||||||
ClientPNames.VIRTUAL_HOST);
|
ClientPNames.VIRTUAL_HOST);
|
||||||
|
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
|
@ -331,21 +338,21 @@ public class DefaultClientRequestDirector
|
||||||
targetAuthState);
|
targetAuthState);
|
||||||
context.setAttribute(ClientContext.PROXY_AUTH_STATE,
|
context.setAttribute(ClientContext.PROXY_AUTH_STATE,
|
||||||
proxyAuthState);
|
proxyAuthState);
|
||||||
requestExec.preProcess(request, httpProcessor, context);
|
requestExec.preProcess(reqwrap, httpProcessor, context);
|
||||||
|
|
||||||
if (orig instanceof AbortableHttpRequest) {
|
if (orig instanceof AbortableHttpRequest) {
|
||||||
((AbortableHttpRequest) orig).setReleaseTrigger(managedConn);
|
((AbortableHttpRequest) orig).setReleaseTrigger(managedConn);
|
||||||
}
|
}
|
||||||
|
|
||||||
context.setAttribute(ExecutionContext.HTTP_REQUEST,
|
context.setAttribute(ExecutionContext.HTTP_REQUEST,
|
||||||
request);
|
reqwrap);
|
||||||
|
|
||||||
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(request, managedConn, context);
|
response = requestExec.execute(reqwrap, managedConn, context);
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
LOG.debug("Closing the connection.");
|
LOG.debug("Closing the connection.");
|
||||||
|
@ -369,7 +376,7 @@ public class DefaultClientRequestDirector
|
||||||
requestExec.postProcess(response, httpProcessor, context);
|
requestExec.postProcess(response, httpProcessor, context);
|
||||||
|
|
||||||
RoutedRequest followup =
|
RoutedRequest followup =
|
||||||
handleResponse(roureq, request, response, context);
|
handleResponse(roureq, reqwrap, response, context);
|
||||||
if (followup == null) {
|
if (followup == null) {
|
||||||
done = true;
|
done = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue