Consistently upgraded Apache HttpComponents usage to 4.2

Issue: SPR-9475
This commit is contained in:
Juergen Hoeller 2012-10-04 16:14:51 +02:00 committed by unknown
parent 8bdc6be074
commit 6445f09c36
2 changed files with 6 additions and 19 deletions

View File

@ -34,13 +34,13 @@ import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.protocol.HttpContext;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.http.HttpMethod;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* {@link org.springframework.http.client.ClientHttpRequestFactory} implementation that uses
@ -56,9 +56,6 @@ import org.springframework.util.ClassUtils;
*/
public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequestFactory, DisposableBean {
private static final boolean HTTP_PATCH_AVAILABLE = ClassUtils.isPresent(
"org.apache.http.client.methods.HttpPatch", HttpComponentsClientHttpRequestFactory.class.getClassLoader());
private static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 100;
private static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 5;
@ -70,14 +67,14 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
/**
* Create a new instance of the HttpComponentsClientHttpRequestFactory with a default
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager}.
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}.
*/
public HttpComponentsClientHttpRequestFactory() {
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(schemeRegistry);
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry);
connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL_CONNECTIONS);
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
@ -160,22 +157,12 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
case TRACE:
return new HttpTrace(uri);
case PATCH:
return createHttpPatch(uri);
return new HttpPatch(uri);
default:
throw new IllegalArgumentException("Invalid HTTP method: " + httpMethod);
}
}
private HttpUriRequest createHttpPatch(URI uri) {
if (!HTTP_PATCH_AVAILABLE) {
throw new IllegalArgumentException(
"HTTP method PATCH not available before Apache HttpComponents HttpClient 4.2");
}
else {
return new HttpPatch(uri);
}
}
/**
* Template method that allows for manipulating the {@link HttpUriRequest} before it is
* returned as part of a {@link HttpComponentsClientHttpRequest}.

View File

@ -70,7 +70,7 @@ public class HttpComponentsHttpInvokerRequestExecutor extends AbstractHttpInvoke
/**
* Create a new instance of the HttpComponentsHttpInvokerRequestExecutor with a default
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager}.
* {@link HttpClient} that uses a default {@link org.apache.http.impl.conn.PoolingClientConnectionManager}.
*/
public HttpComponentsHttpInvokerRequestExecutor() {
SchemeRegistry schemeRegistry = new SchemeRegistry();