org.springframework.http.client

## Class HttpComponentsAsyncClientHttpRequestFactory

- java.lang.Object
- - org.springframework.http.client.HttpComponentsClientHttpRequestFactory
  - - org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory

- All Implemented Interfaces:
    DisposableBean, InitializingBean, AsyncClientHttpRequestFactory, ClientHttpRequestFactory

      public class HttpComponentsAsyncClientHttpRequestFactory
      extends HttpComponentsClientHttpRequestFactory
      implements AsyncClientHttpRequestFactory, InitializingBean

  Asynchronous extension of the `HttpComponentsClientHttpRequestFactory`. Uses Apache HttpComponents HttpAsyncClient 4.0 to create requests.
  Since:
    4.0
  Author:
    Arjen Poutsma
  See Also:
    `HttpAsyncClient`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpComponentsAsyncClientHttpRequestFactory()` Create a new instance of the `HttpComponentsAsyncClientHttpRequestFactory` with a default `HttpAsyncClient` and `HttpClient`.
    `HttpComponentsAsyncClientHttpRequestFactory(org.apache.http.impl.nio.client.CloseableHttpAsyncClient httpAsyncClient)` Create a new instance of the `HttpComponentsAsyncClientHttpRequestFactory` with the given `HttpAsyncClient` instance and a default `HttpClient`.
    `HttpComponentsAsyncClientHttpRequestFactory(org.apache.http.impl.client.CloseableHttpClient httpClient, org.apache.http.impl.nio.client.CloseableHttpAsyncClient httpAsyncClient)` Create a new instance of the `HttpComponentsAsyncClientHttpRequestFactory` with the given `HttpClient` and `HttpAsyncClient` instances.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
    `AsyncClientHttpRequest` | `createAsyncRequest(URI uri, HttpMethod httpMethod)` Create a new asynchronous `AsyncClientHttpRequest` for the specified URI and HTTP method.
    `void` | `destroy()` Shutdown hook that closes the underlying `ClientConnectionManager`'s connection pool, if any.
    `org.apache.http.impl.nio.client.CloseableHttpAsyncClient` | `getHttpAsyncClient()` Return the `HttpClient` used for asynchronous execution.
    `void` | `setHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient httpAsyncClient)` Set the `HttpClient` used for asynchronous execution.

    - ### Methods inherited from class org.springframework.http.client.HttpComponentsClientHttpRequestFactory

      `createHttpContext, createHttpUriRequest, createRequest, getHttpClient, postProcessHttpRequest, setBufferRequestBody, setConnectTimeout, setHttpClient, setReadTimeout`

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

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

- - ### Constructor Detail

    - #### HttpComponentsAsyncClientHttpRequestFactory

          public HttpComponentsAsyncClientHttpRequestFactory()

      Create a new instance of the `HttpComponentsAsyncClientHttpRequestFactory` with a default `HttpAsyncClient` and `HttpClient`.

    - #### HttpComponentsAsyncClientHttpRequestFactory

          public HttpComponentsAsyncClientHttpRequestFactory(org.apache.http.impl.nio.client.CloseableHttpAsyncClient httpAsyncClient)

      Create a new instance of the `HttpComponentsAsyncClientHttpRequestFactory` with the given `HttpAsyncClient` instance and a default `HttpClient`.
      Parameters:
        `httpAsyncClient` - the HttpAsyncClient instance to use for this request factory

    - #### HttpComponentsAsyncClientHttpRequestFactory

          public HttpComponentsAsyncClientHttpRequestFactory(org.apache.http.impl.client.CloseableHttpClient httpClient,
                                                             org.apache.http.impl.nio.client.CloseableHttpAsyncClient httpAsyncClient)

      Create a new instance of the `HttpComponentsAsyncClientHttpRequestFactory` with the given `HttpClient` and `HttpAsyncClient` instances.
      Parameters:
        `httpClient` - the HttpClient instance to use for this request factory
        `httpAsyncClient` - the HttpAsyncClient instance to use for this request factory

  - ### Method Detail

    - #### setHttpAsyncClient

          public void setHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient httpAsyncClient)

      Set the `HttpClient` used for asynchronous execution.

    - #### getHttpAsyncClient

          public org.apache.http.impl.nio.client.CloseableHttpAsyncClient getHttpAsyncClient()

      Return the `HttpClient` used for asynchronous execution.

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      Description copied from interface: `InitializingBean`
      Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

      This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

      Specified by:
        `afterPropertiesSet` in interface `InitializingBean`

    - #### createAsyncRequest

          public AsyncClientHttpRequest createAsyncRequest(URI uri,
                                                           HttpMethod httpMethod)
                                                    throws IOException

      Description copied from interface: `AsyncClientHttpRequestFactory`
      Create a new asynchronous `AsyncClientHttpRequest` for the specified URI and HTTP method.

      The returned request can be written to, and then executed by calling `AsyncClientHttpRequest.executeAsync()`.

      Specified by:
        `createAsyncRequest` in interface `AsyncClientHttpRequestFactory`
      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

    - #### destroy

          public void destroy()
                       throws Exception

      Description copied from class: `HttpComponentsClientHttpRequestFactory`
      Shutdown hook that closes the underlying `ClientConnectionManager`'s connection pool, if any.
      Specified by:
        `destroy` in interface `DisposableBean`
      Overrides:
        `destroy` in class `HttpComponentsClientHttpRequestFactory`
      Throws:
        `Exception` - in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to release their resources too.