public class CloseableHttpComponentsMessageSender
extends org.springframework.ws.transport.http.HttpComponentsMessageSender
WebServiceMessageSender
implementation that uses Apache
HttpClient (CloseableHttpClient
) 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
). Out of box contains CloseableHttpComponentsMessageSender.RemoveSoapHeadersInterceptor
.
HttpClient
,
CloseableHttpClient
,
PoolingHttpClientConnectionManager
,
UsernamePasswordCredentials
Modifier and Type | Class and Description |
---|---|
static class |
CloseableHttpComponentsMessageSender.PreemptiveAuthInterceptor
HttpClient
HttpRequestInterceptor implementation that configures the Apache Http Client
for preemptive authentication. |
static class |
CloseableHttpComponentsMessageSender.RemoveSoapHeadersInterceptor
HttpClient
HttpRequestInterceptor implementation that removes Content-Length and
Transfer-Encoding headers from the request. |
Modifier and Type | Field and Description |
---|---|
protected static String |
MACHINE_NAME |
Constructor and Description |
---|
CloseableHttpComponentsMessageSender()
Create a new instance of the
HttpClientMessageSender with a default HttpClient
that uses a default PoolingHttpClientConnectionManager . |
CloseableHttpComponentsMessageSender(boolean usePreemptiveAuth)
Create a new instance of the
HttpClientMessageSender with a default HttpClient
that uses a default PoolingHttpClientConnectionManager . |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
void |
closeIdleConnections(long timeout)
Closes connections that have been idle for at least the given amount of time.
|
protected org.apache.http.protocol.HttpContext |
createContext(URI uri)
Template method that allows for creation of a
HttpContext for the given uri. |
void |
destroy() |
protected org.apache.http.impl.client.HttpClientBuilder |
getClientBuilder()
Gets the
HttpClientBuilder . |
org.apache.http.pool.ConnPoolControl |
getConnPoolControl()
Gets the
ConnPoolControl . |
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.
|
protected void |
setCredentialsProvider(org.apache.http.client.CredentialsProvider credentialsProvider)
Sets the implementation of
CredentialsProvider . |
void |
setDefaultMaxPerHost(int defaultMaxPerHost)
Sets the default maximum number of connections allowed per host for the underlying HttpClient.
|
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.
|
createConnection, setHttpClient
protected static final String MACHINE_NAME
public CloseableHttpComponentsMessageSender()
HttpClientMessageSender
with a default HttpClient
that uses a default PoolingHttpClientConnectionManager
.public CloseableHttpComponentsMessageSender(boolean usePreemptiveAuth)
HttpClientMessageSender
with a default HttpClient
that uses a default PoolingHttpClientConnectionManager
.usePreemptiveAuth
- as flag whether preemptive authentication should be usedpublic void setCredentials(org.apache.http.auth.Credentials credentials)
setCredentials
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
UsernamePasswordCredentials
,
NTCredentials
public org.apache.http.client.HttpClient getHttpClient()
HttpClient
used by this message sender.getHttpClient
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
public void setConnectionTimeout(int timeout)
setConnectionTimeout
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
timeout
- the timeout value in millisecondsRequestConfig.Builder.setConnectTimeout(int)
,
RequestConfig.Builder.setConnectionRequestTimeout(int)
public void setReadTimeout(int timeout)
setReadTimeout
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
timeout
- the timeout value in millisecondsRequestConfig.Builder.setSocketTimeout(int)
public void closeIdleConnections(long timeout)
timeout
- the timeout value in millisecondsPoolingHttpClientConnectionManager.closeIdleConnections(long, java.util.concurrent.TimeUnit)
public void setMaxTotalConnections(int maxTotalConnections)
setMaxTotalConnections
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
maxTotalConnections
- the maximum number of connections allowedHttpClientBuilder.setMaxConnTotal(int)
,
PoolingHttpClientConnectionManager.setMaxTotal(int)
public void setDefaultMaxPerHost(int defaultMaxPerHost)
defaultMaxPerHost
- the maximum number of connections allowed per hostHttpClientBuilder.setMaxConnPerRoute(int)
,
PoolingHttpClientConnectionManager.setDefaultMaxPerRoute(int)
public void setMaxConnectionsPerHost(Map<String,String> maxConnectionsPerHost) throws URISyntaxException
java.util.Properties
class, like as follows:
https://esb.openhubframework.org/esb/=1 http://esb.openhubframework.org:8080/esb/=7 http://esb.openhubframework.org/esb/=10
The host can be specified as a URI (with scheme and port).
setMaxConnectionsPerHost
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
maxConnectionsPerHost
- a properties object specifying the maximum number of connectionURISyntaxException
PoolingHttpClientConnectionManager.setMaxPerRoute(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.
setAuthScope
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
setCredentials(Credentials)
protected org.apache.http.protocol.HttpContext createContext(URI uri)
HttpContext
for the given uri. Default implementation
returns null
.createContext
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
uri
- the uri to create the context fornull
public org.apache.http.pool.ConnPoolControl getConnPoolControl()
ConnPoolControl
.ConnPoolControl
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
afterPropertiesSet
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
Exception
public void destroy() throws Exception
destroy
in interface org.springframework.beans.factory.DisposableBean
destroy
in class org.springframework.ws.transport.http.HttpComponentsMessageSender
Exception
protected org.apache.http.impl.client.HttpClientBuilder getClientBuilder()
HttpClientBuilder
.HttpClientBuilder
protected void setCredentialsProvider(org.apache.http.client.CredentialsProvider credentialsProvider)
CredentialsProvider
.credentialsProvider
- the implementation of CredentialsProvider
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.