Class HttpComponentsMessageSender
java.lang.Object
org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender
org.springframework.ws.transport.http.HttpComponentsMessageSender
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
,WebServiceMessageSender
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
).
- Since:
- 2.1.0
- Author:
- Alan Stewart, Barry Pitman, Arjen Poutsma, Greg Turnquist
- See Also:
-
HttpClient
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
HttpClientHttpRequestInterceptor
implementation that removesContent-Length
andTransfer-Encoding
headers from the request. -
Field Summary
Fields inherited from class org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender
logger
-
Constructor Summary
ConstructorDescriptionCreate a new instance of theHttpClientMessageSender
with a defaultHttpClient
that uses a defaultPoolingClientConnectionManager
.HttpComponentsMessageSender
(org.apache.http.client.HttpClient httpClient) Create a new instance of theHttpClientMessageSender
with the givenHttpClient
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
createConnection
(URI uri) Create a newWebServiceConnection
to the specified URI.protected org.apache.http.protocol.HttpContext
createContext
(URI uri) Template method that allows for creation of aHttpContext
for the given uri.void
destroy()
org.apache.http.client.HttpClient
Returns theHttpClient
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 theHttpClient
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.Methods inherited from class org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender
isAcceptGzipEncoding, setAcceptGzipEncoding, supports
-
Constructor Details
-
HttpComponentsMessageSender
public HttpComponentsMessageSender()Create a new instance of theHttpClientMessageSender
with a defaultHttpClient
that uses a defaultPoolingClientConnectionManager
. -
HttpComponentsMessageSender
public HttpComponentsMessageSender(org.apache.http.client.HttpClient httpClient) Create a new instance of theHttpClientMessageSender
with the givenHttpClient
instance.This constructor does not change the given
HttpClient
in any way. As such, it does not set timeouts, nor does it add theHttpComponentsMessageSender.RemoveSoapHeadersInterceptor
.- Parameters:
httpClient
- the HttpClient instance to use for this sender
-
-
Method Details
-
setCredentials
public void setCredentials(org.apache.http.auth.Credentials credentials) Sets the credentials to be used. If not set, no authentication is done.- See Also:
-
UsernamePasswordCredentials
NTCredentials
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()Returns theHttpClient
used by this message sender. -
setHttpClient
public void setHttpClient(org.apache.http.client.HttpClient httpClient) Set theHttpClient
used by this message sender. -
setConnectionTimeout
public void setConnectionTimeout(int timeout) Sets the timeout until a connection is established. A value of 0 means never timeout.- Parameters:
timeout
- the timeout value in milliseconds- See Also:
-
HttpConnectionParams.setConnectionTimeout(org.apache.http.params.HttpParams, int)
-
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:
-
HttpConnectionParams.setSoTimeout(org.apache.http.params.HttpParams, int)
-
setMaxTotalConnections
public void setMaxTotalConnections(int maxTotalConnections) Sets the maximum number of connections allowed for the underlying HttpClient.- Parameters:
maxTotalConnections
- the maximum number of connections allowed- See Also:
-
PoolingClientConnectionManager.setMaxTotal(int)
-
setMaxConnectionsPerHost
public void setMaxConnectionsPerHost(Map<String, String> maxConnectionsPerHost) throws URISyntaxExceptionSets the maximum number of connections per host for the underlying HttpClient. The maximum number of connections per host can be set in a form accepted by thejava.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).
- Parameters:
maxConnectionsPerHost
- a properties object specifying the maximum number of connection- Throws:
URISyntaxException
- See Also:
-
PoolingClientConnectionManager.setMaxPerRoute(HttpRoute, int)
-
setAuthScope
public void setAuthScope(org.apache.http.auth.AuthScope authScope) Sets the authentication scope to be used. Only used when thecredentials
property has been set.By default, the
AuthScope.ANY
is used.- See Also:
-
afterPropertiesSet
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
createConnection
Description copied from interface:WebServiceMessageSender
Create a newWebServiceConnection
to the specified URI.- Specified by:
createConnection
in interfaceWebServiceMessageSender
- Parameters:
uri
- the URI to open a connection to- Returns:
- the new connection
- Throws:
IOException
- in case of I/O errors
-
createContext
Template method that allows for creation of aHttpContext
for the given uri. Default implementation returnsnull
.- Parameters:
uri
- the URI to create the context for- Returns:
- the context, or
null
-
destroy
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
- Throws:
Exception
-