public abstract class

AbstractHttpClient

extends Object
implements HttpClient
java.lang.Object
   ↳ org.apache.http.impl.client.AbstractHttpClient
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Base class for 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:

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 java.util.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 shutdown()!

Summary

Protected Constructors
AbstractHttpClient(ClientConnectionManager conman, HttpParams params)
Creates a new HTTP client.
Public Methods
synchronized void addRequestInterceptor(HttpRequestInterceptor itcp)
synchronized void addRequestInterceptor(HttpRequestInterceptor itcp, int index)
synchronized void addResponseInterceptor(HttpResponseInterceptor itcp, int index)
synchronized void addResponseInterceptor(HttpResponseInterceptor itcp)
synchronized void clearRequestInterceptors()
synchronized void clearResponseInterceptors()
final HttpResponse execute(HttpUriRequest request)
Executes a request using the default context.
<T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
Executes a request using the given context and processes the response using the given response handler.
final HttpResponse execute(HttpUriRequest request, HttpContext context)
<T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler)
Executes a request to the target using the default context and processes the response using the given response handler.
final HttpResponse execute(HttpHost target, HttpRequest request)
Executes a request to the target using the default context.
final HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context)
Executes a request to the target using the given context.
<T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)
Executes a request to the target using the given context and processes the response using the given response handler.
<T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler)
Executes a request using the default context and processes the response using the given response handler.
synchronized final AuthSchemeRegistry getAuthSchemes()
synchronized final ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy()
synchronized final ClientConnectionManager getConnectionManager()
Obtains the connection manager used by this client.
synchronized final ConnectionReuseStrategy getConnectionReuseStrategy()
synchronized final CookieSpecRegistry getCookieSpecs()
synchronized final CookieStore getCookieStore()
synchronized final CredentialsProvider getCredentialsProvider()
synchronized final HttpRequestRetryHandler getHttpRequestRetryHandler()
synchronized final HttpParams getParams()
Obtains the parameters for this client.
synchronized final AuthenticationHandler getProxyAuthenticationHandler()
synchronized final RedirectHandler getRedirectHandler()
synchronized final RedirectStrategy getRedirectStrategy()
synchronized final HttpRequestExecutor getRequestExecutor()
synchronized HttpRequestInterceptor getRequestInterceptor(int index)
synchronized int getRequestInterceptorCount()
synchronized HttpResponseInterceptor getResponseInterceptor(int index)
synchronized int getResponseInterceptorCount()
synchronized final HttpRoutePlanner getRoutePlanner()
synchronized final AuthenticationHandler getTargetAuthenticationHandler()
synchronized final UserTokenHandler getUserTokenHandler()
synchronized void removeRequestInterceptorByClass(Class<? extends HttpRequestInterceptor> clazz)
synchronized void removeResponseInterceptorByClass(Class<? extends HttpResponseInterceptor> clazz)
synchronized void setAuthSchemes(AuthSchemeRegistry authSchemeRegistry)
synchronized void setCookieSpecs(CookieSpecRegistry cookieSpecRegistry)
synchronized void setCookieStore(CookieStore cookieStore)
synchronized void setCredentialsProvider(CredentialsProvider credsProvider)
synchronized void setHttpRequestRetryHandler(HttpRequestRetryHandler retryHandler)
synchronized void setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy)
synchronized void setParams(HttpParams params)
Replaces the parameters.
synchronized void setProxyAuthenticationHandler(AuthenticationHandler proxyAuthHandler)
synchronized void setRedirectHandler(RedirectHandler redirectHandler)
synchronized void setRedirectStrategy(RedirectStrategy redirectStrategy)
synchronized void setReuseStrategy(ConnectionReuseStrategy reuseStrategy)
synchronized void setRoutePlanner(HttpRoutePlanner routePlanner)
synchronized void setTargetAuthenticationHandler(AuthenticationHandler targetAuthHandler)
synchronized void setUserTokenHandler(UserTokenHandler userTokenHandler)
Protected Methods
AuthSchemeRegistry createAuthSchemeRegistry()
ClientConnectionManager createClientConnectionManager()
RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler stateHandler, HttpParams params)
RequestDirector createClientRequestDirector(HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler stateHandler, HttpParams params)
ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
ConnectionReuseStrategy createConnectionReuseStrategy()
CookieSpecRegistry createCookieSpecRegistry()
CookieStore createCookieStore()
CredentialsProvider createCredentialsProvider()
HttpContext createHttpContext()
abstract HttpParams createHttpParams()
abstract BasicHttpProcessor createHttpProcessor()
HttpRequestRetryHandler createHttpRequestRetryHandler()
HttpRoutePlanner createHttpRoutePlanner()
AuthenticationHandler createProxyAuthenticationHandler()
RedirectHandler createRedirectHandler()
HttpRequestExecutor createRequestExecutor()
AuthenticationHandler createTargetAuthenticationHandler()
UserTokenHandler createUserTokenHandler()
HttpParams determineParams(HttpRequest req)
Obtains parameters for executing a request.
synchronized final BasicHttpProcessor getHttpProcessor()
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.http.client.HttpClient

