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

Since: API Level 1

Creates a new HTTP client.

Parameters
conman the connection manager
params the parameters

Public Methods

public synchronized void addRequestInterceptor (HttpRequestInterceptor itcp)

Since: API Level 1

public synchronized void addRequestInterceptor (HttpRequestInterceptor itcp, int index)

Since: API Level 1

public synchronized void addResponseInterceptor (HttpResponseInterceptor itcp, int index)

Since: API Level 1

public synchronized void addResponseInterceptor (HttpResponseInterceptor itcp)

Since: API Level 1

public synchronized void clearRequestInterceptors ()

Since: API Level 1

public synchronized void clearResponseInterceptors ()

Since: API Level 1

public final HttpResponse execute (HttpUriRequest request)

Since: API Level 1

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)

Since: API Level 1

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)

Since: API Level 1

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)

Since: API Level 1

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)

Since: API Level 1

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)

Since: API Level 1

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)

Since: API Level 1

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)

Since: API Level 1

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

Since: API Level 1

public final synchronized ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy ()

Since: API Level 1

public final synchronized ClientConnectionManager getConnectionManager ()

Since: API Level 1

Obtains the connection manager used by this client.

Returns
  • the connection manager

public final synchronized ConnectionReuseStrategy getConnectionReuseStrategy ()

Since: API Level 1

public final synchronized CookieSpecRegistry getCookieSpecs ()

Since: API Level 1

public final synchronized CookieStore getCookieStore ()

Since: API Level 1

public final synchronized CredentialsProvider getCredentialsProvider ()

Since: API Level 1

public final synchronized HttpRequestRetryHandler getHttpRequestRetryHandler ()

Since: API Level 1

public final synchronized HttpParams getParams ()

Since: API Level 1

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

Since: API Level 1

public final synchronized RedirectHandler getRedirectHandler ()

Since: API Level 1

public final synchronized HttpRequestExecutor getRequestExecutor ()

Since: API Level 1

public synchronized HttpRequestInterceptor getRequestInterceptor (int index)

Since: API Level 1

public synchronized int getRequestInterceptorCount ()

Since: API Level 1

public synchronized HttpResponseInterceptor getResponseInterceptor (int index)

Since: API Level 1

public synchronized int getResponseInterceptorCount ()

Since: API Level 1

public final synchronized HttpRoutePlanner getRoutePlanner ()

Since: API Level 1

public final synchronized AuthenticationHandler getTargetAuthenticationHandler ()

Since: API Level 1

public final synchronized UserTokenHandler getUserTokenHandler ()

Since: API Level 1

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

Since: API Level 1

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

Since: API Level 1

public synchronized void setAuthSchemes (AuthSchemeRegistry authSchemeRegistry)

Since: API Level 1

public synchronized void setCookieSpecs (CookieSpecRegistry cookieSpecRegistry)

Since: API Level 1

public synchronized void setCookieStore (CookieStore cookieStore)

Since: API Level 1

public synchronized void setCredentialsProvider (CredentialsProvider credsProvider)

Since: API Level 1

public synchronized void setHttpRequestRetryHandler (HttpRequestRetryHandler retryHandler)

Since: API Level 1

public synchronized void setKeepAliveStrategy (ConnectionKeepAliveStrategy keepAliveStrategy)

Since: API Level 1

public synchronized void setParams (HttpParams params)

Since: API Level 1

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)

Since: API Level 1

public synchronized void setRedirectHandler (RedirectHandler redirectHandler)

Since: API Level 1

public synchronized void setReuseStrategy (ConnectionReuseStrategy reuseStrategy)

Since: API Level 1

public synchronized void setRoutePlanner (HttpRoutePlanner routePlanner)

Since: API Level 1

public synchronized void setTargetAuthenticationHandler (AuthenticationHandler targetAuthHandler)

Since: API Level 1

public synchronized void setUserTokenHandler (UserTokenHandler userTokenHandler)

Since: API Level 1

Protected Methods

protected abstract AuthSchemeRegistry createAuthSchemeRegistry ()

Since: API Level 1

protected abstract ClientConnectionManager createClientConnectionManager ()

Since: API Level 1

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)

Since: API Level 1

protected abstract ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy ()

Since: API Level 1

protected abstract ConnectionReuseStrategy createConnectionReuseStrategy ()

Since: API Level 1

protected abstract CookieSpecRegistry createCookieSpecRegistry ()

Since: API Level 1

protected abstract CookieStore createCookieStore ()

Since: API Level 1

protected abstract CredentialsProvider createCredentialsProvider ()

Since: API Level 1

protected abstract HttpContext createHttpContext ()

Since: API Level 1

protected abstract HttpParams createHttpParams ()

Since: API Level 1

protected abstract BasicHttpProcessor createHttpProcessor ()

Since: API Level 1

protected abstract HttpRequestRetryHandler createHttpRequestRetryHandler ()

Since: API Level 1

protected abstract HttpRoutePlanner createHttpRoutePlanner ()

Since: API Level 1

protected abstract AuthenticationHandler createProxyAuthenticationHandler ()

Since: API Level 1

protected abstract RedirectHandler createRedirectHandler ()

Since: API Level 1

protected abstract HttpRequestExecutor createRequestExecutor ()

Since: API Level 1

protected abstract AuthenticationHandler createTargetAuthenticationHandler ()

Since: API Level 1

protected abstract UserTokenHandler createUserTokenHandler ()

Since: API Level 1

protected HttpParams determineParams (HttpRequest req)

Since: API Level 1

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

Since: API Level 1