From 7f04b88f12965175b9961b0442a2d03502d91e3c Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 10 Oct 2011 14:28:07 +0000 Subject: [PATCH] HTTPCLIENT-1128: added SystemDefaultHttpClient, an extension of DefaultHttpClient pre-configured using system properties git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1180994 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/impl/client/DefaultHttpClient.java | 5 +- .../impl/client/SystemDefaultHttpClient.java | 92 +++++++++++++++++++ .../http/impl/conn/SchemeRegistryFactory.java | 5 +- 3 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java diff --git a/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java b/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java index ebebca766..b7055487a 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/DefaultHttpClient.java @@ -56,8 +56,8 @@ import org.apache.http.util.VersionInfo; /** * Default implementation of {@link HttpClient} pre-configured for most common use scenarios. *

- * Please see the Javadoc for {@link #createHttpProcessor()} for the details of the interceptors that are set up - * by default. + * Please see the Javadoc for {@link #createHttpProcessor()} for the details of the interceptors + * that are set up by default. *

* Additional interceptors can be added as follows, but * take care not to add the same interceptor more than once. @@ -108,7 +108,6 @@ import org.apache.http.util.VersionInfo; *

  • {@link org.apache.http.client.params.ClientPNames#VIRTUAL_HOST}
  • *
  • {@link org.apache.http.client.params.ClientPNames#DEFAULT_HOST}
  • *
  • {@link org.apache.http.client.params.ClientPNames#DEFAULT_HEADERS}
  • - *
  • {@link org.apache.http.client.params.ClientPNames#CONNECTION_MANAGER_FACTORY_CLASS_NAME}
  • *
  • {@link org.apache.http.client.params.ClientPNames#CONN_MANAGER_TIMEOUT}
  • * * 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 new file mode 100644 index 000000000..5caba9294 --- /dev/null +++ b/httpclient/src/main/java/org/apache/http/impl/client/SystemDefaultHttpClient.java @@ -0,0 +1,92 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.impl.client; + +import org.apache.http.annotation.ThreadSafe; +import org.apache.http.conn.ClientConnectionManager; +import org.apache.http.impl.conn.PoolingClientConnectionManager; +import org.apache.http.impl.conn.SchemeRegistryFactory; +import org.apache.http.params.HttpParams; + +/** + * An extension of {@link DefaultHttpClient} pre-configured using system properties. + *

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

    + * + * @since 4.2 + */ +@ThreadSafe +public class SystemDefaultHttpClient extends DefaultHttpClient { + + public SystemDefaultHttpClient(final HttpParams params) { + super(null, params); + } + + public SystemDefaultHttpClient() { + super(null, null); + } + + @Override + protected ClientConnectionManager createClientConnectionManager() { + return new PoolingClientConnectionManager(SchemeRegistryFactory.createSystemDefault()); + } + +} 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 1cada3a1c..c37ee300f 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 @@ -26,9 +26,6 @@ */ package org.apache.http.impl.conn; -import java.io.IOException; -import java.security.GeneralSecurityException; - import org.apache.http.annotation.ThreadSafe; import org.apache.http.conn.scheme.PlainSocketFactory; import org.apache.http.conn.scheme.Scheme; @@ -62,7 +59,7 @@ public final class SchemeRegistryFactory { * * @since 4.2 */ - public static SchemeRegistry createSystemDefault() throws IOException, GeneralSecurityException { + public static SchemeRegistry createSystemDefault() { SchemeRegistry registry = new SchemeRegistry(); registry.register( new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));