Package org.springframework.http.client.reactive

# Class HttpComponentsClientHttpConnector

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

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `ClientHttpConnector`

public class HttpComponentsClientHttpConnector extends Object implements ClientHttpConnector, Closeable
`ClientHttpConnector` implementation for the Apache HttpComponents HttpClient 5.x.

Since:
  5.3
Author:
  Martin Tarjányi, Arjen Poutsma
See Also:
  - Apache HttpComponents

## Constructor Summary

Constructors
Constructor
Description
`HttpComponentsClientHttpConnector()`
Default constructor that creates and starts a new instance of `CloseableHttpAsyncClient`.
`HttpComponentsClientHttpConnector(CloseableHttpAsyncClient client)`
Constructor with a pre-configured `CloseableHttpAsyncClient` instance.
`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.

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
`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.

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

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

## Constructor Details

### HttpComponentsClientHttpConnector

public HttpComponentsClientHttpConnector()
Default constructor that creates and starts a new instance of `CloseableHttpAsyncClient`.

### HttpComponentsClientHttpConnector

public HttpComponentsClientHttpConnector(CloseableHttpAsyncClient client)
Constructor with a pre-configured `CloseableHttpAsyncClient` instance.

Parameters:
  `client` - the client to use

### HttpComponentsClientHttpConnector

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` - the client to use
  `contextProvider` - a `HttpClientContext` supplier

## Method Details

### setBufferFactory

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

### 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`

### close

public void close() throws IOException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Throws:
  `IOException`