Class DefaultRequestDirector
java.lang.Object
org.robolectric.shadows.httpclient.DefaultRequestDirector
- All Implemented Interfaces:
- org.apache.http.client.RequestDirector
public class DefaultRequestDirector extends Object implements org.apache.http.client.RequestDirector
Default implementation of 
RequestDirector.
 The following parameters can be used to customize the behavior of this class:
- CoreProtocolPNames.PROTOCOL_VERSION
- CoreProtocolPNames.STRICT_TRANSFER_ENCODING
- CoreProtocolPNames.HTTP_ELEMENT_CHARSET
- CoreProtocolPNames.USE_EXPECT_CONTINUE
- CoreProtocolPNames.WAIT_FOR_CONTINUE
- CoreProtocolPNames.USER_AGENT
- CoreConnectionPNames.SOCKET_BUFFER_SIZE
- CoreConnectionPNames.MAX_LINE_LENGTH
- CoreConnectionPNames.MAX_HEADER_COUNT
- CoreConnectionPNames.SO_TIMEOUT
- CoreConnectionPNames.SO_LINGER
- CoreConnectionPNames.TCP_NODELAY
- CoreConnectionPNames.CONNECTION_TIMEOUT
- CoreConnectionPNames.STALE_CONNECTION_CHECK
- ConnRoutePNames.FORCED_ROUTE
- ConnRoutePNames.LOCAL_ADDRESS
- ConnRoutePNames.DEFAULT_PROXY
- ConnManagerPNames.TIMEOUT
- ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE
- ConnManagerPNames.MAX_TOTAL_CONNECTIONS
- CookieSpecPNames.DATE_PATTERNS
- CookieSpecPNames.SINGLE_COOKIE_HEADER
- AuthPNames.CREDENTIAL_CHARSET
- ClientPNames.COOKIE_POLICY
- ClientPNames.HANDLE_AUTHENTICATION
- ClientPNames.HANDLE_REDIRECTS
- ClientPNames.MAX_REDIRECTS
- ClientPNames.ALLOW_CIRCULAR_REDIRECTS
- ClientPNames.VIRTUAL_HOST
- ClientPNames.DEFAULT_HOST
- ClientPNames.DEFAULT_HEADERS
- Since:
- 4.0
- 
Field SummaryFields Modifier and Type Field Description protected ClientConnectionManagerconnManagerThe connection manager.protected org.apache.http.protocol.HttpProcessorhttpProcessorThe HTTP protocol processor.protected ConnectionKeepAliveStrategykeepAliveStrategyThe keep-alive duration strategy.protected ManagedClientConnectionmanagedConnThe currently allocated connection.protected HttpParamsparamsThe HTTP parameters.protected org.apache.http.client.AuthenticationHandlerproxyAuthHandlerThe proxy authentication handler.protected org.apache.http.auth.AuthStateproxyAuthStateprotected org.apache.http.client.RedirectHandlerredirectHandlerThe redirect handler.protected org.apache.http.protocol.HttpRequestExecutorrequestExecThe request executor.protected org.apache.http.client.HttpRequestRetryHandlerretryHandlerThe request retry handler.protected org.apache.http.ConnectionReuseStrategyreuseStrategyThe connection re-use strategy.protected org.apache.http.conn.routing.HttpRoutePlannerroutePlannerThe route planner.protected org.apache.http.client.AuthenticationHandlertargetAuthHandlerThe target authentication handler.protected org.apache.http.auth.AuthStatetargetAuthStateprotected org.apache.http.client.UserTokenHandleruserTokenHandlerThe user token handler.
- 
Constructor SummaryConstructors Constructor Description DefaultRequestDirector(org.apache.commons.logging.Log log, org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, org.apache.http.conn.routing.HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, org.apache.http.client.HttpRequestRetryHandler retryHandler, org.apache.http.client.RedirectHandler redirectHandler, org.apache.http.client.AuthenticationHandler targetAuthHandler, org.apache.http.client.AuthenticationHandler proxyAuthHandler, org.apache.http.client.UserTokenHandler userTokenHandler, HttpParams params)DefaultRequestDirector(org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, org.apache.http.conn.routing.HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, org.apache.http.client.HttpRequestRetryHandler retryHandler, org.apache.http.client.RedirectHandler redirectHandler, org.apache.http.client.AuthenticationHandler targetAuthHandler, org.apache.http.client.AuthenticationHandler proxyAuthHandler, org.apache.http.client.UserTokenHandler userTokenHandler, HttpParams params)
- 
Method SummaryModifier and Type Method Description protected org.apache.http.HttpRequestcreateConnectRequest(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context)Creates the CONNECT request for tunnelling.protected booleancreateTunnelToProxy(org.apache.http.conn.routing.HttpRoute route, int hop, org.apache.http.protocol.HttpContext context)Creates a tunnel to an intermediate proxy.protected booleancreateTunnelToTarget(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context)Creates a tunnel to the target server.protected org.apache.http.conn.routing.HttpRoutedetermineRoute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)Determines the route for a request.protected voidestablishRoute(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context)Establishes the target route.org.apache.http.HttpResponseexecute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)protected org.apache.http.impl.client.RoutedRequesthandleResponse(org.apache.http.impl.client.RoutedRequest roureq, org.apache.http.HttpResponse response, org.apache.http.protocol.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(org.apache.http.impl.client.RequestWrapper request, org.apache.http.conn.routing.HttpRoute route)
- 
Field Details- 
connManagerThe connection manager.
- 
routePlannerprotected final org.apache.http.conn.routing.HttpRoutePlanner routePlannerThe route planner.
- 
reuseStrategyprotected final org.apache.http.ConnectionReuseStrategy reuseStrategyThe connection re-use strategy.
- 
keepAliveStrategyThe keep-alive duration strategy.
- 
requestExecprotected final org.apache.http.protocol.HttpRequestExecutor requestExecThe request executor.
- 
httpProcessorprotected final org.apache.http.protocol.HttpProcessor httpProcessorThe HTTP protocol processor.
- 
retryHandlerprotected final org.apache.http.client.HttpRequestRetryHandler retryHandlerThe request retry handler.
- 
redirectHandlerprotected final org.apache.http.client.RedirectHandler redirectHandlerThe redirect handler.
- 
targetAuthHandlerprotected final org.apache.http.client.AuthenticationHandler targetAuthHandlerThe target authentication handler.
- 
proxyAuthHandlerprotected final org.apache.http.client.AuthenticationHandler proxyAuthHandlerThe proxy authentication handler.
- 
userTokenHandlerprotected final org.apache.http.client.UserTokenHandler userTokenHandlerThe user token handler.
- 
paramsThe HTTP parameters.
- 
managedConnThe currently allocated connection.
- 
targetAuthStateprotected final org.apache.http.auth.AuthState targetAuthState
- 
proxyAuthStateprotected final org.apache.http.auth.AuthState proxyAuthState
 
- 
- 
Constructor Details- 
DefaultRequestDirectorpublic DefaultRequestDirector(org.apache.commons.logging.Log log, org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, org.apache.http.conn.routing.HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, org.apache.http.client.HttpRequestRetryHandler retryHandler, org.apache.http.client.RedirectHandler redirectHandler, org.apache.http.client.AuthenticationHandler targetAuthHandler, org.apache.http.client.AuthenticationHandler proxyAuthHandler, org.apache.http.client.UserTokenHandler userTokenHandler, HttpParams params)
- 
DefaultRequestDirectorpublic DefaultRequestDirector(org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, org.apache.http.conn.routing.HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, org.apache.http.client.HttpRequestRetryHandler retryHandler, org.apache.http.client.RedirectHandler redirectHandler, org.apache.http.client.AuthenticationHandler targetAuthHandler, org.apache.http.client.AuthenticationHandler proxyAuthHandler, org.apache.http.client.UserTokenHandler userTokenHandler, HttpParams params)
 
- 
- 
Method Details- 
rewriteRequestURIprotected void rewriteRequestURI(org.apache.http.impl.client.RequestWrapper request, org.apache.http.conn.routing.HttpRoute route) throws org.apache.http.ProtocolException- Throws:
- org.apache.http.ProtocolException
 
- 
executepublic org.apache.http.HttpResponse execute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context) throws org.apache.http.HttpException, IOException- Specified by:
- executein interface- org.apache.http.client.RequestDirector
- Throws:
- org.apache.http.HttpException
- IOException
 
