Class AbstractHttpClient

java.lang.Object
org.apache.http.impl.client.AbstractHttpClient
All Implemented Interfaces:
HttpClient
Direct Known Subclasses:
DefaultHttpClient

public abstract class AbstractHttpClient
extends Object
implements HttpClient
Convenience base class for HTTP client implementations.
Since:
4.0
Version:
$Revision: 677250 $
Author:
Roland Weber, Oleg Kalnichevski
  • Constructor Details

    • AbstractHttpClient

      protected AbstractHttpClient​(ClientConnectionManager conman, HttpParams params)
      Creates a new HTTP client.
      Parameters:
      conman - the connection manager
      params - the parameters
  • Method Details

    • createHttpParams

      protected abstract HttpParams createHttpParams()
    • createHttpContext

      protected abstract HttpContext createHttpContext()
    • createRequestExecutor

      protected abstract HttpRequestExecutor createRequestExecutor()
    • createClientConnectionManager

      protected abstract ClientConnectionManager createClientConnectionManager()
    • createAuthSchemeRegistry

      protected abstract AuthSchemeRegistry createAuthSchemeRegistry()
    • createCookieSpecRegistry

      protected abstract CookieSpecRegistry createCookieSpecRegistry()
    • createConnectionReuseStrategy

      protected abstract ConnectionReuseStrategy createConnectionReuseStrategy()
    • createConnectionKeepAliveStrategy

      protected abstract ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
    • createHttpProcessor

      protected abstract BasicHttpProcessor createHttpProcessor()
    • createHttpRequestRetryHandler

      protected abstract HttpRequestRetryHandler createHttpRequestRetryHandler()
    • createRedirectHandler

      protected abstract RedirectHandler createRedirectHandler()
    • createTargetAuthenticationHandler

      protected abstract AuthenticationHandler createTargetAuthenticationHandler()
    • createProxyAuthenticationHandler

      protected abstract AuthenticationHandler createProxyAuthenticationHandler()
    • createCookieStore

      protected abstract CookieStore createCookieStore()
    • createCredentialsProvider

      protected abstract CredentialsProvider createCredentialsProvider()
    • createHttpRoutePlanner

      protected abstract HttpRoutePlanner createHttpRoutePlanner()
    • createUserTokenHandler

      protected abstract UserTokenHandler createUserTokenHandler()
    • getParams

      public final HttpParams getParams()
      Description copied from interface: 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.
      Specified by:
      getParams in interface HttpClient
      Returns:
      the default parameters
    • setParams

      public void setParams​(HttpParams params)
      Replaces the parameters. The implementation here does not update parameters of dependent objects.
      Parameters:
      params - the new default parameters
    • getConnectionManager

      public final ClientConnectionManager getConnectionManager()
      Description copied from interface: HttpClient
      Obtains the connection manager used by this client.
      Specified by:
      getConnectionManager in interface HttpClient
      Returns:
      the connection manager
    • getRequestExecutor

      public final HttpRequestExecutor getRequestExecutor()
    • getAuthSchemes

      public final AuthSchemeRegistry getAuthSchemes()
    • setAuthSchemes

      public void setAuthSchemes​(AuthSchemeRegistry authSchemeRegistry)
    • getCookieSpecs

      public final CookieSpecRegistry getCookieSpecs()
    • setCookieSpecs

      public void setCookieSpecs​(CookieSpecRegistry cookieSpecRegistry)
    • getConnectionReuseStrategy

      public final ConnectionReuseStrategy getConnectionReuseStrategy()
    • setReuseStrategy

      public void setReuseStrategy​(ConnectionReuseStrategy reuseStrategy)
    • getConnectionKeepAliveStrategy

      public final ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy()
    • setKeepAliveStrategy

      public void setKeepAliveStrategy​(ConnectionKeepAliveStrategy keepAliveStrategy)
    • getHttpRequestRetryHandler

      public final HttpRequestRetryHandler getHttpRequestRetryHandler()
    • setHttpRequestRetryHandler

      public void setHttpRequestRetryHandler​(HttpRequestRetryHandler retryHandler)
    • getRedirectHandler

      public final RedirectHandler getRedirectHandler()
    • setRedirectHandler

      public void setRedirectHandler​(RedirectHandler redirectHandler)
    • getTargetAuthenticationHandler

      public final AuthenticationHandler getTargetAuthenticationHandler()
    • setTargetAuthenticationHandler

      public void setTargetAuthenticationHandler​(AuthenticationHandler targetAuthHandler)
    • getProxyAuthenticationHandler

      public final AuthenticationHandler getProxyAuthenticationHandler()
    • setProxyAuthenticationHandler

      public void setProxyAuthenticationHandler​(AuthenticationHandler proxyAuthHandler)
    • getCookieStore

      public final CookieStore getCookieStore()
    • setCookieStore

      public void setCookieStore​(CookieStore cookieStore)
    • getCredentialsProvider

      public final CredentialsProvider getCredentialsProvider()
    • setCredentialsProvider

      public void setCredentialsProvider​(CredentialsProvider credsProvider)
    • getRoutePlanner

      public final HttpRoutePlanner getRoutePlanner()
    • setRoutePlanner

      public void setRoutePlanner​(HttpRoutePlanner routePlanner)
    • getUserTokenHandler

      public final UserTokenHandler getUserTokenHandler()
    • setUserTokenHandler

      public void setUserTokenHandler​(UserTokenHandler userTokenHandler)
    • getHttpProcessor

      protected final BasicHttpProcessor getHttpProcessor()
    • addResponseInterceptor

      public void addResponseInterceptor​(HttpResponseInterceptor itcp)
    • addResponseInterceptor

      public void addResponseInterceptor​(HttpResponseInterceptor itcp, int index)
    • getResponseInterceptor

      public HttpResponseInterceptor getResponseInterceptor​(int index)
    • getResponseInterceptorCount

      public int getResponseInterceptorCount()
    • clearResponseInterceptors

      public void clearResponseInterceptors()
    • removeResponseInterceptorByClass

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

      public void addRequestInterceptor​(HttpRequestInterceptor itcp)
    • addRequestInterceptor

      public void addRequestInterceptor​(HttpRequestInterceptor itcp, int index)
    • getRequestInterceptor

      public HttpRequestInterceptor getRequestInterceptor​(int index)
    • getRequestInterceptorCount

      public int getRequestInterceptorCount()
    • clearRequestInterceptors

      public void clearRequestInterceptors()
    • removeRequestInterceptorByClass

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

      public final HttpResponse execute​(HttpUriRequest request) throws IOException, ClientProtocolException
      Description copied from interface: HttpClient
      Executes a request using the default context.
      Specified by:
      execute in interface HttpClient
      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.
      Throws:
      IOException - in case of a problem or the connection was aborted
      ClientProtocolException - in case of an http protocol error
    • execute

      public final HttpResponse execute​(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException
      Maps to execute(target, request, context). The target is determined from the URI of the request.
      Specified by:
      execute in interface HttpClient
      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.
      Throws:
      IOException - in case of a problem or the connection was aborted
      ClientProtocolException - in case of an http protocol error
    • execute

      public final HttpResponse execute​(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException
      Description copied from interface: HttpClient
      Executes a request to the target using the default context.
      Specified by:
      execute in interface HttpClient
      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.
      Throws:
      IOException - in case of a problem or the connection was aborted
      ClientProtocolException - in case of an http protocol error
    • execute

      public final HttpResponse execute​(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException
      Description copied from interface: HttpClient
      Executes a request to the target using the given context.
      Specified by:
      execute in interface HttpClient
      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.
      Throws:
      IOException - in case of a problem or the connection was aborted
      ClientProtocolException - in case of an http protocol error
    • createClientRequestDirector

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

      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
    • execute

      public <T> T execute​(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException
      Description copied from interface: HttpClient
      Executes a request using the default context and processes the response using the given response handler.
      Specified by:
      execute in interface HttpClient
      Parameters:
      request - the request to execute
      responseHandler - the response handler
      Returns:
      the response object as generated by the response handler.
      Throws:
      IOException - in case of a problem or the connection was aborted
      ClientProtocolException - in case of an http protocol error
    • execute

      public <T> T execute​(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException, ClientProtocolException
      Description copied from interface: HttpClient
      Executes a request using the given context and processes the response using the given response handler.
      Specified by:
      execute in interface HttpClient
      Parameters:
      request - the request to execute
      responseHandler - the response handler
      Returns:
      the response object as generated by the response handler.
      Throws:
      IOException - in case of a problem or the connection was aborted
      ClientProtocolException - in case of an http protocol error
    • execute

      public <T> T execute​(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException
      Description copied from interface: HttpClient
      Executes a request to the target using the default context and processes the response using the given response handler.
      Specified by:
      execute in interface HttpClient
      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.
      Throws:
      IOException - in case of a problem or the connection was aborted
      ClientProtocolException - in case of an http protocol error
    • execute

      public <T> T execute​(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException, ClientProtocolException
      Description copied from interface: HttpClient
      Executes a request to the target using the given context and processes the response using the given response handler.
      Specified by:
      execute in interface HttpClient
      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.
      Throws:
      IOException - in case of a problem or the connection was aborted
      ClientProtocolException - in case of an http protocol error