public class HttpComponentsMessageSender extends AbstractHttpWebServiceMessageSender implements org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
WebServiceMessageSender
implementation that uses Apache
HttpClient to execute POST requests.
Allows to use a pre-configured HttpClient instance, potentially with authentication, HTTP connection pooling, etc.
Authentication can also be set by injecting a Credentials
instance (such as the UsernamePasswordCredentials
).
HttpClient
Modifier and Type | Class and Description |
---|---|
static class |
HttpComponentsMessageSender.RemoveSoapHeadersInterceptor
HttpClient
HttpRequestInterceptor implementation that removes Content-Length and
Transfer-Encoding headers from the request. |
logger
Constructor and Description |
---|
HttpComponentsMessageSender()
Create a new instance of the
HttpClientMessageSender with a default HttpClient that uses a
default org.apache.http.impl.conn.PoolingClientConnectionManager . |
HttpComponentsMessageSender(org.apache.http.client.HttpClient httpClient)
Create a new instance of the
HttpClientMessageSender with the given
HttpClient instance. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
WebServiceConnection |
createConnection(URI uri)
Create a new
WebServiceConnection to the specified URI. |
protected org.apache.http.protocol.HttpContext |
createContext(URI uri)
Template method that allows for creation of a
HttpContext for the given uri. |
void |
destroy() |
org.apache.http.client.HttpClient |
getHttpClient()
Returns the
HttpClient used by this message sender. |
void |
setAuthScope(org.apache.http.auth.AuthScope authScope)
Sets the authentication scope to be used.
|
void |
setConnectionTimeout(int timeout)
Sets the timeout until a connection is established.
|
void |
setCredentials(org.apache.http.auth.Credentials credentials)
Sets the credentials to be used.
|
void |
setHttpClient(org.apache.http.client.HttpClient httpClient)
Set the
HttpClient used by this message sender. |
void |
setMaxConnectionsPerHost(Map<String,String> maxConnectionsPerHost)
Sets the maximum number of connections per host for the underlying HttpClient.
|
void |
setMaxTotalConnections(int maxTotalConnections)
Sets the maximum number of connections allowed for the underlying HttpClient.
|
void |
setReadTimeout(int timeout)
Set the socket read timeout for the underlying HttpClient.
|
isAcceptGzipEncoding, setAcceptGzipEncoding, supports
public HttpComponentsMessageSender()
HttpClientMessageSender
with a default HttpClient
that uses a
default org.apache.http.impl.conn.PoolingClientConnectionManager
.public HttpComponentsMessageSender(org.apache.http.client.HttpClient httpClient)
HttpClientMessageSender
with the given
HttpClient
instance.
This constructor does not change the given HttpClient
in any way. As such,
it does not set timeouts, nor does it
add
the HttpComponentsMessageSender.RemoveSoapHeadersInterceptor
.
httpClient
- the HttpClient instance to use for this senderpublic void setCredentials(org.apache.http.auth.Credentials credentials)
UsernamePasswordCredentials
,
NTCredentials
public org.apache.http.client.HttpClient getHttpClient()
HttpClient
used by this message sender.public void setHttpClient(org.apache.http.client.HttpClient httpClient)
HttpClient
used by this message sender.public void setConnectionTimeout(int timeout)
timeout
- the timeout value in millisecondsorg.apache.http.params.HttpConnectionParams#setConnectionTimeout(org.apache.http.params.HttpParams, int)
public void setReadTimeout(int timeout)
timeout
- the timeout value in millisecondsorg.apache.http.params.HttpConnectionParams#setSoTimeout(org.apache.http.params.HttpParams, int)
public void setMaxTotalConnections(int maxTotalConnections)
maxTotalConnections
- the maximum number of connections allowedorg.apache.http.impl.conn.PoolingClientConnectionManager#setMaxTotal(int)
public void setMaxConnectionsPerHost(Map<String,String> maxConnectionsPerHost) throws URISyntaxException
java.util.Properties
class, like as follows:
https://www.example.com=1 http://www.example.com:8080=7 http://www.springframework.org=10
The host can be specified as a URI (with scheme and port).
maxConnectionsPerHost
- a properties object specifying the maximum number of connectionURISyntaxException
org.apache.http.impl.conn.PoolingClientConnectionManager#setMaxPerRoute(HttpRoute, int)
public void setAuthScope(org.apache.http.auth.AuthScope authScope)
credentials
property has been set.
By default, the AuthScope.ANY
is used.
setCredentials(Credentials)
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public WebServiceConnection createConnection(URI uri) throws IOException
WebServiceMessageSender
WebServiceConnection
to the specified URI.createConnection
in interface WebServiceMessageSender
uri
- the URI to open a connection toIOException
- in case of I/O errorsprotected org.apache.http.protocol.HttpContext createContext(URI uri)
HttpContext
for the given uri. Default implementation
returns null
.uri
- the URI to create the context fornull