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
This commit is contained in:
Oleg Kalnichevski 2011-10-10 18:46:08 +00:00
parent e41274c27d
commit 287d839410
3 changed files with 77 additions and 1 deletions

View File

@ -179,6 +179,22 @@ public class SSLSocketFactory implements LayeredSchemeSocketFactory, LayeredSock
* <a href="http://download.oracle.com/javase/1,5.0/docs/guide/security/jsse/JSSERefGuide.html">
* "JavaTM Secure Socket Extension (JSSE) Reference Guide for the JavaTM 2 Platform
* Standard Edition 5</a>
* <p>
* The following system properties are taken into account by this method:
* <ul>
* <li>ssl.TrustManagerFactory.algorithm</li>
* <li>javax.net.ssl.trustStoreType</li>
* <li>javax.net.ssl.trustStore</li>
* <li>javax.net.ssl.trustStoreProvider</li>
* <li>javax.net.ssl.trustStorePassword</li>
* <li>java.home</li>
* <li>ssl.KeyManagerFactory.algorithm</li>
* <li>javax.net.ssl.keyStoreType</li>
* <li>javax.net.ssl.keyStore</li>
* <li>javax.net.ssl.keyStoreProvider</li>
* <li>javax.net.ssl.keyStorePassword</li>
* </ul>
* <p>
*
* @return the system SSL socket factory
*/

View File

@ -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.
* <p>
* The following system properties are taken into account by this class:
* <ul>
* <li>ssl.TrustManagerFactory.algorithm</li>
* <li>javax.net.ssl.trustStoreType</li>
* <li>javax.net.ssl.trustStore</li>
* <li>javax.net.ssl.trustStoreProvider</li>
* <li>javax.net.ssl.trustStorePassword</li>
* <li>java.home</li>
* <li>ssl.KeyManagerFactory.algorithm</li>
* <li>javax.net.ssl.keyStoreType</li>
* <li>javax.net.ssl.keyStore</li>
* <li>javax.net.ssl.keyStoreProvider</li>
* <li>javax.net.ssl.keyStorePassword</li>
* <li>http.proxyHost</li>
* <li>http.proxyPort</li>
* <li>http.nonProxyHosts</li>
* <li>http.keepAlive</li>
* <li>http.maxConnections</li>
* </ul>
* <p>
* <p>
* The following parameters can be used to customize the behavior of this
* class:
* <ul>
@ -74,6 +98,7 @@ import org.apache.http.params.HttpParams;
* <li>{@link org.apache.http.client.params.ClientPNames#DEFAULT_HEADERS}</li>
* <li>{@link org.apache.http.client.params.ClientPNames#CONN_MANAGER_TIMEOUT}</li>
* </ul>
* </p>
*
* @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();
}
}
}

View File

@ -56,6 +56,22 @@ public final class SchemeRegistryFactory {
* <a href="http://download.oracle.com/javase/1,5.0/docs/guide/security/jsse/JSSERefGuide.html">
* "JavaTM Secure Socket Extension (JSSE) Reference Guide for the JavaTM 2 Platform
* Standard Edition 5</a>
* <p>
* The following system properties are taken into account by this method:
* <ul>
* <li>ssl.TrustManagerFactory.algorithm</li>
* <li>javax.net.ssl.trustStoreType</li>
* <li>javax.net.ssl.trustStore</li>
* <li>javax.net.ssl.trustStoreProvider</li>
* <li>javax.net.ssl.trustStorePassword</li>
* <li>java.home</li>
* <li>ssl.KeyManagerFactory.algorithm</li>
* <li>javax.net.ssl.keyStoreType</li>
* <li>javax.net.ssl.keyStore</li>
* <li>javax.net.ssl.keyStoreProvider</li>
* <li>javax.net.ssl.keyStorePassword</li>
* </ul>
* <p>
*
* @since 4.2
*/