Class JdkClientHttpRequestFactory
java.lang.Object
org.springframework.http.client.JdkClientHttpRequestFactory
- All Implemented Interfaces:
ClientHttpRequestFactory
ClientHttpRequestFactory
implementation based on the Java HttpClient
.- Since:
- 6.1
- Author:
- Marten Deinum, Arjen Poutsma
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance of theJdkClientHttpRequestFactory
with a defaultHttpClient
.JdkClientHttpRequestFactory
(HttpClient httpClient) Create a new instance of theJdkClientHttpRequestFactory
based on the givenHttpClient
.JdkClientHttpRequestFactory
(HttpClient httpClient, Executor executor) Create a new instance of theJdkClientHttpRequestFactory
based on the givenHttpClient
andExecutor
. -
Method Summary
Modifier and TypeMethodDescriptioncreateRequest
(URI uri, HttpMethod httpMethod) Create a newClientHttpRequest
for the specified URI and HTTP method.void
enableCompression
(boolean enable) Set whether support for uncompressing "gzip" and "deflate" HTTP responses is enabled.void
setReadTimeout
(int readTimeout) Set the underlyingHttpClient
's read timeout (in milliseconds).void
setReadTimeout
(Duration readTimeout) Set the underlyingHttpClient
's read timeout as aDuration
.
-
Constructor Details
-
JdkClientHttpRequestFactory
public JdkClientHttpRequestFactory()Create a new instance of theJdkClientHttpRequestFactory
with a defaultHttpClient
. -
JdkClientHttpRequestFactory
Create a new instance of theJdkClientHttpRequestFactory
based on the givenHttpClient
.- Parameters:
httpClient
- the client to base on
-
JdkClientHttpRequestFactory
Create a new instance of theJdkClientHttpRequestFactory
based on the givenHttpClient
andExecutor
.- Parameters:
httpClient
- the client to base onexecutor
- the executor to use for blocking write operations
-
-
Method Details
-
setReadTimeout
public void setReadTimeout(int readTimeout) Set the underlyingHttpClient
's read timeout (in milliseconds). A timeout value of 0 specifies an infinite timeout.Default is the system's default timeout.
- See Also:
-
setReadTimeout
Set the underlyingHttpClient
's read timeout as aDuration
.Default is the system's default timeout.
- See Also:
-
enableCompression
public void enableCompression(boolean enable) Set whether support for uncompressing "gzip" and "deflate" HTTP responses is enabled.- Since:
- 7.0
-
createRequest
Description copied from interface:ClientHttpRequestFactory
Create a newClientHttpRequest
for the specified URI and HTTP method.The returned request can be written to, and then executed by calling
ClientHttpRequest.execute()
.- Specified by:
createRequest
in interfaceClientHttpRequestFactory
- Parameters:
uri
- the URI to create a request forhttpMethod
- the HTTP method to execute- Returns:
- the created request
- Throws:
IOException
- in case of I/O errors
-