@ThreadSafe public abstract class AbstractHttpClient extends Object implements HttpClient
HttpClient implementations. This class acts as
a facade to a number of special purpose handler or strategy
implementations responsible for handling of a particular aspect of
the HTTP protocol such as redirect or authentication handling or
making decision about connection persistence and keep alive duration.
This enables the users to selectively replace default implementation
of those aspects with custom, application specific ones. This class
also provides factory methods to instantiate those objects:
HttpRequestExecutorcreateRequestExecutor() must be
implemented by concrete super classes to instantiate this object.
BasicHttpProcessorcreateHttpProcessor() must be
implemented by concrete super classes to instantiate this object.
HttpRequestRetryHandlercreateHttpRequestRetryHandler() must be
implemented by concrete super classes to instantiate this object.
ClientConnectionManagerConnectionReuseStrategycreateConnectionReuseStrategy() must be
implemented by concrete super classes to instantiate this object.
ConnectionKeepAliveStrategycreateConnectionKeepAliveStrategy() must be
implemented by concrete super classes to instantiate this object.
CookieSpecRegistrycreateCookieSpecRegistry() must be implemented by concrete
super classes to instantiate this object.
CookieStorecreateCookieStore() must be implemented by
concrete super classes to instantiate this object.
AuthSchemeRegistrycreateAuthSchemeRegistry() must be implemented by concrete
super classes to instantiate this object.
CredentialsProvidercreateCredentialsProvider()
must be implemented by concrete super classes to instantiate
this object.
AuthenticationStrategycreateTargetAuthenticationStrategy() must be implemented
by concrete super classes to instantiate this object.
AuthenticationStrategycreateProxyAuthenticationStrategy() must be implemented
by concrete super classes to instantiate this object.
HttpRoutePlannercreateHttpRoutePlanner() must be implemented
by concrete super classes to instantiate this object.
RedirectStrategyUserTokenHandlercreateUserTokenHandler() must be implemented by
concrete super classes to instantiate this object.
This class also maintains a list of protocol interceptors intended
for processing outgoing requests and incoming responses and provides
methods for managing those interceptors. New protocol interceptors can be
introduced to the protocol processor chain or removed from it if needed.
Internally protocol interceptors are stored in a simple
ArrayList. They are executed in the same natural order
as they are added to the list.
AbstractHttpClient is thread safe. It is recommended that the same
instance of this class is reused for multiple request executions.
When an instance of DefaultHttpClient is no longer needed and is about
to go out of scope the connection manager associated with it must be
shut down by calling ClientConnectionManager.shutdown()!
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractHttpClient(ClientConnectionManager conman,
HttpParams params)
Creates a new HTTP client.
|
protected AbstractHttpClient(ClientConnectionManager conman, HttpParams params)
conman - the connection managerparams - the parametersprotected abstract HttpParams createHttpParams()
protected abstract BasicHttpProcessor createHttpProcessor()
protected HttpContext createHttpContext()
protected ClientConnectionManager createClientConnectionManager()
protected AuthSchemeRegistry createAuthSchemeRegistry()
protected CookieSpecRegistry createCookieSpecRegistry()
protected HttpRequestExecutor createRequestExecutor()
protected ConnectionReuseStrategy createConnectionReuseStrategy()
protected ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
protected HttpRequestRetryHandler createHttpRequestRetryHandler()
@Deprecated protected RedirectHandler createRedirectHandler()
protected AuthenticationStrategy createTargetAuthenticationStrategy()
@Deprecated protected AuthenticationHandler createTargetAuthenticationHandler()
protected AuthenticationStrategy createProxyAuthenticationStrategy()
@Deprecated protected AuthenticationHandler createProxyAuthenticationHandler()
protected CookieStore createCookieStore()
protected CredentialsProvider createCredentialsProvider()
protected HttpRoutePlanner createHttpRoutePlanner()
protected UserTokenHandler createUserTokenHandler()
public final HttpParams getParams()
HttpClientgetParams in interface HttpClientpublic void setParams(HttpParams params)
params - the new default parameterspublic final ClientConnectionManager getConnectionManager()
HttpClientgetConnectionManager in interface HttpClientpublic final HttpRequestExecutor getRequestExecutor()
public final AuthSchemeRegistry getAuthSchemes()
public void setAuthSchemes(AuthSchemeRegistry registry)
public final ConnectionBackoffStrategy getConnectionBackoffStrategy()
public void setConnectionBackoffStrategy(ConnectionBackoffStrategy strategy)
public final CookieSpecRegistry getCookieSpecs()
public final BackoffManager getBackoffManager()
public void setBackoffManager(BackoffManager manager)
public void setCookieSpecs(CookieSpecRegistry registry)
public final ConnectionReuseStrategy getConnectionReuseStrategy()
public void setReuseStrategy(ConnectionReuseStrategy strategy)
public final ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy()
public void setKeepAliveStrategy(ConnectionKeepAliveStrategy strategy)
public final HttpRequestRetryHandler getHttpRequestRetryHandler()
public void setHttpRequestRetryHandler(HttpRequestRetryHandler handler)
@Deprecated public final RedirectHandler getRedirectHandler()
@Deprecated public void setRedirectHandler(RedirectHandler handler)
public final RedirectStrategy getRedirectStrategy()
public void setRedirectStrategy(RedirectStrategy strategy)
@Deprecated public final AuthenticationHandler getTargetAuthenticationHandler()
@Deprecated public void setTargetAuthenticationHandler(AuthenticationHandler handler)
public final AuthenticationStrategy getTargetAuthenticationStrategy()
public void setTargetAuthenticationStrategy(AuthenticationStrategy strategy)
@Deprecated public final AuthenticationHandler getProxyAuthenticationHandler()
@Deprecated public void setProxyAuthenticationHandler(AuthenticationHandler handler)
public final AuthenticationStrategy getProxyAuthenticationStrategy()
public void setProxyAuthenticationStrategy(AuthenticationStrategy strategy)
public final CookieStore getCookieStore()
public void setCookieStore(CookieStore cookieStore)
public final CredentialsProvider getCredentialsProvider()
public void setCredentialsProvider(CredentialsProvider credsProvider)
public final HttpRoutePlanner getRoutePlanner()
public void setRoutePlanner(HttpRoutePlanner routePlanner)
public final UserTokenHandler getUserTokenHandler()
public void setUserTokenHandler(UserTokenHandler handler)
protected final BasicHttpProcessor getHttpProcessor()
public int getResponseInterceptorCount()
public HttpResponseInterceptor getResponseInterceptor(int index)
public HttpRequestInterceptor getRequestInterceptor(int index)
public int getRequestInterceptorCount()
public void addResponseInterceptor(HttpResponseInterceptor itcp)
public void addResponseInterceptor(HttpResponseInterceptor itcp, int index)
public void clearResponseInterceptors()
public void removeResponseInterceptorByClass(Class<? extends HttpResponseInterceptor> clazz)
public void addRequestInterceptor(HttpRequestInterceptor itcp)
public void addRequestInterceptor(HttpRequestInterceptor itcp, int index)
public void clearRequestInterceptors()
public void removeRequestInterceptorByClass(Class<? extends HttpRequestInterceptor> clazz)
public final HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException
HttpClientexecute in interface HttpClientrequest - the request to executeIOException - in case of a problem or the connection was abortedClientProtocolException - in case of an http protocol errorpublic final HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException
execute(target, request, context).
The target is determined from the URI of the request.execute in interface HttpClientrequest - the request to executecontext - the request-specific execution context,
or null to use a default contextIOException - in case of a problem or the connection was abortedClientProtocolException - in case of an http protocol errorpublic final HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException
HttpClientexecute in interface HttpClienttarget - the target host for the request.
Implementations may accept null
if they can still determine a route, for example
to a default target or by inspecting the request.request - the request to executeIOException - in case of a problem or the connection was abortedClientProtocolException - in case of an http protocol errorpublic final HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException
HttpClientexecute in interface HttpClienttarget - the target host for the request.
Implementations may accept null
if 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, or
null to use the default contextIOException - in case of a problem or the connection was abortedClientProtocolException - in case of an http protocol error@Deprecated protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, HttpParams params)
@Deprecated protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, HttpParams params)
protected RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationStrategy targetAuthStrategy, AuthenticationStrategy proxyAuthStrategy, UserTokenHandler userTokenHandler, HttpParams params)
protected HttpParams determineParams(HttpRequest req)
ClientParamsStack from the request parameters
and the client parameters.
execute(HttpHost,HttpRequest,HttpContext)
to obtain the parameters for the
DefaultRequestDirector.req - the request that will be executedpublic <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException
ResponseHandlers from having to manage
resource deallocation internally.execute in interface HttpClientrequest - the request to executeresponseHandler - the response handlerIOException - in case of a problem or the connection was abortedClientProtocolException - in case of an http protocol errorpublic <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException, ClientProtocolException
ResponseHandlers from having to manage
resource deallocation internally.execute in interface HttpClientrequest - the request to executeresponseHandler - the response handlercontext - the context to use for the execution, or
null to use the default contextIOException - in case of a problem or the connection was abortedClientProtocolException - in case of an http protocol errorpublic <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException
ResponseHandlers from having to manage
resource deallocation internally.execute in interface HttpClienttarget - the target host for the request.
Implementations may accept null
if they can still determine a route, for example
to a default target or by inspecting the request.request - the request to executeresponseHandler - the response handlerIOException - in case of a problem or the connection was abortedClientProtocolException - in case of an http protocol errorpublic <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException, ClientProtocolException
ResponseHandlers from having to manage
resource deallocation internally.execute in interface HttpClienttarget - the target host for the request.
Implementations may accept null
if they can still determine a route, for example
to a default target or by inspecting the request.request - the request to executeresponseHandler - the response handlercontext - the context to use for the execution, or
null to use the default contextIOException - in case of a problem or the connection was abortedClientProtocolException - in case of an http protocol errorCopyright © 1999–2013 The Apache Software Foundation. All rights reserved.