public class HttpComponentsMessageSender extends AbstractHttpWebServiceMessageSender implements InitializingBean, 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 PoolingClientConnectionManager. |
HttpComponentsMessageSender(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 HttpContext |
createContext(URI uri)
Template method that allows for creation of a
HttpContext for the given uri. |
void |
destroy() |
HttpClient |
getHttpClient()
Returns the
HttpClient used by this message sender. |
void |
setAuthScope(AuthScope authScope)
Sets the authentication scope to be used.
|
void |
setConnectionTimeout(int timeout)
Sets the timeout until a connection is established.
|
void |
setCredentials(Credentials credentials)
Sets the credentials to be used.
|
void |
setHttpClient(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, supportspublic HttpComponentsMessageSender()
HttpClientMessageSender with a default HttpClient that uses a
default PoolingClientConnectionManager.public HttpComponentsMessageSender(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(Credentials credentials)
UsernamePasswordCredentials,
NTCredentialspublic HttpClient getHttpClient()
HttpClient used by this message sender.public void setHttpClient(HttpClient httpClient)
HttpClient used by this message sender.public void setConnectionTimeout(int timeout)
timeout - the timeout value in millisecondsHttpConnectionParamspublic void setReadTimeout(int timeout)
timeout - the timeout value in millisecondsHttpConnectionParamspublic void setMaxTotalConnections(int maxTotalConnections)
maxTotalConnections - the maximum number of connections allowedPoolingClientConnectionManagerpublic 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 connectionURISyntaxExceptionPoolingClientConnectionManagerpublic void setAuthScope(AuthScope authScope)
credentials property has been set.
By default, the AuthScope.ANY is used.
setCredentials(Credentials)public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface InitializingBeanExceptionpublic WebServiceConnection createConnection(URI uri) throws IOException
WebServiceMessageSenderWebServiceConnection to the specified URI.createConnection in interface WebServiceMessageSenderuri - the URI to open a connection toIOException - in case of I/O errorsprotected HttpContext createContext(URI uri)
HttpContext for the given uri. Default implementation
returns null.uri - the URI to create the context fornullpublic void destroy()
throws Exception
destroy in interface DisposableBeanException