Protected Constructors

protected AbstractHttpClient (ClientConnectionManager conman, HttpParams params)

Also: HttpClient

Creates a new HTTP client.

Parameters
conman the connection manager
params the parameters

Public Methods

public synchronized void addRequestInterceptor (HttpRequestInterceptor itcp)

Also: HttpClient

public synchronized void addRequestInterceptor (HttpRequestInterceptor itcp, int index)

Also: HttpClient

public synchronized void addResponseInterceptor (HttpResponseInterceptor itcp, int index)

Also: HttpClient

public synchronized void addResponseInterceptor (HttpResponseInterceptor itcp)

Also: HttpClient

public synchronized void clearRequestInterceptors ()

Also: HttpClient

public synchronized void clearResponseInterceptors ()

Also: HttpClient

public final HttpResponse execute (HttpUriRequest request)

Also: HttpClient

Executes a request using the default context.

Parameters
request the request to execute
Returns
  • the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.

public T execute (HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)

Also: HttpClient

Executes a request using the given context and processes the response using the given response handler.

Parameters
request the request to execute
responseHandler the response handler
Returns
  • the response object as generated by the response handler.

public final HttpResponse execute (HttpUriRequest request, HttpContext context)

Also: HttpClient

Maps to execute(target, request, context). The target is determined from the URI of the request.

Parameters
request the request to execute
context the request-specific execution context, or null to use a default context
Returns
  • the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.

public T execute (HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler)

Also: HttpClient

Executes a request to the target using the default context and processes the response using the given response handler.

Parameters
target 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 execute
responseHandler the response handler
Returns
  • the response object as generated by the response handler.

public final HttpResponse execute (HttpHost target, HttpRequest request)

Also: HttpClient

Executes a request to the target using the default context.

Parameters
target 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 execute
Returns
  • the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.

public final HttpResponse execute (HttpHost target, HttpRequest request, HttpContext context)

Also: HttpClient

Executes a request to the target using the given context.

Parameters
target 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 execute
context the context to use for the execution, or null to use the default context
Returns
  • the response to the request. This is always a final response, never an intermediate response with an 1xx status code. Whether redirects or authentication challenges will be returned or handled automatically depends on the implementation and configuration of this client.

public T execute (HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context)

Also: HttpClient

Executes a request to the target using the given context and processes the response using the given response handler.

Parameters
target 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 execute
responseHandler the response handler
context the context to use for the execution, or null to use the default context
Returns
  • the response object as generated by the response handler.

public T execute (HttpUriRequest request, ResponseHandler<? extends T> responseHandler)

Also: HttpClient

Executes a request using the default context and processes the response using the given response handler.

Parameters
request the request to execute
responseHandler the response handler
Returns
  • the response object as generated by the response handler.

public final synchronized AuthSchemeRegistry getAuthSchemes ()

Also: HttpClient

public final synchronized ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy ()

Also: HttpClient

public final synchronized ClientConnectionManager getConnectionManager ()

Also: HttpClient

Obtains the connection manager used by this client.

Returns
  • the connection manager

public final synchronized ConnectionReuseStrategy getConnectionReuseStrategy ()

Also: HttpClient

public final synchronized CookieSpecRegistry getCookieSpecs ()

Also: HttpClient

public final synchronized CookieStore getCookieStore ()

Also: HttpClient

public final synchronized CredentialsProvider getCredentialsProvider ()

Also: HttpClient

public final synchronized HttpRequestRetryHandler getHttpRequestRetryHandler ()

Also: HttpClient

public final synchronized HttpParams getParams ()

Also: HttpClient

Obtains 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

public final synchronized AuthenticationHandler getProxyAuthenticationHandler ()

Also: HttpClient

public final synchronized RedirectHandler getRedirectHandler ()

Also: HttpClient

public final synchronized RedirectStrategy getRedirectStrategy ()

Also: HttpClient

public final synchronized HttpRequestExecutor getRequestExecutor ()

Also: HttpClient

public synchronized HttpRequestInterceptor getRequestInterceptor (int index)

Also: HttpClient

public synchronized int getRequestInterceptorCount ()

Also: HttpClient

public synchronized HttpResponseInterceptor getResponseInterceptor (int index)

Also: HttpClient

public synchronized int getResponseInterceptorCount ()

Also: HttpClient

