Removes dependency management for okhttp3 and httpclient
These are managed by boot. Fixes gh-813
This commit is contained in:
@@ -66,8 +66,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<okhttp3.version>3.6.0</okhttp3.version>
|
||||
<apachehttpclient.version>4.5.4</apachehttpclient.version>
|
||||
<evictor.version>1.0.0</evictor.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
@@ -139,19 +137,16 @@
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>${okhttp3.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>logging-interceptor</artifactId>
|
||||
<version>${okhttp3.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${apachehttpclient.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -41,37 +41,35 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
public class DefaultApacheHttpClientConnectionManagerFactoryTests {
|
||||
|
||||
@Test
|
||||
public void newConnectionManager() throws Exception {
|
||||
public void newConnectionManager() {
|
||||
HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
|
||||
.newConnectionManager(false, 2, 6);
|
||||
then(((PoolingHttpClientConnectionManager) connectionManager)
|
||||
.getDefaultMaxPerRoute()).isEqualTo(6);
|
||||
then(((PoolingHttpClientConnectionManager) connectionManager).getMaxTotal())
|
||||
.isEqualTo(2);
|
||||
Object pool = getField(((PoolingHttpClientConnectionManager) connectionManager),
|
||||
"pool");
|
||||
Object pool = getField((connectionManager), "pool");
|
||||
then((Long) getField(pool, "timeToLive")).isEqualTo(new Long(-1));
|
||||
TimeUnit timeUnit = getField(pool, "tunit");
|
||||
TimeUnit timeUnit = getField(pool, "timeUnit");
|
||||
then(timeUnit).isEqualTo(TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newConnectionManagerWithTTL() throws Exception {
|
||||
public void newConnectionManagerWithTTL() {
|
||||
HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
|
||||
.newConnectionManager(false, 2, 6, 56L, TimeUnit.DAYS, null);
|
||||
then(((PoolingHttpClientConnectionManager) connectionManager)
|
||||
.getDefaultMaxPerRoute()).isEqualTo(6);
|
||||
then(((PoolingHttpClientConnectionManager) connectionManager).getMaxTotal())
|
||||
.isEqualTo(2);
|
||||
Object pool = getField(((PoolingHttpClientConnectionManager) connectionManager),
|
||||
"pool");
|
||||
Object pool = getField((connectionManager), "pool");
|
||||
then((Long) getField(pool, "timeToLive")).isEqualTo(new Long(56));
|
||||
TimeUnit timeUnit = getField(pool, "tunit");
|
||||
TimeUnit timeUnit = getField(pool, "timeUnit");
|
||||
then(timeUnit).isEqualTo(TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newConnectionManagerWithSSL() throws Exception {
|
||||
public void newConnectionManagerWithSSL() {
|
||||
HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
|
||||
.newConnectionManager(false, 2, 6);
|
||||
|
||||
@@ -82,7 +80,7 @@ public class DefaultApacheHttpClientConnectionManagerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newConnectionManagerWithDisabledSSLValidation() throws Exception {
|
||||
public void newConnectionManagerWithDisabledSSLValidation() {
|
||||
HttpClientConnectionManager connectionManager = new DefaultApacheHttpClientConnectionManagerFactory()
|
||||
.newConnectionManager(true, 2, 6);
|
||||
|
||||
@@ -112,6 +110,10 @@ public class DefaultApacheHttpClientConnectionManagerFactoryTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <T> T getField(Object target, String name) {
|
||||
Field field = ReflectionUtils.findField(target.getClass(), name);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can not find field " + name + " in " + target.getClass());
|
||||
}
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
Object value = ReflectionUtils.getField(field, target);
|
||||
return (T) value;
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.lang.reflect.Field;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.ConnectionPool;
|
||||
import okhttp3.internal.connection.RealConnectionPool;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -32,18 +33,23 @@ import static org.assertj.core.api.BDDAssertions.then;
|
||||
public class DefaultOkHttpClientConnectionPoolFactoryTest {
|
||||
|
||||
@Test
|
||||
public void create() throws Exception {
|
||||
public void create() {
|
||||
DefaultOkHttpClientConnectionPoolFactory connectionPoolFactory = new DefaultOkHttpClientConnectionPoolFactory();
|
||||
ConnectionPool connectionPool = connectionPoolFactory.create(2, 3,
|
||||
TimeUnit.MILLISECONDS);
|
||||
int idleConnections = getField(connectionPool, "maxIdleConnections");
|
||||
long keepAliveDuration = getField(connectionPool, "keepAliveDurationNs");
|
||||
RealConnectionPool delegate = getField(connectionPool, "delegate");
|
||||
int idleConnections = getField(delegate, "maxIdleConnections");
|
||||
long keepAliveDuration = getField(delegate, "keepAliveDurationNs");
|
||||
then(idleConnections).isEqualTo(2);
|
||||
then(keepAliveDuration).isEqualTo(TimeUnit.MILLISECONDS.toNanos(3));
|
||||
}
|
||||
|
||||
protected <T> T getField(Object target, String name) {
|
||||
Field field = ReflectionUtils.findField(target.getClass(), name);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Can not find field " + name + " in " + target.getClass());
|
||||
}
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
Object value = ReflectionUtils.getField(field, target);
|
||||
return (T) value;
|
||||
|
||||
Reference in New Issue
Block a user