hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1793761 - in /httpcomponents/httpclient/trunk: httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/ httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/ httpclient5-testing/src/test/java/org/apache/hc/clie...
Date Thu, 04 May 2017 09:42:43 GMT
Author: olegk
Date: Thu May  4 09:42:43 2017
New Revision: 1793761

URL: http://svn.apache.org/viewvc?rev=1793761&view=rev
Log:
HTTPCLIENT-1691: HttpClient instance used internally by HC Fluent to take system properties
into account by default

Modified:
    httpcomponents/httpclient/trunk/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java
    httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
    httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java

Modified: httpcomponents/httpclient/trunk/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java?rev=1793761&r1=1793760&r2=1793761&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Executor.java
Thu May  4 09:42:43 2017
@@ -28,10 +28,6 @@ package org.apache.hc.client5.http.fluen
 
 import java.io.IOException;
 import java.net.URISyntaxException;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
-
-import javax.net.ssl.SSLContext;
 
 import org.apache.hc.client5.http.auth.AuthCache;
 import org.apache.hc.client5.http.auth.AuthScope;
@@ -42,58 +38,35 @@ import org.apache.hc.client5.http.auth.U
 import org.apache.hc.client5.http.cookie.CookieStore;
 import org.apache.hc.client5.http.impl.auth.BasicAuthCache;
 import org.apache.hc.client5.http.impl.auth.BasicScheme;
-import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
 import org.apache.hc.client5.http.impl.sync.BasicCredentialsProvider;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
 import org.apache.hc.client5.http.impl.sync.HttpClientBuilder;
 import org.apache.hc.client5.http.protocol.HttpClientContext;
-import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
-import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory;
-import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
-import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
-import org.apache.hc.client5.http.ssl.SSLInitializationException;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.config.Registry;
-import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.apache.hc.core5.util.TimeValue;
 
 /**
  * An Executor for fluent requests.
  * <p>
- * A {@link PoolingHttpClientConnectionManager} with maximum 100 connections per route and
+ * A connection pool with maximum 100 connections per route and
  * a total maximum of 200 connections is used internally.
- * </p>
  */
 public class Executor {
 
-    final static PoolingHttpClientConnectionManager CONNMGR;
     final static CloseableHttpClient CLIENT;
 
     static {
-        LayeredConnectionSocketFactory ssl = null;
-        try {
-            ssl = SSLConnectionSocketFactory.getSystemSocketFactory();
-        } catch (final SSLInitializationException ex) {
-            final SSLContext sslcontext;
-            try {
-                sslcontext = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
-                sslcontext.init(null, null, null);
-                ssl = new SSLConnectionSocketFactory(sslcontext);
-            } catch (final SecurityException | NoSuchAlgorithmException | KeyManagementException
ignore) {
-            }
-        }
-
-        final Registry<ConnectionSocketFactory> sfr = RegistryBuilder.<ConnectionSocketFactory>create()
-            .register("http", PlainConnectionSocketFactory.getSocketFactory())
-            .register("https", ssl != null ? ssl : SSLConnectionSocketFactory.getSocketFactory())
-            .build();
-
-        CONNMGR = new PoolingHttpClientConnectionManager(sfr);
-        CONNMGR.setDefaultMaxPerRoute(100);
-        CONNMGR.setMaxTotal(200);
-        CONNMGR.setValidateAfterInactivity(TimeValue.ofSeconds(1));
         CLIENT = HttpClientBuilder.create()
-                .setConnectionManager(CONNMGR)
+                .setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create()
+                        .useSystemProperties()
+                        .setMaxConnPerRoute(100)
+                        .setMaxConnTotal(200)
+                        .setValidateAfterInactivity(TimeValue.ofSeconds(10))
+                        .build())
+                .useSystemProperties()
+                .evictExpiredConnections()
+                .evictIdleConnections(TimeValue.ofMinutes(1))
                 .build();
     }
 
@@ -270,12 +243,4 @@ public class Executor {
         return new Response(request.internalExecute(this.httpclient, localContext));
     }
 
-    /**
-     * Closes all idle persistent connections used by the internal pool.
-     * @since 4.4
-     */
-    public static void closeIdleConnections() {
-        CONNMGR.closeIdle(TimeValue.NEG_ONE_MILLISECONDS);
-    }
-
 }

Modified: httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java?rev=1793761&r1=1793760&r2=1793761&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/fluent/TestFluent.java
Thu May  4 09:42:43 2017
@@ -32,7 +32,6 @@ import java.net.URI;
 import java.nio.charset.Charset;
 
 import org.apache.hc.client5.http.fluent.Content;
-import org.apache.hc.client5.http.fluent.Executor;
 import org.apache.hc.client5.http.fluent.Request;
 import org.apache.hc.client5.http.protocol.ClientProtocolException;
 import org.apache.hc.client5.testing.sync.LocalServerTestBase;
@@ -47,7 +46,6 @@ import org.apache.hc.core5.http.io.Respo
 import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.protocol.HttpContext;
-import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -93,12 +91,6 @@ public class TestFluent extends LocalSer
         });
     }
 
-    @After @Override
-    public void shutDown() throws Exception {
-        Executor.closeIdleConnections();
-        super.shutDown();
-    }
-
     @Test
     public void testGetRequest() throws Exception {
         final HttpHost target = start();

Modified: httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java?rev=1793761&r1=1793760&r2=1793761&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/LocalServerTestBase.java
Thu May  4 09:42:43 2017
@@ -93,7 +93,7 @@ public abstract class LocalServerTestBas
             this.httpclient.close();
         }
         if (this.server != null) {
-            this.server.shutdown(ShutdownType.GRACEFUL);
+            this.server.shutdown(ShutdownType.IMMEDIATE);
         }
     }
 



Mime
View raw message