Skip to content

Commit 7788210

Browse files
author
Arjen Poutsma
committed
Use PoolingClientConnectionManager
Use PoolingClientConnectionManager instead of the deprecated ThreadSafeClientConnManager in the HttpComponentsMessageSender. Issue: SWS-838
1 parent faaae2d commit 7788210

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

core/src/main/java/org/springframework/ws/transport/http/HttpComponentsMessageSender.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
import org.apache.http.conn.ClientConnectionManager;
3535
import org.apache.http.conn.routing.HttpRoute;
3636
import org.apache.http.impl.client.DefaultHttpClient;
37-
import org.apache.http.impl.conn.SingleClientConnManager;
38-
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
37+
import org.apache.http.impl.conn.PoolingClientConnectionManager;
3938
import org.apache.http.params.HttpConnectionParams;
4039
import org.apache.http.protocol.HTTP;
4140
import org.apache.http.protocol.HttpContext;
@@ -74,10 +73,10 @@ public class HttpComponentsMessageSender extends AbstractHttpWebServiceMessageSe
7473

7574
/**
7675
* Create a new instance of the {@code HttpClientMessageSender} with a default {@link HttpClient} that uses a
77-
* default {@link SingleClientConnManager}.
76+
* default {@link PoolingClientConnectionManager}.
7877
*/
7978
public HttpComponentsMessageSender() {
80-
DefaultHttpClient defaultClient = new DefaultHttpClient(new ThreadSafeClientConnManager());
79+
DefaultHttpClient defaultClient = new DefaultHttpClient(new PoolingClientConnectionManager());
8180
defaultClient.addRequestInterceptor(new RemoveSoapHeadersInterceptor(), 0);
8281

8382
this.httpClient = defaultClient;
@@ -155,19 +154,19 @@ public void setReadTimeout(int timeout) {
155154
* Sets the maximum number of connections allowed for the underlying HttpClient.
156155
*
157156
* @param maxTotalConnections the maximum number of connections allowed
158-
* @see ThreadSafeClientConnManager#setMaxTotal(int)
157+
* @see PoolingClientConnectionManager#setMaxTotal(int)
159158
*/
160159
public void setMaxTotalConnections(int maxTotalConnections) {
161160
if (maxTotalConnections <= 0) {
162161
throw new IllegalArgumentException("maxTotalConnections must be a positive value");
163162
}
164163
ClientConnectionManager connectionManager = getHttpClient().getConnectionManager();
165-
if (!(connectionManager instanceof ThreadSafeClientConnManager)) {
164+
if (!(connectionManager instanceof PoolingClientConnectionManager)) {
166165
throw new IllegalArgumentException("maxTotalConnections is not supported on " +
167-
connectionManager.getClass().getName() + ". Use " + ThreadSafeClientConnManager.class.getName() +
166+
connectionManager.getClass().getName() + ". Use " + PoolingClientConnectionManager.class.getName() +
168167
" instead");
169168
}
170-
((ThreadSafeClientConnManager) connectionManager).setMaxTotal(maxTotalConnections);
169+
((PoolingClientConnectionManager) connectionManager).setMaxTotal(maxTotalConnections);
171170
}
172171

173172
/**
@@ -183,24 +182,26 @@ public void setMaxTotalConnections(int maxTotalConnections) {
183182
* The host can be specified as a URI (with scheme and port).
184183
*
185184
* @param maxConnectionsPerHost a properties object specifying the maximum number of connection
186-
* @see org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager#setMaxForRoute(org.apache.http.conn.routing.HttpRoute,
187-
* int)
185+
* @see PoolingClientConnectionManager#setMaxPerRoute(HttpRoute, int)
188186
*/
189187
public void setMaxConnectionsPerHost(Map<String, String> maxConnectionsPerHost) throws URISyntaxException {
190188
ClientConnectionManager connectionManager = getHttpClient().getConnectionManager();
191-
if (!(connectionManager instanceof ThreadSafeClientConnManager)) {
189+
if (!(connectionManager instanceof PoolingClientConnectionManager)) {
192190
throw new IllegalArgumentException("maxConnectionsPerHost is not supported on " +
193-
connectionManager.getClass().getName() + ". Use " + ThreadSafeClientConnManager.class.getName() +
191+
connectionManager.getClass().getName() + ". Use " + PoolingClientConnectionManager.class.getName() +
194192
" instead");
195193
}
194+
PoolingClientConnectionManager poolingConnectionManager =
195+
(PoolingClientConnectionManager) connectionManager;
196196

197-
for (Object o : maxConnectionsPerHost.keySet()) {
198-
String host = (String) o;
199-
URI uri = new URI(host);
200-
HttpHost httpHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
201-
int maxHostConnections = Integer.parseInt(maxConnectionsPerHost.get(host));
202-
((ThreadSafeClientConnManager) connectionManager)
203-
.setMaxForRoute(new HttpRoute(httpHost), maxHostConnections);
197+
for (Map.Entry<String, String> entry : maxConnectionsPerHost.entrySet()) {
198+
URI uri = new URI(entry.getKey());
199+
HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
200+
HttpRoute route = new HttpRoute(host);
201+
202+
int max = Integer.parseInt(entry.getValue());
203+
204+
poolingConnectionManager.setMaxPerRoute(route, max);
204205
}
205206
}
206207

parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@
638638
<dependency>
639639
<groupId>org.apache.httpcomponents</groupId>
640640
<artifactId>httpclient</artifactId>
641-
<version>4.1.3</version>
641+
<version>4.2.5</version>
642642
</dependency>
643643
<dependency>
644644
<groupId>commons-httpclient</groupId>

0 commit comments

Comments
 (0)