public class

CommonsClientHttpRequestFactory

extends Object
implements DisposableBean ClientHttpRequestFactory
java.lang.Object
   ↳ org.springframework.http.client.CommonsClientHttpRequestFactory

Class Overview

ClientHttpRequestFactory implementation that uses Jakarta Commons HttpClient to create requests.

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

Summary

Public Constructors
CommonsClientHttpRequestFactory()
Create a new instance of the CommonsHttpRequestFactory with a default HttpClient that uses a default MultiThreadedHttpConnectionManager.
CommonsClientHttpRequestFactory(HttpClient httpClient)
Create a new instance of the CommonsHttpRequestFactory with the given HttpClient instance.
Public Methods
ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod)
Create a new ClientHttpRequest for the specified URI and HTTP method.
void destroy()
Shutdown hook that closes the underlying HttpConnectionManager's connection pool, if any.
HttpClient getHttpClient()
Return the HttpClient used by this factory.
void setHttpClient(HttpClient httpClient)
Set the HttpClient used by this factory.
void setReadTimeout(int timeout)
Set the socket read timeout for the underlying HttpClient.
Protected Methods
HttpMethodBase createCommonsHttpMethod(HttpMethod httpMethod, String uri)
Create a Commons HttpMethodBase object for the given HTTP method and URI specification.
void postProcessCommonsHttpMethod(HttpMethodBase httpMethod)
Template method that allows for manipulating the org.apache.commons.httpclient.HttpMethodBase before it is returned as part of a CommonsClientHttpRequest.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.DisposableBean
From interface org.springframework.http.client.ClientHttpRequestFactory

Public Constructors

public CommonsClientHttpRequestFactory ()

Create a new instance of the CommonsHttpRequestFactory with a default HttpClient that uses a default MultiThreadedHttpConnectionManager.

public CommonsClientHttpRequestFactory (HttpClient httpClient)

Create a new instance of the CommonsHttpRequestFactory with the given HttpClient instance.

Parameters
httpClient the HttpClient instance to use for this factory

Public Methods

public ClientHttpRequest createRequest (URI uri, HttpMethod httpMethod)

Create a new ClientHttpRequest for the specified URI and HTTP method.

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

Parameters
uri the URI to create a request for
httpMethod the HTTP method to execute
Returns
  • the created request
Throws
IOException

public void destroy ()

Shutdown hook that closes the underlying HttpConnectionManager's connection pool, if any.

public HttpClient getHttpClient ()

Return the HttpClient used by this factory.

public void setHttpClient (HttpClient httpClient)

Set the HttpClient used by this factory.

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
  • org.apache.commons.httpclient.params.HttpConnectionManagerParams#setSoTimeout(int)

Protected Methods

protected HttpMethodBase createCommonsHttpMethod (HttpMethod httpMethod, String uri)

Create a Commons HttpMethodBase object for the given HTTP method and URI specification.

Parameters
httpMethod the HTTP method
uri the URI
Returns
  • the Commons HttpMethodBase object

protected void postProcessCommonsHttpMethod (HttpMethodBase httpMethod)

Template method that allows for manipulating the org.apache.commons.httpclient.HttpMethodBase before it is returned as part of a CommonsClientHttpRequest.

The default implementation is empty.

Parameters
httpMethod the Commons HTTP method object to process