org.springframework.http.client
Class HttpComponentsClientHttpRequestFactory

java.lang.Object
  extended by org.springframework.http.client.HttpComponentsClientHttpRequestFactory
All Implemented Interfaces:
DisposableBean, ClientHttpRequestFactory

public class HttpComponentsClientHttpRequestFactory
extends java.lang.Object
implements ClientHttpRequestFactory, DisposableBean

ClientHttpRequestFactory implementation that uses Apache HttpClient to create requests.

Allows to use a pre-configured HttpClient instance - potentially with authentication, HTTP connection pooling, etc.

Since:
1.0.0
See Also:
SimpleClientHttpRequestFactory

Constructor Summary
HttpComponentsClientHttpRequestFactory()
          Create a new instance of the HttpComponentsClientHttpRequestFactory with a default HttpClient that uses a default MultiThreadedHttpConnectionManager.
HttpComponentsClientHttpRequestFactory(org.apache.http.client.HttpClient httpClient)
          Create a new instance of the HttpComponentsHttpRequestFactory with the given HttpClient instance.
 
Method Summary
protected  org.apache.http.client.methods.HttpUriRequest createHttpRequest(HttpMethod httpMethod, java.net.URI uri)
          Create a HttpComponents HttpUrlRequest object for the given HTTP method and URI specification.
 ClientHttpRequest createRequest(java.net.URI uri, HttpMethod httpMethod)
           
 void destroy()
          Shutdown hook that closes the underlying ClientConnectionManager's connection pool, if any.
 org.apache.http.client.HttpClient getHttpClient()
          Return the HttpClient used by this factory.
protected  void postProcessHttpRequest(org.apache.http.client.methods.HttpUriRequest httpRequest)
          Template method that allows for manipulating the HttpUriRequest before it is returned as part of a HttpComponentsClientHttpRequest.
 void setHttpClient(org.apache.http.client.HttpClient httpClient)
          Set the HttpClient used by this factory.
 void setReadTimeout(int timeout)
          Set the socket read timeout for the underlying HttpClient.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpComponentsClientHttpRequestFactory

public HttpComponentsClientHttpRequestFactory()
Create a new instance of the HttpComponentsClientHttpRequestFactory with a default HttpClient that uses a default MultiThreadedHttpConnectionManager.


HttpComponentsClientHttpRequestFactory

public HttpComponentsClientHttpRequestFactory(org.apache.http.client.HttpClient httpClient)
Create a new instance of the HttpComponentsHttpRequestFactory with the given HttpClient instance.

Parameters:
httpClient - the HttpClient instance to use for this factory
Method Detail

setHttpClient

public void setHttpClient(org.apache.http.client.HttpClient httpClient)
Set the HttpClient used by this factory.


getHttpClient

public org.apache.http.client.HttpClient getHttpClient()
Return the HttpClient used by this factory.


setReadTimeout

public void setReadTimeout(int timeout)
Set the socket read timeout for the underlying HttpClient. A value of 0 means never timeout.

Parameters:
timeout - the timeout value in milliseconds
See Also:
HttpParams.setIntParameter(String, int)

createRequest

public ClientHttpRequest createRequest(java.net.URI uri,
                                       HttpMethod httpMethod)
                                throws java.io.IOException
Specified by:
createRequest in interface ClientHttpRequestFactory
Throws:
java.io.IOException

createHttpRequest

protected org.apache.http.client.methods.HttpUriRequest createHttpRequest(HttpMethod httpMethod,
                                                                          java.net.URI uri)
Create a HttpComponents HttpUrlRequest object for the given HTTP method and URI specification.

Parameters:
httpMethod - the HTTP method
uri - the URI
Returns:
the HttpComponents HttpUrlRequest object

postProcessHttpRequest

protected void postProcessHttpRequest(org.apache.http.client.methods.HttpUriRequest httpRequest)
Template method that allows for manipulating the HttpUriRequest before it is returned as part of a HttpComponentsClientHttpRequest.

The default implementation is empty.

Parameters:
httpMethod - the Commons HTTP method object to process

destroy

public void destroy()
Shutdown hook that closes the underlying ClientConnectionManager's connection pool, if any.

Specified by:
destroy in interface DisposableBean