Skip to content

Commit eb57168

Browse files
committed
Removes dependency management for okhttp3 and httpclient
These are managed by boot. Fixes gh-813
1 parent fb8b1d8 commit eb57168

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

spring-cloud-commons/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@
6666
</build>
6767

6868
<properties>
69-
<okhttp3.version>3.6.0</okhttp3.version>
70-
<apachehttpclient.version>4.5.4</apachehttpclient.version>
7169
<evictor.version>1.0.0</evictor.version>
7270
</properties>
7371
<dependencies>
@@ -139,19 +137,16 @@
139137
<dependency>
140138
<groupId>com.squareup.okhttp3</groupId>
141139
<artifactId>okhttp</artifactId>
142-
<version>${okhttp3.version}</version>
143140
<optional>true</optional>
144141
</dependency>
145142
<dependency>
146143
<groupId>com.squareup.okhttp3</groupId>
147144
<artifactId>logging-interceptor</artifactId>
148-
<version>${okhttp3.version}</version>
149145
<optional>true</optional>
150146
</dependency>
151147
<dependency>
152148
<groupId>org.apache.httpcomponents</groupId>
153149
<artifactId>httpclient</artifactId>
154-
<version>${apachehttpclient.version}</version>
155150
<optional>true</optional>
156151
</dependency>
157152
<dependency>

spring-cloud-commons/src/test/java/org/springframework/cloud/commons/httpclient/DefaultApacheHttpClientConnectionManagerFactoryTests.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,37 +41,35 @@
4141
public class DefaultApacheHttpClientConnectionManagerFactoryTests {
4242

4343
@Test
44-
public void newConnectionManager() throws Exception {
44+
public void newConnectionManager() {
4545
HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
4646
.newConnectionManager(false, 2, 6);
4747
then(((PoolingHttpClientConnectionManager) connectionManager)
4848
.getDefaultMaxPerRoute()).isEqualTo(6);
4949
then(((PoolingHttpClientConnectionManager) connectionManager).getMaxTotal())
5050
.isEqualTo(2);
51-
Object pool = getField(((PoolingHttpClientConnectionManager) connectionManager),
52-
"pool");
51+
Object pool = getField((connectionManager), "pool");
5352
then((Long) getField(pool, "timeToLive")).isEqualTo(new Long(-1));
54-
TimeUnit timeUnit = getField(pool, "tunit");
53+
TimeUnit timeUnit = getField(pool, "timeUnit");
5554
then(timeUnit).isEqualTo(TimeUnit.MILLISECONDS);
5655
}
5756

5857
@Test
59-
public void newConnectionManagerWithTTL() throws Exception {
58+
public void newConnectionManagerWithTTL() {
6059
HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
6160
.newConnectionManager(false, 2, 6, 56L, TimeUnit.DAYS, null);
6261
then(((PoolingHttpClientConnectionManager) connectionManager)
6362
.getDefaultMaxPerRoute()).isEqualTo(6);
6463
then(((PoolingHttpClientConnectionManager) connectionManager).getMaxTotal())
6564
.isEqualTo(2);
66-
Object pool = getField(((PoolingHttpClientConnectionManager) connectionManager),
67-
"pool");
65+
Object pool = getField((connectionManager), "pool");
6866
then((Long) getField(pool, "timeToLive")).isEqualTo(new Long(56));
69-
TimeUnit timeUnit = getField(pool, "tunit");
67+
TimeUnit timeUnit = getField(pool, "timeUnit");
7068
then(timeUnit).isEqualTo(TimeUnit.DAYS);
7169
}
7270

7371
@Test
74-
public void newConnectionManagerWithSSL() throws Exception {
72+
public void newConnectionManagerWithSSL() {
7573
HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
7674
.newConnectionManager(false, 2, 6);
7775

@@ -82,7 +80,7 @@ public void newConnectionManagerWithSSL() throws Exception {
8280
}
8381

8482
@Test
85-
public void newConnectionManagerWithDisabledSSLValidation() throws Exception {
83+
public void newConnectionManagerWithDisabledSSLValidation() {
8684
HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
8785
.newConnectionManager(true, 2, 6);
8886

@@ -112,6 +110,10 @@ private X509TrustManager getX509TrustManager(
112110
@SuppressWarnings("unchecked")
113111
protected <T> T getField(Object target, String name) {
114112
Field field = ReflectionUtils.findField(target.getClass(), name);
113+
if (field == null) {
114+
throw new IllegalArgumentException(
115+
"Can not find field " + name + " in " + target.getClass());
116+
}
115117
ReflectionUtils.makeAccessible(field);
116118
Object value = ReflectionUtils.getField(field, target);
117119
return (T) value;

spring-cloud-commons/src/test/java/org/springframework/cloud/commons/httpclient/DefaultOkHttpClientConnectionPoolFactoryTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.concurrent.TimeUnit;
2121

2222
import okhttp3.ConnectionPool;
23+
import okhttp3.internal.connection.RealConnectionPool;
2324
import org.junit.Test;
2425

2526
import org.springframework.util.ReflectionUtils;
@@ -32,18 +33,23 @@
3233
public class DefaultOkHttpClientConnectionPoolFactoryTest {
3334

3435
@Test
35-
public void create() throws Exception {
36+
public void create() {
3637
DefaultOkHttpClientConnectionPoolFactory connectionPoolFactory = new DefaultOkHttpClientConnectionPoolFactory();
3738
ConnectionPool connectionPool = connectionPoolFactory.create(2, 3,
3839
TimeUnit.MILLISECONDS);
39-
int idleConnections = getField(connectionPool, "maxIdleConnections");
40-
long keepAliveDuration = getField(connectionPool, "keepAliveDurationNs");
40+
RealConnectionPool delegate = getField(connectionPool, "delegate");
41+
int idleConnections = getField(delegate, "maxIdleConnections");
42+
long keepAliveDuration = getField(delegate, "keepAliveDurationNs");
4143
then(idleConnections).isEqualTo(2);
4244
then(keepAliveDuration).isEqualTo(TimeUnit.MILLISECONDS.toNanos(3));
4345
}
4446

4547
protected <T> T getField(Object target, String name) {
4648
Field field = ReflectionUtils.findField(target.getClass(), name);
49+
if (field == null) {
50+
throw new IllegalArgumentException(
51+
"Can not find field " + name + " in " + target.getClass());
52+
}
4753
ReflectionUtils.makeAccessible(field);
4854
Object value = ReflectionUtils.getField(field, target);
4955
return (T) value;

0 commit comments

Comments
 (0)