public final synchronized HttpRoutePlanner getRoutePlanner ()

Also: HttpClient

public final synchronized AuthenticationHandler getTargetAuthenticationHandler ()

Also: HttpClient

public final synchronized UserTokenHandler getUserTokenHandler ()

Also: HttpClient

public synchronized void removeRequestInterceptorByClass (Class<? extends HttpRequestInterceptor> clazz)

Also: HttpClient

public synchronized void removeResponseInterceptorByClass (Class<? extends HttpResponseInterceptor> clazz)

Also: HttpClient

public synchronized void setAuthSchemes (AuthSchemeRegistry authSchemeRegistry)

Also: HttpClient

public synchronized void setCookieSpecs (CookieSpecRegistry cookieSpecRegistry)

Also: HttpClient

public synchronized void setCookieStore (CookieStore cookieStore)

Also: HttpClient

public synchronized void setCredentialsProvider (CredentialsProvider credsProvider)

Also: HttpClient

public synchronized void setHttpRequestRetryHandler (HttpRequestRetryHandler retryHandler)

Also: HttpClient

public synchronized void setKeepAliveStrategy (ConnectionKeepAliveStrategy keepAliveStrategy)

Also: HttpClient

public synchronized void setParams (HttpParams params)

Also: HttpClient

Replaces the parameters. The implementation here does not update parameters of dependent objects.

Parameters
params the new default parameters

public synchronized void setProxyAuthenticationHandler (AuthenticationHandler proxyAuthHandler)

Also: HttpClient

public synchronized void setRedirectHandler (RedirectHandler redirectHandler)

Also: HttpClient

public synchronized void setRedirectStrategy (RedirectStrategy redirectStrategy)

Also: HttpClient

public synchronized void setReuseStrategy (ConnectionReuseStrategy reuseStrategy)

Also: HttpClient

public synchronized void setRoutePlanner (HttpRoutePlanner routePlanner)

Also: HttpClient

public synchronized void setTargetAuthenticationHandler (AuthenticationHandler targetAuthHandler)

Also: HttpClient

public synchronized void setUserTokenHandler (UserTokenHandler userTokenHandler)

Also: HttpClient

Protected Methods

protected AuthSchemeRegistry createAuthSchemeRegistry ()

Also: HttpClient

protected ClientConnectionManager createClientConnectionManager ()

Also: HttpClient

protected RequestDirector createClientRequestDirector (HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectHandler redirectHandler, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler stateHandler, HttpParams params)

Also: HttpClient

protected RequestDirector createClientRequestDirector (HttpRequestExecutor requestExec, ClientConnectionManager conman, ConnectionReuseStrategy reustrat, ConnectionKeepAliveStrategy kastrat, HttpRoutePlanner rouplan, HttpProcessor httpProcessor, HttpRequestRetryHandler retryHandler, RedirectStrategy redirectStrategy, AuthenticationHandler targetAuthHandler, AuthenticationHandler proxyAuthHandler, UserTokenHandler stateHandler, HttpParams params)

Also: HttpClient

protected ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy ()

Also: HttpClient

protected ConnectionReuseStrategy createConnectionReuseStrategy ()

Also: HttpClient

protected CookieSpecRegistry createCookieSpecRegistry ()

Also: HttpClient

protected CookieStore createCookieStore ()

Also: HttpClient

protected CredentialsProvider createCredentialsProvider ()

Also: HttpClient

protected HttpContext createHttpContext ()

Also: HttpClient

protected abstract HttpParams createHttpParams ()

Also: HttpClient

protected abstract BasicHttpProcessor createHttpProcessor ()

Also: HttpClient

protected HttpRequestRetryHandler createHttpRequestRetryHandler ()

Also: HttpClient

protected HttpRoutePlanner createHttpRoutePlanner ()

Also: HttpClient

protected AuthenticationHandler createProxyAuthenticationHandler ()

Also: HttpClient

protected RedirectHandler createRedirectHandler ()

Also: HttpClient

protected HttpRequestExecutor createRequestExecutor ()

Also: HttpClient

protected AuthenticationHandler createTargetAuthenticationHandler ()

Also: HttpClient

protected UserTokenHandler createUserTokenHandler ()

Also: HttpClient

protected HttpParams determineParams (HttpRequest req)

Also: HttpClient

Obtains parameters for executing a request. The default implementation in this class creates a new ClientParamsStack from the request parameters and the client parameters.
This method is called by the default implementation of execute(HttpHost, HttpRequest, HttpContext) to obtain the parameters for the DefaultRequestDirector.

Parameters
req the request that will be executed
Returns
  • the parameters to use

protected final synchronized BasicHttpProcessor getHttpProcessor ()

Also: HttpClient