From 447835465fe209d00b9cbb309f32ef40cc71d6ba Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 4 Jul 2016 23:21:42 +0200 Subject: [PATCH] Remove support for deprecated AbstractHttpClient class Issue: SPR-14422 --- ...ttpComponentsClientHttpRequestFactory.java | 51 ------------------- ...pComponentsHttpInvokerRequestExecutor.java | 51 ------------------- ...mponentsClientHttpRequestFactoryTests.java | 16 +----- ...onentsHttpInvokerRequestExecutorTests.java | 17 +------ 4 files changed, 2 insertions(+), 133 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java index d61231d9d0..0367a73864 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactory.java @@ -59,20 +59,6 @@ import org.springframework.util.ClassUtils; */ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean { - private static Class abstractHttpClientClass; - - static { - try { - // Looking for AbstractHttpClient class (deprecated as of HttpComponents 4.3) - abstractHttpClientClass = ClassUtils.forName("org.apache.http.impl.client.AbstractHttpClient", - HttpComponentsClientHttpRequestFactory.class.getClassLoader()); - } - catch (ClassNotFoundException ex) { - // Probably removed from HttpComponents in the meantime... - } - } - - private HttpClient httpClient; private RequestConfig requestConfig; @@ -126,28 +112,6 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest public void setConnectTimeout(int timeout) { Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value"); this.requestConfig = requestConfigBuilder().setConnectTimeout(timeout).build(); - setLegacyConnectionTimeout(getHttpClient(), timeout); - } - - /** - * Apply the specified connection timeout to deprecated {@link HttpClient} - * implementations. - *

As of HttpClient 4.3, default parameters have to be exposed through a - * {@link RequestConfig} instance instead of setting the parameters on the - * client. Unfortunately, this behavior is not backward-compatible and older - * {@link HttpClient} implementations will ignore the {@link RequestConfig} - * object set in the context. - *

If the specified client is an older implementation, we set the custom - * connection timeout through the deprecated API. Otherwise, we just return - * as it is set through {@link RequestConfig} with newer clients. - * @param client the client to configure - * @param timeout the custom connection timeout - */ - @SuppressWarnings("deprecation") - private void setLegacyConnectionTimeout(HttpClient client, int timeout) { - if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) { - client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); - } } /** @@ -174,21 +138,6 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest public void setReadTimeout(int timeout) { Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value"); this.requestConfig = requestConfigBuilder().setSocketTimeout(timeout).build(); - setLegacySocketTimeout(getHttpClient(), timeout); - } - - /** - * Apply the specified socket timeout to deprecated {@link HttpClient} - * implementations. See {@link #setLegacyConnectionTimeout}. - * @param client the client to configure - * @param timeout the custom socket timeout - * @see #setLegacyConnectionTimeout - */ - @SuppressWarnings("deprecation") - private void setLegacySocketTimeout(HttpClient client, int timeout) { - if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) { - client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout); - } } /** diff --git a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java index 7f78a8227b..cd3a06d643 100644 --- a/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java +++ b/spring-web/src/main/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutor.java @@ -71,20 +71,6 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke private static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = (60 * 1000); - private static Class abstractHttpClientClass; - - static { - try { - // Looking for AbstractHttpClient class (deprecated as of HttpComponents 4.3) - abstractHttpClientClass = ClassUtils.forName("org.apache.http.impl.client.AbstractHttpClient", - HttpComponentsHttpInvokerRequestExecutor.class.getClassLoader()); - } - catch (ClassNotFoundException ex) { - // Probably removed from HttpComponents in the meantime... - } - } - - private HttpClient httpClient; private RequestConfig requestConfig; @@ -153,28 +139,6 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke public void setConnectTimeout(int timeout) { Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value"); this.requestConfig = cloneRequestConfig().setConnectTimeout(timeout).build(); - setLegacyConnectionTimeout(getHttpClient(), timeout); - } - - /** - * Apply the specified connection timeout to deprecated {@link HttpClient} - * implementations. - *

As of HttpClient 4.3, default parameters have to be exposed through a - * {@link RequestConfig} instance instead of setting the parameters on the - * client. Unfortunately, this behavior is not backward-compatible and older - * {@link HttpClient} implementations will ignore the {@link RequestConfig} - * object set in the context. - *

If the specified client is an older implementation, we set the custom - * connection timeout through the deprecated API. Otherwise, we just return - * as it is set through {@link RequestConfig} with newer clients. - * @param client the client to configure - * @param timeout the custom connection timeout - */ - @SuppressWarnings("deprecation") - private void setLegacyConnectionTimeout(HttpClient client, int timeout) { - if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) { - client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); - } } /** @@ -202,21 +166,6 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke public void setReadTimeout(int timeout) { Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value"); this.requestConfig = cloneRequestConfig().setSocketTimeout(timeout).build(); - setLegacySocketTimeout(getHttpClient(), timeout); - } - - /** - * Apply the specified socket timeout to deprecated {@link HttpClient} - * implementations. See {@link #setLegacyConnectionTimeout}. - * @param client the client to configure - * @param timeout the custom socket timeout - * @see #setLegacyConnectionTimeout - */ - @SuppressWarnings("deprecation") - private void setLegacySocketTimeout(HttpClient client, int timeout) { - if (abstractHttpClientClass != null && abstractHttpClientClass.isInstance(client)) { - client.getParams().setIntParameter(org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, timeout); - } } private RequestConfig.Builder cloneRequestConfig() { diff --git a/spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java index 7678a6a7ad..657fde197a 100644 --- a/spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/HttpComponentsClientHttpRequestFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,20 +49,6 @@ public class HttpComponentsClientHttpRequestFactoryTests extends AbstractHttpReq assertHttpMethod("patch", HttpMethod.PATCH); } - @SuppressWarnings("deprecation") - @Test - public void assertLegacyCustomConfig() { - HttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient(); // Does not support RequestConfig - HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(httpClient); - hrf.setConnectTimeout(1234); - assertEquals(1234, httpClient.getParams().getIntParameter( - org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, 0)); - - hrf.setReadTimeout(4567); - assertEquals(4567, httpClient.getParams().getIntParameter( - org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, 0)); - } - @Test public void assertCustomConfig() throws Exception { HttpClient httpClient = HttpClientBuilder.create().build(); diff --git a/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutorTests.java b/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutorTests.java index f58491a39f..22f60585ca 100644 --- a/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutorTests.java +++ b/spring-web/src/test/java/org/springframework/remoting/httpinvoker/HttpComponentsHttpInvokerRequestExecutorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,21 +34,6 @@ import static org.mockito.Mockito.*; */ public class HttpComponentsHttpInvokerRequestExecutorTests { - @SuppressWarnings("deprecation") - @Test - public void assertLegacyCustomConfig() { - HttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient(); // Does not support RequestConfig - HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor(httpClient); - - executor.setConnectTimeout(1234); - assertEquals(1234, httpClient.getParams().getIntParameter( - org.apache.http.params.CoreConnectionPNames.CONNECTION_TIMEOUT, 0)); - - executor.setReadTimeout(4567); - assertEquals(4567, httpClient.getParams().getIntParameter( - org.apache.http.params.CoreConnectionPNames.SO_TIMEOUT, 0)); - } - @Test public void customizeConnectionTimeout() throws IOException { HttpComponentsHttpInvokerRequestExecutor executor = new HttpComponentsHttpInvokerRequestExecutor();