Class AbstractHttpClient
- All Implemented Interfaces:
Closeable,AutoCloseable,HttpClient
- Direct Known Subclasses:
DefaultHttpClient
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:
HttpRequestExecutorobject used to transmit messages over HTTP connections. ThecreateRequestExecutor()must be implemented by concrete super classes to instantiate this object.BasicHttpProcessorobject to manage a list of protocol interceptors and apply cross-cutting protocol logic to all incoming and outgoing HTTP messages. ThecreateHttpProcessor()must be implemented by concrete super classes to instantiate this object.HttpRequestRetryHandlerobject used to decide whether or not a failed HTTP request is safe to retry automatically. ThecreateHttpRequestRetryHandler()must be implemented by concrete super classes to instantiate this object.ClientConnectionManagerobject used to manage persistent HTTP connections.ConnectionReuseStrategyobject used to decide whether or not a HTTP connection can be kept alive and re-used for subsequent HTTP requests. ThecreateConnectionReuseStrategy()must be implemented by concrete super classes to instantiate this object.ConnectionKeepAliveStrategyobject used to decide how long a persistent HTTP connection can be kept alive. ThecreateConnectionKeepAliveStrategy()must be implemented by concrete super classes to instantiate this object.CookieSpecRegistryobject used to maintain a list of supported cookie specifications. ThecreateCookieSpecRegistry()must be implemented by concrete super classes to instantiate this object.CookieStoreobject used to maintain a collection of cookies. ThecreateCookieStore()must be implemented by concrete super classes to instantiate this object.AuthSchemeRegistryobject used to maintain a list of supported authentication schemes. ThecreateAuthSchemeRegistry()must be implemented by concrete super classes to instantiate this object.CredentialsProviderobject used to maintain a collection user credentials. ThecreateCredentialsProvider()must be implemented by concrete super classes to instantiate this object.AuthenticationStrategyobject used to authenticate against the target host. ThecreateTargetAuthenticationStrategy()must be implemented by concrete super classes to instantiate this object.AuthenticationStrategyobject used to authenticate against the proxy host. ThecreateProxyAuthenticationStrategy()must be implemented by concrete super classes to instantiate this object.HttpRoutePlannerobject used to calculate a route for establishing a connection to the target host. The route may involve multiple intermediate hops. ThecreateHttpRoutePlanner()must be implemented by concrete super classes to instantiate this object.RedirectStrategyobject used to determine if an HTTP request should be redirected to a new location in response to an HTTP response received from the target server.UserTokenHandlerobject used to determine if the execution context is user identity specific. ThecreateUserTokenHandler()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()!
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BackoffManagerDeprecated.private ConnectionBackoffStrategyDeprecated.private ClientConnectionManagerDeprecated.private CookieStoreDeprecated.private CredentialsProviderDeprecated.private org.apache.http.params.HttpParamsDeprecated.private ConnectionKeepAliveStrategyDeprecated.private final org.apache.commons.logging.LogDeprecated.private org.apache.http.protocol.BasicHttpProcessorDeprecated.private org.apache.http.protocol.ImmutableHttpProcessorDeprecated.private AuthenticationStrategyDeprecated.private RedirectStrategyDeprecated.private org.apache.http.protocol.HttpRequestExecutorDeprecated.private HttpRequestRetryHandlerDeprecated.private org.apache.http.ConnectionReuseStrategyDeprecated.private HttpRoutePlannerDeprecated.private AuthSchemeRegistryDeprecated.private CookieSpecRegistryDeprecated.private AuthenticationStrategyDeprecated.private UserTokenHandlerDeprecated. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractHttpClient(ClientConnectionManager conman, org.apache.http.params.HttpParams params) Deprecated.Creates a new HTTP client. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp) Deprecated.voidaddRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp, int index) Deprecated.voidaddResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp) Deprecated.voidaddResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp, int index) Deprecated.voidDeprecated.voidDeprecated.voidclose()Deprecated.protected AuthSchemeRegistryDeprecated.protected ClientConnectionManagerDeprecated.protected RequestDirectorcreateClientRequestDirector(org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, org.apache.http.params.HttpParams params) Deprecated.(4.1) do not useprotected RequestDirectorcreateClientRequestDirector(org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, org.apache.http.params.HttpParams params) Deprecated.(4.2) do not useprotected RequestDirectorcreateClientRequestDirector(org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationStrategy targetAuthStrategy, AuthenticationStrategy proxyAuthStrategy, UserTokenHandler userTokenHandler, org.apache.http.params.HttpParams params) Deprecated.protected ConnectionKeepAliveStrategyDeprecated.protected org.apache.http.ConnectionReuseStrategyDeprecated.protected CookieSpecRegistryDeprecated.protected CookieStoreDeprecated.protected CredentialsProviderDeprecated.protected org.apache.http.protocol.HttpContextDeprecated.protected abstract org.apache.http.params.HttpParamsDeprecated.protected abstract org.apache.http.protocol.BasicHttpProcessorDeprecated.protected HttpRequestRetryHandlerDeprecated.protected HttpRoutePlannerDeprecated.protected AuthenticationHandlerDeprecated.(4.2) do not useprotected AuthenticationStrategyDeprecated.protected RedirectHandlerDeprecated.(4.1) do not useprotected org.apache.http.protocol.HttpRequestExecutorDeprecated.protected AuthenticationHandlerDeprecated.(4.2) do not useprotected AuthenticationStrategyDeprecated.protected UserTokenHandlerDeprecated.protected org.apache.http.params.HttpParamsdetermineParams(org.apache.http.HttpRequest req) Deprecated.Obtains parameters for executing a request.protected final CloseableHttpResponsedoExecute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context) Deprecated.final AuthSchemeRegistryDeprecated.final BackoffManagerDeprecated.Deprecated.Deprecated.final ClientConnectionManagerDeprecated.Obtains the connection manager used by this client.final org.apache.http.ConnectionReuseStrategyDeprecated.final CookieSpecRegistryDeprecated.final CookieStoreDeprecated.final CredentialsProviderDeprecated.protected final org.apache.http.protocol.BasicHttpProcessorDeprecated.final HttpRequestRetryHandlerDeprecated.final org.apache.http.params.HttpParamsDeprecated.Obtains the parameters for this client.private org.apache.http.protocol.HttpProcessorDeprecated.final AuthenticationHandlerDeprecated.(4.2) do not usefinal AuthenticationStrategyDeprecated.final RedirectHandlerDeprecated.(4.1) do not usefinal RedirectStrategyDeprecated.final org.apache.http.protocol.HttpRequestExecutorDeprecated.org.apache.http.HttpRequestInterceptorgetRequestInterceptor(int index) Deprecated.intDeprecated.org.apache.http.HttpResponseInterceptorgetResponseInterceptor(int index) Deprecated.intDeprecated.final HttpRoutePlannerDeprecated.final AuthenticationHandlerDeprecated.(4.2) do not usefinal AuthenticationStrategyDeprecated.final UserTokenHandlerDeprecated.voidremoveRequestInterceptorByClass(Class<? extends org.apache.http.HttpRequestInterceptor> clazz) Deprecated.voidremoveResponseInterceptorByClass(Class<? extends org.apache.http.HttpResponseInterceptor> clazz) Deprecated.voidsetAuthSchemes(AuthSchemeRegistry registry) Deprecated.voidsetBackoffManager(BackoffManager manager) Deprecated.voidDeprecated.voidsetCookieSpecs(CookieSpecRegistry registry) Deprecated.voidsetCookieStore(CookieStore cookieStore) Deprecated.voidsetCredentialsProvider(CredentialsProvider credsProvider) Deprecated.voidDeprecated.voidDeprecated.voidsetParams(org.apache.http.params.HttpParams params) Deprecated.Replaces the parameters.voidDeprecated.(4.2) do not usevoidDeprecated.voidsetRedirectHandler(RedirectHandler handler) Deprecated.(4.1) do not usevoidsetRedirectStrategy(RedirectStrategy strategy) Deprecated.voidsetReuseStrategy(org.apache.http.ConnectionReuseStrategy strategy) Deprecated.voidsetRoutePlanner(HttpRoutePlanner routePlanner) Deprecated.voidDeprecated.(4.2) do not usevoidDeprecated.voidsetUserTokenHandler(UserTokenHandler handler) Deprecated.
-
Field Details
-
log
private final org.apache.commons.logging.Log logDeprecated. -
defaultParams
private org.apache.http.params.HttpParams defaultParamsDeprecated. -
requestExec
private org.apache.http.protocol.HttpRequestExecutor requestExecDeprecated. -
connManager
Deprecated. -
reuseStrategy
private org.apache.http.ConnectionReuseStrategy reuseStrategyDeprecated. -
keepAliveStrategy
Deprecated. -
supportedCookieSpecs
Deprecated. -
supportedAuthSchemes
Deprecated. -
mutableProcessor
private org.apache.http.protocol.BasicHttpProcessor mutableProcessorDeprecated. -
protocolProcessor
private org.apache.http.protocol.ImmutableHttpProcessor protocolProcessorDeprecated. -
retryHandler
Deprecated. -
redirectStrategy
Deprecated. -
targetAuthStrategy
Deprecated. -
proxyAuthStrategy
Deprecated. -
cookieStore
Deprecated. -
credsProvider
Deprecated. -
routePlanner
Deprecated. -
userTokenHandler
Deprecated. -
connectionBackoffStrategy
Deprecated. -
backoffManager
Deprecated.
-
-
Constructor Details
-
AbstractHttpClient
protected AbstractHttpClient(ClientConnectionManager conman, org.apache.http.params.HttpParams params) Deprecated.Creates a new HTTP client.- Parameters:
conman- the connection managerparams- the parameters
-
-
Method Details
-
createHttpParams
protected abstract org.apache.http.params.HttpParams createHttpParams()Deprecated. -
createHttpProcessor
protected abstract org.apache.http.protocol.BasicHttpProcessor createHttpProcessor()Deprecated. -
createHttpContext
protected org.apache.http.protocol.HttpContext createHttpContext()Deprecated. -
createClientConnectionManager
Deprecated. -
createAuthSchemeRegistry
Deprecated. -
createCookieSpecRegistry
Deprecated. -
createRequestExecutor
protected org.apache.http.protocol.HttpRequestExecutor createRequestExecutor()Deprecated. -
createConnectionReuseStrategy
protected org.apache.http.ConnectionReuseStrategy createConnectionReuseStrategy()Deprecated. -
createConnectionKeepAliveStrategy
Deprecated. -
createHttpRequestRetryHandler
Deprecated. -
createRedirectHandler
Deprecated.(4.1) do not use -
createTargetAuthenticationStrategy
Deprecated. -
createTargetAuthenticationHandler
Deprecated.(4.2) do not use -
createProxyAuthenticationStrategy
Deprecated. -
createProxyAuthenticationHandler
Deprecated.(4.2) do not use -
createCookieStore
Deprecated. -
createCredentialsProvider
Deprecated. -
createHttpRoutePlanner
Deprecated. -
createUserTokenHandler
Deprecated. -
getParams
public final org.apache.http.params.HttpParams getParams()Deprecated.Description copied from interface:HttpClientObtains the parameters for this client. These parameters will become defaults for all requests being executed with this client, and for the parameters of dependent objects in this client.- Returns:
- the default parameters
-
setParams
public void setParams(org.apache.http.params.HttpParams params) Deprecated.Replaces the parameters. The implementation here does not update parameters of dependent objects.- Parameters:
params- the new default parameters
-
getConnectionManager
Deprecated.Description copied from interface:HttpClientObtains the connection manager used by this client.- Returns:
- the connection manager
-
getRequestExecutor
public final org.apache.http.protocol.HttpRequestExecutor getRequestExecutor()Deprecated. -
getAuthSchemes
Deprecated. -
setAuthSchemes
Deprecated. -
getConnectionBackoffStrategy
Deprecated. -
setConnectionBackoffStrategy
Deprecated. -
getCookieSpecs
Deprecated. -
getBackoffManager
Deprecated. -
setBackoffManager
Deprecated. -
setCookieSpecs
Deprecated. -
getConnectionReuseStrategy
public final org.apache.http.ConnectionReuseStrategy getConnectionReuseStrategy()Deprecated. -
setReuseStrategy
public void setReuseStrategy(org.apache.http.ConnectionReuseStrategy strategy) Deprecated. -
getConnectionKeepAliveStrategy
Deprecated. -
setKeepAliveStrategy
Deprecated. -
getHttpRequestRetryHandler
Deprecated. -
setHttpRequestRetryHandler
Deprecated. -
getRedirectHandler
Deprecated.(4.1) do not use -
setRedirectHandler
Deprecated.(4.1) do not use -
getRedirectStrategy
Deprecated.- Since:
- 4.1
-
setRedirectStrategy
Deprecated.- Since:
- 4.1
-
getTargetAuthenticationHandler
Deprecated.(4.2) do not use -
setTargetAuthenticationHandler
Deprecated.(4.2) do not use -
getTargetAuthenticationStrategy
Deprecated.- Since:
- 4.2
-
setTargetAuthenticationStrategy
Deprecated.- Since:
- 4.2
-
getProxyAuthenticationHandler
Deprecated.(4.2) do not use -
setProxyAuthenticationHandler
Deprecated.(4.2) do not use -
getProxyAuthenticationStrategy
Deprecated.- Since:
- 4.2
-
setProxyAuthenticationStrategy
Deprecated.- Since:
- 4.2
-
getCookieStore
Deprecated. -
setCookieStore
Deprecated. -
getCredentialsProvider
Deprecated. -
setCredentialsProvider
Deprecated. -
getRoutePlanner
Deprecated. -
setRoutePlanner
Deprecated. -
getUserTokenHandler
Deprecated. -
setUserTokenHandler
Deprecated. -
getHttpProcessor
protected final org.apache.http.protocol.BasicHttpProcessor getHttpProcessor()Deprecated. -
getProtocolProcessor
private org.apache.http.protocol.HttpProcessor getProtocolProcessor()Deprecated. -
getResponseInterceptorCount
public int getResponseInterceptorCount()Deprecated. -
getResponseInterceptor
public org.apache.http.HttpResponseInterceptor getResponseInterceptor(int index) Deprecated. -
getRequestInterceptor
public org.apache.http.HttpRequestInterceptor getRequestInterceptor(int index) Deprecated. -
getRequestInterceptorCount
public int getRequestInterceptorCount()Deprecated. -
addResponseInterceptor
public void addResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp) Deprecated. -
addResponseInterceptor
public void addResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp, int index) Deprecated. -
clearResponseInterceptors
public void clearResponseInterceptors()Deprecated. -
removeResponseInterceptorByClass
public void removeResponseInterceptorByClass(Class<? extends org.apache.http.HttpResponseInterceptor> clazz) Deprecated. -
addRequestInterceptor
public void addRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp) Deprecated. -
addRequestInterceptor
public void addRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp, int index) Deprecated. -
clearRequestInterceptors
public void clearRequestInterceptors()Deprecated. -
removeRequestInterceptorByClass
public void removeRequestInterceptorByClass(Class<? extends org.apache.http.HttpRequestInterceptor> clazz) Deprecated. -
doExecute
protected final CloseableHttpResponse doExecute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context) throws IOException, ClientProtocolException Deprecated.- Specified by:
doExecutein classCloseableHttpClient- Throws:
IOExceptionClientProtocolException
-
createClientRequestDirector
@Deprecated protected RequestDirector createClientRequestDirector(org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, org.apache.http.params.HttpParams params) Deprecated.(4.1) do not use -
createClientRequestDirector
@Deprecated protected RequestDirector createClientRequestDirector(org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler userTokenHandler, org.apache.http.params.HttpParams params) Deprecated.(4.2) do not use -
createClientRequestDirector
protected RequestDirector createClientRequestDirector(org.apache.http.protocol.HttpRequestExecutor requestExec, ClientConnectionManager conman, org.apache.http.ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, org.apache.http.protocol.HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationStrategy targetAuthStrategy, AuthenticationStrategy proxyAuthStrategy, UserTokenHandler userTokenHandler, org.apache.http.params.HttpParams params) Deprecated.- Since:
- 4.2
-
determineParams
protected org.apache.http.params.HttpParams determineParams(org.apache.http.HttpRequest req) Deprecated.Obtains parameters for executing a request. The default implementation in this class creates a newClientParamsStackfrom the request parameters and the client parameters.This method is called by the default implementation of
CloseableHttpClient.execute(HttpHost,HttpRequest,HttpContext)to obtain the parameters for theDefaultRequestDirector.- Parameters:
req- the request that will be executed- Returns:
- the parameters to use
-
close
public void close()Deprecated.
-
HttpClientBuilder.