From 287d8394103db1b8b0ad74b0acde45e3259cfd61 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 10 Oct 2011 18:46:08 +0000 Subject: [PATCH] HTTPCLIENT-1128: SystemDefaultHttpClient to take http.keepAlive and http.maxConnections system properties into account git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1181130 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/conn/ssl/SSLSocketFactory.java | 16 +++++++ .../impl/client/SystemDefaultHttpClient.java | 46 ++++++++++++++++++- .../http/impl/conn/SchemeRegistryFactory.java | 16 +++++++ 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java b/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java index 5506583ef..17b31bf3d 100644 --- a/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java +++ b/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java @@ -179,6 +179,22 @@ public class SSLSocketFactory implements LayeredSchemeSocketFactory, LayeredSock * * "JavaTM Secure Socket Extension (JSSE) Reference Guide for the JavaTM 2 Platform * Standard Edition 5 + *

+ * The following system properties are taken into account by this method: + *

+ *

* * @return the system SSL socket factory */ diff --git a/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java index d60053daf..43b785569 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java @@ -29,9 +29,12 @@ package org.apache.http.impl.client; import java.net.ProxySelector; +import org.apache.http.ConnectionReuseStrategy; import org.apache.http.annotation.ThreadSafe; import org.apache.http.conn.ClientConnectionManager; import org.apache.http.conn.routing.HttpRoutePlanner; +import org.apache.http.impl.DefaultConnectionReuseStrategy; +import org.apache.http.impl.NoConnectionReuseStrategy; import org.apache.http.impl.conn.PoolingClientConnectionManager; import org.apache.http.impl.conn.ProxySelectorRoutePlanner; import org.apache.http.impl.conn.SchemeRegistryFactory; @@ -40,6 +43,27 @@ import org.apache.http.params.HttpParams; /** * An extension of {@link DefaultHttpClient} pre-configured using system properties. *

+ * The following system properties are taken into account by this class: + *

+ *

+ *

* The following parameters can be used to customize the behavior of this * class: *

+ *

* * @since 4.2 */ @@ -90,7 +115,16 @@ public class SystemDefaultHttpClient extends DefaultHttpClient { @Override protected ClientConnectionManager createClientConnectionManager() { - return new PoolingClientConnectionManager(SchemeRegistryFactory.createSystemDefault()); + PoolingClientConnectionManager connmgr = new PoolingClientConnectionManager( + SchemeRegistryFactory.createSystemDefault()); + String s = System.getProperty("http.keepAlive"); + if ("true".equalsIgnoreCase(s)) { + s = System.getProperty("http.maxConnections", "5"); + int max = Integer.parseInt(s); + connmgr.setDefaultMaxPerRoute(max); + connmgr.setMaxTotal(2 * max); + } + return connmgr; } @Override @@ -99,4 +133,14 @@ public class SystemDefaultHttpClient extends DefaultHttpClient { ProxySelector.getDefault()); } + @Override + protected ConnectionReuseStrategy createConnectionReuseStrategy() { + String s = System.getProperty("http.keepAlive"); + if ("true".equalsIgnoreCase(s)) { + return new DefaultConnectionReuseStrategy(); + } else { + return new NoConnectionReuseStrategy(); + } + } + } diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/SchemeRegistryFactory.java b/httpclient/src/main/java/org/apache/http/impl/conn/SchemeRegistryFactory.java index c37ee300f..b94c0383a 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/SchemeRegistryFactory.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/SchemeRegistryFactory.java @@ -56,6 +56,22 @@ public final class SchemeRegistryFactory { * * "JavaTM Secure Socket Extension (JSSE) Reference Guide for the JavaTM 2 Platform * Standard Edition 5 + *

+ * The following system properties are taken into account by this method: + *

+ *

* * @since 4.2 */