Package 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 theHttpComponentsClientHttpRequestFactory. Uses Apache HttpComponents HttpAsyncClient 4.0 to create requests.- Since:
- 4.0
- Author:
- Arjen Poutsma, Stephane Nicoll
- See Also:
HttpAsyncClient
Constructor Summary
Constructors Constructor Description HttpComponentsAsyncClientHttpRequestFactory()Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith a defaultHttpAsyncClientandHttpClient.HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, org.apache.http.nio.client.HttpAsyncClient asyncClient)Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith the givenHttpClientandHttpAsyncClientinstances.HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpClient httpClient, org.apache.http.impl.nio.client.CloseableHttpAsyncClient asyncClient)Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith the givenCloseableHttpClientandCloseableHttpAsyncClientinstances.HttpComponentsAsyncClientHttpRequestFactory(org.apache.http.impl.nio.client.CloseableHttpAsyncClient asyncClient)Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith the givenCloseableHttpAsyncClientinstance and a defaultHttpClient.HttpComponentsAsyncClientHttpRequestFactory(org.apache.http.nio.client.HttpAsyncClient asyncClient)Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith the givenHttpAsyncClientinstance and a defaultHttpClient.
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidafterPropertiesSet()Invoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.AsyncClientHttpRequestcreateAsyncRequest(URI uri, HttpMethod httpMethod)Create a new asynchronousAsyncClientHttpRequestfor the specified URI and HTTP method.voiddestroy()Shutdown hook that closes the underlyingClientConnectionManager's connection pool, if any.org.apache.http.nio.client.HttpAsyncClientgetAsyncClient()Return theHttpAsyncClientused for synchronous execution.org.apache.http.impl.nio.client.CloseableHttpAsyncClientgetHttpAsyncClient()Deprecated.as of 4.3.10, in favor ofgetAsyncClient()voidsetAsyncClient(org.apache.http.nio.client.HttpAsyncClient asyncClient)Set theHttpAsyncClientused for synchronous execution.voidsetHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient asyncClient)Deprecated.as of 4.3.10, in favor ofsetAsyncClient(HttpAsyncClient)Methods inherited from class org.springframework.http.client.HttpComponentsClientHttpRequestFactory
createHttpContext, createHttpUriRequest, createRequest, createRequestConfig, getHttpClient, mergeRequestConfig, postProcessHttpRequest, setBufferRequestBody, setConnectionRequestTimeout, setConnectTimeout, setHttpClient, setReadTimeout
Constructor Detail
HttpComponentsAsyncClientHttpRequestFactory
public HttpComponentsAsyncClientHttpRequestFactory()
Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith a defaultHttpAsyncClientandHttpClient.
HttpComponentsAsyncClientHttpRequestFactory
public HttpComponentsAsyncClientHttpRequestFactory(org.apache.http.nio.client.HttpAsyncClient asyncClient)
Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith the givenHttpAsyncClientinstance and a defaultHttpClient.- Parameters:
asyncClient- the HttpAsyncClient instance to use for this request factory- Since:
- 4.3.10
HttpComponentsAsyncClientHttpRequestFactory
public HttpComponentsAsyncClientHttpRequestFactory(org.apache.http.impl.nio.client.CloseableHttpAsyncClient asyncClient)
Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith the givenCloseableHttpAsyncClientinstance and a defaultHttpClient.- Parameters:
asyncClient- the CloseableHttpAsyncClient instance to use for this request factory
HttpComponentsAsyncClientHttpRequestFactory
public HttpComponentsAsyncClientHttpRequestFactory(HttpClient httpClient, org.apache.http.nio.client.HttpAsyncClient asyncClient)
Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith the givenHttpClientandHttpAsyncClientinstances.- Parameters:
httpClient- the HttpClient instance to use for this request factoryasyncClient- the HttpAsyncClient instance to use for this request factory- Since:
- 4.3.10
HttpComponentsAsyncClientHttpRequestFactory
public HttpComponentsAsyncClientHttpRequestFactory(CloseableHttpClient httpClient, org.apache.http.impl.nio.client.CloseableHttpAsyncClient asyncClient)
Create a new instance of theHttpComponentsAsyncClientHttpRequestFactorywith the givenCloseableHttpClientandCloseableHttpAsyncClientinstances.- Parameters:
httpClient- the CloseableHttpClient instance to use for this request factoryasyncClient- the CloseableHttpAsyncClient instance to use for this request factory
Method Detail
setAsyncClient
public void setAsyncClient(org.apache.http.nio.client.HttpAsyncClient asyncClient)
Set theHttpAsyncClientused for synchronous execution.- Since:
- 4.3.10
- See Also:
HttpComponentsClientHttpRequestFactory.setHttpClient(HttpClient)
getAsyncClient
public org.apache.http.nio.client.HttpAsyncClient getAsyncClient()
Return theHttpAsyncClientused for synchronous execution.- Since:
- 4.3.10
- See Also:
HttpComponentsClientHttpRequestFactory.getHttpClient()
setHttpAsyncClient
@Deprecated public void setHttpAsyncClient(org.apache.http.impl.nio.client.CloseableHttpAsyncClient asyncClient)
Deprecated.as of 4.3.10, in favor ofsetAsyncClient(HttpAsyncClient)Set theCloseableHttpAsyncClientused for asynchronous execution.
getHttpAsyncClient
@Deprecated public org.apache.http.impl.nio.client.CloseableHttpAsyncClient getHttpAsyncClient()
Deprecated.as of 4.3.10, in favor ofgetAsyncClient()Return theCloseableHttpAsyncClientused for asynchronous execution.
afterPropertiesSet
public void afterPropertiesSet()
Description copied from interface:InitializingBeanInvoked by the containingBeanFactoryafter it has set all bean properties and satisfiedBeanFactoryAware,ApplicationContextAwareetc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
- Specified by:
afterPropertiesSetin interfaceInitializingBean
createAsyncRequest
public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod) throws IOException
Description copied from interface:AsyncClientHttpRequestFactoryCreate a new asynchronousAsyncClientHttpRequestfor the specified URI and HTTP method.The returned request can be written to, and then executed by calling
AsyncClientHttpRequest.executeAsync().- Specified by:
createAsyncRequestin interfaceAsyncClientHttpRequestFactory- Parameters:
uri- the URI to create a request forhttpMethod- 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:HttpComponentsClientHttpRequestFactoryShutdown hook that closes the underlyingClientConnectionManager's connection pool, if any.- Specified by:
destroyin interfaceDisposableBean- Overrides:
destroyin classHttpComponentsClientHttpRequestFactory- Throws:
Exception- in case of shutdown errors. Exceptions will get logged but not rethrown to allow other beans to release their resources as well.