Package org.springframework.http.client.reactive

# Class JdkClientHttpConnector

java.lang.Object
org.springframework.http.client.reactive.JdkClientHttpConnector

All Implemented Interfaces:
  `ClientHttpConnector`

public class JdkClientHttpConnector extends Object implements ClientHttpConnector
`ClientHttpConnector` for the Java `HttpClient`.

Since:
  6.0
Author:
  Julien Eyraud, Rossen Stoyanchev
See Also:
  - HttpClient

## Constructor Summary

Constructors
Constructor
Description
`JdkClientHttpConnector()`
Default constructor that uses `HttpClient.newHttpClient()`.
`JdkClientHttpConnector(HttpClient httpClient)`
Constructor with an initialized `HttpClient` and a `DataBufferFactory`.
`JdkClientHttpConnector(HttpClient.Builder clientBuilder, JdkHttpClientResourceFactory resourceFactory)`
Constructor with a `JdkHttpClientResourceFactory` that provides shared resources.

## Method Summary

Modifier and Type
Method
Description
`reactor.core.publisher.Mono<ClientHttpResponse>`
`connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest,reactor.core.publisher.Mono<Void>> requestCallback)`
Connect to the origin server using the given `HttpMethod` and `URI` and apply the given `requestCallback` when the HTTP request of the underlying API can be initialized and written to.
`void`
`setBufferFactory(org.springframework.core.io.buffer.DataBufferFactory bufferFactory)`
Set the buffer factory to use.
`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

### JdkClientHttpConnector

public JdkClientHttpConnector()
Default constructor that uses `HttpClient.newHttpClient()`.

### JdkClientHttpConnector

public JdkClientHttpConnector(HttpClient httpClient)
Constructor with an initialized `HttpClient` and a `DataBufferFactory`.

### JdkClientHttpConnector

public JdkClientHttpConnector(HttpClient.Builder clientBuilder, @Nullable JdkHttpClientResourceFactory resourceFactory)
Constructor with a `JdkHttpClientResourceFactory` that provides shared resources.

Parameters:
  `clientBuilder` - a pre-initialized builder for the client that will be further initialized with the shared resources to use
  `resourceFactory` - the `JdkHttpClientResourceFactory` to use

## Method Details

### setBufferFactory

public void setBufferFactory(org.springframework.core.io.buffer.DataBufferFactory bufferFactory)
Set the buffer factory to use.

By default, this is `DefaultDataBufferFactory.sharedInstance`.

### setReadTimeout

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

Default is the system's default timeout.

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

### connect

public reactor.core.publisher.Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest,reactor.core.publisher.Mono<Void>> requestCallback)
Description copied from interface: `ClientHttpConnector`
Connect to the origin server using the given `HttpMethod` and `URI` and apply the given `requestCallback` when the HTTP request of the underlying API can be initialized and written to.

Specified by:
  `connect` in interface `ClientHttpConnector`
Parameters:
  `method` - the HTTP request method
  `uri` - the HTTP request URI
  `requestCallback` - a function that prepares and writes to the request, returning a publisher that signals when it's done writing. Implementations can return a `Mono<Void>` by calling `ReactiveHttpOutputMessage.writeWith(org.reactivestreams.Publisher<? extends org.springframework.core.io.buffer.DataBuffer>)` or `ReactiveHttpOutputMessage.setComplete()`.
Returns:
  publisher for the `ClientHttpResponse`