org.apache.http.impl.client
Class AbstractHttpClient

java.lang.Object
  extended by org.apache.http.impl.client.AbstractHttpClient
All Implemented Interfaces:
HttpClient, org.apache.http.protocol.HttpRequestInterceptorList, org.apache.http.protocol.HttpResponseInterceptorList
Direct Known Subclasses:
DefaultHttpClient

public abstract class AbstractHttpClient
extends java.lang.Object
implements HttpClient, org.apache.http.protocol.HttpRequestInterceptorList, org.apache.http.protocol.HttpResponseInterceptorList

Convenience base class for HTTP client implementations.

Since:
4.0
Version:
$Revision: 586567 $
Author:
Roland Weber, Oleg Kalnichevski

Constructor Summary
protected AbstractHttpClient(ClientConnectionManager conman, org.apache.http.params.HttpParams params)
          Creates a new HTTP client.
 
Method Summary
 void addRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp)
           
 void addRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp, int index)
           
 void addResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp)
           
 void addResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp, int index)
           
 void clearRequestInterceptors()
           
 void clearResponseInterceptors()
           
protected abstract  AuthSchemeRegistry createAuthSchemeRegistry()
           
protected abstract  ClientConnectionManager createClientConnectionManager()
           
protected abstract  org.apache.http.ConnectionReuseStrategy createConnectionReuseStrategy()
           
protected abstract  CookieSpecRegistry createCookieSpecRegistry()
           
protected abstract  CookieStore createCookieStore()
           
protected abstract  CredentialsProvider createCredentialsProvider()
           
protected abstract  org.apache.http.protocol.HttpContext createHttpContext()
           
protected abstract  org.apache.http.params.HttpParams createHttpParams()
           
protected abstract  org.apache.http.protocol.BasicHttpProcessor createHttpProcessor()
           
protected abstract  HttpRequestRetryHandler createHttpRequestRetryHandler()
           
protected abstract  HttpRoutePlanner createHttpRoutePlanner()
           
protected abstract  AuthenticationHandler createProxyAuthenticationHandler()
           
protected abstract  RedirectHandler createRedirectHandler()
           
protected abstract  AuthenticationHandler createTargetAuthenticationHandler()
           
protected  org.apache.http.params.HttpParams determineParams(org.apache.http.HttpRequest req)
          Obtains parameters for executing a request.
protected abstract  RoutedRequest determineRoute(org.apache.http.HttpHost target, org.apache.http.HttpRequest request, org.apache.http.protocol.HttpContext context)
          Determines the route for a request.
 org.apache.http.HttpResponse execute(HttpUriRequest request)
          Executes a request using the default context.
 org.apache.http.HttpResponse execute(HttpUriRequest request, org.apache.http.protocol.HttpContext context)
          Maps to execute(roureq, context).
 org.apache.http.HttpResponse execute(RoutedRequest roureq)
          Executes a request along the given route using the default context.
 org.apache.http.HttpResponse execute(RoutedRequest roureq, org.apache.http.protocol.HttpContext context)
          Executes a request along the given route.
 AuthSchemeRegistry getAuthSchemes()
           
 ClientConnectionManager getConnectionManager()
          Obtains the connection manager used by this client.
 org.apache.http.ConnectionReuseStrategy getConnectionReuseStrategy()
           
 CookieSpecRegistry getCookieSpecs()
           
 CookieStore getCookieStore()
           
 CredentialsProvider getCredentialsProvider()
           
 org.apache.http.protocol.HttpContext getDefaultContext()
          Obtains the default context used by this client populated with default attributes.
protected  org.apache.http.protocol.BasicHttpProcessor getHttpProcessor()
           
 HttpRequestRetryHandler getHttpRequestRetryHandler()
           
 org.apache.http.params.HttpParams getParams()
          Obtains the parameters for this client.
 AuthenticationHandler getProxyAuthenticationHandler()
           
 RedirectHandler getRedirectHandler()
           
 org.apache.http.HttpRequestInterceptor getRequestInterceptor(int index)
           
 int getRequestInterceptorCount()
           
 org.apache.http.HttpResponseInterceptor getResponseInterceptor(int index)
           
 int getResponseInterceptorCount()
           
 HttpRoutePlanner getRoutePlanner()
           
 AuthenticationHandler getTargetAuthenticationHandler()
           
