Package org.apache.http.impl.client
Class DefaultRequestDirector
java.lang.Object
org.apache.http.impl.client.DefaultRequestDirector
- All Implemented Interfaces:
RequestDirector
public class DefaultRequestDirector extends Object implements RequestDirector
Default implementation of
This class replaces the
RequestDirector.
This class replaces the
HttpMethodDirector in HttpClient 3.- Since:
- 4.0
- Version:
- $Revision: 676023 $
- Author:
- Roland Weber, Oleg Kalnichevski
-
Field Summary
Fields Modifier and Type Field Description protected ClientConnectionManagerconnManagerThe connection manager.protected HttpProcessorhttpProcessorThe HTTP protocol processor.protected ConnectionKeepAliveStrategykeepAliveStrategyThe keep-alive duration strategy.protected ManagedClientConnectionmanagedConnThe currently allocated connection.protected HttpParamsparamsThe HTTP parameters.protected RedirectHandlerredirectHandlerThe redirect handler.protected HttpRequestExecutorrequestExecThe request executor.protected HttpRequestRetryHandlerretryHandlerThe request retry handler.protected ConnectionReuseStrategyreuseStrategyThe connection re-use strategy.protected HttpRoutePlannerroutePlannerThe route planner. -
Constructor Summary
Constructors Constructor Description DefaultRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, HttpParams params) -
Method Summary
Modifier and Type Method Description protected HttpRequestcreateConnectRequest(HttpRoute route, HttpContext context)Creates the CONNECT request for tunnelling.protected booleancreateTunnelToProxy(HttpRoute route, int hop, HttpContext context)Creates a tunnel to an intermediate proxy.protected booleancreateTunnelToTarget(HttpRoute route, HttpContext context)Creates a tunnel to the target server.protected HttpRoutedetermineRoute(HttpHost target, HttpRequest request, HttpContext context)Determines the route for a request.protected voidestablishRoute(HttpRoute route, HttpContext context)Establishes the target route.HttpResponseexecute(HttpHost target, HttpRequest request, HttpContext context)Executes a request.protected RoutedRequesthandleResponse(RoutedRequest roureq, HttpResponse response, HttpContext context)Analyzes a response to check need for a followup.protected voidreleaseConnection()Returns the connection back to the connection manager and prepares for retrieving a new connection during the next request.protected voidrewriteRequestURI(RequestWrapper request, HttpRoute route)
-
Field Details
-
connManager
The connection manager. -
routePlanner
The route planner. -
reuseStrategy
The connection re-use strategy. -
keepAliveStrategy
The keep-alive duration strategy. -
requestExec
The request executor. -
httpProcessor
The HTTP protocol processor. -
retryHandler
The request retry handler. -
redirectHandler
The redirect handler. -
params
The HTTP parameters. -
managedConn
The currently allocated connection.
-
-
Constructor Details
-
DefaultRequestDirector
public DefaultRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, HttpParams params)
-
-
Method Details
-
rewriteRequestURI
- Throws:
ProtocolException
-
execute
public HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException, IOExceptionDescription copied from interface:RequestDirectorExecutes a request.
Note: For the time being, a new director is instantiated for each request. This is the same behavior as forHttpMethodDirectorin HttpClient 3.- Specified by:
executein interfaceRequestDirector- Parameters:
target- the target host for the request. Implementations may acceptnullif they can still determine a route, for example to a default target or by inspecting the request.request- the request to executecontext- the context for executing the request- Returns:
- the final response to the request. This is never an intermediate response with status code 1xx.
- Throws:
HttpException- in case of a problemIOException- in case of an IO problem or if the connection was aborted
-
releaseConnection
protected void releaseConnection()Returns the connection back to the connection manager and prepares for retrieving a new connection during the next request. -
determineRoute
protected HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpExceptionDetermines the route for a request. Called byexecute(org.apache.http.HttpHost, org.apache.http.HttpRequest, org.apache.http.protocol.HttpContext)to determine the route for either the original or a followup request.- Parameters:
target- the target host for the request. Implementations may acceptnullif they can still determine a route, for example to a default target or by inspecting the request.request- the request to executecontext- the context to use for the execution, nevernull- Returns:
- the route the request should take
- Throws:
HttpException- in case of a problem
-
establishRoute
protected void establishRoute(HttpRoute route, HttpContext context) throws HttpException, IOExceptionEstablishes the target route.- Parameters:
route- the route to establishcontext- the context for the request execution- Throws:
HttpException- in case of a problemIOException- in case of an IO problem
-
createTunnelToTarget
protected boolean createTunnelToTarget(HttpRoute route, HttpContext context) throws HttpException, IOExceptionCreates a tunnel to the target server. The connection must be established to the (last) proxy. A CONNECT request for tunnelling through the proxy will be created and sent, the response received and checked. This method does not update the connection with information about the tunnel, that is left to the caller.- Parameters:
route- the route to establishcontext- the context for request execution- Returns:
trueif the tunnelled route is secure,falseotherwise. The implementation here always returnsfalse, but derived classes may override.- Throws:
HttpException- in case of a problemIOException- in case of an IO problem
-
createTunnelToProxy
protected boolean createTunnelToProxy(HttpRoute route, int hop, HttpContext context) throws HttpException, IOExceptionCreates a tunnel to an intermediate proxy. This method is not implemented in this class. It just throws an exception here.- Parameters:
route- the route to establishhop- the hop in the route to establish now.route.getHopTarget(hop)will return the proxy to tunnel to.context- the context for request execution- Returns:
trueif the partially tunnelled connection is secure,falseotherwise.- Throws:
HttpException- in case of a problemIOException- in case of an IO problem
-
createConnectRequest
Creates the CONNECT request for tunnelling. Called bycreateTunnelToTarget.- Parameters:
route- the route to establishcontext- the context for request execution- Returns:
- the CONNECT request for tunnelling
-
handleResponse
protected RoutedRequest handleResponse(RoutedRequest roureq, HttpResponse response, HttpContext context) throws HttpException, IOExceptionAnalyzes a response to check need for a followup.- Parameters:
roureq- the request and route.response- the response to analayzecontext- the context used for the current request execution- Returns:
- the followup request and route if there is a followup, or
nullif the response should be returned as is - Throws:
HttpException- in case of a problemIOException- in case of an IO problem
-