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
Nested ClassesModifier and TypeClassDescriptionstatic classHttpClientHttpRequestInterceptorimplementation that removesContent-LengthandTransfer-Encodingheaders from the request. -
Field Summary
Fields inherited from class org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender
logger -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance of theHttpClientMessageSenderwith a defaultHttpClientthat uses a defaultPoolingClientConnectionManager.HttpComponentsMessageSender(org.apache.http.client.HttpClient httpClient) Create a new instance of theHttpClientMessageSenderwith the givenHttpClientinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateConnection(URI uri) Create a newWebServiceConnectionto the specified URI.protected org.apache.http.protocol.HttpContextcreateContext(URI uri) Template method that allows for creation of aHttpContextfor the given uri.voiddestroy()org.apache.http.client.HttpClientReturns theHttpClientused by this message sender.voidsetAuthScope(org.apache.http.auth.AuthScope authScope) Sets the authentication scope to be used.voidsetConnectionTimeout(int timeout) Sets the timeout until a connection is established.voidsetCredentials(org.apache.http.auth.Credentials credentials) Sets the credentials to be used.voidsetHttpClient(org.apache.http.client.HttpClient httpClient) Set theHttpClientused by this message sender.voidsetMaxConnectionsPerHost(Map<String, String> maxConnectionsPerHost) Sets the maximum number of connections per host for the underlying HttpClient.voidsetMaxTotalConnections(int maxTotalConnections) Sets the maximum number of connections allowed for the underlying HttpClient.voidsetReadTimeout(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 theHttpClientMessageSenderwith a defaultHttpClientthat uses a defaultPoolingClientConnectionManager. -
HttpComponentsMessageSender
public HttpComponentsMessageSender(org.apache.http.client.HttpClient httpClient) Create a new instance of theHttpClientMessageSenderwith the givenHttpClientinstance.This constructor does not change the given
HttpClientin 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:
-
UsernamePasswordCredentialsNTCredentials
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()Returns theHttpClientused by this message sender. -
setHttpClient
public void setHttpClient(org.apache.http.client.HttpClient httpClient) Set theHttpClientused 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.Propertiesclass, 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 thecredentialsproperty has been set.By default, the
AuthScope.ANYis used.- See Also:
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
Exception
-
createConnection
Description copied from interface:WebServiceMessageSenderCreate a newWebServiceConnectionto the specified URI.- Specified by:
createConnectionin 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 aHttpContextfor the given uri. Default implementation returnsnull.- Parameters:
uri- the URI to create the context for- Returns:
- the context, or
null
-
destroy
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-