protected abstract  void populateContext(org.apache.http.protocol.HttpContext context)
           
 void removeRequestInterceptorByClass(java.lang.Class clazz)
           
 void removeResponseInterceptorByClass(java.lang.Class clazz)
           
 void setAuthSchemes(AuthSchemeRegistry authSchemeRegistry)
           
 void setCookieSpecs(CookieSpecRegistry cookieSpecRegistry)
           
 void setCookieStore(CookieStore cookieStore)
           
 void setCredentialsProvider(CredentialsProvider credsProvider)
           
 void setHttpRequestRetryHandler(HttpRequestRetryHandler retryHandler)
           
 void setInterceptors(java.util.List itcps)
           
 void setParams(org.apache.http.params.HttpParams params)
          Replaces the parameters.
 void setProxyAuthenticationHandler(AuthenticationHandler proxyAuthHandler)
           
 void setRedirectHandler(RedirectHandler redirectHandler)
           
 void setReuseStrategy(org.apache.http.ConnectionReuseStrategy reuseStrategy)
           
 void setRoutePlanner(HttpRoutePlanner routePlanner)
           
 void setTargetAuthenticationHandler(AuthenticationHandler targetAuthHandler)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHttpClient

protected AbstractHttpClient(ClientConnectionManager conman,
                             org.apache.http.params.HttpParams params)
Creates a new HTTP client.

Parameters:
conman - the connection manager
params - the parameters
Method Detail

createHttpParams

protected abstract org.apache.http.params.HttpParams createHttpParams()

createHttpContext

protected abstract org.apache.http.protocol.HttpContext createHttpContext()

createClientConnectionManager

protected abstract ClientConnectionManager createClientConnectionManager()

createAuthSchemeRegistry

protected abstract AuthSchemeRegistry createAuthSchemeRegistry()

createCookieSpecRegistry

protected abstract CookieSpecRegistry createCookieSpecRegistry()

createConnectionReuseStrategy

protected abstract org.apache.http.ConnectionReuseStrategy createConnectionReuseStrategy()

createHttpProcessor

protected abstract org.apache.http.protocol.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()

populateContext

protected abstract void populateContext(org.apache.http.protocol.HttpContext context)

createHttpRoutePlanner

protected abstract HttpRoutePlanner createHttpRoutePlanner()

getRoutePlanner

public final HttpRoutePlanner getRoutePlanner()

setRoutePlanner

public void setRoutePlanner(HttpRoutePlanner routePlanner)

getParams

public final org.apache.http.params.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(org.apache.http.params.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

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 org.apache.http.ConnectionReuseStrategy getConnectionReuseStrategy()

setReuseStrategy

public void setReuseStrategy(org.apache.http.ConnectionReuseStrategy reuseStrategy)

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)

getHttpProcessor

protected final org.apache.http.protocol.BasicHttpProcessor getHttpProcessor()

getDefaultContext

public final org.apache.http.protocol.HttpContext getDefaultContext()
Description copied from interface: HttpClient
Obtains the default context used by this client populated with default attributes. This context will be used by default when executing requests with this client.

Specified by:
getDefaultContext in interface HttpClient
Returns:
the default context

addResponseInterceptor

public void addResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp)
Specified by:
addResponseInterceptor in interface org.apache.http.protocol.HttpResponseInterceptorList

addResponseInterceptor

public void addResponseInterceptor(org.apache.http.HttpResponseInterceptor itcp,
                                   int index)
Specified by:
addResponseInterceptor in interface org.apache.http.protocol.HttpResponseInterceptorList

getResponseInterceptor

public org.apache.http.HttpResponseInterceptor getResponseInterceptor(int index)
Specified by:
getResponseInterceptor in interface org.apache.http.protocol.HttpResponseInterceptorList

getResponseInterceptorCount

public int getResponseInterceptorCount()
Specified by:
getResponseInterceptorCount in interface org.apache.http.protocol.HttpResponseInterceptorList

clearResponseInterceptors

public void clearResponseInterceptors()
Specified by:
clearResponseInterceptors in interface org.apache.http.protocol.HttpResponseInterceptorList

removeResponseInterceptorByClass

public void removeResponseInterceptorByClass(java.lang.Class clazz)
Specified by:
removeResponseInterceptorByClass in interface org.apache.http.protocol.HttpResponseInterceptorList

