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

public Class HttpComponentsClientHttpConnector

extends Object
implements ClientHttpConnector, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, org.springframework.http.client.reactive.ClientHttpConnector
Imports
java.io.Closeable, .IOException, java.net.URI, java.nio.ByteBuffer, java.util.concurrent.CancellationException, java.util.function.BiFunction, .Function, org.apache.hc.client5.http.cookie.BasicCookieStore, org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient, .HttpAsyncClients, org.apache.hc.client5.http.protocol.HttpClientContext, org.apache.hc.core5.concurrent.FutureCallback, org.apache.hc.core5.http.HttpResponse, .HttpStreamResetException, .Message, org.apache.hc.core5.http.nio.AsyncRequestProducer, org.apache.hc.core5.reactive.ReactiveResponseConsumer, org.reactivestreams.Publisher, reactor.core.publisher.Mono, .MonoSink, org.springframework.core.io.buffer.DataBufferFactory, .DefaultDataBufferFactory, org.springframework.http.HttpMethod, org.springframework.util.Assert

ClientHttpConnector implementation for the Apache HttpComponents HttpClient 5.x.
Authors
Martin Tarjányi, Arjen Poutsma
Since
5.3
See Also
Apache HttpComponents

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
HttpComponentsClientHttpConnector.ResponseCallback

Callback that invoked when a response is received.

private static class
HttpComponentsClientHttpConnector.ResultCallback

Callback that invoked when a request is executed.

Field Summary

Modifier and TypeField and Description
private final CloseableHttpAsyncClient
private final BiFunction<HttpMethod, URI, ? extends HttpClientContext>
private DataBufferFactory

Constructor Summary

AccessConstructor and Description
public
HttpComponentsClientHttpConnector()

Default constructor that creates and starts a new instance of CloseableHttpAsyncClient.

public
HttpComponentsClientHttpConnector(CloseableHttpAsyncClient
the client to use
client
)

Constructor with a pre-configured CloseableHttpAsyncClient instance.

public
HttpComponentsClientHttpConnector(CloseableHttpAsyncClient
the client to use
client
,
BiFunction<HttpMethod, URI, ? extends HttpClientContext> contextProvider)

Constructor with a pre-configured CloseableHttpAsyncClient instance and a HttpClientContext supplier lambda which is called before each request and passed to the client.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.
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.
private Mono<ClientHttpResponse>
public void
setBufferFactory(DataBufferFactory bufferFactory)

Set the buffer factory to use.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

clientback to summary
private final CloseableHttpAsyncClient client
contextProviderback to summary
private final BiFunction<HttpMethod, URI, ? extends HttpClientContext> contextProvider
dataBufferFactoryback to summary
private DataBufferFactory dataBufferFactory

Constructor Detail

HttpComponentsClientHttpConnectorback to summary
public HttpComponentsClientHttpConnector()

Default constructor that creates and starts a new instance of CloseableHttpAsyncClient.

HttpComponentsClientHttpConnectorback to summary
public HttpComponentsClientHttpConnector(CloseableHttpAsyncClient client)

Constructor with a pre-configured CloseableHttpAsyncClient instance.

Parameters
client:CloseableHttpAsyncClient

the client to use

HttpComponentsClientHttpConnectorback to summary
public HttpComponentsClientHttpConnector(CloseableHttpAsyncClient client, BiFunction<HttpMethod, URI, ? extends HttpClientContext> contextProvider)

Constructor with a pre-configured CloseableHttpAsyncClient instance and a HttpClientContext supplier lambda which is called before each request and passed to the client.

Parameters
client:CloseableHttpAsyncClient

the client to use

contextProvider:BiFunction<HttpMethod, URI, ? extends HttpClientContext>

a HttpClientContext supplier

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
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
executeback to summary
private Mono<ClientHttpResponse> execute(HttpComponentsClientHttpRequest request, HttpClientContext context)
setBufferFactoryback to summary
public void setBufferFactory(DataBufferFactory bufferFactory)

Set the buffer factory to use.

org.springframework.http.client.reactive back to summary

private Class HttpComponentsClientHttpConnector.ResponseCallback

extends Object
implements FutureCallback<Message<HttpResponse, Publisher<ByteBuffer>>>
Class Inheritance
  • java.lang.Object
  • org.springframework.http.client.reactive.HttpComponentsClientHttpConnector.ResponseCallback
All Implemented Interfaces
org.apache.hc.core5.concurrent.FutureCallback

Callback that invoked when a response is received.

Field Summary

Modifier and TypeField and Description
private final HttpClientContext
private final DataBufferFactory
private final MonoSink<ClientHttpResponse>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private final HttpClientContext context
dataBufferFactoryback to summary
private final DataBufferFactory dataBufferFactory
sinkback to summary
private final MonoSink<ClientHttpResponse> sink

Constructor Detail

ResponseCallbackback to summary
public ResponseCallback(MonoSink<ClientHttpResponse> sink, DataBufferFactory dataBufferFactory, HttpClientContext context)

Method Detail

cancelledback to summary
public void cancelled()

Implements org.apache.hc.core5.concurrent.FutureCallback.cancelled.

Annotations
@Override
completedback to summary
public void completed(Message<HttpResponse, Publisher<ByteBuffer>> result)

Implements org.apache.hc.core5.concurrent.FutureCallback.completed.

Annotations
@Override
failedback to summary
public void failed(Exception ex)

Implements org.apache.hc.core5.concurrent.FutureCallback.failed.

Annotations
@Override
org.springframework.http.client.reactive back to summary

private Class HttpComponentsClientHttpConnector.ResultCallback

extends Object
implements FutureCallback<Void>
Class Inheritance
  • java.lang.Object
  • org.springframework.http.client.reactive.HttpComponentsClientHttpConnector.ResultCallback
All Implemented Interfaces
org.apache.hc.core5.concurrent.FutureCallback

Callback that invoked when a request is executed.

Field Summary

Modifier and TypeField and Description
private final MonoSink<?>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

sinkback to summary
private final MonoSink<?> sink

Constructor Detail

ResultCallbackback to summary
public ResultCallback(MonoSink<?> sink)

Method Detail

cancelledback to summary
public void cancelled()

Implements org.apache.hc.core5.concurrent.FutureCallback.cancelled.

Annotations
@Override
completedback to summary
public void completed(Void result)

Implements org.apache.hc.core5.concurrent.FutureCallback.completed.

Annotations
@Override
failedback to summary
public void failed(Exception ex)

Implements org.apache.hc.core5.concurrent.FutureCallback.failed.

Annotations
@Override