Top Description Fields Constructors Methods
org.springframework.http.client.reactive

public Class JdkClientHttpConnector

extends Object
implements ClientHttpConnector
Class Inheritance
All Implemented Interfaces
org.springframework.http.client.reactive.ClientHttpConnector
Imports
java.net.URI, java.net.http.HttpClient, java.net.http.HttpRequest, java.net.http.HttpResponse, java.nio.ByteBuffer, java.util.List, java.util.concurrent.CompletableFuture, .Executor, .Flow, java.util.function.Function, reactor.core.publisher.Mono, org.springframework.core.io.buffer.DataBufferFactory, .DefaultDataBufferFactory, org.springframework.http.HttpMethod, org.springframework.lang.Nullable, org.springframework.util.Assert

ClientHttpConnector for the Java HttpClient.
Authors
Julien Eyraud, Rossen Stoyanchev
Since
6.0
See Also
HttpClient

Field Summary

Modifier and TypeField and Description
private DataBufferFactory
private final java.net.http.HttpClient

Constructor Summary

AccessConstructor and Description
public
JdkClientHttpConnector()

Default constructor that uses HttpClient#newHttpClient().

public
JdkClientHttpConnector(java.net.http.HttpClient httpClient)

Constructor with an initialized HttpClient and a DataBufferFactory.

public
JdkClientHttpConnector(java.net.http.HttpClient.Builder
a pre-initialized builder for the client that will be further initialized with the shared resources to use
clientBuilder
,
JdkHttpClientResourceFactory resourceFactory)

Constructor with a JdkHttpClientResourceFactory that provides shared resources.

Method Summary

Modifier and TypeMethod and Description
public Mono<ClientHttpResponse>
connect(HttpMethod
the HTTP request method
method
,
URI
the HTTP request URI
uri
,
Function<? super ClientHttpRequest, Mono<Void>>
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 ClientHttpRequest#writeWith or ClientHttpRequest#setComplete.
requestCallback
)

Implements org.springframework.http.client.reactive.ClientHttpConnector.connect.

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.
public void
setBufferFactory(DataBufferFactory bufferFactory)

Set the buffer factory to use.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferFactoryback to summary
private DataBufferFactory bufferFactory
httpClientback to summary
private final java.net.http.HttpClient httpClient

Constructor Detail

JdkClientHttpConnectorback to summary
public JdkClientHttpConnector()

Default constructor that uses HttpClient#newHttpClient().

JdkClientHttpConnectorback to summary
public JdkClientHttpConnector(java.net.http.HttpClient httpClient)

Constructor with an initialized HttpClient and a DataBufferFactory.

JdkClientHttpConnectorback to summary
public JdkClientHttpConnector(java.net.http.HttpClient.Builder clientBuilder, JdkHttpClientResourceFactory resourceFactory)

Constructor with a JdkHttpClientResourceFactory that provides shared resources.

Parameters
clientBuilder:java.net.http.HttpClient.Builder

a pre-initialized builder for the client that will be further initialized with the shared resources to use

resourceFactory:JdkHttpClientResourceFactory

the JdkHttpClientResourceFactory to use

Method Detail

connectback to summary
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, Function<? super ClientHttpRequest, Mono<Void>> requestCallback)

Implements org.springframework.http.client.reactive.ClientHttpConnector.connect.

Doc from org.springframework.http.client.reactive.ClientHttpConnector.connect.

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.

Parameters
method:HttpMethod

the HTTP request method

uri:URI

the HTTP request URI

requestCallback:Function<? super ClientHttpRequest, Mono<Void>>

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 ClientHttpRequest#writeWith or ClientHttpRequest#setComplete.

Returns:Mono<ClientHttpResponse>

publisher for the ClientHttpResponse

Annotations
@Override
setBufferFactoryback to summary
public void setBufferFactory(DataBufferFactory bufferFactory)

Set the buffer factory to use.

By default, this is DefaultDataBufferFactory#sharedInstance.