public class HttpComponentsClientHttpRequestFactory extends java.lang.Object implements ClientHttpRequestFactory, DisposableBean
ClientHttpRequestFactory
implementation that uses
Apache HttpComponents HttpClient
to create requests.
Allows to use a pre-configured HttpClient
instance -
potentially with authentication, HTTP connection pooling, etc.
Modifier and Type | Field and Description |
---|---|
private static int |
DEFAULT_MAX_CONNECTIONS_PER_ROUTE |
private static int |
DEFAULT_MAX_TOTAL_CONNECTIONS |
private static int |
DEFAULT_READ_TIMEOUT_MILLISECONDS |
private static boolean |
HTTP_PATCH_AVAILABLE |
private HttpClient |
httpClient |
Constructor and Description |
---|
HttpComponentsClientHttpRequestFactory()
Create a new instance of the HttpComponentsClientHttpRequestFactory with a default
HttpClient that uses a default org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager . |
HttpComponentsClientHttpRequestFactory(HttpClient httpClient)
Create a new instance of the HttpComponentsClientHttpRequestFactory
with the given
HttpClient instance. |
Modifier and Type | Method and Description |
---|---|
protected HttpContext |
createHttpContext(HttpMethod httpMethod,
java.net.URI uri)
Template methods that creates a
HttpContext for the given HTTP method and URI. |
private HttpUriRequest |
createHttpPatch(java.net.URI uri) |
protected HttpUriRequest |
createHttpUriRequest(HttpMethod httpMethod,
java.net.URI uri)
Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
|
ClientHttpRequest |
createRequest(java.net.URI uri,
HttpMethod httpMethod)
Create a new
ClientHttpRequest for the specified URI and HTTP method. |
void |
destroy()
Shutdown hook that closes the underlying
ClientConnectionManager 's
connection pool, if any. |
HttpClient |
getHttpClient()
Return the
HttpClient used by this factory. |
protected void |
postProcessHttpRequest(HttpUriRequest request)
Template method that allows for manipulating the
HttpUriRequest before it is
returned as part of a HttpComponentsClientHttpRequest . |
void |
setConnectTimeout(int timeout)
Set the connection timeout for the underlying HttpClient.
|
void |
setHttpClient(HttpClient httpClient)
Set the
HttpClient used by this factory. |
void |
setReadTimeout(int timeout)
Set the socket read timeout for the underlying HttpClient.
|
private static final boolean HTTP_PATCH_AVAILABLE
private static final int DEFAULT_MAX_TOTAL_CONNECTIONS
private static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE
private static final int DEFAULT_READ_TIMEOUT_MILLISECONDS
private HttpClient httpClient
public HttpComponentsClientHttpRequestFactory()
HttpClient
that uses a default org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager
.public HttpComponentsClientHttpRequestFactory(HttpClient httpClient)
HttpClient
instance.httpClient
- the HttpClient instance to use for this request factorypublic void setHttpClient(HttpClient httpClient)
HttpClient
used by this factory.public HttpClient getHttpClient()
HttpClient
used by this factory.public void setConnectTimeout(int timeout)
timeout
- the timeout value in millisecondspublic void setReadTimeout(int timeout)
timeout
- the timeout value in millisecondspublic ClientHttpRequest createRequest(java.net.URI uri, HttpMethod httpMethod) throws java.io.IOException
ClientHttpRequestFactory
ClientHttpRequest
for the specified URI and HTTP method.
The returned request can be written to, and then executed by calling
ClientHttpRequest.execute()
.
createRequest
in interface ClientHttpRequestFactory
uri
- the URI to create a request forhttpMethod
- the HTTP method to executejava.io.IOException
- in case of I/O errorsprotected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, java.net.URI uri)
httpMethod
- the HTTP methoduri
- the URIprivate HttpUriRequest createHttpPatch(java.net.URI uri)
protected void postProcessHttpRequest(HttpUriRequest request)
HttpUriRequest
before it is
returned as part of a HttpComponentsClientHttpRequest
.
The default implementation is empty.
request
- the request to processprotected HttpContext createHttpContext(HttpMethod httpMethod, java.net.URI uri)
HttpContext
for the given HTTP method and URI.
The default implementation returns null
.
httpMethod
- the HTTP methoduri
- the URIpublic void destroy()
ClientConnectionManager
's
connection pool, if any.destroy
in interface DisposableBean