Skip to content

Commit 4478354

Browse files
committed
Remove support for deprecated AbstractHttpClient class
Issue: SPR-14422
1 parent 0900808 commit 4478354

File tree

4 files changed

+2
-133
lines changed

4 files changed

+2
-133
lines changed

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@
5959
*/
6060
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
6161

62-
private static Class<?> abstractHttpClientClass;
63-
64-
static {
65-
try {
66-
// Looking for AbstractHttpClient class (deprecated as of HttpComponents 4.3)
67-
abstractHttpClientClass = ClassUtils.forName("org.apache.http.impl.client.AbstractHttpClient",
68-
HttpComponentsClientHttpRequestFactory.class.getClassLoader());
69-
}
70-
catch (ClassNotFoundException ex) {
71-
// Probably removed from HttpComponents in the meantime...
72-
}
73-
}
74-
75-
7662
private HttpClient httpClient;
7763

7864
private RequestConfig requestConfig;
@@ -126,28 +112,6 @@ public HttpClient getHttpClient() {
126112
public void setConnectTimeout(int timeout) {
127113
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
128114
this.requestConfig = requestConfigBuilder().setConnectTimeout(timeout).build();
129-
setLegacyConnectionTimeout(getHttpClient(), timeout);
130-
}
131-
132-
/**
133-
* Apply the specified connection timeout to deprecated {@link HttpClient}
134-
* implementations.
135-
* <p>As of HttpClient 4.3, default parameters have to be exposed through a
136-
* {@link RequestConfig} instance instead of setting the parameters on the
137-
* client. Unfortunately, this behavior is not backward-compatible and older
138-
* {@link HttpClient} implementations will ignore the {@link RequestConfig}
139-
* object set in the context.
140-
* <p>If the specified client is an older implementation, we set the custom
141-
* connection timeout through the deprecated API. Otherwise, we just return
142-
* as it is set through {@link RequestConfig} with newer clients.
143-
* @param client the client to configure
144-
* @param timeout the custom connection timeout
145-
*/
146-
@SuppressWarnings("deprecation")
147-
private void setLegacyConnectionTimeout(HttpClient client, int timeout) {
148-
if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) {
149-
client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
150-
}
151115
}
152116

153117
/**
@@ -174,21 +138,6 @@ public void setConnectionRequestTimeout(int connectionRequestTimeout) {
174138
public void setReadTimeout(int timeout) {
175139
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
176140
this.requestConfig = requestConfigBuilder().setSocketTimeout(timeout).build();
177-
setLegacySocketTimeout(getHttpClient(), timeout);
178-
}
179-
180-
/**
181-
* Apply the specified socket timeout to deprecated {@link HttpClient}
182-
* implementations. See {@link #setLegacyConnectionTimeout}.
183-
* @param client the client to configure
184-
* @param timeout the custom socket timeout
185-
* @see #setLegacyConnectionTimeout
186-
*/
187-
@SuppressWarnings("deprecation")
188-
private void setLegacySocketTimeout(HttpClient client, int timeout) {
189-
if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) {
190-
client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout);
191-
}
192141
}
193142

194143
/**

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,6 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
7171
private static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = (60 * 1000);
7272

7373

74-
private static Class<?> abstractHttpClientClass;
75-
76-
static {
77-
try {
78-
// Looking for AbstractHttpClient class (deprecated as of HttpComponents 4.3)
79-
abstractHttpClientClass = ClassUtils.forName("org.apache.http.impl.client.AbstractHttpClient",
80-
HttpComponentsHttpInvokerRequestExecutor.class.getClassLoader());
81-
}
82-
catch (ClassNotFoundException ex) {
83-
// Probably removed from HttpComponents in the meantime...
84-
}
85-
}
86-
87-
8874
private HttpClient httpClient;
8975

9076
private RequestConfig requestConfig;
@@ -153,28 +139,6 @@ public HttpClient getHttpClient() {
153139
public void setConnectTimeout(int timeout) {
154140
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
155141
this.requestConfig = cloneRequestConfig().setConnectTimeout(timeout).build();
156-
setLegacyConnectionTimeout(getHttpClient(), timeout);
157-
}
158-
159-
/**
160-
* Apply the specified connection timeout to deprecated {@link HttpClient}
161-
* implementations.
162-
* <p>As of HttpClient 4.3, default parameters have to be exposed through a
163-
* {@link RequestConfig} instance instead of setting the parameters on the
164-
* client. Unfortunately, this behavior is not backward-compatible and older
165-
* {@link HttpClient} implementations will ignore the {@link RequestConfig}
166-
* object set in the context.
167-
* <p>If the specified client is an older implementation, we set the custom
168-
* connection timeout through the deprecated API. Otherwise, we just return
169-
* as it is set through {@link RequestConfig} with newer clients.
170-
* @param client the client to configure
171-
* @param timeout the custom connection timeout
172-
*/
173-
@SuppressWarnings("deprecation")
174-
private void setLegacyConnectionTimeout(HttpClient client, int timeout) {
175-
if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) {
176-
client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
177-
}
178142
}
179143

180144
/**
@@ -202,21 +166,6 @@ public void setConnectionRequestTimeout(int connectionRequestTimeout) {
202166
public void setReadTimeout(int timeout) {
203167
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
204168
this.requestConfig = cloneRequestConfig().setSocketTimeout(timeout).build();
205-
setLegacySocketTimeout(getHttpClient(), timeout);
206-
}
207-
208-
/**
209-
* Apply the specified socket timeout to deprecated {@link HttpClient}
210-
* implementations. See {@link #setLegacyConnectionTimeout}.
211-
* @param client the client to configure
212-
* @param timeout the custom socket timeout
213-
* @see #setLegacyConnectionTimeout
214-
*/
215-
@SuppressWarnings("deprecation")
216-
private void setLegacySocketTimeout(HttpClient client, int timeout) {
217-
if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) {
218-
client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout);
219-
}
220169
}
221170

222171
private RequestConfig.Builder cloneRequestConfig() {

spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,20 +49,6 @@ public void httpMethods() throws Exception {
4949
assertHttpMethod("patch", HttpMethod.PATCH);
5050
}
5151

52-
@SuppressWarnings("deprecation")
53-
@Test
54-
public void assertLegacyCustomConfig() {
55-
HttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient(); // Does not support RequestConfig
56-
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(httpClient);
57-
hrf.setConnectTimeout(1234);
58-
assertEquals(1234, httpClient.getParams().getIntParameter(
59-
org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, 0));
60-
61-
hrf.setReadTimeout(4567);
62-
assertEquals(4567, httpClient.getParams().getIntParameter(
63-
org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, 0));
64-
}
65-
6652
@Test
6753
public void assertCustomConfig() throws Exception {
6854
HttpClient httpClient = HttpClientBuilder.create().build();

spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutorTests.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,21 +34,6 @@
3434
*/
3535
public class HttpComponentsHttpInvokerRequestExecutorTests {
3636

37-
@SuppressWarnings("deprecation")
38-
@Test
39-
public void assertLegacyCustomConfig() {
40-
HttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient(); // Does not support RequestConfig
41-
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(httpClient);
42-
43-
executor.setConnectTimeout(1234);
44-
assertEquals(1234, httpClient.getParams().getIntParameter(
45-
org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, 0));
46-
47-
executor.setReadTimeout(4567);
48-
assertEquals(4567, httpClient.getParams().getIntParameter(
49-
org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, 0));
50-
}
51-
5237
@Test
5338
public void customizeConnectionTimeout() throws IOException {
5439
HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor();

0 commit comments

Comments
 (0)