You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2017/08/01 19:07:02 UTC

[4/6] httpcomponents-core git commit: More flexible wiring of the classic test server and client

More flexible wiring of the classic test server and client


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/41291fa2
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/41291fa2
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/41291fa2

Branch: refs/heads/master
Commit: 41291fa241ae41a8e1e1bfdf590eedef842dda39
Parents: 9f39bfd
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Jul 31 15:05:50 2017 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Jul 31 15:05:50 2017 +0200

----------------------------------------------------------------------
 .../testing/classic/ClassicTestClient.java      | 35 ++++++++++++++----
 .../testing/classic/ClassicTestServer.java      | 39 ++++++++++++++------
 2 files changed, 55 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41291fa2/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
index 0291813..aea5b1f 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestClient.java
@@ -36,13 +36,22 @@ import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.config.SocketConfig;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.bootstrap.HttpRequester;
-import org.apache.hc.core5.http.impl.bootstrap.RequesterBootstrap;
+import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnectionFactory;
+import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.io.HttpClientConnection;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.net.URIAuthority;
+import org.apache.hc.core5.pool.ConnPoolPolicy;
+import org.apache.hc.core5.pool.StrictConnPool;
+import org.apache.hc.core5.util.TimeValue;
 
 public class ClassicTestClient {
 
@@ -72,13 +81,23 @@ public class ClassicTestClient {
 
     public void start(final HttpProcessor httpProcessor) {
         if (requesterRef.get() == null) {
-            final HttpRequester requester = RequesterBootstrap.bootstrap()
-                    .setSslSocketFactory(sslContext != null ? sslContext.getSocketFactory() : null)
-                    .setHttpProcessor(httpProcessor)
-                    .setConnectFactory(LoggingBHttpClientConnectionFactory.INSTANCE)
-                    .setStreamListener(LoggingHttp1StreamListener.INSTANCE_CLIENT)
-                    .setConnPoolListener(LoggingConnPoolListener.INSTANCE)
-                    .create();
+            final HttpRequestExecutor requestExecutor = new HttpRequestExecutor(
+                    HttpRequestExecutor.DEFAULT_WAIT_FOR_CONTINUE,
+                    DefaultConnectionReuseStrategy.INSTANCE,
+                    LoggingHttp1StreamListener.INSTANCE_CLIENT);
+            final StrictConnPool<HttpHost, HttpClientConnection> connPool = new StrictConnPool<>(
+                    20,
+                    50,
+                    TimeValue.NEG_ONE_MILLISECONDS,
+                    ConnPoolPolicy.LIFO,
+                    LoggingConnPoolListener.INSTANCE);
+            final HttpRequester requester = new HttpRequester(
+                    requestExecutor,
+                    httpProcessor != null ? httpProcessor : HttpProcessors.client(),
+                    connPool,
+                    socketConfig,
+                    new DefaultBHttpClientConnectionFactory(H1Config.DEFAULT, CharCodingConfig.DEFAULT),
+                    sslContext != null ? sslContext.getSocketFactory() : null);
             requesterRef.compareAndSet(null, requester);
         } else {
             throw new IllegalStateException("Requester has already been started");

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/41291fa2/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
index ac9026e..323fd2d 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/ClassicTestServer.java
@@ -31,11 +31,19 @@ import java.io.IOException;
 import java.net.InetAddress;
 import java.util.concurrent.atomic.AtomicReference;
 
+import javax.net.ServerSocketFactory;
 import javax.net.ssl.SSLContext;
 
+import org.apache.hc.core5.http.URIScheme;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.config.SocketConfig;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
-import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
+import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnectionFactory;
+import org.apache.hc.core5.http.impl.io.DefaultClassicHttpResponseFactory;
+import org.apache.hc.core5.http.impl.io.HttpService;
 import org.apache.hc.core5.http.io.HttpExpectationVerifier;
 import org.apache.hc.core5.http.io.HttpRequestHandler;
 import org.apache.hc.core5.http.io.support.UriHttpRequestHandlerMapper;
@@ -92,16 +100,25 @@ public class ClassicTestServer {
 
     public void start(final HttpProcessor httpProcessor, final HttpExpectationVerifier expectationVerifier) throws IOException {
         if (serverRef.get() == null) {
-            final HttpServer server = ServerBootstrap.bootstrap()
-                    .setSocketConfig(socketConfig)
-                    .setSslContext(sslContext)
-                    .setHttpProcessor(httpProcessor)
-                    .setExpectationVerifier(expectationVerifier)
-                    .setHandlerMapper(this.registry)
-                    .setConnectionFactory(LoggingBHttpServerConnectionFactory.INSTANCE)
-                    .setStreamListener(LoggingHttp1StreamListener.INSTANCE_CLIENT)
-                    .setExceptionListener(LoggingExceptionListener.INSTANCE)
-                    .create();
+            final HttpService httpService = new HttpService(
+                    httpProcessor != null ? httpProcessor : HttpProcessors.server(),
+                    DefaultConnectionReuseStrategy.INSTANCE,
+                    DefaultClassicHttpResponseFactory.INSTANCE,
+                    registry,
+                    expectationVerifier,
+                    LoggingHttp1StreamListener.INSTANCE_CLIENT);
+            final HttpServer server = new HttpServer(
+                    0,
+                    httpService,
+                    null,
+                    socketConfig,
+                    sslContext != null ? sslContext.getServerSocketFactory() : ServerSocketFactory.getDefault(),
+                    new DefaultBHttpServerConnectionFactory(
+                            sslContext != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+                            H1Config.DEFAULT,
+                            CharCodingConfig.DEFAULT),
+                    null,
+                    LoggingExceptionListener.INSTANCE);
             if (serverRef.compareAndSet(null, server)) {
                 server.start();
             }