|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.http.impl.client.AbstractHttpClient
@ThreadSafe public abstract class AbstractHttpClient
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:
HttpRequestExecutor
createRequestExecutor()
must be
implemented by concrete super classes to instantiate this object.
BasicHttpProcessor
createHttpProcessor()
must be
implemented by concrete super classes to instantiate this object.
HttpRequestRetryHandler
createHttpRequestRetryHandler()
must be
implemented by concrete super classes to instantiate this object.
ClientConnectionManager
ConnectionReuseStrategy
createConnectionReuseStrategy()
must be
implemented by concrete super classes to instantiate this object.
ConnectionKeepAliveStrategy
createConnectionKeepAliveStrategy()
must be
implemented by concrete super classes to instantiate this object.
CookieSpecRegistry
createCookieSpecRegistry()
must be implemented by concrete
super classes to instantiate this object.
CookieStore
createCookieStore()
must be implemented by
concrete super classes to instantiate this object.
AuthSchemeRegistry
createAuthSchemeRegistry()
must be implemented by concrete
super classes to instantiate this object.
CredentialsProvider
createCredentialsProvider()
must be implemented by concrete super classes to instantiate
this object.
AuthenticationHandler
createTargetAuthenticationHandler()
must be implemented
by concrete super classes to instantiate this object.
AuthenticationHandler
createProxyAuthenticationHandler()
must be implemented
by concrete super classes to instantiate this object.
HttpRoutePlanner
createHttpRoutePlanner()
must be implemented
by concrete super classes to instantiate this object.
RedirectHandler
createRedirectHandler()
must be implemented
by concrete super classes to instantiate this object.
UserTokenHandler
createUserTokenHandler()
must be implemented by
concrete super classes to instantiate this object.
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
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 ClientConnectionManager.shutdown()
!
Constructor Summary | |
---|---|
protected |
AbstractHttpClient(ClientConnectionManager conman,
HttpParams params)
Creates a new HTTP client. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected AbstractHttpClient(ClientConnectionManager conman, HttpParams params)
conman
- the connection managerparams
- the parametersMethod Detail |
---|
protected abstract HttpParams createHttpParams()
protected abstract HttpContext createHttpContext()
protected abstract HttpRequestExecutor createRequestExecutor()
protected abstract ClientConnectionManager createClientConnectionManager()
protected abstract AuthSchemeRegistry createAuthSchemeRegistry()
protected abstract CookieSpecRegistry createCookieSpecRegistry()
protected abstract ConnectionReuseStrategy createConnectionReuseStrategy()
protected abstract ConnectionKeepAliveStrategy createConnectionKeepAliveStrategy()
protected abstract BasicHttpProcessor createHttpProcessor()
protected abstract HttpRequestRetryHandler createHttpRequestRetryHandler()
protected abstract RedirectHandler createRedirectHandler()
protected abstract AuthenticationHandler createTargetAuthenticationHandler()
protected abstract AuthenticationHandler createProxyAuthenticationHandler()
protected abstract CookieStore createCookieStore()
protected abstract CredentialsProvider createCredentialsProvider()
protected abstract HttpRoutePlanner createHttpRoutePlanner()
protected abstract UserTokenHandler createUserTokenHandler()
public final HttpParams getParams()
HttpClient
getParams
in interface HttpClient
public void setParams(HttpParams params)
params
- the new default parameterspublic final ClientConnectionManager getConnectionManager()
HttpClient
getConnectionManager
in interface HttpClient
public final HttpRequestExecutor getRequestExecutor()
public final AuthSchemeRegistry getAuthSchemes()
public void setAuthSchemes(AuthSchemeRegistry authSchemeRegistry)
public final CookieSpecRegistry getCookieSpecs()
public void setCookieSpecs(CookieSpecRegistry cookieSpecRegistry)
public final ConnectionReuseStrategy getConnectionReuseStrategy()
public void setReuseStrategy(ConnectionReuseStrategy reuseStrategy)
public final ConnectionKeepAliveStrategy getConnectionKeepAliveStrategy()
public void setKeepAliveStrategy(ConnectionKeepAliveStrategy keepAliveStrategy)
public final HttpRequestRetryHandler getHttpRequestRetryHandler()
public void setHttpRequestRetryHandler(HttpRequestRetryHandler retryHandler)
public final RedirectHandler getRedirectHandler()
public void setRedirectHandler(RedirectHandler redirectHandler)
public final AuthenticationHandler getTargetAuthenticationHandler()
public void setTargetAuthenticationHandler(AuthenticationHandler targetAuthHandler)
public final AuthenticationHandler getProxyAuthenticationHandler()
public void setProxyAuthenticationHandler(AuthenticationHandler proxyAuthHandler)
public final CookieStore getCookieStore()
public void setCookieStore(CookieStore cookieStore)
public final CredentialsProvider getCredentialsProvider()
public void setCredentialsProvider(CredentialsProvider credsProvider)
public final HttpRoutePlanner getRoutePlanner()
public void setRoutePlanner(HttpRoutePlanner routePlanner)
public final UserTokenHandler getUserTokenHandler()
public void setUserTokenHandler(UserTokenHandler userTokenHandler)
protected final BasicHttpProcessor getHttpProcessor()
public void addResponseInterceptor(HttpResponseInterceptor itcp)
public void addResponseInterceptor(HttpResponseInterceptor itcp, int index)
public HttpResponseInterceptor getResponseInterceptor(int index)
public int getResponseInterceptorCount()
public void clearResponseInterceptors()
public void removeResponseInterceptorByClass(Class<? extends HttpResponseInterceptor> clazz)
public void addRequestInterceptor(HttpRequestInterceptor itcp)
public void addRequestInterceptor(HttpRequestInterceptor itcp, int index)
public HttpRequestInterceptor getRequestInterceptor(int index)
public int getRequestInterceptorCount()
public void clearRequestInterceptors()
public void removeRequestInterceptorByClass(Class<? extends HttpRequestInterceptor> clazz)
public final HttpResponse execute(HttpUriRequest request) throws IOException, ClientProtocolException
HttpClient
execute
in interface HttpClient
request
- the request to execute
IOException
- in case of a problem or the connection was aborted
ClientProtocolException
- in case of an http protocol errorpublic final HttpResponse execute(HttpUriRequest request, HttpContext context) throws IOException, ClientProtocolException
execute(target, request, context)
.
The target is determined from the URI of the request.
execute
in interface HttpClient
request
- the request to executecontext
- the request-specific execution context,
or null
to use a default context
IOException
- in case of a problem or the connection was aborted
ClientProtocolException
- in case of an http protocol errorpublic final HttpResponse execute(HttpHost target, HttpRequest request) throws IOException, ClientProtocolException
HttpClient
execute
in interface HttpClient
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
IOException
- in case of a problem or the connection was aborted
ClientProtocolException
- in case of an http protocol errorpublic final HttpResponse execute(HttpHost target, HttpRequest request, HttpContext context) throws IOException, ClientProtocolException
HttpClient
execute
in interface HttpClient
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 executecontext
- the context to use for the execution, or
null
to use the default context
IOException
- in case of a problem or the connection was aborted
ClientProtocolException
- in case of an http protocol errorprotected 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 HttpParams determineParams(HttpRequest req)
ClientParamsStack
from the request parameters
and the client parameters.
execute(HttpHost,HttpRequest,HttpContext)
to obtain the parameters for the
DefaultRequestDirector
.
req
- the request that will be executed
public <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException
HttpClient
execute
in interface HttpClient
request
- the request to executeresponseHandler
- the response handler
IOException
- in case of a problem or the connection was aborted
ClientProtocolException
- in case of an http protocol errorpublic <T> T execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException, ClientProtocolException
HttpClient
execute
in interface HttpClient
request
- the request to executeresponseHandler
- the response handler
IOException
- in case of a problem or the connection was aborted
ClientProtocolException
- in case of an http protocol errorpublic <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler) throws IOException, ClientProtocolException
HttpClient
execute
in interface HttpClient
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 executeresponseHandler
- the response handler
IOException
- in case of a problem or the connection was aborted
ClientProtocolException
- in case of an http protocol errorpublic <T> T execute(HttpHost target, HttpRequest request, ResponseHandler<? extends T> responseHandler, HttpContext context) throws IOException, ClientProtocolException
HttpClient
execute
in interface HttpClient
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 executeresponseHandler
- the response handlercontext
- the context to use for the execution, or
null
to use the default context
IOException
- in case of a problem or the connection was aborted
ClientProtocolException
- in case of an http protocol error
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |