Skip to content

Commit 6445f09

Browse files
jhoellerunknown
authored andcommitted
Consistently upgraded Apache HttpComponents usage to 4.2
Issue: SPR-9475
1 parent 8bdc6be commit 6445f09

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
import org.apache.http.conn.scheme.SchemeRegistry;
3535
import org.apache.http.conn.ssl.SSLSocketFactory;
3636
import org.apache.http.impl.client.DefaultHttpClient;
37-
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
37+
import org.apache.http.impl.conn.PoolingClientConnectionManager;
3838
import org.apache.http.params.CoreConnectionPNames;
3939
import org.apache.http.protocol.HttpContext;
40+
4041
import org.springframework.beans.factory.DisposableBean;
4142
import org.springframework.http.HttpMethod;
4243
import org.springframework.util.Assert;
43-
import org.springframework.util.ClassUtils;
4444

4545
/**
4646
* {@link org.springframework.http.client.ClientHttpRequestFactory} implementation that uses
@@ -56,9 +56,6 @@
5656
*/
5757
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
5858

59-
private static final boolean HTTP_PATCH_AVAILABLE = ClassUtils.isPresent(
60-
"org.apache.http.client.methods.HttpPatch", HttpComponentsClientHttpRequestFactory.class.getClassLoader());
61-
6259
private static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 100;
6360

6461
private static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 5;
@@ -70,14 +67,14 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
7067

7168
/**
7269
* Create a new instance of the HttpComponentsClientHttpRequestFactory with a default
73-
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager}.
70+
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}.
7471
*/
7572
public HttpComponentsClientHttpRequestFactory() {
7673
SchemeRegistry schemeRegistry = new SchemeRegistry();
7774
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
7875
schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
7976

80-
ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(schemeRegistry);
77+
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
8178
connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
8279
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
8380

@@ -160,22 +157,12 @@ protected HttpUriRequest createHttpUriRequest(HttpMethod httpMethod, URI uri) {
160157
case TRACE:
161158
return new HttpTrace(uri);
162159
case PATCH:
163-
return createHttpPatch(uri);
160+
return new HttpPatch(uri);
164161
default:
165162
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
166163
}
167164
}
168165

169-
private HttpUriRequest createHttpPatch(URI uri) {
170-
if (!HTTP_PATCH_AVAILABLE) {
171-
throw new IllegalArgumentException(
172-
"HTTP method PATCH not available before Apache HttpComponents HttpClient 4.2");
173-
}
174-
else {
175-
return new HttpPatch(uri);
176-
}
177-
}
178-
179166
/**
180167
* Template method that allows for manipulating the {@link HttpUriRequest} before it is
181168
* returned as part of a {@link HttpComponentsClientHttpRequest}.

spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
7070

7171
/**
7272
* Create a new instance of the HttpComponentsHttpInvokerRequestExecutor with a default
73-
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager}.
73+
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}.
7474
*/
7575
public HttpComponentsHttpInvokerRequestExecutor() {
7676
SchemeRegistry schemeRegistry = new SchemeRegistry();

0 commit comments

Comments
 (0)