Package org.springframework.http.client

# Class JdkClientHttpRequestFactory

java.lang.Object
org.springframework.http.client.JdkClientHttpRequestFactory

All Implemented Interfaces:
  `ClientHttpRequestFactory`

public class JdkClientHttpRequestFactory extends Object implements ClientHttpRequestFactory
`ClientHttpRequestFactory` implementation based on the Java `HttpClient`.

Since:
  6.1
Author:
  Marten Deinum, Arjen Poutsma

## Constructor Summary

Constructors
Constructor
Description
`JdkClientHttpRequestFactory()`
Create a new instance of the `JdkClientHttpRequestFactory` with a default `HttpClient`.
`JdkClientHttpRequestFactory(HttpClient httpClient)`
Create a new instance of the `JdkClientHttpRequestFactory` based on the given `HttpClient`.
`JdkClientHttpRequestFactory(HttpClient httpClient, Executor executor)`
Create a new instance of the `JdkClientHttpRequestFactory` based on the given `HttpClient` and `Executor`.

## Method Summary

Modifier and Type
Method
Description
`ClientHttpRequest`
`createRequest(URI uri, HttpMethod httpMethod)`
Create a new `ClientHttpRequest` for the specified URI and HTTP method.
`void`
`setReadTimeout(int readTimeout)`
Set the underlying `HttpClient`'s read timeout (in milliseconds).
`void`
`setReadTimeout(Duration readTimeout)`
Set the underlying `HttpClient`'s read timeout as a `Duration`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### JdkClientHttpRequestFactory

public JdkClientHttpRequestFactory()
Create a new instance of the `JdkClientHttpRequestFactory` with a default `HttpClient`.

### JdkClientHttpRequestFactory

public JdkClientHttpRequestFactory(HttpClient httpClient)
Create a new instance of the `JdkClientHttpRequestFactory` based on the given `HttpClient`.

Parameters:
  `httpClient` - the client to base on

### JdkClientHttpRequestFactory

public JdkClientHttpRequestFactory(HttpClient httpClient, Executor executor)
Create a new instance of the `JdkClientHttpRequestFactory` based on the given `HttpClient` and `Executor`.

Parameters:
  `httpClient` - the client to base on
  `executor` - the executor to use for blocking write operations

## Method Details

### setReadTimeout

public void setReadTimeout(int readTimeout)
Set the underlying `HttpClient`'s read timeout (in milliseconds). A timeout value of 0 specifies an infinite timeout.

Default is the system's default timeout.

See Also:
  - `HttpRequest.Builder.timeout(java.time.Duration)`

### setReadTimeout

public void setReadTimeout(Duration readTimeout)
Set the underlying `HttpClient`'s read timeout as a `Duration`.

Default is the system's default timeout.

See Also:
  - `HttpRequest.Builder.timeout(java.time.Duration)`

### createRequest

public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException
Description copied from interface: `ClientHttpRequestFactory`
Create a new `ClientHttpRequest` 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 interface `ClientHttpRequestFactory`
Parameters:
  `uri` - the URI to create a request for
  `httpMethod` - the HTTP method to execute
Returns:
  the created request
Throws:
  `IOException` - in case of I/O errors