addRequestInterceptor

public void addRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp)
Specified by:
addRequestInterceptor in interface org.apache.http.protocol.HttpRequestInterceptorList

addRequestInterceptor

public void addRequestInterceptor(org.apache.http.HttpRequestInterceptor itcp,
                                  int index)
Specified by:
addRequestInterceptor in interface org.apache.http.protocol.HttpRequestInterceptorList

getRequestInterceptor

public org.apache.http.HttpRequestInterceptor getRequestInterceptor(int index)
Specified by:
getRequestInterceptor in interface org.apache.http.protocol.HttpRequestInterceptorList

getRequestInterceptorCount

public int getRequestInterceptorCount()
Specified by:
getRequestInterceptorCount in interface org.apache.http.protocol.HttpRequestInterceptorList

clearRequestInterceptors

public void clearRequestInterceptors()
Specified by:
clearRequestInterceptors in interface org.apache.http.protocol.HttpRequestInterceptorList

removeRequestInterceptorByClass

public void removeRequestInterceptorByClass(java.lang.Class clazz)
Specified by:
removeRequestInterceptorByClass in interface org.apache.http.protocol.HttpRequestInterceptorList

setInterceptors

public void setInterceptors(java.util.List itcps)
Specified by:
setInterceptors in interface org.apache.http.protocol.HttpRequestInterceptorList
Specified by:
setInterceptors in interface org.apache.http.protocol.HttpResponseInterceptorList

execute

public final org.apache.http.HttpResponse execute(HttpUriRequest request)
                                           throws org.apache.http.HttpException,
                                                  java.io.IOException,
                                                  java.lang.InterruptedException
Description copied from interface: HttpClient
Executes a request using the default context. See there for details.

Specified by:
execute in interface HttpClient
Parameters:
request - the request to execute
Returns:
the response to the request
Throws:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem
java.lang.InterruptedException - in case of an interrupt
timeout exceptions?

execute

public final org.apache.http.HttpResponse execute(HttpUriRequest request,
                                                  org.apache.http.protocol.HttpContext context)
                                           throws org.apache.http.HttpException,
                                                  java.io.IOException,
                                                  java.lang.InterruptedException
Maps to execute(roureq, context). The route is computed by determineRoute.

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:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem
java.lang.InterruptedException - in case of an interrupt
timeout exceptions?

execute

public org.apache.http.HttpResponse execute(RoutedRequest roureq)
                                     throws org.apache.http.HttpException,
                                            java.io.IOException,
                                            java.lang.InterruptedException
Description copied from interface: HttpClient
Executes a request along the given route using the default context.

Specified by:
execute in interface HttpClient
Parameters:
roureq - the request to execute along with the route
Returns:
the response to the request. See HttpClient.execute(HttpUriRequest,HttpContext) for details.
Throws:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem
java.lang.InterruptedException - in case of an interrupt
timeout exceptions?

execute

public final org.apache.http.HttpResponse execute(RoutedRequest roureq,
                                                  org.apache.http.protocol.HttpContext context)
                                           throws org.apache.http.HttpException,
                                                  java.io.IOException,
                                                  java.lang.InterruptedException
Description copied from interface: HttpClient
Executes a request along the given route.

Specified by:
execute in interface HttpClient
Parameters:
roureq - the request to execute along with the route
context - the context to use for the execution, or null to use the default context
Returns:
the response to the request. See HttpClient.execute(HttpUriRequest,HttpContext) for details.
Throws:
org.apache.http.HttpException - in case of a problem
java.io.IOException - in case of an IO problem
java.lang.InterruptedException - in case of an interrupt
timeout exceptions?

determineParams

protected org.apache.http.params.HttpParams determineParams(org.apache.http.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(RoutedRequest,HttpContext) to obtain the parameters for the DefaultClientRequestDirector.

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

determineRoute

protected abstract RoutedRequest determineRoute(org.apache.http.HttpHost target,
                                                org.apache.http.HttpRequest request,
                                                org.apache.http.protocol.HttpContext context)
                                         throws org.apache.http.HttpException
Determines the route for a request. Called by execute(urirequest, context) to map to execute(roureq, 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, never null
Returns:
the request along with the route it should take
Throws:
org.apache.http.HttpException - in case of a problem


Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.