Spring Web Services Framework

org.springframework.ws.transport.http
Class HttpComponentsMessageSender

java.lang.Object
  extended by org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender
      extended by org.springframework.ws.transport.http.HttpComponentsMessageSender
All Implemented Interfaces:
DisposableBean, InitializingBean, WebServiceMessageSender

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).

Since:
2.1.0
Author:
Alan Stewart, Barry Pitman, Arjen Poutsma
See Also:
HttpClient

Nested Class Summary
static class HttpComponentsMessageSender.RemoveSoapHeadersInterceptor
          HttpClient HttpRequestInterceptor implementation that removes Content-Length and Transfer-Encoding headers from the request.
 
Field Summary
 
Fields inherited from class org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender
logger
 
Constructor Summary
HttpComponentsMessageSender()
          Create a new instance of the HttpClientMessageSender with a default HttpClient that uses a default PoolingClientConnectionManager.
HttpComponentsMessageSender(org.apache.http.client.HttpClient httpClient)
          Create a new instance of the HttpClientMessageSender with the given HttpClient instance.
 
Method Summary
 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.
 
Methods inherited from class org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender
isAcceptGzipEncoding, setAcceptGzipEncoding, supports
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpComponentsMessageSender

public HttpComponentsMessageSender()
Create a new instance of the HttpClientMessageSender with a default HttpClient that uses a default PoolingClientConnectionManager.


HttpComponentsMessageSender

public HttpComponentsMessageSender(org.apache.http.client.HttpClient httpClient)
Create a new instance of the 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.

Parameters:
httpClient - the HttpClient instance to use for this sender
Method Detail

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 the HttpClient used by this message sender.


setHttpClient

public void setHttpClient(org.apache.http.client.HttpClient httpClient)
Set the HttpClient 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 URISyntaxException
Sets 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 the 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).

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 the credentials property has been set.

By default, the AuthScope.ANY is used.

See Also:
setCredentials(Credentials)

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
Exception

createConnection

public WebServiceConnection createConnection(URI uri)
                                      throws IOException
Description copied from interface: WebServiceMessageSender
Create a new WebServiceConnection to the specified URI.

Specified by:
createConnection in interface WebServiceMessageSender
Parameters:
uri - the URI to open a connection to
Returns:
the new connection
Throws:
IOException - in case of I/O errors

createContext

protected org.apache.http.protocol.HttpContext createContext(URI uri)
Template method that allows for creation of a HttpContext for the given uri. Default implementation returns null.

Parameters:
uri - the URI to create the context for
Returns:
the context, or null

destroy

public void destroy()
             throws Exception
Specified by:
destroy in interface DisposableBean
Throws:
Exception

Spring Web Services Framework

Copyright © 2005-2013 The Spring Web Services Framework. All Rights Reserved.