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).HttpClientlogger| Constructor and Description |
|---|
HttpComponentsMessageSender()
Create a new instance of the
HttpClientMessageSender with a default HttpClient that uses a
default SingleClientConnManager. |
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, supportspublic HttpComponentsMessageSender()
HttpClientMessageSender with a default HttpClient that uses a
default SingleClientConnManager.public HttpComponentsMessageSender(org.apache.http.client.HttpClient httpClient)
HttpClientMessageSender with the given HttpClient instance.httpClient - the HttpClient instance to use for this senderpublic void setCredentials(org.apache.http.auth.Credentials credentials)
UsernamePasswordCredentials,
NTCredentialspublic 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 millisecondsHttpConnectionParams.setConnectionTimeout(org.apache.http.params.HttpParams, int)public void setReadTimeout(int timeout)
timeout - the timeout value in millisecondsHttpConnectionParams.setSoTimeout(org.apache.http.params.HttpParams, int)public void setMaxTotalConnections(int maxTotalConnections)
maxTotalConnections - the maximum number of connections allowedThreadSafeClientConnManager.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=10The host can be specified as a URI (with scheme and port).
maxConnectionsPerHost - a properties object specifying the maximum number of connectionURISyntaxExceptionThreadSafeClientConnManager.setMaxForRoute(org.apache.http.conn.routing.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.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 org.apache.http.protocol.HttpContext createContext(URI uri)
HttpContext for the given uri. Default implementation
returns null.uri - the URI to create the context fornullCopyright © 2005–2015 The Spring Web Services Framework. All rights reserved.