public abstract class

AbstractHttpClient

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

Class Overview

Convenience base class for HTTP client implementations.

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, HttpContext context)
final HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context)
Executes a request to the target using the given context.
<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.
<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(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(HttpUriRequest request)
Executes a request using the default context.
final HttpResponse execute(HttpHost target, HttpRequest request)
Executes a request to the target 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.
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 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()
void removeRequestInterceptorByClass(Class<? extends HttpRequestInterceptor> clazz)
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 setReuseStrategy(ConnectionReuseStrategy reuseStrategy)
synchronized void setRoutePlanner(HttpRoutePlanner routePlanner)
synchronized void setTargetAuthenticationHandler(AuthenticationHandler targetAuthHandler)
synchronized void setUserTokenHandler(UserTokenHandler userTokenHandler)
Protected Methods
abstract AuthSchemeRegistry createAuthSchemeRegistry()
abstract 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)
abstract ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
abstract ConnectionReuseStrategy createConnectionReuseStrategy()
abstract CookieSpecRegistry createCookieSpecRegistry()
abstract CookieStore createCookieStore()
abstract CredentialsProvider createCredentialsProvider()
abstract HttpContext createHttpContext()
abstract HttpParams createHttpParams()
abstract BasicHttpProcessor createHttpProcessor()
abstract HttpRequestRetryHandler createHttpRequestRetryHandler()
abstract HttpRoutePlanner createHttpRoutePlanner()
abstract AuthenticationHandler createProxyAuthenticationHandler()
abstract RedirectHandler createRedirectHandler()
abstract HttpRequestExecutor createRequestExecutor()
abstract AuthenticationHandler createTargetAuthenticationHandler()
abstract 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)

Creates a new HTTP client.

Parameters
conman the connection manager
params the parameters

Public Methods

public synchronized void addRequestInterceptor (HttpRequestInterceptor itcp)

public synchronized void addRequestInterceptor (HttpRequestInterceptor itcp, int index)

public synchronized void addResponseInterceptor (HttpResponseInterceptor itcp, int index)

public synchronized void addResponseInterceptor (HttpResponseInterceptor itcp)

public synchronized void clearRequestInterceptors ()

public synchronized void clearResponseInterceptors ()

public final HttpResponse execute (HttpUriRequest request, HttpContext context)

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 final HttpResponse execute (HttpHost target, HttpRequest request, HttpContext context)

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 (HttpUriRequest request, ResponseHandler<? extends T> responseHandler)

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 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.

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 (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.

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 (HttpUriRequest request)

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 final HttpResponse execute (HttpHost target, HttpRequest request)

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 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.

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 ()

public final synchronized ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy ()

public final synchronized ClientConnectionManager getConnectionManager ()

Obtains the connection manager used by this client.

Returns
  • the connection manager

public final synchronized ConnectionReuseStrategy getConnectionReuseStrategy ()

public final synchronized CookieSpecRegistry getCookieSpecs ()

public final synchronized CookieStore getCookieStore ()

public final synchronized CredentialsProvider getCredentialsProvider ()

public final synchronized HttpRequestRetryHandler getHttpRequestRetryHandler ()

public final synchronized HttpParams getParams ()

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 ()

public final synchronized RedirectHandler getRedirectHandler ()

public final synchronized HttpRequestExecutor getRequestExecutor ()

public synchronized HttpRequestInterceptor getRequestInterceptor (int index)

public synchronized int getRequestInterceptorCount ()

public synchronized HttpResponseInterceptor getResponseInterceptor (int index)

public synchronized int getResponseInterceptorCount ()

public final synchronized HttpRoutePlanner getRoutePlanner ()

public final synchronized AuthenticationHandler getTargetAuthenticationHandler ()

public final synchronized UserTokenHandler getUserTokenHandler ()

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

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

public synchronized void setAuthSchemes (AuthSchemeRegistry authSchemeRegistry)

public synchronized void setCookieSpecs (CookieSpecRegistry cookieSpecRegistry)

public synchronized void setCookieStore (CookieStore cookieStore)

public synchronized void setCredentialsProvider (CredentialsProvider credsProvider)

public synchronized void setHttpRequestRetryHandler (HttpRequestRetryHandler retryHandler)

public synchronized void setKeepAliveStrategy (ConnectionKeepAliveStrategy keepAliveStrategy)

public synchronized void setParams (HttpParams params)

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)

public synchronized void setRedirectHandler (RedirectHandler redirectHandler)

public synchronized void setReuseStrategy (ConnectionReuseStrategy reuseStrategy)

public synchronized void setRoutePlanner (HttpRoutePlanner routePlanner)

public synchronized void setTargetAuthenticationHandler (AuthenticationHandler targetAuthHandler)

public synchronized void setUserTokenHandler (UserTokenHandler userTokenHandler)

Protected Methods

protected abstract AuthSchemeRegistry createAuthSchemeRegistry ()

protected abstract ClientConnectionManager createClientConnectionManager ()

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)

protected abstract ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy ()

protected abstract ConnectionReuseStrategy createConnectionReuseStrategy ()

protected abstract CookieSpecRegistry createCookieSpecRegistry ()

protected abstract CookieStore createCookieStore ()

protected abstract CredentialsProvider createCredentialsProvider ()

protected abstract HttpContext createHttpContext ()

protected abstract HttpParams createHttpParams ()

protected abstract BasicHttpProcessor createHttpProcessor ()

protected abstract HttpRequestRetryHandler createHttpRequestRetryHandler ()

protected abstract HttpRoutePlanner createHttpRoutePlanner ()

protected abstract AuthenticationHandler createProxyAuthenticationHandler ()

protected abstract RedirectHandler createRedirectHandler ()

protected abstract HttpRequestExecutor createRequestExecutor ()

protected abstract AuthenticationHandler createTargetAuthenticationHandler ()

protected abstract UserTokenHandler createUserTokenHandler ()

protected HttpParams determineParams (HttpRequest req)

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 ()