- 
releaseConnectionprotected void releaseConnection()Returns the connection back to the connection manager and prepares for retrieving a new connection during the next request.
- 
determineRouteprotected org.apache.http.conn.routing.HttpRoute determineRoute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context) throws org.apache.http.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 accept- nullif they can still determine a route, for example to a default target or by inspecting the request.
- request- the request to execute
- context- the context to use for the execution, never- null
- Returns:
- the route the request should take
- Throws:
- org.apache.http.HttpException- in case of a problem
 
- 
establishRouteprotected void establishRoute(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context) throws org.apache.http.HttpException, IOExceptionEstablishes the target route.- Parameters:
- route- the route to establish
- context- the context for the request execution
- Throws:
- org.apache.http.HttpException- in case of a problem
- IOException- in case of an IO problem
 
- 
createTunnelToTargetprotected boolean createTunnelToTarget(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context) throws org.apache.http.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 establish
- context- the context for request execution
- Returns:
- trueif the tunnelled route is secure,- falseotherwise. The implementation here always returns- false, but derived classes may override.
- Throws:
- org.apache.http.HttpException- in case of a problem
- IOException- in case of an IO problem
 
- 
createTunnelToProxyprotected boolean createTunnelToProxy(org.apache.http.conn.routing.HttpRoute route, int hop, org.apache.http.protocol.HttpContext context) throws org.apache.http.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 establish
- hop- 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:
- org.apache.http.HttpException- in case of a problem
- IOException- in case of an IO problem
 
- 
createConnectRequestprotected org.apache.http.HttpRequest createConnectRequest(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context)Creates the CONNECT request for tunnelling. Called bycreateTunnelToTarget.- Parameters:
- route- the route to establish
- context- the context for request execution
- Returns:
- the CONNECT request for tunnelling
 
- 
handleResponseprotected org.apache.http.impl.client.RoutedRequest handleResponse(org.apache.http.impl.client.RoutedRequest roureq, org.apache.http.HttpResponse response, org.apache.http.protocol.HttpContext context) throws org.apache.http.HttpException, IOExceptionAnalyzes a response to check need for a followup.- Parameters:
- roureq- the request and route.
- response- the response to analayze
- context- 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:
- org.apache.http.HttpException- in case of a problem
- IOException- in case of an IO problem
 
 
-