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_VERSIONCoreProtocolPNames.STRICT_TRANSFER_ENCODINGCoreProtocolPNames.HTTP_ELEMENT_CHARSETCoreProtocolPNames.USE_EXPECT_CONTINUECoreProtocolPNames.WAIT_FOR_CONTINUECoreProtocolPNames.USER_AGENTCoreConnectionPNames.SOCKET_BUFFER_SIZECoreConnectionPNames.MAX_LINE_LENGTHCoreConnectionPNames.MAX_HEADER_COUNTCoreConnectionPNames.SO_TIMEOUTCoreConnectionPNames.SO_LINGERCoreConnectionPNames.TCP_NODELAYCoreConnectionPNames.CONNECTION_TIMEOUTCoreConnectionPNames.STALE_CONNECTION_CHECKConnRoutePNames.FORCED_ROUTEConnRoutePNames.LOCAL_ADDRESSConnRoutePNames.DEFAULT_PROXYConnManagerPNames.TIMEOUTConnManagerPNames.MAX_CONNECTIONS_PER_ROUTEConnManagerPNames.MAX_TOTAL_CONNECTIONSCookieSpecPNames.DATE_PATTERNSCookieSpecPNames.SINGLE_COOKIE_HEADERAuthPNames.CREDENTIAL_CHARSETClientPNames.COOKIE_POLICYClientPNames.HANDLE_AUTHENTICATIONClientPNames.HANDLE_REDIRECTSClientPNames.MAX_REDIRECTSClientPNames.ALLOW_CIRCULAR_REDIRECTSClientPNames.VIRTUAL_HOSTClientPNames.DEFAULT_HOSTClientPNames.DEFAULT_HEADERS
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ClientConnectionManagerThe connection manager.protected final org.apache.http.protocol.HttpProcessorThe HTTP protocol processor.protected final ConnectionKeepAliveStrategyThe keep-alive duration strategy.protected ManagedClientConnectionThe currently allocated connection.protected final HttpParamsThe HTTP parameters.protected final org.apache.http.client.AuthenticationHandlerThe proxy authentication handler.protected final org.apache.http.auth.AuthStateprotected final org.apache.http.client.RedirectHandlerThe redirect handler.protected final org.apache.http.protocol.HttpRequestExecutorThe request executor.protected final org.apache.http.client.HttpRequestRetryHandlerThe request retry handler.protected final org.apache.http.ConnectionReuseStrategyThe connection re-use strategy.protected final org.apache.http.conn.routing.HttpRoutePlannerThe route planner.protected final org.apache.http.client.AuthenticationHandlerThe target authentication handler.protected final org.apache.http.auth.AuthStateprotected final org.apache.http.client.UserTokenHandlerThe user token handler. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultRequestDirector(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 Summary
Modifier and TypeMethodDescriptionprotected 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 voidReturns 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
-
connManager
The connection manager. -
routePlanner
protected final org.apache.http.conn.routing.HttpRoutePlanner routePlannerThe route planner. -
reuseStrategy
protected final org.apache.http.ConnectionReuseStrategy reuseStrategyThe connection re-use strategy. -
keepAliveStrategy
The keep-alive duration strategy. -
requestExec
protected final org.apache.http.protocol.HttpRequestExecutor requestExecThe request executor. -
httpProcessor
protected final org.apache.http.protocol.HttpProcessor httpProcessorThe HTTP protocol processor. -
retryHandler
protected final org.apache.http.client.HttpRequestRetryHandler retryHandlerThe request retry handler. -
redirectHandler
protected final org.apache.http.client.RedirectHandler redirectHandlerThe redirect handler. -
targetAuthHandler
protected final org.apache.http.client.AuthenticationHandler targetAuthHandlerThe target authentication handler. -
proxyAuthHandler
protected final org.apache.http.client.AuthenticationHandler proxyAuthHandlerThe proxy authentication handler. -
userTokenHandler
protected final org.apache.http.client.UserTokenHandler userTokenHandlerThe user token handler. -
params
The HTTP parameters. -
managedConn
The currently allocated connection. -
targetAuthState
protected final org.apache.http.auth.AuthState targetAuthState -
proxyAuthState
protected final org.apache.http.auth.AuthState proxyAuthState
-
-
Constructor Details
-
DefaultRequestDirector
public 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
public 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
-
rewriteRequestURI
protected 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
-
execute
public 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 interfaceorg.apache.http.client.RequestDirector- Throws:
org.apache.http.HttpExceptionIOException
-
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 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.HttpException Determines 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:
org.apache.http.HttpException- in case of a problem
-
establishRoute
protected void establishRoute(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context) throws org.apache.http.HttpException, IOException Establishes the target route.- Parameters:
route- the route to establishcontext- the context for the request execution- Throws:
org.apache.http.HttpException- in case of a problemIOException- in case of an IO problem
-
createTunnelToTarget
protected boolean createTunnelToTarget(org.apache.http.conn.routing.HttpRoute route, org.apache.http.protocol.HttpContext context) throws org.apache.http.HttpException, IOException Creates 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:
org.apache.http.HttpException- in case of a problemIOException- in case of an IO problem
-
createTunnelToProxy
protected boolean createTunnelToProxy(org.apache.http.conn.routing.HttpRoute route, int hop, org.apache.http.protocol.HttpContext context) throws org.apache.http.HttpException, IOException Creates 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:
org.apache.http.HttpException- in case of a problemIOException- in case of an IO problem
-
createConnectRequest
protected 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 establishcontext- the context for request execution- Returns:
- the CONNECT request for tunnelling
-
handleResponse
protected 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, IOException Analyzes 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:
org.apache.http.HttpException- in case of a problemIOException- in case of an IO problem
-