org.springframework.http.client.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.
Note
Requires Apache HttpComponents 5.1 or higher, as of Spring 6.0.
| Modifier and Type | Field and Description |
|---|---|
| private long | |
| private long | |
| private HttpClient | |
| private BiFunction |
| Access | Constructor and Description |
|---|---|
| public | HttpComponentsClientHttpRequestFactory()
Create a new instance of the |
| public | HttpComponentsClientHttpRequestFactory(HttpClient
the HttpClient instance to use for this request factory httpClient)Create a new instance of the |
| Modifier and Type | Method and Description |
|---|---|
| protected HttpContext | Returns: the http contextthe HTTP method httpMethod, URI the URI uri)Template methods that creates a |
| protected ClassicHttpRequest | Returns: the Commons HttpMethodBase objectthe HTTP method httpMethod, URI the URI uri)Create a Commons HttpMethodBase object for the given HTTP method and URI specification. |
| public ClientHttpRequest | createRequest(URI
the URI to create a request for uri, HttpMethod the HTTP method to execute httpMethod)Implements org. Create a new |
| protected RequestConfig | Returns: the actual RequestConfig to use (may benull)the client)HttpClient (or HttpAsyncClient) to checkCreate a default |
| public void | destroy()
Implements org. Shutdown hook that closes the underlying
|
| public HttpClient | |
| protected RequestConfig | Returns: the merged request configthe config held by the current clientConfig)Merge the given |
| protected void | postProcessHttpRequest(ClassicHttpRequest
the request to process request)Template method that allows for manipulating the |
| public void | setBufferRequestBody(boolean bufferRequestBody)
Deprecated
for removal since 6.1. since 6.1 requests are never buffered, as if this property is
false
Indicates whether this request factory should buffer the request body internally. |
| public void | setConnectionRequestTimeout(int
the timeout value to request a connection in milliseconds connectionRequestTimeout)Set the timeout in milliseconds used when requesting a connection
from the connection manager using the underlying |
| public void | setConnectionRequestTimeout(Duration
the timeout value to request a connection in milliseconds connectionRequestTimeout)Set the timeout in milliseconds used when requesting a connection
from the connection manager using the underlying |
| public void | setConnectTimeout(int
the timeout value in milliseconds connectTimeout)Set the connection timeout for the underlying |
| public void | setConnectTimeout(Duration
the timeout value in milliseconds connectTimeout)Set the connection timeout for the underlying |
| public void | |
| public void | setHttpContextFactory(BiFunction<HttpMethod, URI, HttpContext>
the context factory to use httpContextFactory)Configure a factory to pre-create the |
| connectionRequestTimeout | back to summary |
|---|---|
| private long connectionRequestTimeout | |
| connectTimeout | back to summary |
|---|---|
| private long connectTimeout | |
| httpClient | back to summary |
|---|---|
| private HttpClient httpClient | |
| httpContextFactory | back to summary |
|---|---|
| private BiFunction<HttpMethod, URI, HttpContext> httpContextFactory
| |
| HttpComponentsClientHttpRequestFactory | back to summary |
|---|---|
| public HttpComponentsClientHttpRequestFactory() Create a new instance of the | |
| HttpComponentsClientHttpRequestFactory | back to summary |
|---|---|
| public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) Create a new instance of the
| |
| createHttpContext | back to summary |
|---|---|
| protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) Template methods that creates a The default implementation returns
| |
| createHttpUriRequest | back to summary |
|---|---|
| protected ClassicHttpRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
| |
| createRequest | back to summary |
|---|---|
| public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException Implements org. Doc from org. Create a new The returned request can be written to, and then executed by calling
| |
| createRequestConfig | back to summary |
|---|---|
| protected RequestConfig createRequestConfig(Object client) Create a default The default implementation tries to merge the defaults of the client with the local customizations of this factory instance, if any.
| |
| destroy | back to summary |
|---|---|
| public void destroy() throws Exception Implements org. Shutdown hook that closes the underlying
| |
| getHttpClient | back to summary |
|---|---|
| public HttpClient getHttpClient() Return the | |
| mergeRequestConfig | back to summary |
|---|---|
| protected RequestConfig mergeRequestConfig(RequestConfig clientConfig) Merge the given
| |
| postProcessHttpRequest | back to summary |
|---|---|
| protected void postProcessHttpRequest(ClassicHttpRequest request) Template method that allows for manipulating the The default implementation is empty.
| |
| setBufferRequestBody | back to summary |
|---|---|
| public void setBufferRequestBody(boolean bufferRequestBody)
Deprecated for removal since 6.1. since 6.1 requests are never buffered, as if this property is Indicates whether this request factory should buffer the request body internally. Default is
| |
| setConnectionRequestTimeout | back to summary |
|---|---|
| public void setConnectionRequestTimeout(int connectionRequestTimeout) Set the timeout in milliseconds used when requesting a connection
from the connection manager using the underlying Additional properties can be configured by specifying a
| |
| setConnectionRequestTimeout | back to summary |
|---|---|
| public void setConnectionRequestTimeout(Duration connectionRequestTimeout) Set the timeout in milliseconds used when requesting a connection
from the connection manager using the underlying Additional properties can be configured by specifying a
| |
| setConnectTimeout | back to summary |
|---|---|
| public void setConnectTimeout(int connectTimeout) Set the connection timeout for the underlying Additional properties can be configured by specifying a
This options does not affect connection timeouts for SSL
handshakes or CONNECT requests; for that, it is required to
use the
| |
| setConnectTimeout | back to summary |
|---|---|
| public void setConnectTimeout(Duration connectTimeout) Set the connection timeout for the underlying Additional properties can be configured by specifying a
This options does not affect connection timeouts for SSL
handshakes or CONNECT requests; for that, it is required to
use the
| |
| setHttpClient | back to summary |
|---|---|
| public void setHttpClient(HttpClient httpClient) Set the | |
| setHttpContextFactory | back to summary |
|---|---|
| public void setHttpContextFactory(BiFunction<HttpMethod, URI, HttpContext> httpContextFactory) Configure a factory to pre-create the This may be useful for example in mutual TLS authentication where a
different
| |