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/05/09 19:57:53 UTC

[01/50] [abbrv] httpcomponents-core git commit: Fixed copy-paste bug

Repository: httpcomponents-core
Updated Branches:
  refs/heads/trunk [created] 9c362d4a2


Fixed copy-paste bug

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791941 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 3778bbb1b03bdcbb4cd2bf3004b17466ea6c4065
Parents: e8479bb
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Apr 19 16:39:29 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Apr 19 16:39:29 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/http/nio/BasicResponseConsumer.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3778bbb1/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicResponseConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicResponseConsumer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicResponseConsumer.java
index de45123..9ede4b3 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicResponseConsumer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/BasicResponseConsumer.java
@@ -67,7 +67,7 @@ public class BasicResponseConsumer<T> implements AsyncResponseConsumer<Message<H
                     if (resultCallback != null) {
                         resultCallback.completed(result);
                     }
-                    resultCallback.completed(result);
+                    dataConsumer.releaseResources();
                 }
 
                 @Override


[17/50] [abbrv] httpcomponents-core git commit: Minor refactoring of I/O reactor code

Posted by ol...@apache.org.
Minor refactoring of I/O reactor code

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792526 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: af44438d73091a7e9ba8351cf521f95f79b28825
Parents: 61a8518
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Apr 24 18:10:55 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Apr 24 18:10:55 2017 +0000

----------------------------------------------------------------------
 .../hc/core5/testing/nio/AsyncRequester.java    |  5 +-
 .../hc/core5/testing/nio/AsyncServer.java       |  5 +-
 .../hc/core5/testing/nio/IOReactorExecutor.java |  3 +-
 .../hc/core5/testing/nio/ThreadFactoryImpl.java | 61 --------------
 .../nio/TestDefaultListeningIOReactor.java      | 88 ++++++++++----------
 .../core5/concurrent/DefaultThreadFactory.java  | 64 ++++++++++++++
 .../http/impl/bootstrap/AsyncRequester.java     |  5 +-
 .../core5/http/impl/bootstrap/AsyncServer.java  |  5 +-
 .../core5/http/impl/bootstrap/HttpServer.java   |  5 +-
 .../http/impl/bootstrap/ThreadFactoryImpl.java  | 64 --------------
 .../reactor/AbstractMultiworkerIOReactor.java   | 54 ++++--------
 .../reactor/DefaultConnectingIOReactor.java     | 15 ++--
 .../reactor/DefaultListeningIOReactor.java      | 39 ++++-----
 .../reactor/IOReactorExceptionHandler.java      | 12 ---
 .../apache/hc/core5/reactor/IOReactorImpl.java  | 21 +----
 15 files changed, 174 insertions(+), 272 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
index 6b864b1..436fdf0 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
@@ -32,6 +32,7 @@ import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 import java.util.concurrent.ThreadFactory;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.net.NamedEndpoint;
@@ -49,8 +50,8 @@ public class AsyncRequester extends IOReactorExecutor<DefaultConnectingIOReactor
 
     public AsyncRequester(final IOReactorConfig ioReactorConfig) {
         super(ioReactorConfig,
-                new ThreadFactoryImpl("connector", true),
-                new ThreadFactoryImpl("requester-dispatch", true));
+                new DefaultThreadFactory("connector", true),
+                new DefaultThreadFactory("requester-dispatch", true));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java
index 798cf1f..8698134 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncServer.java
@@ -32,6 +32,7 @@ import java.net.InetSocketAddress;
 import java.util.Set;
 import java.util.concurrent.ThreadFactory;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.reactor.DefaultListeningIOReactor;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -42,7 +43,7 @@ import org.apache.hc.core5.reactor.ListenerEndpoint;
 public class AsyncServer extends IOReactorExecutor<DefaultListeningIOReactor> {
 
     public AsyncServer(final IOReactorConfig ioReactorConfig) {
-        super(ioReactorConfig, new ThreadFactoryImpl("listener", true), new ThreadFactoryImpl("server-dispatch", true));
+        super(ioReactorConfig, new DefaultThreadFactory("listener", true), new DefaultThreadFactory("server-dispatch", true));
     }
 
     @Override
@@ -52,7 +53,7 @@ public class AsyncServer extends IOReactorExecutor<DefaultListeningIOReactor> {
             final ThreadFactory threadFactory,
             final Callback<IOSession> sessionShutdownCallback) throws IOException {
         return new DefaultListeningIOReactor(
-                ioEventHandlerFactory, ioReactorConfig, threadFactory, sessionShutdownCallback);
+                ioEventHandlerFactory, ioReactorConfig, threadFactory, null, sessionShutdownCallback);
     }
 
     public ListenerEndpoint listen(final InetSocketAddress address) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
index 2af9092..e0ed7e4 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/IOReactorExecutor.java
@@ -34,6 +34,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.nio.command.ShutdownCommand;
@@ -94,7 +95,7 @@ abstract class IOReactorExecutor<T extends AbstractMultiworkerIOReactor> impleme
         if (ioReactorRef.compareAndSet(null, createIOReactor(
                 ioEventHandlerFactory,
                 ioReactorConfig,
-                workerThreadFactory != null ? workerThreadFactory : new ThreadFactoryImpl("i/o dispatch"),
+                workerThreadFactory != null ? workerThreadFactory : new DefaultThreadFactory("i/o dispatch"),
                 new Callback<IOSession>() {
 
                     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ThreadFactoryImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ThreadFactoryImpl.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ThreadFactoryImpl.java
deleted file mode 100644
index 48d95dd..0000000
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/ThreadFactoryImpl.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * ====================================================================
- * 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
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.core5.testing.nio;
-
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicLong;
-
-class ThreadFactoryImpl implements ThreadFactory {
-
-    private final String namePrefix;
-    private final ThreadGroup group;
-    private final AtomicLong count;
-    private final boolean daemon;
-
-    ThreadFactoryImpl(final String namePrefix, final ThreadGroup group, final boolean daemon) {
-        this.namePrefix = namePrefix;
-        this.group = group;
-        this.daemon = daemon;
-        this.count = new AtomicLong();
-    }
-
-    ThreadFactoryImpl(final String namePrefix, final boolean daemon) {
-        this(namePrefix, null, daemon);
-    }
-
-    ThreadFactoryImpl(final String namePrefix) {
-        this(namePrefix, null, false);
-    }
-
-    @Override
-    public Thread newThread(final Runnable target) {
-        final Thread thread = new Thread(this.group, target, this.namePrefix + "-"  + this.count.incrementAndGet());
-        thread.setDaemon(daemon);
-        return thread;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
index cdc79df..6c7ff90 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/TestDefaultListeningIOReactor.java
@@ -54,45 +54,47 @@ import org.junit.Test;
  */
 public class TestDefaultListeningIOReactor {
 
-    protected DefaultListeningIOReactor ioreactor;
+    private DefaultListeningIOReactor ioreactor;
 
-    @Before
-    public void setup() throws Exception {
-        final IOReactorConfig reactorConfig = IOReactorConfig.custom()
-                .setIoThreadCount(1)
-                .build();
-        this.ioreactor = new DefaultListeningIOReactor(new IOEventHandlerFactory() {
+    private static class NoopIOEventHandlerFactory implements IOEventHandlerFactory {
 
-            @Override
-            public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
-                return new IOEventHandler() {
+        @Override
+        public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
+            return new IOEventHandler() {
 
-                    @Override
-                    public void connected(final IOSession session) {
-                    }
+                @Override
+                public void connected(final IOSession session) {
+                }
 
-                    @Override
-                    public void inputReady(final IOSession session) {
-                    }
+                @Override
+                public void inputReady(final IOSession session) {
+                }
 
-                    @Override
-                    public void outputReady(final IOSession session) {
-                    }
+                @Override
+                public void outputReady(final IOSession session) {
+                }
 
-                    @Override
-                    public void timeout(final IOSession session) {
-                    }
+                @Override
+                public void timeout(final IOSession session) {
+                }
 
-                    @Override
-                    public void exception(final IOSession session, final Exception cause) {
-                    }
+                @Override
+                public void exception(final IOSession session, final Exception cause) {
+                }
 
-                    @Override
-                    public void disconnected(final IOSession session) {
-                    }
-                };
-            }
-        }, reactorConfig, null);
+                @Override
+                public void disconnected(final IOSession session) {
+                }
+            };
+        }
+    }
+
+    @Before
+    public void setup() throws Exception {
+        final IOReactorConfig reactorConfig = IOReactorConfig.custom()
+                .setIoThreadCount(1)
+                .build();
+        this.ioreactor = new DefaultListeningIOReactor(new NoopIOEventHandlerFactory(), reactorConfig, null, null);
     }
 
     @After
@@ -194,20 +196,20 @@ public class TestDefaultListeningIOReactor {
 
     @Test
     public void testEndpointAlreadyBoundNonFatal() throws Exception {
-        ioreactor.setExceptionHandler(new IOReactorExceptionHandler() {
-
-            @Override
-            public boolean handle(final IOException ex) {
-                return (ex instanceof BindException);
-            }
-
-            @Override
-            public boolean handle(final RuntimeException ex) {
-                return false;
-            }
+        final IOReactorConfig reactorConfig = IOReactorConfig.custom()
+                .setIoThreadCount(1)
+                .build();
+        ioreactor = new DefaultListeningIOReactor(
+                new NoopIOEventHandlerFactory(),
+                reactorConfig,
+                new IOReactorExceptionHandler() {
 
-        });
+                    @Override
+                    public boolean handle(final IOException ex) {
+                        return (ex instanceof BindException);
+                    }
 
+                }, null);
         final Thread t = new Thread(new Runnable() {
 
             @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
new file mode 100644
index 0000000..ab589e9
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/concurrent/DefaultThreadFactory.java
@@ -0,0 +1,64 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.concurrent;
+
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * @since 5.0
+ */
+public class DefaultThreadFactory implements ThreadFactory {
+
+    private final String namePrefix;
+    private final ThreadGroup group;
+    private final AtomicLong count;
+    private final boolean daemon;
+
+    public DefaultThreadFactory(final String namePrefix, final ThreadGroup group, final boolean daemon) {
+        this.namePrefix = namePrefix;
+        this.group = group;
+        this.daemon = daemon;
+        this.count = new AtomicLong();
+    }
+
+    public DefaultThreadFactory(final String namePrefix, final boolean daemon) {
+        this(namePrefix, null, daemon);
+    }
+
+    public DefaultThreadFactory(final String namePrefix) {
+        this(namePrefix, null, false);
+    }
+
+    @Override
+    public Thread newThread(final Runnable target) {
+        final Thread thread = new Thread(this.group, target, this.namePrefix + "-"  + this.count.incrementAndGet());
+        thread.setDaemon(daemon);
+        return thread;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
index f0da106..181bd74 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
@@ -30,6 +30,7 @@ package org.apache.hc.core5.http.impl.bootstrap;
 import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.HttpHost;
@@ -53,9 +54,9 @@ public class AsyncRequester extends IOReactorExecutor<DefaultConnectingIOReactor
             final ExceptionListener exceptionListener,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException {
         super(new DefaultConnectingIOReactor(
-                        eventHandlerFactory, ioReactorConfig, new ThreadFactoryImpl("requester-dispatch", true), sessionShutdownCallback),
+                        eventHandlerFactory, ioReactorConfig, new DefaultThreadFactory("requester-dispatch", true), sessionShutdownCallback),
                 exceptionListener,
-                new ThreadFactoryImpl("connector", true));
+                new DefaultThreadFactory("connector", true));
     }
 
     private InetSocketAddress toSocketAddress(final HttpHost host) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
index 031223b..0e0ed5e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServer.java
@@ -30,6 +30,7 @@ package org.apache.hc.core5.http.impl.bootstrap;
 import java.net.InetSocketAddress;
 import java.util.Set;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.reactor.DefaultListeningIOReactor;
@@ -47,9 +48,9 @@ public class AsyncServer extends IOReactorExecutor<DefaultListeningIOReactor> {
             final ExceptionListener exceptionListener,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException {
         super(new DefaultListeningIOReactor(
-                    eventHandlerFactory, ioReactorConfig, new ThreadFactoryImpl("server-dispatch", true), sessionShutdownCallback),
+                    eventHandlerFactory, ioReactorConfig, new DefaultThreadFactory("server-dispatch", true), null, sessionShutdownCallback),
                 exceptionListener,
-                new ThreadFactoryImpl("listener", true));
+                new DefaultThreadFactory("listener", true));
     }
 
     public ListenerEndpoint listen(final InetSocketAddress address) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
index 8d3da4a..258f926 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
@@ -38,6 +38,7 @@ import java.util.concurrent.atomic.AtomicReference;
 import javax.net.ServerSocketFactory;
 import javax.net.ssl.SSLServerSocket;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection;
@@ -93,12 +94,12 @@ public class HttpServer implements GracefullyCloseable {
         this.listenerExecutorService = new ThreadPoolExecutor(
                 1, 1, 0L, TimeUnit.MILLISECONDS,
                 new SynchronousQueue<Runnable>(),
-                new ThreadFactoryImpl("HTTP-listener-" + this.port));
+                new DefaultThreadFactory("HTTP-listener-" + this.port));
         this.workerThreads = new ThreadGroup("HTTP-workers");
         this.workerExecutorService = new WorkerPoolExecutor(
                 0, Integer.MAX_VALUE, 1L, TimeUnit.SECONDS,
                 new SynchronousQueue<Runnable>(),
-                new ThreadFactoryImpl("HTTP-worker", this.workerThreads, false));
+                new DefaultThreadFactory("HTTP-worker", this.workerThreads, false));
         this.status = new AtomicReference<>(Status.READY);
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java
deleted file mode 100644
index 32ce23e..0000000
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ThreadFactoryImpl.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * ====================================================================
- * 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
- * <http://www.apache.org/>.
- *
- */
-package org.apache.hc.core5.http.impl.bootstrap;
-
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.atomic.AtomicLong;
-
-/**
- * @since 4.4
- */
-class ThreadFactoryImpl implements ThreadFactory {
-
-    private final String namePrefix;
-    private final ThreadGroup group;
-    private final AtomicLong count;
-    private final boolean daemon;
-
-    ThreadFactoryImpl(final String namePrefix, final ThreadGroup group, final boolean daemon) {
-        this.namePrefix = namePrefix;
-        this.group = group;
-        this.daemon = daemon;
-        this.count = new AtomicLong();
-    }
-
-    ThreadFactoryImpl(final String namePrefix, final boolean daemon) {
-        this(namePrefix, null, daemon);
-    }
-
-    ThreadFactoryImpl(final String namePrefix) {
-        this(namePrefix, null, false);
-    }
-
-    @Override
-    public Thread newThread(final Runnable target) {
-        final Thread thread = new Thread(this.group, target, this.namePrefix + "-"  + this.count.incrementAndGet());
-        thread.setDaemon(daemon);
-        return thread;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
index ebb9c77..1ea7634 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
@@ -42,9 +42,9 @@ import java.util.Date;
 import java.util.List;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.util.Args;
@@ -92,22 +92,19 @@ import org.apache.hc.core5.util.TimeValue;
  */
 public abstract class AbstractMultiworkerIOReactor implements IOReactor {
 
-    protected final IOReactorConfig reactorConfig;
-    protected final Selector selector;
+    private final IOReactorConfig reactorConfig;
+    private final Selector selector;
     private final int workerCount;
     private final IOEventHandlerFactory eventHandlerFactory;
     private final ThreadFactory threadFactory;
     private final Callback<IOSession> sessionShutdownCallback;
     private final IOReactorImpl[] dispatchers;
-    private final Worker[] workers;
+    private final IODispatchWorker[] workers;
     private final Thread[] threads;
+    private final List<ExceptionEvent> auditLog;
     private final AtomicReference<IOReactorStatus> status;
     private final Object shutdownMutex;
 
-    //TODO: make final
-    protected IOReactorExceptionHandler exceptionHandler;
-    protected List<ExceptionEvent> auditLog;
-
     private int currentWorker = 0;
 
     /**
@@ -134,12 +131,12 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
         } catch (final IOException ex) {
             throw new IOReactorException("Failure opening selector", ex);
         }
-        this.threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory();
+        this.threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory("I/O dispatcher", true);
         this.sessionShutdownCallback = sessionShutdownCallback;
         this.auditLog = new ArrayList<>();
         this.workerCount = this.reactorConfig.getIoThreadCount();
         this.dispatchers = new IOReactorImpl[workerCount];
-        this.workers = new Worker[workerCount];
+        this.workers = new IODispatchWorker[workerCount];
         this.threads = new Thread[workerCount];
         this.status = new AtomicReference<>(IOReactorStatus.INACTIVE);
         this.shutdownMutex = new Object();
@@ -151,6 +148,10 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
         this(eventHandlerFactory, null, null, sessionShutdownCallback);
     }
 
+    Selector selector() {
+        return selector;
+    }
+
     @Override
     public IOReactorStatus getStatus() {
         return this.status.get();
@@ -176,7 +177,7 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
      * @param timestamp the time stamp of the exception. Can be
      * {@code null} in which case the current date / time will be used.
      */
-    protected synchronized void addExceptionEvent(final Throwable ex, final Date timestamp) {
+    void addExceptionEvent(final Throwable ex, final Date timestamp) {
         if (ex == null) {
             return;
         }
@@ -190,20 +191,11 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
      *
      * @param ex the exception thrown by the I/O reactor.
      */
-    protected void addExceptionEvent(final Throwable ex) {
+    void addExceptionEvent(final Throwable ex) {
         addExceptionEvent(ex, null);
     }
 
     /**
-     * Sets exception handler for this I/O reactor.
-     *
-     * @param exceptionHandler the exception handler.
-     */
-    public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
-        this.exceptionHandler = exceptionHandler;
-    }
-
-    /**
      * Triggered to process I/O events registered by the main {@link Selector}.
      * <p>
      * Super-classes can implement this method to react to the event.
@@ -256,13 +248,12 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
                 final IOReactorImpl dispatcher = new IOReactorImpl(
                         this.eventHandlerFactory,
                         this.reactorConfig,
-                        this.exceptionHandler,
                         this.sessionShutdownCallback);
                 this.dispatchers[i] = dispatcher;
             }
             for (int i = 0; i < this.workerCount; i++) {
                 final IOReactorImpl dispatcher = this.dispatchers[i];
-                this.workers[i] = new Worker(dispatcher);
+                this.workers[i] = new IODispatchWorker(dispatcher);
                 this.threads[i] = this.threadFactory.newThread(this.workers[i]);
             }
 
@@ -296,7 +287,7 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
 
                 // Verify I/O dispatchers
                 for (int i = 0; i < this.workerCount; i++) {
-                    final Worker worker = this.workers[i];
+                    final IODispatchWorker worker = this.workers[i];
                     final Throwable ex = worker.getThrowable();
                     if (ex != null) {
                         throw new IOReactorException("I/O dispatch worker terminated abnormally", ex);
@@ -487,13 +478,13 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
         }
     }
 
-    static class Worker implements Runnable {
+    static class IODispatchWorker implements Runnable {
 
         final IOReactorImpl dispatcher;
 
         private volatile Throwable throwable;
 
-        public Worker(final IOReactorImpl dispatcher) {
+        public IODispatchWorker(final IOReactorImpl dispatcher) {
             super();
             this.dispatcher = dispatcher;
         }
@@ -516,15 +507,4 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
 
     }
 
-    static class DefaultThreadFactory implements ThreadFactory {
-
-        private final static AtomicLong COUNT = new AtomicLong(1);
-
-        @Override
-        public Thread newThread(final Runnable r) {
-            return new Thread(r, "I/O dispatcher " + COUNT.getAndIncrement());
-        }
-
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
index 5b5c9f2..bd914ae 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultConnectingIOReactor.java
@@ -55,17 +55,18 @@ import org.apache.hc.core5.util.Asserts;
 public class DefaultConnectingIOReactor extends AbstractMultiworkerIOReactor
         implements ConnectingIOReactor {
 
+    private final IOReactorConfig reactorConfig;
     private final Queue<SessionRequestImpl> requestQueue;
-
     private final long selectInterval;
     private long lastTimeoutCheck;
 
     public DefaultConnectingIOReactor(
             final IOEventHandlerFactory eventHandlerFactory,
-            final IOReactorConfig reactorConfig,
+            final IOReactorConfig ioReactorConfig,
             final ThreadFactory threadFactory,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException {
-        super(eventHandlerFactory, reactorConfig, threadFactory, sessionShutdownCallback);
+        super(eventHandlerFactory, ioReactorConfig, threadFactory, sessionShutdownCallback);
+        this.reactorConfig = ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT;
         this.requestQueue = new ConcurrentLinkedQueue<>();
         this.selectInterval = this.reactorConfig.getSelectInterval();
         this.lastTimeoutCheck = System.currentTimeMillis();
@@ -103,7 +104,7 @@ public class DefaultConnectingIOReactor extends AbstractMultiworkerIOReactor
         processSessionRequests();
 
         if (readyCount > 0) {
-            final Set<SelectionKey> selectedKeys = this.selector.selectedKeys();
+            final Set<SelectionKey> selectedKeys = selector().selectedKeys();
             for (final SelectionKey key : selectedKeys) {
 
                 processEvent(key);
@@ -115,7 +116,7 @@ public class DefaultConnectingIOReactor extends AbstractMultiworkerIOReactor
         final long currentTime = System.currentTimeMillis();
         if ((currentTime - this.lastTimeoutCheck) >= this.selectInterval) {
             this.lastTimeoutCheck = currentTime;
-            final Set<SelectionKey> keys = this.selector.keys();
+            final Set<SelectionKey> keys = selector().keys();
             processTimeouts(keys);
         }
     }
@@ -197,7 +198,7 @@ public class DefaultConnectingIOReactor extends AbstractMultiworkerIOReactor
                 callback);
 
         this.requestQueue.add(sessionRequest);
-        this.selector.wakeup();
+        selector().wakeup();
 
         return sessionRequest;
     }
@@ -252,7 +253,7 @@ public class DefaultConnectingIOReactor extends AbstractMultiworkerIOReactor
 
             final SessionRequestHandle requestHandle = new SessionRequestHandle(request);
             try {
-                final SelectionKey key = socketChannel.register(this.selector, SelectionKey.OP_CONNECT,
+                final SelectionKey key = socketChannel.register(selector(), SelectionKey.OP_CONNECT,
                         requestHandle);
                 request.setKey(key);
             } catch (final IOException ex) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
index 2a8c3d1..1276435 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/DefaultListeningIOReactor.java
@@ -55,6 +55,8 @@ import org.apache.hc.core5.util.Asserts;
 public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
         implements ListeningIOReactor {
 
+    private final IOReactorConfig reactorConfig;
+    private final IOReactorExceptionHandler exceptionHandler;
     private final Queue<ListenerEndpointImpl> requestQueue;
     private final Set<ListenerEndpointImpl> endpoints;
     private final Set<SocketAddress> pausedEndpoints;
@@ -65,7 +67,7 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
      * Creates an instance of DefaultListeningIOReactor with the given configuration.
      *
      * @param eventHandlerFactory the factory to create I/O event handlers.
-     * @param config I/O reactor configuration.
+     * @param ioReactorConfig I/O reactor configuration.
      * @param threadFactory the factory to create threads.
      *   Can be {@code null}.
      * @throws IOReactorException in case if a non-recoverable I/O error.
@@ -74,10 +76,13 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
      */
     public DefaultListeningIOReactor(
             final IOEventHandlerFactory eventHandlerFactory,
-            final IOReactorConfig config,
+            final IOReactorConfig ioReactorConfig,
             final ThreadFactory threadFactory,
+            final IOReactorExceptionHandler exceptionHandler,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException {
-        super(eventHandlerFactory, config, threadFactory, sessionShutdownCallback);
+        super(eventHandlerFactory, ioReactorConfig, threadFactory, sessionShutdownCallback);
+        this.reactorConfig = ioReactorConfig != null ? ioReactorConfig : IOReactorConfig.DEFAULT;
+        this.exceptionHandler = exceptionHandler;
         this.requestQueue = new ConcurrentLinkedQueue<>();
         this.endpoints = Collections.synchronizedSet(new HashSet<ListenerEndpointImpl>());
         this.pausedEndpoints = new HashSet<>();
@@ -96,8 +101,9 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
     public DefaultListeningIOReactor(
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig config,
+            final IOReactorExceptionHandler exceptionHandler,
             final Callback<IOSession> sessionShutdownCallback) throws IOReactorException {
-        this(eventHandlerFactory, config, null, sessionShutdownCallback);
+        this(eventHandlerFactory, config, null, exceptionHandler, sessionShutdownCallback);
     }
 
     /**
@@ -108,9 +114,8 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
      *
      * @since 5.0
      */
-    public DefaultListeningIOReactor(
-            final IOEventHandlerFactory eventHandlerFactory) throws IOReactorException {
-        this(eventHandlerFactory, null, null);
+    public DefaultListeningIOReactor(final IOEventHandlerFactory eventHandlerFactory) throws IOReactorException {
+        this(eventHandlerFactory, null, null, null);
     }
 
     @Override
@@ -128,7 +133,7 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
         }
 
         if (readyCount > 0) {
-            final Set<SelectionKey> selectedKeys = this.selector.selectedKeys();
+            final Set<SelectionKey> selectedKeys = selector().selectedKeys();
             for (final SelectionKey key : selectedKeys) {
 
                 processEvent(key);
@@ -150,10 +155,8 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
                     try {
                         socketChannel = serverChannel.accept();
                     } catch (final IOException ex) {
-                        if (this.exceptionHandler == null ||
-                                !this.exceptionHandler.handle(ex)) {
-                            throw new IOReactorException(
-                                    "Failure accepting connection", ex);
+                        if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex)) {
+                            throw new IOReactorException("Failure accepting connection", ex);
                         }
                     }
                     if (socketChannel == null) {
@@ -162,10 +165,8 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
                     try {
                         prepareSocket(socketChannel.socket());
                     } catch (final IOException ex) {
-                        if (this.exceptionHandler == null ||
-                                !this.exceptionHandler.handle(ex)) {
-                            throw new IOReactorException(
-                                    "Failure initalizing socket", ex);
+                        if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex)) {
+                            throw new IOReactorException("Failure initalizing socket", ex);
                         }
                     }
                     enqueuePendingSession(socketChannel, null);
@@ -198,7 +199,7 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
         Asserts.check(status == IOReactorStatus.INACTIVE || status == IOReactorStatus.ACTIVE, "I/O reactor has been shut down");
         final ListenerEndpointImpl request = createEndpoint(address);
         this.requestQueue.add(request);
-        this.selector.wakeup();
+        selector().wakeup();
         return request;
     }
 
@@ -234,7 +235,7 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
                 return;
             }
             try {
-                final SelectionKey key = serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);
+                final SelectionKey key = serverChannel.register(selector(), SelectionKey.OP_ACCEPT);
                 key.attach(request);
                 request.setKey(key);
             } catch (final IOException ex) {
@@ -293,7 +294,7 @@ public class DefaultListeningIOReactor extends AbstractMultiworkerIOReactor
             this.requestQueue.add(request);
         }
         this.pausedEndpoints.clear();
-        this.selector.wakeup();
+        selector().wakeup();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java
index 021cc21..3327641 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorExceptionHandler.java
@@ -49,16 +49,4 @@ public interface IOReactorExceptionHandler {
      */
     boolean handle(IOException ex);
 
-    /**
-     * This method is expected to examine the runtime exception passed as
-     * a parameter and decide whether it is safe to continue execution of
-     * the I/O reactor.
-     *
-     * @param ex potentially recoverable runtime exception
-     * @return {@code true} if it is safe to ignore the exception
-     * and continue execution of the I/O reactor; {@code false} if the
-     * I/O reactor must throw {@link RuntimeException} and terminate
-     */
-    boolean handle(RuntimeException ex);
-
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/af44438d/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
index 34731af..dbdce05 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
@@ -63,7 +63,6 @@ class IOReactorImpl implements IOReactor {
     private final AtomicReference<IOReactorStatus> status;
     private final AtomicBoolean shutdownInitiated;
     private final Object shutdownMutex;
-    private final IOReactorExceptionHandler exceptionHandler;
     private final Callback<IOSession> sessionShutdownCallback;
 
     private volatile long lastTimeoutCheck;
@@ -71,12 +70,10 @@ class IOReactorImpl implements IOReactor {
     IOReactorImpl(
             final IOEventHandlerFactory eventHandlerFactory,
             final IOReactorConfig reactorConfig,
-            final IOReactorExceptionHandler exceptionHandler,
             final Callback<IOSession> sessionShutdownCallback) {
         super();
         this.reactorConfig = Args.notNull(reactorConfig, "I/O reactor config");
         this.eventHandlerFactory = Args.notNull(eventHandlerFactory, "Event handler factory");
-        this.exceptionHandler = exceptionHandler;
         this.sessionShutdownCallback = sessionShutdownCallback;
         this.shutdownInitiated = new AtomicBoolean(false);
         this.closedSessions = new ConcurrentLinkedQueue<>();
@@ -232,12 +229,6 @@ class IOReactorImpl implements IOReactor {
         selectedKeys.clear();
     }
 
-    private void handleRuntimeException(final RuntimeException ex) {
-        if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex)) {
-            throw ex;
-        }
-    }
-
     private void processEvent(final SelectionKey key) {
         final InternalIOSession session = (InternalIOSession) key.attachment();
         try {
@@ -253,7 +244,7 @@ class IOReactorImpl implements IOReactor {
             session.shutdown(ShutdownType.GRACEFUL);
         } catch (final RuntimeException ex) {
             session.shutdown(ShutdownType.IMMEDIATE);
-            handleRuntimeException(ex);
+            throw ex;
         }
     }
 
@@ -288,11 +279,7 @@ class IOReactorImpl implements IOReactor {
                 if (sessionRequest != null) {
                     sessionRequest.completed(session);
                 }
-                try {
-                    session.onConnected();
-                } catch (final RuntimeException ex) {
-                    handleRuntimeException(ex);
-                }
+                session.onConnected();
             } catch (final CancelledKeyException ex) {
                 session.shutdown(ShutdownType.GRACEFUL);
             }
@@ -309,8 +296,6 @@ class IOReactorImpl implements IOReactor {
                 session.onDisconnected();
             } catch (final CancelledKeyException ex) {
                 // ignore and move on
-            } catch (final RuntimeException ex) {
-                handleRuntimeException(ex);
             }
         }
     }
@@ -329,7 +314,7 @@ class IOReactorImpl implements IOReactor {
                 session.shutdown(ShutdownType.GRACEFUL);
             } catch (final RuntimeException ex) {
                 session.shutdown(ShutdownType.IMMEDIATE);
-                handleRuntimeException(ex);
+                throw ex;
             }
         }
     }


[15/50] [abbrv] httpcomponents-core git commit: HTTPCORE-456: BasicFuture fails to honor Future interface contract by not throwing CancellationException when cancelled

Posted by ol...@apache.org.
HTTPCORE-456: BasicFuture fails to honor Future interface contract by not throwing CancellationException when cancelled

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792448 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: c0815154c785054f4a66f6f2876ffa465891519c
Parents: 2bb3e67
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Apr 24 10:06:38 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Apr 24 10:06:38 2017 +0000

----------------------------------------------------------------------
 .../core5/testing/nio/Http1IntegrationTest.java | 21 +++++++++++---------
 .../apache/hc/core5/concurrent/BasicFuture.java |  4 ++++
 .../hc/core5/concurrent/TestBasicFuture.java    | 13 +++++++-----
 3 files changed, 24 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c0815154/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index 2d0430a..b6dbaba 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -52,6 +52,7 @@ import java.util.Map;
 import java.util.Queue;
 import java.util.Random;
 import java.util.StringTokenizer;
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -1212,9 +1213,8 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
         Assert.assertEquals("Hi back", entity2);
 
         try {
-            final Message<HttpResponse, String> result3 = future3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
-            Assert.assertNull(result3);
-            Assert.assertTrue(future3.isCancelled());
+            future3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+            Assert.fail("ExecutionException expected");
         } catch (final ExecutionException ignore) {
         }
 
@@ -1222,9 +1222,12 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
                 new BasicRequestProducer("POST", createRequestURI(serverEndpoint, "/hello-3"),
                         new BasicAsyncEntityProducer("Hi there")),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result4 = future4.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
-        Assert.assertNull(result4);
-        Assert.assertTrue(future4.isCancelled());
+        try {
+            future4.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+            Assert.fail("CancellationException expected");
+        } catch (CancellationException ignore) {
+            Assert.assertTrue(future4.isCancelled());
+        }
     }
 
     @Test
@@ -1276,10 +1279,10 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
         Assert.assertTrue(entity2.length() > 0);
 
         try {
-            final Message<HttpResponse, String> result3 = future3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
-            Assert.assertNull(result3);
+            future3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+            Assert.fail("CancellationException expected");
+        } catch (final CancellationException ignore) {
             Assert.assertTrue(future3.isCancelled());
-        } catch (final ExecutionException ignore) {
         }
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c0815154/httpcore5/src/main/java/org/apache/hc/core5/concurrent/BasicFuture.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/concurrent/BasicFuture.java b/httpcore5/src/main/java/org/apache/hc/core5/concurrent/BasicFuture.java
index f33a37f..399e46d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/concurrent/BasicFuture.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/concurrent/BasicFuture.java
@@ -26,6 +26,7 @@
  */
 package org.apache.hc.core5.concurrent;
 
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -69,6 +70,9 @@ public class BasicFuture<T> implements Future<T>, Cancellable {
         if (this.ex != null) {
             throw new ExecutionException(this.ex);
         }
+        if (cancelled) {
+            throw new CancellationException();
+        }
         return this.result;
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c0815154/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestBasicFuture.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestBasicFuture.java b/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestBasicFuture.java
index 5667800..5a827e9 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestBasicFuture.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/concurrent/TestBasicFuture.java
@@ -26,6 +26,7 @@
  */
 package org.apache.hc.core5.concurrent;
 
+import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
@@ -118,7 +119,11 @@ public class TestBasicFuture {
         Assert.assertNull(callback.getException());
         Assert.assertTrue(callback.isCancelled());
 
-        Assert.assertNull(future.get());
+        try {
+            future.get();
+            Assert.fail("CancellationException expected");
+        } catch (final CancellationException ex) {
+        }
         Assert.assertTrue(future.isDone());
         Assert.assertTrue(future.isCancelled());
     }
@@ -175,7 +180,7 @@ public class TestBasicFuture {
         Assert.assertFalse(future.isCancelled());
     }
 
-    @Test
+    @Test(expected = CancellationException.class)
     public void testAsyncCancelled() throws Exception {
         final BasicFuture<Object> future = new BasicFuture<>(null);
 
@@ -193,9 +198,7 @@ public class TestBasicFuture {
         };
         t.setDaemon(true);
         t.start();
-        Assert.assertNull(future.get(60, TimeUnit.SECONDS));
-        Assert.assertTrue(future.isDone());
-        Assert.assertTrue(future.isCancelled());
+        future.get(60, TimeUnit.SECONDS);
     }
 
     @Test(expected=TimeoutException.class)


[39/50] [abbrv] httpcomponents-core git commit: Updated NOTICE and BUILDING

Posted by ol...@apache.org.
Updated NOTICE and BUILDING

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792909 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: fd5edfc2aee149ef96a984195e3abefb585b24c1
Parents: 9d6ec2b
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Thu Apr 27 15:08:17 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Thu Apr 27 15:08:17 2017 +0000

----------------------------------------------------------------------
 BUILDING.txt | 23 ++++-------------------
 NOTICE.txt   |  2 +-
 2 files changed, 5 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fd5edfc2/BUILDING.txt
----------------------------------------------------------------------
diff --git a/BUILDING.txt b/BUILDING.txt
index 4f7f7dd..e0677c3 100644
--- a/BUILDING.txt
+++ b/BUILDING.txt
@@ -27,24 +27,9 @@ mvn install
 
 The JAR packages can be found in the target folders of their respective modules
 
-httpcore/target/httpcore5-<VERSION>.jar
-httpcore-osgi/target/org.apache.httpcomponents.httpcore_<VERSION>.jar
+httpcore5/target/httpcore5-<VERSION>.jar
+httpcore5-h2/target/httpcore5-h2-<VERSION>.jar
+httpcore5-testing/target/httpcore5-testing-<VERSION>.jar
+httpcore5-osgi/target/org.apache.httpcomponents.httpcore_<VERSION>.jar
 
 where <VERSION> is the release version
-
-(4) Validating packages
-
-Check for binary compatibility with the previous version with:
-
-mvn clirr:check
-
-Check for proper license headers with:
-
-mvn apache-rat:check
-
-(5) Building documentation
-
-Execute the following command in order to generate javadoc:
-
-mvn compile javadoc:aggregate
-

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fd5edfc2/NOTICE.txt
----------------------------------------------------------------------
diff --git a/NOTICE.txt b/NOTICE.txt
index 779695f..40ba6b7 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -1,5 +1,5 @@
 Apache HttpComponents Core
-Copyright 2005-2014 The Apache Software Foundation
+Copyright 2005-2017 The Apache Software Foundation
 
 This product includes software developed at
 The Apache Software Foundation (http://www.apache.org/).


[29/50] [abbrv] httpcomponents-core git commit: Refactor range validation into new Args util methods.

Posted by ol...@apache.org.
Refactor range validation into new Args util methods.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792667 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: f29e5fe4f887f122cae3dcdcd34dc4d172abf4e5
Parents: 65b1b58
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 22:34:03 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 22:34:03 2017 +0000

----------------------------------------------------------------------
 .../apache/hc/core5/http2/config/H2Config.java  |  3 +--
 .../hc/core5/http/io/entity/EntityUtils.java    |  6 ++----
 .../java/org/apache/hc/core5/util/Args.java     | 20 +++++++++++---------
 3 files changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f29e5fe4/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
index b7b5e45..ce4821f 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
@@ -165,9 +165,8 @@ public class H2Config {
         }
 
         public Builder setMaxFrameSize(final int maxFrameSize) {
-            Args.checkRange(maxFrameSize, FrameConsts.MIN_FRAME_SIZE, FrameConsts.MAX_FRAME_SIZE,
+            this.maxFrameSize = Args.checkRange(maxFrameSize, FrameConsts.MIN_FRAME_SIZE, FrameConsts.MAX_FRAME_SIZE,
                     "Invalid max frame size");
-            this.maxFrameSize = maxFrameSize;
             return this;
         }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f29e5fe4/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
index 975befa..546e9cd 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
@@ -201,8 +201,7 @@ public final class EntityUtils {
             return null;
         }
         try {
-            Args.checkContentLength(entity);
-            int i = (int)entity.getContentLength();
+            int i = (int) Args.checkContentLength(entity);
             if (i < 0) {
                 i = 4096;
             }
@@ -226,8 +225,7 @@ public final class EntityUtils {
             return null;
         }
         try {
-            Args.checkContentLength(entity);
-            int i = (int) entity.getContentLength();
+            int i = (int) Args.checkContentLength(entity);
             if (i < 0) {
                 i = 4096;
             }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f29e5fe4/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
index 98d8ad8..78fadc4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
@@ -51,27 +51,29 @@ public class Args {
         }
     }
 
-    public static void checkRange(final int value, final int lowInclusive, final int highInclusive,
+    public static long checkContentLength(final EntityDetails entityDetails) {
+        // -1 is a special value
+        // 0 is allowed as well
+        return checkRange(entityDetails.getContentLength(), -1, Integer.MAX_VALUE,
+                "HTTP entity too large to be buffered in memory)");
+    }
+
+    public static int checkRange(final int value, final int lowInclusive, final int highInclusive,
             final String message) {
         if (value < lowInclusive || value > highInclusive) {
             throw new IllegalArgumentException(String.format("%s: %,d is out of range [%,d, %,d]", message,
                     Integer.valueOf(value), Integer.valueOf(lowInclusive), Integer.valueOf(highInclusive)));
         }
+        return value;
     }
 
-    public static void checkRange(final long value, final long lowInclusive, final long highInclusive,
+    public static long checkRange(final long value, final long lowInclusive, final long highInclusive,
             final String message) {
         if (value < lowInclusive || value > highInclusive) {
             throw new IllegalArgumentException(String.format("%s: %,d is out of range [%,d, %,d]", message,
                     Long.valueOf(value), Long.valueOf(lowInclusive), Long.valueOf(highInclusive)));
         }
-    }
-
-    public static void checkContentLength(final EntityDetails entityDetails) {
-        // -1 is a special value
-        // 0 is allowed as well
-        checkRange(entityDetails.getContentLength(), -1, Integer.MAX_VALUE,
-                "HTTP entity too large to be buffered in memory)");
+        return value;
     }
 
     public static <T extends CharSequence> T containsNoBlanks(final T argument, final String name) {


[47/50] [abbrv] httpcomponents-core git commit: Fix Javadoc typos ("SSl" -> "SSL").

Posted by ol...@apache.org.
Fix Javadoc typos ("SSl" -> "SSL").

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793846 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 1484c673461423f823a3ce3d4d68306750e652db
Parents: 993ee4d
Author: Gary D. Gregory <gg...@apache.org>
Authored: Thu May 4 18:40:15 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Thu May 4 18:40:15 2017 +0000

----------------------------------------------------------------------
 .../org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java     | 2 +-
 .../java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/1484c673/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
index d9a7f52..439394e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
@@ -33,7 +33,7 @@ import org.apache.hc.core5.net.NamedEndpoint;
 
 /**
  * Callback interface that can be used to customize various aspects of
- * the TLS/SSl protocol.
+ * the TLS/SSL protocol.
  *
  * @since 4.2
  */

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/1484c673/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
index b6f98d1..eb9bdb4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
@@ -34,7 +34,7 @@ import org.apache.hc.core5.net.NamedEndpoint;
 
 /**
  * Callback interface that can be used to customize various aspects of
- * the TLS/SSl protocol.
+ * the TLS/SSL protocol.
  *
  * @since 4.2
  */


[02/50] [abbrv] httpcomponents-core git commit: Upgraded to Mockito 2.7

Posted by ol...@apache.org.
Upgraded to Mockito 2.7

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791942 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 572bbd3a0275d0c30f0485e2ac39567778f8a395
Parents: 3778bbb
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Apr 19 16:39:42 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Apr 19 16:39:42 2017 +0000

----------------------------------------------------------------------
 .../testing/framework/ClientTestingAdapter.java |  2 +-
 .../testing/framework/TestTestingFramework.java |  8 ++--
 .../core5/http/impl/nio/TestChunkEncoder.java   |  4 +-
 .../http/impl/nio/TestIdentityEncoder.java      | 46 +++++++++---------
 .../impl/nio/TestLengthDelimitedEncoder.java    | 50 ++++++++++----------
 pom.xml                                         |  2 +-
 6 files changed, 56 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/572bbd3a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java
index 50ac49b..33ba080 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/framework/ClientTestingAdapter.java
@@ -110,7 +110,7 @@ public class ClientTestingAdapter {
      * See the documentation for the same method in {@link ClientPOJOAdapter}.
      */
     public boolean isRequestSupported(final Map<String, Object> request) {
-        return (adapter == null) ? true : adapter.checkRequestSupport(request) == null;
+        return (adapter == null) || adapter.checkRequestSupport(request) == null;
     };
 
     /**

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/572bbd3a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java
index 9e6b3dd..fd720ee 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/framework/TestTestingFramework.java
@@ -44,9 +44,9 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.hc.core5.http.ContentType;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.ContentType;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
 import org.hamcrest.Matcher;
@@ -129,7 +129,7 @@ public class TestTestingFramework {
         final ClientTestingAdapter adapter = Mockito.mock(ClientTestingAdapter.class);
 
         // Have isRequestSupported() return false so no test will run.
-        Mockito.when(adapter.isRequestSupported(Mockito.anyMap()))
+        Mockito.when(adapter.isRequestSupported(Mockito.<String, Object>anyMap()))
                      .thenReturn(false);
 
         final TestingFramework framework = newWebServerTestingFramework(adapter);
@@ -142,8 +142,8 @@ public class TestTestingFramework {
 
     @SuppressWarnings("unchecked")
     private void verifyCallMethodNeverCalled(final ClientTestingAdapter adapter) throws Exception {
-        Mockito.verify(adapter, Mockito.never()).execute(Mockito.anyString(), Mockito.anyMap(),
-                       Mockito.any(TestingFrameworkRequestHandler.class), Mockito.anyMap());
+        Mockito.verify(adapter, Mockito.never()).execute(Mockito.anyString(), Mockito.<String, Object>anyMap(),
+                       Mockito.any(TestingFrameworkRequestHandler.class), Mockito.<String, Object>anyMap());
     }
 
     private TestingFramework newFrameworkAndSetAdapter(final ClientTestingAdapter adapter)

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/572bbd3a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestChunkEncoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestChunkEncoder.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestChunkEncoder.java
index 4b604a9..921356d 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestChunkEncoder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestChunkEncoder.java
@@ -38,7 +38,7 @@ import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.nio.SessionOutputBuffer;
 import org.junit.Assert;
 import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
 import org.mockito.Mockito;
 
 /**
@@ -128,7 +128,7 @@ public class TestChunkEncoder {
         Assert.assertEquals(16, encoder.write(CodecTestUtils.wrap("0123456789ABCDEF")));
         Assert.assertEquals(16, encoder.write(CodecTestUtils.wrap("0123456789ABCDEF")));
 
-        Mockito.verify(channel, Mockito.never()).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
 
         outbuf.flush(channel);
         final String s = channel.dump(StandardCharsets.US_ASCII);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/572bbd3a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityEncoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityEncoder.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityEncoder.java
index 9e62c75..fcba011 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityEncoder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestIdentityEncoder.java
@@ -41,7 +41,7 @@ import org.apache.hc.core5.util.CharArrayBuffer;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
 import org.mockito.Mockito;
 
 /**
@@ -318,8 +318,8 @@ public class TestIdentityEncoder {
         final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics, 0);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 
-        Mockito.verify(channel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.never()).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(2)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(13, metrics.getBytesTransferred());
@@ -342,8 +342,8 @@ public class TestIdentityEncoder {
         final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics, 32);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 
-        Mockito.verify(channel, Mockito.never()).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(1)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(1)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.never()).flush(channel);
 
         Assert.assertEquals(0, metrics.getBytesTransferred());
@@ -365,8 +365,8 @@ public class TestIdentityEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.never()).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.never()).flush(channel);
 
         Assert.assertEquals(0, metrics.getBytesTransferred());
@@ -389,8 +389,8 @@ public class TestIdentityEncoder {
         final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics, 2);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 
-        Mockito.verify(channel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.never()).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(2)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(13, metrics.getBytesTransferred());
@@ -413,8 +413,8 @@ public class TestIdentityEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.times(5)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(5)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(3)).flush(channel);
 
         Assert.assertEquals(18, metrics.getBytesTransferred());
@@ -438,8 +438,8 @@ public class TestIdentityEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.times(4)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(4)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(2)).flush(channel);
 
         Assert.assertEquals(18, metrics.getBytesTransferred());
@@ -465,8 +465,8 @@ public class TestIdentityEncoder {
         Assert.assertEquals(2, encoder.write(CodecTestUtils.wrap("--")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.times(4)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(5)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(4)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(5)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(2)).flush(channel);
 
         Assert.assertEquals(21, metrics.getBytesTransferred());
@@ -487,8 +487,8 @@ public class TestIdentityEncoder {
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
         Assert.assertEquals(6, encoder.write(CodecTestUtils.wrap("-stuff")));
 
-        Mockito.verify(channel, Mockito.times(1)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(1)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(8, metrics.getBytesTransferred());
@@ -510,8 +510,8 @@ public class TestIdentityEncoder {
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
         Assert.assertEquals(16, encoder.write(CodecTestUtils.wrap("-much more stuff")));
 
-        Mockito.verify(channel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(1)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(2)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(1)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(21, metrics.getBytesTransferred());
@@ -540,8 +540,8 @@ public class TestIdentityEncoder {
         Assert.assertEquals(0, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(0, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.times(5)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(6)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(5)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(6)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(4)).flush(channel);
 
         Assert.assertEquals(8, metrics.getBytesTransferred());
@@ -565,8 +565,8 @@ public class TestIdentityEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("much more stuff")));
 
-        Mockito.verify(channel, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(8, metrics.getBytesTransferred());

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/572bbd3a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedEncoder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedEncoder.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedEncoder.java
index 36b57f0..248eaac 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedEncoder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/nio/TestLengthDelimitedEncoder.java
@@ -41,7 +41,7 @@ import org.apache.hc.core5.util.CharArrayBuffer;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
-import org.mockito.Matchers;
+import org.mockito.ArgumentMatchers;
 import org.mockito.Mockito;
 
 /**
@@ -377,8 +377,8 @@ public class TestLengthDelimitedEncoder {
             100, 0);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 
-        Mockito.verify(channel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.never()).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(2)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(13, metrics.getBytesTransferred());
@@ -402,8 +402,8 @@ public class TestLengthDelimitedEncoder {
             100, 32);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 
-        Mockito.verify(channel, Mockito.never()).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(1)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(1)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.never()).flush(channel);
 
         Assert.assertEquals(0, metrics.getBytesTransferred());
@@ -426,8 +426,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.never()).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.never()).flush(channel);
 
         Assert.assertEquals(0, metrics.getBytesTransferred());
@@ -450,8 +450,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff; and a lot more stuff")));
 
-        Mockito.verify(channel, Mockito.never()).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.never()).flush(channel);
 
         Assert.assertEquals(0, metrics.getBytesTransferred());
@@ -475,8 +475,8 @@ public class TestLengthDelimitedEncoder {
             100, 2);
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
 
-        Mockito.verify(channel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.never()).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(2)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.never()).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(13, metrics.getBytesTransferred());
@@ -500,8 +500,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.times(5)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(5)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(3)).flush(channel);
 
         Assert.assertEquals(18, metrics.getBytesTransferred());
@@ -526,8 +526,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.times(4)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(4)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(2)).flush(channel);
 
         Assert.assertEquals(18, metrics.getBytesTransferred());
@@ -554,8 +554,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(2, encoder.write(CodecTestUtils.wrap("--")));
         Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.times(4)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(5)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(4)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(5)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(2)).flush(channel);
 
         Assert.assertEquals(21, metrics.getBytesTransferred());
@@ -577,8 +577,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
         Assert.assertEquals(6, encoder.write(CodecTestUtils.wrap("-stuff")));
 
-        Mockito.verify(channel, Mockito.times(1)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(1)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(8, metrics.getBytesTransferred());
@@ -601,8 +601,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
         Assert.assertEquals(16, encoder.write(CodecTestUtils.wrap("-much more stuff")));
 
-        Mockito.verify(channel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(1)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(2)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(1)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(21, metrics.getBytesTransferred());
@@ -632,8 +632,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(0, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(0, encoder.write(CodecTestUtils.wrap("more stuff")));
 
-        Mockito.verify(channel, Mockito.times(5)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(6)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(5)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(6)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(4)).flush(channel);
 
         Assert.assertEquals(8, metrics.getBytesTransferred());
@@ -658,8 +658,8 @@ public class TestLengthDelimitedEncoder {
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
         Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("much more stuff")));
 
-        Mockito.verify(channel, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
-        Mockito.verify(outbuf, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
+        Mockito.verify(channel, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
+        Mockito.verify(outbuf, Mockito.times(3)).write(ArgumentMatchers.<ByteBuffer>any());
         Mockito.verify(outbuf, Mockito.times(1)).flush(channel);
 
         Assert.assertEquals(8, metrics.getBytesTransferred());

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/572bbd3a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index de29905..3386352 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,7 +78,7 @@
     <maven.compiler.target>1.7</maven.compiler.target>
     <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
     <junit.version>4.12</junit.version>
-    <mockito.version>1.10.19</mockito.version>
+    <mockito.version>2.7.22</mockito.version>
     <log4j.version>2.8</log4j.version>
     <hc.stylecheck.version>1</hc.stylecheck.version>
   </properties>


[06/50] [abbrv] httpcomponents-core git commit: HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Reuse factory method.

Posted by ol...@apache.org.
HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Reuse factory method.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791967 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 5f87041d1e8d03003c49037ad4729d8c61e7b958
Parents: e7043b5
Author: Gary D. Gregory <gg...@apache.org>
Authored: Wed Apr 19 20:12:15 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Wed Apr 19 20:12:15 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/util/TimeValue.java    | 16 ++++++++--------
 .../org/apache/hc/core5/util/TestTimeValue.java     | 14 +++++++-------
 2 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/5f87041d/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
index 23ac579..770264f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
@@ -41,9 +41,9 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
 public class TimeValue {
 
     private static final int UNDEFINED = -1;
-    public static final TimeValue NEG_ONE_MILLISECONDS = new TimeValue(UNDEFINED, TimeUnit.MILLISECONDS);
-    public static final TimeValue NEG_ONE_SECONDS = new TimeValue(UNDEFINED, TimeUnit.SECONDS);
-    public static final TimeValue ZERO_MILLISECONDS = new TimeValue(0, TimeUnit.MILLISECONDS);
+    public static final TimeValue NEG_ONE_MILLISECONDS = TimeValue.of(UNDEFINED, TimeUnit.MILLISECONDS);
+    public static final TimeValue NEG_ONE_SECONDS = TimeValue.of(UNDEFINED, TimeUnit.SECONDS);
+    public static final TimeValue ZERO_MILLISECONDS = TimeValue.of(0, TimeUnit.MILLISECONDS);
 
     /**
      * Returns the given {@code long} value as an {@code int} where long values out of int range are returned as
@@ -120,23 +120,23 @@ public class TimeValue {
     }
 
     public static TimeValue ofDays(final long days) {
-        return new TimeValue(days, TimeUnit.DAYS);
+        return of(days, TimeUnit.DAYS);
     }
 
     public static TimeValue ofHours(final long hours) {
-        return new TimeValue(hours, TimeUnit.HOURS);
+        return of(hours, TimeUnit.HOURS);
     }
 
     public static TimeValue ofMillis(final long millis) {
-        return new TimeValue(millis, TimeUnit.MILLISECONDS);
+        return of(millis, TimeUnit.MILLISECONDS);
     }
 
     public static TimeValue ofMinutes(final long minutes) {
-        return new TimeValue(minutes, TimeUnit.MINUTES);
+        return of(minutes, TimeUnit.MINUTES);
     }
 
     public static TimeValue ofSeconds(final long seconds) {
-        return new TimeValue(seconds, TimeUnit.SECONDS);
+        return of(seconds, TimeUnit.SECONDS);
     }
 
     public static boolean isPositive(final TimeValue timeValue) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/5f87041d/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
index 0e5c56f..559b11a 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
@@ -35,31 +35,31 @@ import org.junit.Test;
 public class TestTimeValue {
 
     private void checkToSeconds(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toSeconds(value), new TimeValue(value, timeUnit).toSeconds());
+        Assert.assertEquals(timeUnit.toSeconds(value), TimeValue.of(value, timeUnit).toSeconds());
     }
 
     private void checkToDays(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toDays(value), new TimeValue(value, timeUnit).toDays());
+        Assert.assertEquals(timeUnit.toDays(value), TimeValue.of(value, timeUnit).toDays());
     }
 
     private void checkToHours(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toHours(value), new TimeValue(value, timeUnit).toHours());
+        Assert.assertEquals(timeUnit.toHours(value), TimeValue.of(value, timeUnit).toHours());
     }
 
     private void checkToMinutes(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toMinutes(value), new TimeValue(value, timeUnit).toMinutes());
+        Assert.assertEquals(timeUnit.toMinutes(value), TimeValue.of(value, timeUnit).toMinutes());
     }
 
     private void checkToMillis(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toMillis(value), new TimeValue(value, timeUnit).toMillis());
+        Assert.assertEquals(timeUnit.toMillis(value), TimeValue.of(value, timeUnit).toMillis());
     }
 
     private void checkToMicros(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toMicros(value), new TimeValue(value, timeUnit).toMicros());
+        Assert.assertEquals(timeUnit.toMicros(value), TimeValue.of(value, timeUnit).toMicros());
     }
 
     private void checkToNanos(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toNanos(value), new TimeValue(value, timeUnit).toNanos());
+        Assert.assertEquals(timeUnit.toNanos(value), TimeValue.of(value, timeUnit).toNanos());
     }
 
     @Test


[45/50] [abbrv] httpcomponents-core git commit: Use try-with-resources. Fix Checkstyle in Javadocs.

Posted by ol...@apache.org.
Use try-with-resources. Fix Checkstyle in Javadocs.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793825 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: f392d69048c6ff624398d53d930eb4d93fe5b931
Parents: bc75d33
Author: Gary D. Gregory <gg...@apache.org>
Authored: Thu May 4 15:28:08 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Thu May 4 15:28:08 2017 +0000

----------------------------------------------------------------------
 .../apache/hc/core5/ssl/SSLContextBuilder.java  | 22 +++++---------------
 1 file changed, 5 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f392d690/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
index 4300ac7..d06d526 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
@@ -96,7 +96,7 @@ public class SSLContextBuilder {
 
     /**
      * Sets the SSLContext algorithm name.
-     * 
+     *
      * @param protocol
      *            the SSLContext algorithm name of the requested protocol. See
      *            the SSLContext section in the <a href=
@@ -158,11 +158,8 @@ public class SSLContextBuilder {
             final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
         Args.notNull(file, "Truststore file");
         final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
-        final FileInputStream instream = new FileInputStream(file);
-        try {
+        try (final FileInputStream instream = new FileInputStream(file)) {
             trustStore.load(instream, storePassword);
-        } finally {
-            instream.close();
         }
         return loadTrustMaterial(trustStore, trustStrategy);
     }
@@ -184,11 +181,8 @@ public class SSLContextBuilder {
             final TrustStrategy trustStrategy) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
         Args.notNull(url, "Truststore URL");
         final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
-        final InputStream instream = url.openStream();
-        try {
+        try (final InputStream instream = url.openStream()) {
             trustStore.load(instream, storePassword);
-        } finally {
-            instream.close();
         }
         return loadTrustMaterial(trustStore, trustStrategy);
     }
@@ -237,11 +231,8 @@ public class SSLContextBuilder {
             final PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException {
         Args.notNull(file, "Keystore file");
         final KeyStore identityStore = KeyStore.getInstance(KeyStore.getDefaultType());
-        final FileInputStream instream = new FileInputStream(file);
-        try {
+        try (final FileInputStream instream = new FileInputStream(file)) {
             identityStore.load(instream, storePassword);
-        } finally {
-            instream.close();
         }
         return loadKeyMaterial(identityStore, keyPassword, aliasStrategy);
     }
@@ -260,11 +251,8 @@ public class SSLContextBuilder {
             final PrivateKeyStrategy aliasStrategy) throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, CertificateException, IOException {
         Args.notNull(url, "Keystore URL");
         final KeyStore identityStore = KeyStore.getInstance(KeyStore.getDefaultType());
-        final InputStream instream = url.openStream();
-        try {
+        try (final InputStream instream = url.openStream()) {
             identityStore.load(instream, storePassword);
-        } finally {
-            instream.close();
         }
         return loadKeyMaterial(identityStore, keyPassword, aliasStrategy);
     }


[40/50] [abbrv] httpcomponents-core git commit: Upgraded HttpCore version to 5.0-alpha4-SNAPSHOT

Posted by ol...@apache.org.
Upgraded HttpCore version to 5.0-alpha4-SNAPSHOT

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793293 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 056f44dddc5d36a4cb24fea68957cf9b1e0ad4fc
Parents: fd5edfc
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon May 1 08:32:35 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon May 1 08:32:35 2017 +0000

----------------------------------------------------------------------
 httpcore5-ab/pom.xml      | 2 +-
 httpcore5-h2/pom.xml      | 2 +-
 httpcore5-osgi/pom.xml    | 2 +-
 httpcore5-testing/pom.xml | 2 +-
 httpcore5/pom.xml         | 2 +-
 pom.xml                   | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/056f44dd/httpcore5-ab/pom.xml
----------------------------------------------------------------------
diff --git a/httpcore5-ab/pom.xml b/httpcore5-ab/pom.xml
index da36f0f..d1e300d 100644
--- a/httpcore5-ab/pom.xml
+++ b/httpcore5-ab/pom.xml
@@ -28,7 +28,7 @@
   <parent>
     <groupId>org.apache.httpcomponents.core5</groupId>
     <artifactId>httpcore5-parent</artifactId>
-    <version>5.0-alpha3-SNAPSHOT</version>
+    <version>5.0-alpha4-SNAPSHOT</version>
   </parent>
   <artifactId>httpcore5-ab</artifactId>
   <name>Apache HttpComponents Core Benchmarking Tool</name>

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/056f44dd/httpcore5-h2/pom.xml
----------------------------------------------------------------------
diff --git a/httpcore5-h2/pom.xml b/httpcore5-h2/pom.xml
index 78f5153..6d5d867 100644
--- a/httpcore5-h2/pom.xml
+++ b/httpcore5-h2/pom.xml
@@ -28,7 +28,7 @@
   <parent>
     <groupId>org.apache.httpcomponents.core5</groupId>
     <artifactId>httpcore5-parent</artifactId>
-    <version>5.0-alpha3-SNAPSHOT</version>
+    <version>5.0-alpha4-SNAPSHOT</version>
   </parent>
   <artifactId>httpcore5-h2</artifactId>
   <name>Apache HttpComponents Core HTTP/2</name>

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/056f44dd/httpcore5-osgi/pom.xml
----------------------------------------------------------------------
diff --git a/httpcore5-osgi/pom.xml b/httpcore5-osgi/pom.xml
index 40d933d..114dec0 100644
--- a/httpcore5-osgi/pom.xml
+++ b/httpcore5-osgi/pom.xml
@@ -28,7 +28,7 @@
   <parent>
     <groupId>org.apache.httpcomponents.core5</groupId>
     <artifactId>httpcore5-parent</artifactId>
-    <version>5.0-alpha3-SNAPSHOT</version>
+    <version>5.0-alpha4-SNAPSHOT</version>
   </parent>
   <artifactId>httpcore5-osgi</artifactId>
   <name>Apache HttpComponents Core OSGi Bundle</name>

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/056f44dd/httpcore5-testing/pom.xml
----------------------------------------------------------------------
diff --git a/httpcore5-testing/pom.xml b/httpcore5-testing/pom.xml
index a676d43..0a254f4 100644
--- a/httpcore5-testing/pom.xml
+++ b/httpcore5-testing/pom.xml
@@ -28,7 +28,7 @@
   <parent>
     <groupId>org.apache.httpcomponents.core5</groupId>
     <artifactId>httpcore5-parent</artifactId>
-    <version>5.0-alpha3-SNAPSHOT</version>
+    <version>5.0-alpha4-SNAPSHOT</version>
   </parent>
   <artifactId>httpcore5-testing</artifactId>
   <name>Apache HttpComponents Core Integration Tests</name>

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/056f44dd/httpcore5/pom.xml
----------------------------------------------------------------------
diff --git a/httpcore5/pom.xml b/httpcore5/pom.xml
index b0c9541..7e6aebf 100644
--- a/httpcore5/pom.xml
+++ b/httpcore5/pom.xml
@@ -28,7 +28,7 @@
   <parent>
     <groupId>org.apache.httpcomponents.core5</groupId>
     <artifactId>httpcore5-parent</artifactId>
-    <version>5.0-alpha3-SNAPSHOT</version>
+    <version>5.0-alpha4-SNAPSHOT</version>
   </parent>
   <artifactId>httpcore5</artifactId>
   <name>Apache HttpComponents Core HTTP/1.1</name>

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/056f44dd/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 1756c8e..6d5876b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,7 +34,7 @@
   <groupId>org.apache.httpcomponents.core5</groupId>
   <artifactId>httpcore5-parent</artifactId>
   <name>Apache HttpComponents Core Parent</name>
-  <version>5.0-alpha3-SNAPSHOT</version>
+  <version>5.0-alpha4-SNAPSHOT</version>
   <description>Apache HttpComponents Core is a library of components for building HTTP enabled services</description>
   <url>http://hc.apache.org/httpcomponents-core</url>
   <inceptionYear>2005</inceptionYear>


[11/50] [abbrv] httpcomponents-core git commit: HTTP protocol version negotiation

Posted by ol...@apache.org.
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
index 0b5d7ba..d890360 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequesterBootstrap.java
@@ -30,20 +30,19 @@ import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.ExceptionListener;
 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.impl.ConnectionListener;
-import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
 import org.apache.hc.core5.http.impl.Http1StreamListener;
 import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandlerFactory;
-import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestWriterFactory;
-import org.apache.hc.core5.http.impl.nio.DefaultHttpResponseParserFactory;
+import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http.nio.ssl.BasicClientTlsStrategy;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.pool.ConnPoolListener;
 import org.apache.hc.core5.pool.ConnPoolPolicy;
 import org.apache.hc.core5.pool.StrictConnPool;
+import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.reactor.IOSession;
@@ -55,6 +54,7 @@ import org.apache.hc.core5.util.TimeValue;
 public class AsyncRequesterBootstrap {
 
     private IOReactorConfig ioReactorConfig;
+    private H1Config h1Config;
     private CharCodingConfig charCodingConfig;
     private HttpProcessor httpProcessor;
     private ConnectionReuseStrategy connStrategy;
@@ -84,7 +84,15 @@ public class AsyncRequesterBootstrap {
     }
 
     /**
-     * Sets connection configuration.
+     * Sets HTTP/1.1 protocol parameters
+     */
+    public final AsyncRequesterBootstrap setH1Config(final H1Config h1Config) {
+        this.h1Config = h1Config;
+        return this;
+    }
+
+    /**
+     * Sets message char coding.
      */
     public final AsyncRequesterBootstrap setCharCodingConfig(final CharCodingConfig charCodingConfig) {
         this.charCodingConfig = charCodingConfig;
@@ -177,16 +185,14 @@ public class AsyncRequesterBootstrap {
                 timeToLive,
                 connPoolPolicy,
                 connPoolListener);
-        final ClientHttp1IOEventHandlerFactory ioEventHandlerFactory = new ClientHttp1IOEventHandlerFactory(
+        final ClientHttp1StreamDuplexerFactory streamDuplexerFactory = new ClientHttp1StreamDuplexerFactory(
                 httpProcessor != null ? httpProcessor : HttpProcessors.client(),
-                charCodingConfig,
-                connStrategy != null ? connStrategy : DefaultConnectionReuseStrategy.INSTANCE,
-                DefaultHttpResponseParserFactory.INSTANCE,
-                DefaultHttpRequestWriterFactory.INSTANCE,
-                DefaultContentLengthStrategy.INSTANCE,
-                DefaultContentLengthStrategy.INSTANCE,
+                h1Config != null ? h1Config : H1Config.DEFAULT,
+                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
                 connectionListener,
                 streamListener);
+        final IOEventHandlerFactory ioEventHandlerFactory = new ClientHttp1IOEventHandlerFactory(
+                streamDuplexerFactory);
         try {
             return new HttpAsyncRequester(
                     ioReactorConfig,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
index 535bb41..7cf6cd9 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncServerBootstrap.java
@@ -33,6 +33,7 @@ import org.apache.hc.core5.function.Supplier;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.ConnectionListener;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
@@ -41,6 +42,7 @@ import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestParserFactory;
 import org.apache.hc.core5.http.impl.nio.DefaultHttpResponseWriterFactory;
 import org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandlerFactory;
+import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
 import org.apache.hc.core5.http.nio.ssl.BasicServerTlsStrategy;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
@@ -49,6 +51,7 @@ import org.apache.hc.core5.http.nio.support.RequestConsumerSupplier;
 import org.apache.hc.core5.http.nio.support.ResponseHandler;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.net.InetAddressUtils;
+import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.util.Args;
@@ -61,6 +64,7 @@ public class AsyncServerBootstrap {
     private final List<HandlerEntry> handlerList;
     private String canonicalHostName;
     private IOReactorConfig ioReactorConfig;
+    private H1Config h1Config;
     private CharCodingConfig charCodingConfig;
     private HttpProcessor httpProcessor;
     private ConnectionReuseStrategy connStrategy;
@@ -96,6 +100,14 @@ public class AsyncServerBootstrap {
     }
 
     /**
+     * Sets HTTP/1.1 protocol parameters.
+     */
+    public final AsyncServerBootstrap setH1Config(final H1Config h1Config) {
+        this.h1Config = h1Config;
+        return this;
+    }
+
+    /**
      * Sets connection configuration.
      */
     public final AsyncServerBootstrap setCharCodingConfig(final CharCodingConfig charCodingConfig) {
@@ -205,18 +217,21 @@ public class AsyncServerBootstrap {
         for (final HandlerEntry entry: handlerList) {
             exchangeHandlerFactory.register(entry.hostname, entry.uriPattern, entry.supplier);
         }
-        final ServerHttp1IOEventHandlerFactory ioEventHandlerFactory = new ServerHttp1IOEventHandlerFactory(
+        final ServerHttp1StreamDuplexerFactory streamHandlerFactory = new ServerHttp1StreamDuplexerFactory(
                 httpProcessor != null ? httpProcessor : HttpProcessors.server(),
                 exchangeHandlerFactory,
-                charCodingConfig,
+                h1Config != null ? h1Config : H1Config.DEFAULT,
+                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
                 connStrategy != null ? connStrategy : DefaultConnectionReuseStrategy.INSTANCE,
                 DefaultHttpRequestParserFactory.INSTANCE,
                 DefaultHttpResponseWriterFactory.INSTANCE,
                 DefaultContentLengthStrategy.INSTANCE,
                 DefaultContentLengthStrategy.INSTANCE,
-                tlsStrategy != null ? tlsStrategy : new BasicServerTlsStrategy(new int[] {443, 8443}),
                 connectionListener,
                 streamListener);
+        final IOEventHandlerFactory ioEventHandlerFactory = new ServerHttp1IOEventHandlerFactory(
+                streamHandlerFactory,
+                tlsStrategy != null ? tlsStrategy : new BasicServerTlsStrategy(new int[] {443, 8443}));
         try {
             return new HttpAsyncServer(
                     ioEventHandlerFactory,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
index 769ac2a..f7ea9be 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
@@ -69,7 +69,7 @@ import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.SessionRequestCallback;
-import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.TimeValue;
 
@@ -106,6 +106,15 @@ public class HttpAsyncRequester extends AsyncRequester {
     public Future<AsyncClientEndpoint> connect(
             final HttpHost host,
             final TimeValue timeout,
+            final Object attachment,
+            final FutureCallback<AsyncClientEndpoint> callback) {
+        return doConnect(host, timeout, attachment, callback);
+    }
+
+    protected Future<AsyncClientEndpoint> doConnect(
+            final HttpHost host,
+            final TimeValue timeout,
+            final Object attachment,
             final FutureCallback<AsyncClientEndpoint> callback) {
         Args.notNull(host, "Host");
         Args.notNull(timeout, "Timeout");
@@ -123,17 +132,18 @@ public class HttpAsyncRequester extends AsyncRequester {
                 if (poolEntry.hasConnection()) {
                     resultFuture.completed(endpoint);
                 } else {
-                    final SessionRequest sessionRequest = requestSession(host, timeout, new SessionRequestCallback() {
+                    final SessionRequest sessionRequest = requestSession(host, timeout, attachment, new SessionRequestCallback() {
 
                         @Override
                         public void completed(final SessionRequest request) {
-                            final IOSession session = request.getSession();
-                            if (tlsStrategy != null && session instanceof TransportSecurityLayer) {
+                            final TlsCapableIOSession session = request.getSession();
+                            if (tlsStrategy != null && "https".equalsIgnoreCase(host.getSchemeName())) {
                                 tlsStrategy.upgrade(
-                                        (TransportSecurityLayer) session,
+                                        session,
                                         host,
                                         session.getLocalAddress(),
-                                        session.getRemoteAddress());
+                                        session.getRemoteAddress(),
+                                        attachment);
                             }
                             session.setSocketTimeout(timeout.toMillisIntBound());
                             poolEntry.assignConnection(session);
@@ -188,7 +198,7 @@ public class HttpAsyncRequester extends AsyncRequester {
     }
 
     public Future<AsyncClientEndpoint> connect(final HttpHost host, final TimeValue timeout) throws InterruptedException {
-        return connect(host, timeout, null);
+        return connect(host, timeout, null, null);
     }
 
     public void execute(
@@ -211,7 +221,7 @@ public class HttpAsyncRequester extends AsyncRequester {
                         throw new ProtocolException("Request authority not specified");
                     }
                     final HttpHost target = new HttpHost(authority, scheme);
-                    connect(target, timeout, new FutureCallback<AsyncClientEndpoint>() {
+                    connect(target, timeout, null, new FutureCallback<AsyncClientEndpoint>() {
 
                         @Override
                         public void completed(final AsyncClientEndpoint endpoint) {
@@ -371,7 +381,7 @@ public class HttpAsyncRequester extends AsyncRequester {
             final PoolEntry<HttpHost, IOSession> poolEntry = poolEntryRef.getAndSet(null);
             if (poolEntry != null) {
                 final IOSession ioSession = poolEntry.getConnection();
-                connPool.release(poolEntry, ioSession != null && !ioSession.isClosed());    ;
+                connPool.release(poolEntry, ioSession != null && !ioSession.isClosed());
             }
         }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
index 667bed2..392622f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1IOEventHandler.java
@@ -49,7 +49,7 @@ class AbstractHttp1IOEventHandler implements HttpConnectionEventHandler {
     @Override
     public void connected(final IOSession session) {
         try {
-            streamDuplexer.onConnect();
+            streamDuplexer.onConnect(null);
         } catch (final Exception ex) {
             streamDuplexer.onException(ex);
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
index bbda5c8..259de37 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
@@ -77,6 +77,7 @@ import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.util.Args;
 
 abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage, OutgoingMessage extends HttpMessage>
@@ -217,10 +218,13 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
         }
     }
 
-    public final void onConnect() throws HttpException, IOException {
+    public final void onConnect(final ByteBuffer prefeed) throws HttpException, IOException {
         if (connectionListener != null) {
             connectionListener.onConnect(this);
         }
+        if (prefeed != null) {
+            inbuf.put(prefeed);
+        }
         connState = ConnectionState.ACTIVE;
         processCommands();
     }
@@ -579,7 +583,13 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
 
     @Override
     public SSLSession getSSLSession() {
-        return ioSession.getSSLSession();
+        final TlsDetails tlsDetails = ioSession.getTlsDetails();
+        return tlsDetails != null ? tlsDetails.getSSLSession() : null;
+    }
+
+    @Override
+    public TlsDetails getTlsDetails() {
+        return ioSession.getTlsDetails();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java
index 55c5547..43f0379 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1IOEventHandlerFactory.java
@@ -29,19 +29,6 @@ package org.apache.hc.core5.http.impl.nio;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ConnectionReuseStrategy;
-import org.apache.hc.core5.http.ContentLengthStrategy;
-import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.config.H1Config;
-import org.apache.hc.core5.http.impl.ConnectionListener;
-import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
-import org.apache.hc.core5.http.impl.Http1StreamListener;
-import org.apache.hc.core5.http.nio.NHttpMessageParserFactory;
-import org.apache.hc.core5.http.nio.NHttpMessageWriterFactory;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
@@ -53,86 +40,15 @@ import org.apache.hc.core5.util.Args;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class ClientHttp1IOEventHandlerFactory implements IOEventHandlerFactory {
 
-    private final HttpProcessor httpProcessor;
-    private final CharCodingConfig charCodingConfig;
-    private final ConnectionReuseStrategy connectionReuseStrategy;
-    private final NHttpMessageParserFactory<HttpResponse> responseParserFactory;
-    private final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory;
-    private final ContentLengthStrategy incomingContentStrategy;
-    private final ContentLengthStrategy outgoingContentStrategy;
-    private final ConnectionListener connectionListener;
-    private final Http1StreamListener streamListener;
+    private final ClientHttp1StreamDuplexerFactory streamDuplexerFactory;
 
-    public ClientHttp1IOEventHandlerFactory(
-            final HttpProcessor httpProcessor,
-            final CharCodingConfig charCodingConfig,
-            final ConnectionReuseStrategy connectionReuseStrategy,
-            final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
-            final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
-            final ContentLengthStrategy incomingContentStrategy,
-            final ContentLengthStrategy outgoingContentStrategy,
-            final ConnectionListener connectionListener,
-            final Http1StreamListener streamListener) {
-        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
-        this.charCodingConfig = charCodingConfig !=  null ? charCodingConfig : CharCodingConfig.DEFAULT;
-        this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
-                DefaultConnectionReuseStrategy.INSTANCE;
-        this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
-                DefaultHttpResponseParserFactory.INSTANCE;
-        this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory :
-                DefaultHttpRequestWriterFactory.INSTANCE;
-        this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
-                DefaultContentLengthStrategy.INSTANCE;
-        this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
-                DefaultContentLengthStrategy.INSTANCE;
-        this.connectionListener = connectionListener;
-        this.streamListener = streamListener;
-    }
-
-    public ClientHttp1IOEventHandlerFactory(
-            final HttpProcessor httpProcessor,
-            final CharCodingConfig charCodingConfig,
-            final ConnectionReuseStrategy connectionReuseStrategy,
-            final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
-            final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
-            final ConnectionListener connectionListener,
-            final Http1StreamListener streamListener) {
-        this(httpProcessor, charCodingConfig, connectionReuseStrategy,
-                responseParserFactory, requestWriterFactory, null ,null, connectionListener, streamListener);
-    }
-
-    public ClientHttp1IOEventHandlerFactory(
-            final HttpProcessor httpProcessor,
-            final CharCodingConfig charCodingConfig,
-            final ConnectionListener connectionListener,
-            final Http1StreamListener streamListener) {
-        this(httpProcessor, charCodingConfig, null, null, null, connectionListener, streamListener);
-    }
-
-    public ClientHttp1IOEventHandlerFactory(
-            final HttpProcessor httpProcessor,
-            final CharCodingConfig charCodingConfig) {
-        this(httpProcessor, charCodingConfig, null, null);
+    public ClientHttp1IOEventHandlerFactory(final ClientHttp1StreamDuplexerFactory streamDuplexerFactory) {
+        this.streamDuplexerFactory = Args.notNull(streamDuplexerFactory, "Stream duplexer factory");
     }
 
     @Override
     public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
-        return new ClientHttp1IOEventHandler(createStreamDuplexer(ioSession));
-    }
-
-    protected ClientHttp1StreamDuplexer createStreamDuplexer(final TlsCapableIOSession ioSession) {
-        return new ClientHttp1StreamDuplexer(
-                ioSession,
-                httpProcessor,
-                H1Config.DEFAULT,
-                charCodingConfig,
-                connectionReuseStrategy,
-                responseParserFactory.create(),
-                requestWriterFactory.create(),
-                incomingContentStrategy,
-                outgoingContentStrategy,
-                connectionListener,
-                streamListener);
+        return new ClientHttp1IOEventHandler(streamDuplexerFactory.create(ioSession));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexerFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexerFactory.java
new file mode 100644
index 0000000..bb26d13
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexerFactory.java
@@ -0,0 +1,137 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http.impl.nio;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ConnectionReuseStrategy;
+import org.apache.hc.core5.http.ContentLengthStrategy;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
+import org.apache.hc.core5.http.impl.Http1StreamListener;
+import org.apache.hc.core5.http.nio.NHttpMessageParserFactory;
+import org.apache.hc.core5.http.nio.NHttpMessageWriterFactory;
+import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public final class ClientHttp1StreamDuplexerFactory {
+
+    private final HttpProcessor httpProcessor;
+    private final H1Config h1Config;
+    private final CharCodingConfig charCodingConfig;
+    private final ConnectionReuseStrategy connectionReuseStrategy;
+    private final NHttpMessageParserFactory<HttpResponse> responseParserFactory;
+    private final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory;
+    private final ContentLengthStrategy incomingContentStrategy;
+    private final ContentLengthStrategy outgoingContentStrategy;
+    private final ConnectionListener connectionListener;
+    private final Http1StreamListener streamListener;
+
+    public ClientHttp1StreamDuplexerFactory(
+            final HttpProcessor httpProcessor,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionReuseStrategy connectionReuseStrategy,
+            final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+            final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+            final ContentLengthStrategy incomingContentStrategy,
+            final ContentLengthStrategy outgoingContentStrategy,
+            final ConnectionListener connectionListener,
+            final Http1StreamListener streamListener) {
+        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
+        this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
+        this.charCodingConfig = charCodingConfig !=  null ? charCodingConfig : CharCodingConfig.DEFAULT;
+        this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
+                DefaultConnectionReuseStrategy.INSTANCE;
+        this.responseParserFactory = responseParserFactory != null ? responseParserFactory :
+                new DefaultHttpResponseParserFactory(h1Config);
+        this.requestWriterFactory = requestWriterFactory != null ? requestWriterFactory :
+                DefaultHttpRequestWriterFactory.INSTANCE;
+        this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
+                DefaultContentLengthStrategy.INSTANCE;
+        this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
+                DefaultContentLengthStrategy.INSTANCE;
+        this.connectionListener = connectionListener;
+        this.streamListener = streamListener;
+    }
+
+    public ClientHttp1StreamDuplexerFactory(
+            final HttpProcessor httpProcessor,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionReuseStrategy connectionReuseStrategy,
+            final NHttpMessageParserFactory<HttpResponse> responseParserFactory,
+            final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
+            final ConnectionListener connectionListener,
+            final Http1StreamListener streamListener) {
+        this(httpProcessor, h1Config, charCodingConfig, connectionReuseStrategy,
+                responseParserFactory, requestWriterFactory, null ,null, connectionListener, streamListener);
+    }
+
+    public ClientHttp1StreamDuplexerFactory(
+            final HttpProcessor httpProcessor,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionListener connectionListener,
+            final Http1StreamListener streamListener) {
+        this(httpProcessor, h1Config, charCodingConfig, null, null, null, connectionListener, streamListener);
+    }
+
+    public ClientHttp1StreamDuplexerFactory(
+            final HttpProcessor httpProcessor,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig) {
+        this(httpProcessor, h1Config, charCodingConfig, null, null);
+    }
+
+    public ClientHttp1StreamDuplexer create(final TlsCapableIOSession ioSession) {
+        return new ClientHttp1StreamDuplexer(
+                ioSession,
+                httpProcessor,
+                h1Config,
+                charCodingConfig,
+                connectionReuseStrategy,
+                responseParserFactory.create(),
+                requestWriterFactory.create(),
+                incomingContentStrategy,
+                outgoingContentStrategy,
+                connectionListener,
+                streamListener);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
index a38517c..2f24a54 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
@@ -29,23 +29,7 @@ package org.apache.hc.core5.http.impl.nio;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ConnectionReuseStrategy;
-import org.apache.hc.core5.http.ContentLengthStrategy;
-import org.apache.hc.core5.http.ExceptionListener;
-import org.apache.hc.core5.http.HttpRequest;
-import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.config.H1Config;
-import org.apache.hc.core5.http.impl.ConnectionListener;
-import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
-import org.apache.hc.core5.http.impl.Http1StreamListener;
-import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
-import org.apache.hc.core5.http.nio.HandlerFactory;
-import org.apache.hc.core5.http.nio.NHttpMessageParserFactory;
-import org.apache.hc.core5.http.nio.NHttpMessageWriterFactory;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
@@ -57,106 +41,27 @@ import org.apache.hc.core5.util.Args;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class ServerHttp1IOEventHandlerFactory implements IOEventHandlerFactory {
 
-    private final HttpProcessor httpProcessor;
-    private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
-    private final ConnectionReuseStrategy connectionReuseStrategy;
-    private final CharCodingConfig charCodingConfig;
-    private final NHttpMessageParserFactory<HttpRequest> requestParserFactory;
-    private final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory;
-    private final ContentLengthStrategy incomingContentStrategy;
-    private final ContentLengthStrategy outgoingContentStrategy;
+    private final ServerHttp1StreamDuplexerFactory streamDuplexerFactory;
     private final TlsStrategy tlsStrategy;
-    private final ConnectionListener connectionListener;
-    private final Http1StreamListener streamListener;
 
     public ServerHttp1IOEventHandlerFactory(
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final ConnectionReuseStrategy connectionReuseStrategy,
-            final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
-            final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
-            final ContentLengthStrategy incomingContentStrategy,
-            final ContentLengthStrategy outgoingContentStrategy,
-            final TlsStrategy tlsStrategy,
-            final ConnectionListener connectionListener,
-            final Http1StreamListener streamListener) {
-        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
-        this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
-        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
-        this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
-                DefaultConnectionReuseStrategy.INSTANCE;
-        this.requestParserFactory = requestParserFactory != null ? requestParserFactory :
-                DefaultHttpRequestParserFactory.INSTANCE;
-        this.responseWriterFactory = responseWriterFactory != null ? responseWriterFactory :
-                DefaultHttpResponseWriterFactory.INSTANCE;
-        this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
-                DefaultContentLengthStrategy.INSTANCE;
-        this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
-                DefaultContentLengthStrategy.INSTANCE;
+            final ServerHttp1StreamDuplexerFactory streamDuplexerFactory,
+            final TlsStrategy tlsStrategy) {
+        this.streamDuplexerFactory = Args.notNull(streamDuplexerFactory, "Stream duplexer factory");
         this.tlsStrategy = tlsStrategy;
-        this.connectionListener = connectionListener;
-        this.streamListener = streamListener;
-    }
-
-    public ServerHttp1IOEventHandlerFactory(
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final ConnectionReuseStrategy connectionReuseStrategy,
-            final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
-            final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
-            final TlsStrategy tlsStrategy,
-            final ConnectionListener connectionListener,
-            final Http1StreamListener streamListener) {
-        this(httpProcessor, exchangeHandlerFactory, charCodingConfig,
-                connectionReuseStrategy, requestParserFactory, responseWriterFactory,
-                null, null, tlsStrategy, connectionListener, streamListener);
-    }
-
-    public ServerHttp1IOEventHandlerFactory(
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final TlsStrategy tlsStrategy,
-            final ConnectionListener connectionListener,
-            final Http1StreamListener streamListener) {
-        this(httpProcessor, exchangeHandlerFactory, charCodingConfig, null, null ,null,
-                tlsStrategy, connectionListener, streamListener);
-    }
-
-    public ServerHttp1IOEventHandlerFactory(
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final TlsStrategy tlsStrategy,
-            final ExceptionListener errorListener) {
-        this(httpProcessor, exchangeHandlerFactory, charCodingConfig, tlsStrategy, null, null);
     }
 
     @Override
     public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
-        return new ServerHttp1IOEventHandler(createStreamDuplexer(ioSession));
-    }
-
-    protected ServerHttp1StreamDuplexer createStreamDuplexer(final TlsCapableIOSession ioSession) {
         if (tlsStrategy != null) {
             tlsStrategy.upgrade(
                     ioSession,
                     null,
                     ioSession.getLocalAddress(),
-                    ioSession.getRemoteAddress());
+                    ioSession.getRemoteAddress(),
+                    attachment);
         }
-        return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
-                H1Config.DEFAULT,
-                charCodingConfig,
-                connectionReuseStrategy,
-                requestParserFactory.create(),
-                responseWriterFactory.create(),
-                incomingContentStrategy,
-                outgoingContentStrategy,
-                connectionListener,
-                streamListener);
+        return new ServerHttp1IOEventHandler(streamDuplexerFactory.create(ioSession));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
new file mode 100644
index 0000000..568390a
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
@@ -0,0 +1,136 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http.impl.nio;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ConnectionReuseStrategy;
+import org.apache.hc.core5.http.ContentLengthStrategy;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
+import org.apache.hc.core5.http.impl.Http1StreamListener;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.HandlerFactory;
+import org.apache.hc.core5.http.nio.NHttpMessageParserFactory;
+import org.apache.hc.core5.http.nio.NHttpMessageWriterFactory;
+import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public final class ServerHttp1StreamDuplexerFactory {
+
+    private final HttpProcessor httpProcessor;
+    private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
+    private final ConnectionReuseStrategy connectionReuseStrategy;
+    private final H1Config h1Config;
+    private final CharCodingConfig charCodingConfig;
+    private final NHttpMessageParserFactory<HttpRequest> requestParserFactory;
+    private final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory;
+    private final ContentLengthStrategy incomingContentStrategy;
+    private final ContentLengthStrategy outgoingContentStrategy;
+    private final ConnectionListener connectionListener;
+    private final Http1StreamListener streamListener;
+
+    public ServerHttp1StreamDuplexerFactory(
+            final HttpProcessor httpProcessor,
+            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionReuseStrategy connectionReuseStrategy,
+            final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+            final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
+            final ContentLengthStrategy incomingContentStrategy,
+            final ContentLengthStrategy outgoingContentStrategy,
+            final ConnectionListener connectionListener,
+            final Http1StreamListener streamListener) {
+        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
+        this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
+        this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
+        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
+        this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
+                DefaultConnectionReuseStrategy.INSTANCE;
+        this.requestParserFactory = requestParserFactory != null ? requestParserFactory :
+                new DefaultHttpRequestParserFactory(h1Config);
+        this.responseWriterFactory = responseWriterFactory != null ? responseWriterFactory :
+                DefaultHttpResponseWriterFactory.INSTANCE;
+        this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
+                DefaultContentLengthStrategy.INSTANCE;
+        this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
+                DefaultContentLengthStrategy.INSTANCE;
+        this.connectionListener = connectionListener;
+        this.streamListener = streamListener;
+    }
+
+    public ServerHttp1StreamDuplexerFactory(
+            final HttpProcessor httpProcessor,
+            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionReuseStrategy connectionReuseStrategy,
+            final NHttpMessageParserFactory<HttpRequest> requestParserFactory,
+            final NHttpMessageWriterFactory<HttpResponse> responseWriterFactory,
+            final ConnectionListener connectionListener,
+            final Http1StreamListener streamListener) {
+        this(httpProcessor, exchangeHandlerFactory, h1Config, charCodingConfig,
+                connectionReuseStrategy, requestParserFactory, responseWriterFactory,
+                null, null, connectionListener, streamListener);
+    }
+
+    public ServerHttp1StreamDuplexerFactory(
+            final HttpProcessor httpProcessor,
+            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionListener connectionListener,
+            final Http1StreamListener streamListener) {
+        this(httpProcessor, exchangeHandlerFactory, h1Config, charCodingConfig, null, null ,null, connectionListener, streamListener);
+    }
+
+    public ServerHttp1StreamDuplexer create(final TlsCapableIOSession ioSession) {
+        return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
+                h1Config,
+                charCodingConfig,
+                connectionReuseStrategy,
+                requestParserFactory.create(),
+                responseWriterFactory.create(),
+                incomingContentStrategy,
+                outgoingContentStrategy,
+                connectionListener,
+                streamListener);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java
index 6d02fb0..59d0774 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/SessionInputBufferImpl.java
@@ -116,6 +116,14 @@ public class SessionInputBufferImpl extends ExpandableBuffer implements SessionI
         this(buffersize, 256);
     }
 
+    public void put(final ByteBuffer src) {
+        if (src != null && src.hasRemaining()) {
+            setInputMode();
+            ensureCapacity(src.remaining());
+            buffer().put(src);
+        }
+    }
+
     @Override
     public int fill(final ReadableByteChannel channel) throws IOException {
         Args.notNull(channel, "Channel");

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
index 93176d3..9451bf8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
@@ -90,7 +90,7 @@ public class BasicClientTlsStrategy implements TlsStrategy {
             final HttpHost host,
             final SocketAddress localAddress,
             final SocketAddress remoteAddress,
-            final String... parameters) {
+            final Object attachment) {
         final String scheme = host != null ? host.getSchemeName() : null;
         if ("https".equalsIgnoreCase(scheme)) {
             tlsSession.startTls(sslContext, sslBufferManagement, initializer, verifier);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
index 11154cf..0936ceb 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
@@ -96,7 +96,7 @@ public class BasicServerTlsStrategy implements TlsStrategy {
             final HttpHost host,
             final SocketAddress localAddress,
             final SocketAddress remoteAddress,
-            final String... parameters) {
+            final Object attachment) {
         final int port = ((InetSocketAddress) localAddress).getPort();
         for (final int securePort: securePorts) {
             if (port == securePort) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
index 47f009d..24514af 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
@@ -44,6 +44,6 @@ public interface TlsStrategy {
             HttpHost host,
             SocketAddress localAddress,
             SocketAddress remoteAddress,
-            String... parameters);
+            Object attachment);
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java
index f7cf3a6..6c6fce1 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/InternalIOSession.java
@@ -35,7 +35,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
@@ -47,6 +46,7 @@ import org.apache.hc.core5.reactor.ssl.SSLIOSession;
 import org.apache.hc.core5.reactor.ssl.SSLMode;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.util.Asserts;
 
 /**
@@ -239,9 +239,9 @@ class InternalIOSession implements TlsCapableIOSession {
     }
 
     @Override
-    public SSLSession getSSLSession() {
+    public TlsDetails getTlsDetails() {
         final SSLIOSession sslIoSession = tlsSessionRef.get();
-        return sslIoSession != null ? sslIoSession.getSSLSession() : null;
+        return sslIoSession != null ? sslIoSession.getTlsDetails() : null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
index 2edf266..64bf23d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java
@@ -41,7 +41,6 @@ import javax.net.ssl.SSLEngineResult;
 import javax.net.ssl.SSLEngineResult.HandshakeStatus;
 import javax.net.ssl.SSLEngineResult.Status;
 import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLParameters;
 import javax.net.ssl.SSLSession;
 
 import org.apache.hc.core5.annotation.Contract;
@@ -53,6 +52,7 @@ import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.EventMask;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.ssl.ReflectionSupport;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.Asserts;
 
@@ -86,6 +86,7 @@ public class SSLIOSession implements IOSession {
     private volatile SSLMode sslMode;
     private volatile int status;
     private volatile boolean initialized;
+    private TlsDetails tlsDetails;
 
     /**
      * Creates new instance of {@code SSLIOSession} class with static SSL buffers.
@@ -199,7 +200,7 @@ public class SSLIOSession implements IOSession {
 
     /**
      * Initializes the session. This method invokes the {@link
-     * SSLSessionInitializer#initialize(NamedEndpoint, SSLParameters)} callback
+     * SSLSessionInitializer#initialize(NamedEndpoint, SSLEngine)} callback
      * if an instance of {@link SSLSessionInitializer} was specified at the construction time.
      *
      * @throws SSLException in case of a SSL protocol exception.
@@ -219,9 +220,7 @@ public class SSLIOSession implements IOSession {
             break;
         }
         if (this.initializer != null) {
-            final SSLParameters sslParameters = this.sslEngine.getSSLParameters();
-            this.initializer.initialize(this.targetEndpoint, sslParameters);
-            this.sslEngine.setSSLParameters(sslParameters);
+            this.initializer.initialize(this.targetEndpoint, this.sslEngine);
         }
         this.initialized = true;
         this.sslEngine.beginHandshake();
@@ -234,8 +233,8 @@ public class SSLIOSession implements IOSession {
         doHandshake();
     }
 
-    public synchronized SSLSession getSSLSession() {
-        return this.sslEngine.getSession();
+    public synchronized TlsDetails getTlsDetails() {
+        return tlsDetails;
     }
 
     // A works-around for exception handling craziness in Sun/Oracle's SSLEngine
@@ -351,7 +350,12 @@ public class SSLIOSession implements IOSession {
         // It is never generated by SSLEngine.getHandshakeStatus().
         if (result != null && result.getHandshakeStatus() == HandshakeStatus.FINISHED) {
             if (this.verifier != null) {
-                this.verifier.verify(this.targetEndpoint, this.sslEngine.getSession());
+                this.tlsDetails = this.verifier.verify(this.targetEndpoint, this.sslEngine);
+            }
+            if (this.tlsDetails == null) {
+                final SSLSession sslSession = this.sslEngine.getSession();
+                final String applicationProtocol = ReflectionSupport.callGetter(this.sslEngine, "ApplicationProtocol", String.class);
+                this.tlsDetails = new TlsDetails(sslSession, applicationProtocol);
             }
             if (this.callback != null) {
                 this.callback.execute(this);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
index d8c83dd..d9a7f52 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionInitializer.java
@@ -27,7 +27,7 @@
 
 package org.apache.hc.core5.reactor.ssl;
 
-import javax.net.ssl.SSLParameters;
+import javax.net.ssl.SSLEngine;
 
 import org.apache.hc.core5.net.NamedEndpoint;
 
@@ -42,13 +42,12 @@ public interface SSLSessionInitializer {
     /**
      * Triggered when the SSL connection is being initialized. Custom handlers
      * can use this callback to customize properties of the {@link javax.net.ssl.SSLEngine}
-     * used to establish the SSL session by modifying the given
-     * {@link SSLParameters}.
+     * used to establish the SSL session.
      *
      * @param endpoint the endpoint name for a client side session or {@code null}
      *                 for a server side session.
-     * @param sslParameters the actual SSL parameters.
+     * @param sslEngine the SSL engine.
      */
-    void initialize(NamedEndpoint endpoint, SSLParameters sslParameters);
+    void initialize(NamedEndpoint endpoint, SSLEngine sslEngine);
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
index f7b8ef2..b6f98d1 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLSessionVerifier.java
@@ -27,8 +27,8 @@
 
 package org.apache.hc.core5.reactor.ssl;
 
+import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSession;
 
 import org.apache.hc.core5.net.NamedEndpoint;
 
@@ -43,15 +43,15 @@ public interface SSLSessionVerifier {
     /**
      * Triggered when the SSL connection has been established and initial SSL
      * handshake has been successfully completed. Custom handlers can use
-     * this callback to verify properties of the {@link SSLSession}.
+     * this callback to verify properties of the {@link SSLEngine}.
      * For instance this would be the right place to enforce SSL cipher
      * strength, validate certificate chain and do hostname checks.
      *
      * @param endpoint the endpoint name for a client side session or {@code null}
      *                 for a server side session.
-     * @param sslsession newly created SSL session.
+     * @param sslEngine SSL engine.
      * @throws SSLException if case of SSL protocol error.
      */
-    void verify(NamedEndpoint endpoint, SSLSession sslsession) throws SSLException;
+    TlsDetails verify(NamedEndpoint endpoint, SSLEngine sslEngine) throws SSLException;
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TlsDetails.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TlsDetails.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TlsDetails.java
new file mode 100644
index 0000000..9e41ef8
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TlsDetails.java
@@ -0,0 +1,63 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.reactor.ssl;
+
+import javax.net.ssl.SSLSession;
+
+/**
+ * Represents details of a fully established TLS session.
+ *
+ * @since 5.0
+ */
+public final class TlsDetails {
+
+    private final SSLSession sslSession;
+    private final String applicationProtocol;
+
+    public TlsDetails(final SSLSession sslSession, final String applicationProtocol) {
+        this.sslSession = sslSession;
+        this.applicationProtocol = applicationProtocol;
+    }
+
+    public SSLSession getSSLSession() {
+        return sslSession;
+    }
+
+    public String getApplicationProtocol() {
+        return applicationProtocol;
+    }
+
+    @Override
+    public String toString() {
+        return "TlsDetails{" +
+                "sslSession=" + sslSession +
+                ", applicationProtocol='" + applicationProtocol + '\'' +
+                '}';
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
index 0d724be..c63e255 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/TransportSecurityLayer.java
@@ -28,7 +28,6 @@
 package org.apache.hc.core5.reactor.ssl;
 
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
 
 /**
  * Represents a TLS capable session layer.
@@ -43,6 +42,6 @@ public interface TransportSecurityLayer {
             SSLSessionInitializer initializer,
             SSLSessionVerifier verifier) throws UnsupportedOperationException;
 
-    SSLSession getSSLSession();
+    TlsDetails getTlsDetails();
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
new file mode 100644
index 0000000..333d5f0
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
@@ -0,0 +1,54 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.ssl;
+
+import java.lang.reflect.Method;
+
+public final class ReflectionSupport {
+
+    public static void callSetter(final Object object, final String setterName, final Class type, final Object value) {
+        try {
+            final Class<?> clazz = object.getClass();
+            final Method method = clazz.getMethod("set" + setterName, type);
+            method.invoke(object, value);
+        } catch (final Exception ignore) {
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T> T callGetter(final Object object, final String getterName, final Class<T> resultType) {
+        try {
+            final Class<?> clazz = object.getClass();
+            final Method method = clazz.getMethod("get" + getterName);
+            return resultType.cast(method.invoke(object));
+        } catch (final Exception ignore) {
+            return null;
+        }
+    }
+
+}


[41/50] [abbrv] httpcomponents-core git commit: Add test.

Posted by ol...@apache.org.
Add test.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793397 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 3ee0f67c985720debb1891b044510c015ec513ea
Parents: 056f44d
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon May 1 18:45:11 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon May 1 18:45:11 2017 +0000

----------------------------------------------------------------------
 .../src/test/java/org/apache/hc/core5/util/TestTimeValue.java  | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3ee0f67c/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
index 87b27b8..21200bf 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
@@ -138,4 +138,10 @@ public class TestTimeValue {
         test(-1);
     }
 
+    @Test
+    public void testToString() {
+        Assert.assertEquals("9,223,372,036,854,775,807 SECONDS", TimeValue.ofSeconds(Long.MAX_VALUE).toString());
+        Assert.assertEquals("0 MILLISECONDS", TimeValue.ZERO_MILLISECONDS.toString());
+    }
+
 }


[08/50] [abbrv] httpcomponents-core git commit: [HTTPCORE-454] Add a Timeout class that extends TimeValue. First cut. Not used yet. Unit test is there though. Might need some refinements.

Posted by ol...@apache.org.
[HTTPCORE-454] Add a Timeout class that extends TimeValue. First cut. Not used yet. Unit test is there though. Might need some refinements.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791989 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 737714750790d378c14739f0a64ba25716657b12
Parents: c704b3a
Author: Gary D. Gregory <gg...@apache.org>
Authored: Wed Apr 19 21:48:38 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Wed Apr 19 21:48:38 2017 +0000

----------------------------------------------------------------------
 .../org/apache/hc/core5/util/TimeValue.java     |  13 +-
 .../java/org/apache/hc/core5/util/Timeout.java  | 173 +++++++++++++++++++
 .../org/apache/hc/core5/util/TestTimeout.java   | 129 ++++++++++++++
 3 files changed, 313 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/73771475/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
index 770264f..cd7a271 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
@@ -40,7 +40,7 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class TimeValue {
 
-    private static final int UNDEFINED = -1;
+    static final int UNDEFINED = -1;
     public static final TimeValue NEG_ONE_MILLISECONDS = TimeValue.of(UNDEFINED, TimeUnit.MILLISECONDS);
     public static final TimeValue NEG_ONE_SECONDS = TimeValue.of(UNDEFINED, TimeUnit.SECONDS);
     public static final TimeValue ZERO_MILLISECONDS = TimeValue.of(0, TimeUnit.MILLISECONDS);
@@ -115,6 +115,15 @@ public class TimeValue {
         return defaultsTo(timeValue, NEG_ONE_SECONDS);
     }
 
+    /**
+     * Creates a TimeValue.
+     * 
+     * @param duration
+     *            the time duration in the given {@code timeUnit}.
+     * @param timeUnit
+     *            the time unit for the given durarion.
+     * @return a Timeout
+     */
     public static TimeValue of(final long duration, final TimeUnit timeUnit) {
         return new TimeValue(duration, timeUnit);
     }
@@ -233,7 +242,7 @@ public class TimeValue {
     @Override
     public int hashCode() {
         int hash = LangUtils.HASH_SEED;
-        hash = LangUtils.hashCode(hash, duration);
+        hash = LangUtils.hashCode(hash, Long.valueOf(duration));
         hash = LangUtils.hashCode(hash, timeUnit);
         return hash;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/73771475/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
new file mode 100644
index 0000000..f7a4d5d
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
@@ -0,0 +1,173 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.util;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+
+/**
+ * Represents a timeout value as a {@code long} time and {@link TimeUnit}.
+ *
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public class Timeout extends TimeValue {
+
+    /**
+     * A disabled timeout represented as 0 {@code MILLISECONDS}.
+     */
+    public static final Timeout DISABLED = new Timeout(0, TimeUnit.MILLISECONDS);
+
+    /**
+     * An undefined timeout represented as -1 {@code MILLISECONDS}.
+     */
+    public static final Timeout UNDEFINED_MILLISECONDS = new Timeout(UNDEFINED, TimeUnit.MILLISECONDS);
+
+    /**
+     * An undefined timeout represented as -1 {@code SECONDS}.
+     */
+    public static final Timeout UNDEFINED_SECONDS = new Timeout(UNDEFINED, TimeUnit.SECONDS);
+
+    /**
+     * Creates a Timeout.
+     * 
+     * @param duration
+     *            the time duration in the given {@code timeUnit}.
+     * @param timeUnit
+     *            the time unit for the given durarion.
+     * @return a Timeout
+     */
+    public static Timeout of(final long duration, final TimeUnit timeUnit) {
+        return new Timeout(duration, timeUnit);
+    }
+
+    /**
+     * Creates a Timeout.
+     * 
+     * @param days
+     *            the duration in days and the given {@code timeUnit}.
+     * @return a Timeout
+     */
+    public static Timeout ofDays(final long days) {
+        return of(days, TimeUnit.DAYS);
+    }
+
+    /**
+     * Creates a Timeout.
+     * 
+     * @param hours
+     *            the duration in hours and the given {@code timeUnit}.
+     * @return a Timeout
+     */
+    public static Timeout ofHours(final long hours) {
+        return of(hours, TimeUnit.HOURS);
+    }
+
+    /**
+     * Creates a Timeout.
+     * 
+     * @param milliseconds
+     *            the duration in milliseconds and the given {@code timeUnit}.
+     * @return a Timeout
+     */
+    public static Timeout ofMillis(final long milliseconds) {
+        return of(milliseconds, TimeUnit.MILLISECONDS);
+    }
+
+    /**
+     * Creates a Timeout.
+     * 
+     * @param minutes
+     *            the duration in minutes and the given {@code timeUnit}.
+     * @return a Timeout
+     */
+    public static Timeout ofMinutes(final long minutes) {
+        return of(minutes, TimeUnit.MINUTES);
+    }
+
+    /**
+     * Creates a Timeout.
+     * 
+     * @param seconds
+     *            the duration in seconds and the given {@code timeUnit}.
+     * @return a Timeout
+     */
+    public static Timeout ofSeconds(final long seconds) {
+        return of(seconds, TimeUnit.SECONDS);
+    }
+
+    private static long validateDuration(final long duration) {
+        if (duration < UNDEFINED) {
+            throw new IllegalArgumentException("Duration may not be less than " + UNDEFINED);
+        }
+        return duration;
+    }
+
+    Timeout(final long duration, final TimeUnit timeUnit) {
+        super(validateDuration(duration), Args.notNull(timeUnit, "timeUnit"));
+    }
+
+    /**
+     * Whether this timeout is disabled.
+     * 
+     * @return Whether this timeout is disabled.
+     */
+    public boolean isDisabled() {
+        return getDuration() == 0;
+    }
+
+    /**
+     * Whether this timeout is enabled.
+     * 
+     * @return Whether this timeout is disabled.
+     */
+    public boolean isEnabled() {
+        return !isDisabled() && !(isUndefinedMilliseconds() || isUndefinedSeconds());
+    }
+
+    /**
+     * Whether this timeout is undefined.
+     * 
+     * @return Whether this timeout is undefined.
+     */
+    public boolean isUndefinedMilliseconds() {
+        return getDuration() == UNDEFINED && getTimeUnit() == TimeUnit.MILLISECONDS;
+    }
+
+    /**
+     * Whether this timeout is undefined.
+     * 
+     * @return Whether this timeout is undefined.
+     */
+    public boolean isUndefinedSeconds() {
+        return getDuration() == UNDEFINED && getTimeUnit() == TimeUnit.SECONDS;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/73771475/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
new file mode 100644
index 0000000..271a348
--- /dev/null
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
@@ -0,0 +1,129 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.util;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestTimeout {
+
+    private void checkToDays(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toDays(value), Timeout.of(value, timeUnit).toDays());
+    }
+
+    private void checkToHours(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toHours(value), Timeout.of(value, timeUnit).toHours());
+    }
+
+    private void checkToMicros(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toMicros(value), Timeout.of(value, timeUnit).toMicros());
+    }
+
+    private void checkToMillis(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toMillis(value), Timeout.of(value, timeUnit).toMillis());
+    }
+
+    private void checkToMinutes(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toMinutes(value), Timeout.of(value, timeUnit).toMinutes());
+    }
+
+    private void checkToNanos(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toNanos(value), Timeout.of(value, timeUnit).toNanos());
+    }
+
+    private void checkToSeconds(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toSeconds(value), Timeout.of(value, timeUnit).toSeconds());
+    }
+
+    private void test(final long value) {
+        for (final TimeUnit timeUnit : TimeUnit.values()) {
+            checkToDays(value, timeUnit);
+            checkToHours(value, timeUnit);
+            checkToMinutes(value, timeUnit);
+            checkToSeconds(value, timeUnit);
+            checkToMillis(value, timeUnit);
+            checkToMicros(value, timeUnit);
+            checkToNanos(value, timeUnit);
+        }
+    }
+
+    @Test
+    public void test0() {
+        test(0);
+    }
+
+    @Test
+    public void test1() {
+        test(1);
+    }
+
+    @Test
+    public void testDisabled() {
+        Assert.assertTrue(Timeout.DISABLED.isDisabled());
+        Assert.assertFalse(Timeout.DISABLED.isEnabled());
+        Assert.assertFalse(Timeout.DISABLED.isUndefinedMilliseconds());
+        Assert.assertFalse(Timeout.DISABLED.isUndefinedSeconds());
+    }
+
+    @Test
+    public void testMaxInt() {
+        test(Integer.MAX_VALUE);
+    }
+
+    @Test
+    public void testMaxLong() {
+        test(Long.MAX_VALUE);
+    }
+
+    @Test
+    public void testNegative1() {
+        test(-1);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testNegative2() {
+        test(-2);
+    }
+
+    @Test
+    public void testUndefinedMilliseconds() {
+        Assert.assertTrue(Timeout.UNDEFINED_MILLISECONDS.isUndefinedMilliseconds());
+        Assert.assertFalse(Timeout.UNDEFINED_MILLISECONDS.isEnabled());
+        Assert.assertFalse(Timeout.UNDEFINED_MILLISECONDS.isDisabled());
+    }
+
+    @Test
+    public void testUndefinedSeconds() {
+        Assert.assertTrue(Timeout.UNDEFINED_SECONDS.isUndefinedSeconds());
+        Assert.assertFalse(Timeout.UNDEFINED_SECONDS.isEnabled());
+        Assert.assertFalse(Timeout.UNDEFINED_SECONDS.isDisabled());
+    }
+
+}


[28/50] [abbrv] httpcomponents-core git commit: Refactor range validation into new Args util methods.

Posted by ol...@apache.org.
Refactor range validation into new Args util methods.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792665 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 65b1b583fd7259dd24cb8ee74b575a356261b6f8
Parents: 0346029
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 22:12:38 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 22:12:38 2017 +0000

----------------------------------------------------------------------
 .../apache/hc/core5/http2/config/H2Config.java  |  3 +-
 .../http/impl/EnglishReasonPhraseCatalog.java   |  2 +-
 .../hc/core5/http/io/entity/EntityUtils.java    | 10 ++--
 .../java/org/apache/hc/core5/util/Args.java     | 25 +++++++++
 .../java/org/apache/hc/core5/util/TestArgs.java | 58 ++++++++++++++++++++
 5 files changed, 90 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/65b1b583/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
index 56ce70d..b7b5e45 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/config/H2Config.java
@@ -165,7 +165,8 @@ public class H2Config {
         }
 
         public Builder setMaxFrameSize(final int maxFrameSize) {
-            Args.check(maxFrameSize >= FrameConsts.MIN_FRAME_SIZE && maxFrameSize <= FrameConsts.MAX_FRAME_SIZE, "Invalid max frame size");
+            Args.checkRange(maxFrameSize, FrameConsts.MIN_FRAME_SIZE, FrameConsts.MAX_FRAME_SIZE,
+                    "Invalid max frame size");
             this.maxFrameSize = maxFrameSize;
             return this;
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/65b1b583/httpcore5/src/main/java/org/apache/hc/core5/http/impl/EnglishReasonPhraseCatalog.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/EnglishReasonPhraseCatalog.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/EnglishReasonPhraseCatalog.java
index 1514804..39b3a43 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/EnglishReasonPhraseCatalog.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/EnglishReasonPhraseCatalog.java
@@ -74,7 +74,7 @@ public class EnglishReasonPhraseCatalog implements ReasonPhraseCatalog {
      */
     @Override
     public String getReason(final int status, final Locale loc) {
-        Args.check(status >= 100 && status < 600, "Unknown category for status code " + status);
+        Args.checkRange(status, 100, 599, "Unknown category for status code");
         final int category = status / 100;
         final int subcode  = status - 100*category;
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/65b1b583/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
index 5c5203b..975befa 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/entity/EntityUtils.java
@@ -201,8 +201,7 @@ public final class EntityUtils {
             return null;
         }
         try {
-            Args.check(entity.getContentLength() <= Integer.MAX_VALUE,
-                    "HTTP entity too large to be buffered in memory");
+            Args.checkContentLength(entity);
             int i = (int)entity.getContentLength();
             if (i < 0) {
                 i = 4096;
@@ -227,9 +226,8 @@ public final class EntityUtils {
             return null;
         }
         try {
-            Args.check(entity.getContentLength() <= Integer.MAX_VALUE,
-                    "HTTP entity too large to be buffered in memory");
-            int i = (int)entity.getContentLength();
+            Args.checkContentLength(entity);
+            int i = (int) entity.getContentLength();
             if (i < 0) {
                 i = 4096;
             }
@@ -351,7 +349,7 @@ public final class EntityUtils {
             return Collections.emptyList();
         }
         final long len = entity.getContentLength();
-        Args.check(len <= Integer.MAX_VALUE, "HTTP entity is too large");
+        Args.checkRange(len, 0, Integer.MAX_VALUE, "HTTP entity is too large");
         final Charset charset = contentType.getCharset() != null ? contentType.getCharset() : StandardCharsets.ISO_8859_1;
         final InputStream instream = entity.getContent();
         if (instream == null) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/65b1b583/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
index f6fc05f..98d8ad8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
@@ -29,6 +29,8 @@ package org.apache.hc.core5.util;
 
 import java.util.Collection;
 
+import org.apache.hc.core5.http.EntityDetails;
+
 public class Args {
 
     public static void check(final boolean expression, final String message) {
@@ -49,6 +51,29 @@ public class Args {
         }
     }
 
+    public static void checkRange(final int value, final int lowInclusive, final int highInclusive,
+            final String message) {
+        if (value < lowInclusive || value > highInclusive) {
+            throw new IllegalArgumentException(String.format("%s: %,d is out of range [%,d, %,d]", message,
+                    Integer.valueOf(value), Integer.valueOf(lowInclusive), Integer.valueOf(highInclusive)));
+        }
+    }
+
+    public static void checkRange(final long value, final long lowInclusive, final long highInclusive,
+            final String message) {
+        if (value < lowInclusive || value > highInclusive) {
+            throw new IllegalArgumentException(String.format("%s: %,d is out of range [%,d, %,d]", message,
+                    Long.valueOf(value), Long.valueOf(lowInclusive), Long.valueOf(highInclusive)));
+        }
+    }
+
+    public static void checkContentLength(final EntityDetails entityDetails) {
+        // -1 is a special value
+        // 0 is allowed as well
+        checkRange(entityDetails.getContentLength(), -1, Integer.MAX_VALUE,
+                "HTTP entity too large to be buffered in memory)");
+    }
+
     public static <T extends CharSequence> T containsNoBlanks(final T argument, final String name) {
         if (argument == null) {
             throw new IllegalArgumentException(name + " may not be null");

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/65b1b583/httpcore5/src/test/java/org/apache/hc/core5/util/TestArgs.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestArgs.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestArgs.java
index 430d1cb..b957e1e 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestArgs.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestArgs.java
@@ -167,4 +167,62 @@ public class TestArgs {
         Args.notNegative(-1L, "Number");
     }
 
+    //
+    public void testIntSmallestRangeOK() {
+        Args.checkRange(0, 0, 0, "Number");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testIntSmallestRangeFailLow() {
+        Args.checkRange(-1, 0, 0, "Number");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testIntRangeFailLow() {
+        Args.checkRange(-101, -100, 100, "Number");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testIntRangeFailHigh() {
+        Args.checkRange(101, -100, 100, "Number");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testIntSmallestRangeFailHigh() {
+        Args.checkRange(1, 0, 0, "Number");
+    }
+
+    public void testIntFullRangeOK() {
+        Args.checkRange(0, Integer.MIN_VALUE, Integer.MAX_VALUE, "Number");
+    }
+
+    //
+    public void testLongSmallestRangeOK() {
+        Args.checkRange(0L, 0L, 0L, "Number");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testLongSmallestRangeFailLow() {
+        Args.checkRange(-1L, 0L, 0L, "Number");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testLongRangeFailLow() {
+        Args.checkRange(-101L, -100L, 100L, "Number");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testLongRangeFailHigh() {
+        Args.checkRange(101L, -100L, 100L, "Number");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testLongSmallestRangeFailHigh() {
+        Args.checkRange(1L, 0L, 0L, "Number");
+    }
+
+    public void testLongFullRangeOK() {
+        Args.checkRange(0L, Long.MIN_VALUE, Long.MAX_VALUE, "Number");
+    }
+
 }


[38/50] [abbrv] httpcomponents-core git commit: HttpHost to use URIScheme

Posted by ol...@apache.org.
HttpHost to use URIScheme

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792797 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 9d6ec2b541d21752d96035df51daa556091823c2
Parents: e92e3ec
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Apr 26 19:21:54 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Apr 26 19:21:54 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/http/HttpHost.java     | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9d6ec2b5/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
index 405933f..f101c1c 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
@@ -53,7 +53,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
     private static final long serialVersionUID = -7529410654042457626L;
 
     /** The default scheme is "http". */
-    public static final String DEFAULT_SCHEME_NAME = "http";
+    public static final URIScheme DEFAULT_SCHEME = URIScheme.HTTP;
 
     /** The host to use. */
     private final String hostname;
@@ -91,7 +91,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      *                  {@code -1} indicates the scheme default port.
      * @param scheme    the name of the scheme.
      *                  {@code null} indicates the
-     *                  {@link #DEFAULT_SCHEME_NAME default scheme}
+     *                  {@link #DEFAULT_SCHEME default scheme}
      *
      * @throws IllegalArgumentException
      *             If the port parameter is outside the specified range of valid port values, which is between 0 and
@@ -104,7 +104,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
         if (scheme != null) {
             this.schemeName = scheme.toLowerCase(Locale.ROOT);
         } else {
-            this.schemeName = DEFAULT_SCHEME_NAME;
+            this.schemeName = DEFAULT_SCHEME.id;
         }
         this.port = Ports.check(port);
         this.address = null;
@@ -131,7 +131,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @param hostname  the hostname (IP or DNS name)
      * @param scheme    the name of the scheme.
      *                  {@code null} indicates the
-     *                  {@link #DEFAULT_SCHEME_NAME default scheme}
+     *                  {@link #DEFAULT_SCHEME default scheme}
      *
      * @throws IllegalArgumentException
      *             If the port parameter is outside the specified range of valid port values, which is between 0 and
@@ -174,7 +174,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
         return new HttpHost(
                 text.toLowerCase(Locale.ROOT),
                 port,
-                scheme != null ? scheme.toLowerCase(Locale.ROOT) : DEFAULT_SCHEME_NAME, true);
+                scheme != null ? scheme.toLowerCase(Locale.ROOT) : DEFAULT_SCHEME.id, true);
     }
 
     /**
@@ -198,7 +198,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      *                  {@code -1} indicates the scheme default port.
      * @param scheme    the name of the scheme.
      *                  {@code null} indicates the
-     *                  {@link #DEFAULT_SCHEME_NAME default scheme}
+     *                  {@link #DEFAULT_SCHEME default scheme}
      *
      * @throws IllegalArgumentException
      *             If the port parameter is outside the specified range of valid port values, which is between 0 and
@@ -219,7 +219,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      *                  {@code -1} indicates the scheme default port.
      * @param scheme    the name of the scheme.
      *                  {@code null} indicates the
-     *                  {@link #DEFAULT_SCHEME_NAME default scheme}
+     *                  {@link #DEFAULT_SCHEME default scheme}
      *
      * @throws IllegalArgumentException
      *             If the port parameter is outside the specified range of valid port values, which is between 0 and
@@ -235,7 +235,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
         if (scheme != null) {
             this.schemeName = scheme.toLowerCase(Locale.ROOT);
         } else {
-            this.schemeName = DEFAULT_SCHEME_NAME;
+            this.schemeName = DEFAULT_SCHEME.id;
         }
         this.port = Ports.check(port);
     }


[16/50] [abbrv] httpcomponents-core git commit: HTTPCORE-455: fatal Error in an individual worker thread does not cause proper I/O reactor shutdown

Posted by ol...@apache.org.
HTTPCORE-455: fatal Error in an individual worker thread does not cause proper I/O reactor shutdown

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792525 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 61a85181b1e043b36180545d7ea3f2eac3e25422
Parents: c081515
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Apr 24 18:10:38 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Apr 24 18:10:38 2017 +0000

----------------------------------------------------------------------
 .../hc/core5/reactor/AbstractMultiworkerIOReactor.java | 13 ++++++++-----
 .../apache/hc/core5/reactor/IOReactorException.java    |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61a85181/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
index 9fec934..ebb9c77 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
@@ -297,7 +297,7 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
                 // Verify I/O dispatchers
                 for (int i = 0; i < this.workerCount; i++) {
                     final Worker worker = this.workers[i];
-                    final Exception ex = worker.getException();
+                    final Throwable ex = worker.getThrowable();
                     if (ex != null) {
                         throw new IOReactorException("I/O dispatch worker terminated abnormally", ex);
                     }
@@ -491,7 +491,7 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
 
         final IOReactorImpl dispatcher;
 
-        private volatile Exception exception;
+        private volatile Throwable throwable;
 
         public Worker(final IOReactorImpl dispatcher) {
             super();
@@ -502,13 +502,16 @@ public abstract class AbstractMultiworkerIOReactor implements IOReactor {
         public void run() {
             try {
                 this.dispatcher.execute();
+            } catch (final Error ex) {
+                this.throwable = ex;
+                throw ex;
             } catch (final Exception ex) {
-                this.exception = ex;
+                this.throwable = ex;
             }
         }
 
-        public Exception getException() {
-            return this.exception;
+        public Throwable getThrowable() {
+            return this.throwable;
         }
 
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/61a85181/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorException.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorException.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorException.java
index c13c163..27096a5 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorException.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorException.java
@@ -39,7 +39,7 @@ public class IOReactorException extends IOException {
 
     private static final long serialVersionUID = -4248110651729635749L;
 
-    public IOReactorException(final String message, final Exception cause) {
+    public IOReactorException(final String message, final Throwable cause) {
         super(message);
         if (cause != null) {
             initCause(cause);


[37/50] [abbrv] httpcomponents-core git commit: Provide protocol scheme identifiers for server side connections and incoming HTTP/1.1 requests

Posted by ol...@apache.org.
Provide protocol scheme identifiers for server side connections and incoming HTTP/1.1 requests

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792796 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: e92e3ec8e5fcff61f09051816a90b8987c0e41d0
Parents: fe88c7b
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Apr 26 19:21:30 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Apr 26 19:21:30 2017 +0000

----------------------------------------------------------------------
 .../hc/core5/http/benchmark/HttpServer.java     |  2 +-
 .../impl/nio/ServerHttpProtocolNegotiator.java  | 12 +++--
 .../hc/core5/http2/ssl/H2ClientTlsStrategy.java |  7 ++-
 .../hc/core5/http2/ssl/H2ServerTlsStrategy.java |  4 +-
 .../apache/hc/core5/testing/ProtocolScheme.java | 30 ------------
 .../testing/classic/ClassicTestServer.java      |  8 ++-
 .../classic/LoggingBHttpServerConnection.java   |  7 +--
 .../hc/core5/testing/nio/AsyncRequester.java    |  5 +-
 .../InternalServerHttp1EventHandlerFactory.java |  4 +-
 .../core5/testing/nio/Http1IntegrationTest.java | 15 +++---
 .../core5/testing/nio/Http2IntegrationTest.java | 10 ++--
 .../nio/InternalHttp1ServerTestBase.java        | 10 ++--
 .../nio/InternalHttp2ServerTestBase.java        | 10 ++--
 .../org/apache/hc/core5/http/URIScheme.java     | 51 ++++++++++++++++++++
 .../http/impl/bootstrap/AsyncRequester.java     |  5 +-
 .../http/impl/bootstrap/HttpAsyncRequester.java |  3 +-
 .../http/impl/bootstrap/HttpRequester.java      | 12 +++--
 .../core5/http/impl/bootstrap/HttpServer.java   |  9 +++-
 .../http/impl/bootstrap/RequesterBootstrap.java |  5 +-
 .../http/impl/bootstrap/ServerBootstrap.java    | 22 ++++++---
 .../io/DefaultBHttpClientConnectionFactory.java | 14 +++---
 .../impl/io/DefaultBHttpServerConnection.java   | 14 ++++--
 .../io/DefaultBHttpServerConnectionFactory.java | 25 +++++-----
 .../nio/ServerHttp1IOEventHandlerFactory.java   | 10 +++-
 .../impl/nio/ServerHttp1StreamDuplexer.java     |  4 ++
 .../nio/ServerHttp1StreamDuplexerFactory.java   |  3 +-
 .../http/nio/ssl/BasicClientTlsStrategy.java    |  7 ++-
 .../http/nio/ssl/BasicServerTlsStrategy.java    |  5 +-
 .../hc/core5/http/nio/ssl/TlsStrategy.java      |  2 +-
 .../io/TestDefaultBHttpServerConnection.java    |  2 +-
 30 files changed, 202 insertions(+), 115 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java
----------------------------------------------------------------------
diff --git a/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java b/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java
index a8bd9fb..16b37df 100644
--- a/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java
+++ b/httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/HttpServer.java
@@ -82,7 +82,7 @@ public class HttpServer {
 
     private HttpServerConnection acceptConnection() throws IOException {
         final Socket socket = this.serversocket.accept();
-        final DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(H1Config.DEFAULT);
+        final DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(null, H1Config.DEFAULT);
         conn.bind(socket);
         return conn;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
index 50c5f4c..a0200b8 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
@@ -38,6 +38,7 @@ import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.EndpointDetails;
 import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.impl.ConnectionListener;
 import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
 import org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler;
@@ -87,9 +88,9 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
     @Override
     public void connected(final IOSession session) {
         try {
+            final TlsDetails tlsDetails = ioSession.getTlsDetails();
             switch (versionPolicy) {
                 case NEGOTIATE:
-                    final TlsDetails tlsDetails = ioSession.getTlsDetails();
                     if (tlsDetails != null) {
                         if (ApplicationProtocols.HTTP_2.id.equals(tlsDetails.getApplicationProtocol())) {
                             expectValidH2Preface = true;
@@ -99,7 +100,9 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
                     }
                     break;
                 case FORCE_HTTP_1:
-                    final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
+                    final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(
+                            tlsDetails != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+                            ioSession);
                     session.setHandler(new ServerHttp1IOEventHandler(http1StreamHandler));
                     http1StreamHandler.onConnect(null);
                     break;
@@ -134,7 +137,10 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
                     http2StreamHandler.onConnect(bytebuf.hasRemaining() ? bytebuf : null);
                     http2StreamHandler.onInput();
                 } else {
-                    final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
+                    final TlsDetails tlsDetails = ioSession.getTlsDetails();
+                    final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(
+                            tlsDetails != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+                            ioSession);
                     session.setHandler(new ServerHttp1IOEventHandler(http1StreamHandler));
                     bytebuf.rewind();
                     http1StreamHandler.onConnect(bytebuf);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
index 4d3e24b..28760e5 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
@@ -32,6 +32,7 @@ import java.net.SocketAddress;
 import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
@@ -86,18 +87,20 @@ public class H2ClientTlsStrategy implements TlsStrategy {
     }
 
     @Override
-    public void upgrade(
+    public boolean upgrade(
             final TransportSecurityLayer tlsSession,
             final HttpHost host,
             final SocketAddress localAddress,
             final SocketAddress remoteAddress,
             final Object attachment) {
         final String scheme = host != null ? host.getSchemeName() : null;
-        if ("https".equalsIgnoreCase(scheme)) {
+        if (URIScheme.HTTPS.same(scheme)) {
             tlsSession.startTls(sslContext, sslBufferManagement,
                     H2TlsSupport.enforceRequirements(attachment, initializer),
                     verifier);
+            return true;
         }
+        return false;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
index 2cceb77..c6113fb 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
@@ -91,7 +91,7 @@ public class H2ServerTlsStrategy implements TlsStrategy {
     }
 
     @Override
-    public void upgrade(
+    public boolean upgrade(
             final TransportSecurityLayer tlsSession,
             final HttpHost host,
             final SocketAddress localAddress,
@@ -101,7 +101,9 @@ public class H2ServerTlsStrategy implements TlsStrategy {
             tlsSession.startTls(sslContext, sslBufferManagement,
                     H2TlsSupport.enforceRequirements(attachment, initializer),
                     verifier);
+            return true;
         }
+        return false;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java
deleted file mode 100644
index e637256..0000000
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/ProtocolScheme.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * ====================================================================
- * 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
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.hc.core5.testing;
-
-public enum ProtocolScheme { HTTP, HTTPS }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/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 30774de..02cb505 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
@@ -34,9 +34,11 @@ import java.net.SocketException;
 import java.util.concurrent.atomic.AtomicReference;
 
 import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocket;
 
 import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.ExceptionListener;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.config.SocketConfig;
 import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
@@ -131,11 +133,13 @@ public class ClassicTestServer {
         }
     }
 
-    class LoggingConnFactory implements HttpConnectionFactory<LoggingBHttpServerConnection> {
+    static class LoggingConnFactory implements HttpConnectionFactory<LoggingBHttpServerConnection> {
 
         @Override
         public LoggingBHttpServerConnection createConnection(final Socket socket) throws IOException {
-            final LoggingBHttpServerConnection conn = new LoggingBHttpServerConnection(H1Config.DEFAULT);
+            final LoggingBHttpServerConnection conn = new LoggingBHttpServerConnection(
+                    socket instanceof SSLSocket ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+                    H1Config.DEFAULT);
             conn.bind(socket);
             return conn;
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
index 180467e..57dc56e 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/classic/LoggingBHttpServerConnection.java
@@ -58,6 +58,7 @@ public class LoggingBHttpServerConnection extends DefaultBHttpServerConnection i
     private final Wire wire;
 
     public LoggingBHttpServerConnection(
+            final String scheme,
             final H1Config h1Config,
             final CharsetDecoder chardecoder,
             final CharsetEncoder charencoder,
@@ -65,7 +66,7 @@ public class LoggingBHttpServerConnection extends DefaultBHttpServerConnection i
             final ContentLengthStrategy outgoingContentStrategy,
             final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory,
             final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
-        super(h1Config, chardecoder, charencoder,
+        super(scheme, h1Config, chardecoder, charencoder,
                 incomingContentStrategy, outgoingContentStrategy,
                 requestParserFactory, responseWriterFactory);
         this.id = "http-incoming-" + COUNT.incrementAndGet();
@@ -79,8 +80,8 @@ public class LoggingBHttpServerConnection extends DefaultBHttpServerConnection i
         return id;
     }
 
-    public LoggingBHttpServerConnection(final H1Config h1Config) {
-        this(h1Config, null, null, null, null, null, null);
+    public LoggingBHttpServerConnection(final String scheme, final H1Config h1Config) {
+        this(scheme, h1Config, null, null, null, null, null, null);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
index 436fdf0..02be34c 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/AsyncRequester.java
@@ -35,6 +35,7 @@ import java.util.concurrent.ThreadFactory;
 import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.reactor.ConnectionInitiator;
 import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
@@ -68,9 +69,9 @@ public class AsyncRequester extends IOReactorExecutor<DefaultConnectingIOReactor
         int port = host.getPort();
         if (port < 0) {
             final String scheme = host.getSchemeName();
-            if ("http".equalsIgnoreCase(scheme)) {
+            if (URIScheme.HTTP.same(scheme)) {
                 port = 80;
-            } else if ("https".equalsIgnoreCase(scheme)) {
+            } else if (URIScheme.HTTPS.same(scheme)) {
                 port = 443;
             }
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
index bf1ad15..44fdb79 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
@@ -35,6 +35,7 @@ import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.ContentLengthStrategy;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
+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.impl.ConnectionListener;
@@ -105,7 +106,8 @@ class InternalServerHttp1EventHandlerFactory implements IOEventHandlerFactory {
             final ContentLengthStrategy outgoingContentStrategy,
             final ConnectionListener connectionListener,
             final Http1StreamListener streamListener) {
-        return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory, h1Config,
+        return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
+                sslContext != null ? URIScheme.HTTPS.id : URIScheme.HTTP.id, h1Config,
                 charCodingConfig, connectionReuseStrategy, incomingMessageParser, outgoingMessageWriter,
                 incomingContentStrategy, outgoingContentStrategy, connectionListener, streamListener);
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index b6dbaba..2c5f3b0 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -75,6 +75,7 @@ import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.MalformedChunkCodingException;
 import org.apache.hc.core5.http.Message;
 import org.apache.hc.core5.http.ProtocolException;
+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.impl.BasicHttpTransportMetrics;
@@ -124,7 +125,6 @@ import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
-import org.apache.hc.core5.testing.ProtocolScheme;
 import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TextUtils;
@@ -142,12 +142,12 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
     @Parameterized.Parameters(name = "{0}")
     public static Collection<Object[]> protocols() {
         return Arrays.asList(new Object[][]{
-                { ProtocolScheme.HTTP },
-                { ProtocolScheme.HTTPS }
+                { URIScheme.HTTP },
+                { URIScheme.HTTPS }
         });
     }
 
-    public Http1IntegrationTest(final ProtocolScheme scheme) {
+    public Http1IntegrationTest(final URIScheme scheme) {
         super(scheme);
     }
 
@@ -160,7 +160,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
     public void setup() throws Exception {
         client = new Http1TestClient(
                 IOReactorConfig.DEFAULT,
-                scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
+                scheme == URIScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
     }
 
     @After
@@ -172,7 +172,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
 
     private URI createRequestURI(final InetSocketAddress serverEndpoint, final String path) {
         try {
-            return new URI("http", null, "localhost", serverEndpoint.getPort(), path, null, null);
+            return new URI(scheme.id, null, "localhost", serverEndpoint.getPort(), path, null, null);
         } catch (final URISyntaxException e) {
             throw new IllegalStateException();
         }
@@ -1357,7 +1357,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
                 H1Config.DEFAULT,
                 CharCodingConfig.DEFAULT,
                 DefaultConnectionReuseStrategy.INSTANCE,
-                scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null) {
+                scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null) {
 
             @Override
             protected ServerHttp1StreamDuplexer createServerHttp1StreamDuplexer(
@@ -1374,6 +1374,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
                     final ConnectionListener connectionListener,
                     final Http1StreamListener streamListener) {
                 return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
+                        scheme.id,
                         h1Config, connectionConfig, connectionReuseStrategy,
                         incomingMessageParser, outgoingMessageWriter,
                         incomingContentStrategy, outgoingContentStrategy,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
index 438e6db..b66090c 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
@@ -76,6 +76,7 @@ import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.Message;
 import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.impl.nio.AbstractClassicServerExchangeHandler;
 import org.apache.hc.core5.http.impl.nio.entity.AbstractClassicEntityConsumer;
 import org.apache.hc.core5.http.impl.nio.entity.AbstractClassicEntityProducer;
@@ -110,7 +111,6 @@ import org.apache.hc.core5.http2.nio.support.BasicPingHandler;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
-import org.apache.hc.core5.testing.ProtocolScheme;
 import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.TextUtils;
 import org.apache.hc.core5.util.TimeValue;
@@ -128,12 +128,12 @@ public class Http2IntegrationTest extends InternalHttp2ServerTestBase {
     @Parameterized.Parameters(name = "{0}")
     public static Collection<Object[]> protocols() {
         return Arrays.asList(new Object[][]{
-                { ProtocolScheme.HTTP },
-                { ProtocolScheme.HTTPS }
+                { URIScheme.HTTP },
+                { URIScheme.HTTPS }
         });
     }
 
-    public Http2IntegrationTest(final ProtocolScheme scheme) {
+    public Http2IntegrationTest(final URIScheme scheme) {
         super(scheme);
     }
 
@@ -145,7 +145,7 @@ public class Http2IntegrationTest extends InternalHttp2ServerTestBase {
     @Before
     public void setup() throws Exception {
         client = new Http2TestClient(IOReactorConfig.DEFAULT,
-                scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
+                scheme == URIScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
index 94081f6..7c46ad6 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
@@ -27,8 +27,8 @@
 
 package org.apache.hc.core5.testing.nio;
 
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.testing.ProtocolScheme;
 import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.TimeValue;
 import org.junit.Rule;
@@ -36,14 +36,14 @@ import org.junit.rules.ExternalResource;
 
 public abstract class InternalHttp1ServerTestBase {
 
-    protected final ProtocolScheme scheme;
+    protected final URIScheme scheme;
 
-    public InternalHttp1ServerTestBase(final ProtocolScheme scheme) {
+    public InternalHttp1ServerTestBase(final URIScheme scheme) {
         this.scheme = scheme;
     }
 
     public InternalHttp1ServerTestBase() {
-        this(ProtocolScheme.HTTP);
+        this(URIScheme.HTTP);
     }
 
     protected Http1TestServer server;
@@ -55,7 +55,7 @@ public abstract class InternalHttp1ServerTestBase {
         protected void before() throws Throwable {
             server = new Http1TestServer(
                     IOReactorConfig.DEFAULT,
-                    scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
+                    scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
index c2f0e28..7f80a4e 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
@@ -27,8 +27,8 @@
 
 package org.apache.hc.core5.testing.nio;
 
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.testing.ProtocolScheme;
 import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.TimeValue;
 import org.junit.Rule;
@@ -36,14 +36,14 @@ import org.junit.rules.ExternalResource;
 
 public abstract class InternalHttp2ServerTestBase {
 
-    protected final ProtocolScheme scheme;
+    protected final URIScheme scheme;
 
-    public InternalHttp2ServerTestBase(final ProtocolScheme scheme) {
+    public InternalHttp2ServerTestBase(final URIScheme scheme) {
         this.scheme = scheme;
     }
 
     public InternalHttp2ServerTestBase() {
-        this(ProtocolScheme.HTTP);
+        this(URIScheme.HTTP);
     }
 
     protected Http2TestServer server;
@@ -54,7 +54,7 @@ public abstract class InternalHttp2ServerTestBase {
         @Override
         protected void before() throws Throwable {
             server = new Http2TestServer(IOReactorConfig.DEFAULT,
-                    scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
+                    scheme == URIScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java b/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java
new file mode 100644
index 0000000..261bd1e
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/URIScheme.java
@@ -0,0 +1,51 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http;
+
+import org.apache.hc.core5.util.Args;
+
+public enum URIScheme {
+
+    HTTP("http"), HTTPS("https");
+
+    public final String id;
+
+    URIScheme(final String id) {
+        this.id = Args.notBlank(id, "Id");
+    }
+
+    public boolean same(final String scheme) {
+        return id.equalsIgnoreCase(scheme);
+    }
+
+    @Override
+    public String toString() {
+        return id;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
index 181bd74..9a74f28 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
@@ -34,6 +34,7 @@ import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.function.Callback;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.reactor.ConnectionInitiator;
 import org.apache.hc.core5.reactor.DefaultConnectingIOReactor;
@@ -63,9 +64,9 @@ public class AsyncRequester extends IOReactorExecutor<DefaultConnectingIOReactor
         int port = host.getPort();
         if (port < 0) {
             final String scheme = host.getSchemeName();
-            if ("http".equalsIgnoreCase(scheme)) {
+            if (URIScheme.HTTP.same(scheme)) {
                 port = 80;
-            } else if ("https".equalsIgnoreCase(scheme)) {
+            } else if (URIScheme.HTTPS.same(scheme)) {
                 port = 443;
             }
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
index f7ea9be..dd4635d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpAsyncRequester.java
@@ -46,6 +46,7 @@ import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.nio.AsyncRequestProducer;
@@ -137,7 +138,7 @@ public class HttpAsyncRequester extends AsyncRequester {
                         @Override
                         public void completed(final SessionRequest request) {
                             final TlsCapableIOSession session = request.getSession();
-                            if (tlsStrategy != null && "https".equalsIgnoreCase(host.getSchemeName())) {
+                            if (tlsStrategy != null && URIScheme.HTTPS.same(host.getSchemeName())) {
                                 tlsStrategy.upgrade(
                                         session,
                                         host,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
index e1ccdbe..e158573 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpRequester.java
@@ -46,6 +46,9 @@ import org.apache.hc.core5.http.ConnectionRequestTimeoutException;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
+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.io.DefaultBHttpClientConnectionFactory;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
@@ -89,7 +92,8 @@ public class HttpRequester implements GracefullyCloseable {
         this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
         this.connPool = Args.notNull(connPool, "Connection pool");
         this.socketConfig = socketConfig != null ? socketConfig : SocketConfig.DEFAULT;
-        this.connectFactory = connectFactory != null ? connectFactory : DefaultBHttpClientConnectionFactory.INSTANCE;
+        this.connectFactory = connectFactory != null ? connectFactory : new DefaultBHttpClientConnectionFactory(
+                H1Config.DEFAULT, CharCodingConfig.DEFAULT);
         this.sslSocketFactory = sslSocketFactory != null ? sslSocketFactory : (SSLSocketFactory) SSLSocketFactory.getDefault();
     }
 
@@ -160,9 +164,9 @@ public class HttpRequester implements GracefullyCloseable {
         final String scheme = targetHost.getSchemeName();
         int port = targetHost.getPort();
         if (port < 0) {
-            if ("http".equalsIgnoreCase(scheme)) {
+            if (URIScheme.HTTP.same(scheme)) {
                 port = 80;
-            } else if ("https".equalsIgnoreCase(scheme)) {
+            } else if (URIScheme.HTTPS.same(scheme)) {
                 port = 443;
             }
         }
@@ -174,7 +178,7 @@ public class HttpRequester implements GracefullyCloseable {
         }
         sock.connect(targetAddress, socketConfig.getSoTimeout().toMillisIntBound());
 
-        if ("https".equalsIgnoreCase(scheme)) {
+        if (URIScheme.HTTPS.same(scheme)) {
             return sslSocketFactory.createSocket(sock, targetHost.getHostName(), port, true);
         } else {
             return sock;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
index 258f926..68ca53b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/HttpServer.java
@@ -37,9 +37,13 @@ import java.util.concurrent.atomic.AtomicReference;
 
 import javax.net.ServerSocketFactory;
 import javax.net.ssl.SSLServerSocket;
+import javax.net.ssl.SSLServerSocketFactory;
 
 import org.apache.hc.core5.concurrent.DefaultThreadFactory;
 import org.apache.hc.core5.http.ExceptionListener;
+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.io.DefaultBHttpServerConnection;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnectionFactory;
@@ -88,7 +92,10 @@ public class HttpServer implements GracefullyCloseable {
         this.ifAddress = ifAddress;
         this.socketConfig = socketConfig != null ? socketConfig : SocketConfig.DEFAULT;
         this.serverSocketFactory = serverSocketFactory != null ? serverSocketFactory : ServerSocketFactory.getDefault();
-        this.connectionFactory = connectionFactory != null ? connectionFactory : DefaultBHttpServerConnectionFactory.INSTANCE;
+        this.connectionFactory = connectionFactory != null ? connectionFactory : new DefaultBHttpServerConnectionFactory(
+                this.serverSocketFactory instanceof SSLServerSocketFactory ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+                H1Config.DEFAULT,
+                CharCodingConfig.DEFAULT);
         this.sslSetupHandler = sslSetupHandler;
         this.exceptionListener = exceptionListener;
         this.listenerExecutorService = new ThreadPoolExecutor(

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
index 4e9f8f1..435659d 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/RequesterBootstrap.java
@@ -30,6 +30,8 @@ import javax.net.ssl.SSLSocketFactory;
 
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 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.Http1StreamListener;
@@ -148,7 +150,8 @@ public class RequesterBootstrap {
                 httpProcessor != null ? httpProcessor : HttpProcessors.client(),
                 connPool,
                 socketConfig != null ? socketConfig : SocketConfig.DEFAULT,
-                connectFactory != null ? connectFactory : DefaultBHttpClientConnectionFactory.INSTANCE,
+                connectFactory != null ? connectFactory : new DefaultBHttpClientConnectionFactory(
+                        H1Config.DEFAULT, CharCodingConfig.DEFAULT),
                 sslSocketFactory);
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
index 6138e50..ef54ee2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/ServerBootstrap.java
@@ -32,12 +32,15 @@ import java.util.Map;
 
 import javax.net.ServerSocketFactory;
 import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLServerSocketFactory;
 
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.HttpResponseFactory;
+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.Http1StreamListener;
@@ -61,6 +64,7 @@ public class ServerBootstrap {
     private int listenerPort;
     private InetAddress localAddress;
     private SocketConfig socketConfig;
+    private H1Config h1Config;
     private CharCodingConfig charCodingConfig;
     private HttpProcessor httpProcessor;
     private ConnectionReuseStrategy connStrategy;
@@ -108,9 +112,14 @@ public class ServerBootstrap {
 
     /**
      * Sets connection configuration.
-     * <p>
-     * Please note this value can be overridden by the {@link #setConnectionFactory(
-     *HttpConnectionFactory)} method.
+     */
+    public final ServerBootstrap setH1Config(final H1Config h1Config) {
+        this.h1Config = h1Config;
+        return this;
+    }
+
+    /**
+     * Sets connection configuration.
      */
     public final ServerBootstrap setCharCodingConfig(final CharCodingConfig charCodingConfig) {
         this.charCodingConfig = charCodingConfig;
@@ -273,11 +282,8 @@ public class ServerBootstrap {
 
         HttpConnectionFactory<? extends DefaultBHttpServerConnection> connectionFactoryCopy = this.connectionFactory;
         if (connectionFactoryCopy == null) {
-            if (this.charCodingConfig != null) {
-                connectionFactoryCopy = new DefaultBHttpServerConnectionFactory(this.charCodingConfig);
-            } else {
-                connectionFactoryCopy = DefaultBHttpServerConnectionFactory.INSTANCE;
-            }
+            final String scheme = serverSocketFactoryCopy instanceof SSLServerSocketFactory ? URIScheme.HTTPS.id : URIScheme.HTTP.id;
+            connectionFactoryCopy = new DefaultBHttpServerConnectionFactory(scheme, this.h1Config, this.charCodingConfig);
         }
 
         ExceptionListener exceptionListenerCopy = this.exceptionListener;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
index 472e7c5..f11d9df 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpClientConnectionFactory.java
@@ -36,8 +36,8 @@ import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentLengthStrategy;
 import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.impl.CharCodingSupport;
 import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.CharCodingSupport;
 import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.io.HttpMessageParserFactory;
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
@@ -51,8 +51,6 @@ import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
 public class DefaultBHttpClientConnectionFactory
         implements HttpConnectionFactory<DefaultBHttpClientConnection> {
 
-    public static final DefaultBHttpClientConnectionFactory INSTANCE = new DefaultBHttpClientConnectionFactory();
-
     private final H1Config h1Config;
     private final CharCodingConfig charCodingConfig;
     private final ContentLengthStrategy incomingContentStrategy;
@@ -78,14 +76,16 @@ public class DefaultBHttpClientConnectionFactory
 
     public DefaultBHttpClientConnectionFactory(
             final H1Config h1Config,
-            final CharCodingConfig cconfig,
+            final CharCodingConfig charCodingConfig,
             final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
             final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
-        this(h1Config, cconfig, null, null, requestWriterFactory, responseParserFactory);
+        this(h1Config, charCodingConfig, null, null, requestWriterFactory, responseParserFactory);
     }
 
-    public DefaultBHttpClientConnectionFactory(final CharCodingConfig cconfig) {
-        this(null, cconfig, null, null, null, null);
+    public DefaultBHttpClientConnectionFactory(
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig) {
+        this(h1Config, charCodingConfig, null, null, null, null);
     }
 
     public DefaultBHttpClientConnectionFactory() {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
index dca9583..f06ec63 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnection.java
@@ -58,6 +58,7 @@ import org.apache.hc.core5.util.Args;
  */
 public class DefaultBHttpServerConnection extends BHttpConnectionBase implements HttpServerConnection {
 
+    private final String scheme;
     private final ContentLengthStrategy incomingContentStrategy;
     private final ContentLengthStrategy outgoingContentStrategy;
     private final HttpMessageParser<ClassicHttpRequest> requestParser;
@@ -66,6 +67,7 @@ public class DefaultBHttpServerConnection extends BHttpConnectionBase implements
     /**
      * Creates new instance of DefaultBHttpServerConnection.
      *
+     * @param scheme protocol scheme
      * @param h1Config Message h1Config. If {@code null}
      *   {@link H1Config#DEFAULT} will be used.
      * @param chardecoder decoder to be used for decoding HTTP protocol elements.
@@ -82,6 +84,7 @@ public class DefaultBHttpServerConnection extends BHttpConnectionBase implements
      *   {@link DefaultHttpResponseWriterFactory#INSTANCE} will be used.
      */
     public DefaultBHttpServerConnection(
+            final String scheme,
             final H1Config h1Config,
             final CharsetDecoder chardecoder,
             final CharsetEncoder charencoder,
@@ -90,6 +93,7 @@ public class DefaultBHttpServerConnection extends BHttpConnectionBase implements
             final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory,
             final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
         super(h1Config, chardecoder, charencoder);
+        this.scheme = scheme;
         this.requestParser = (requestParserFactory != null ? requestParserFactory :
             DefaultHttpRequestParserFactory.INSTANCE).create(h1Config);
         this.responseWriter = (responseWriterFactory != null ? responseWriterFactory :
@@ -101,14 +105,17 @@ public class DefaultBHttpServerConnection extends BHttpConnectionBase implements
     }
 
     public DefaultBHttpServerConnection(
+            final String scheme,
             final H1Config h1Config,
             final CharsetDecoder chardecoder,
             final CharsetEncoder charencoder) {
-        this(h1Config, chardecoder, charencoder, null, null, null, null);
+        this(scheme, h1Config, chardecoder, charencoder, null, null, null, null);
     }
 
-    public DefaultBHttpServerConnection(final H1Config h1Config) {
-        this(h1Config, null, null);
+    public DefaultBHttpServerConnection(
+            final String scheme,
+            final H1Config h1Config) {
+        this(scheme, h1Config, null, null);
     }
 
     protected void onRequestReceived(final ClassicHttpRequest request) {
@@ -130,6 +137,7 @@ public class DefaultBHttpServerConnection extends BHttpConnectionBase implements
         if (transportVersion != null && transportVersion.greaterEquals(HttpVersion.HTTP_2)) {
             throw new UnsupportedHttpVersionException("Unsupported version: " + transportVersion);
         }
+        request.setScheme(this.scheme);
         this.version = transportVersion;
         onRequestReceived(request);
         incrementRequestCount();

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
index 18c23fc..ed3b08b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/DefaultBHttpServerConnectionFactory.java
@@ -36,8 +36,8 @@ import org.apache.hc.core5.http.ClassicHttpRequest;
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ContentLengthStrategy;
 import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.impl.CharCodingSupport;
 import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.CharCodingSupport;
 import org.apache.hc.core5.http.io.HttpConnectionFactory;
 import org.apache.hc.core5.http.io.HttpMessageParserFactory;
 import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
@@ -48,11 +48,9 @@ import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
  * @since 4.3
  */
 @Contract(threading = ThreadingBehavior.IMMUTABLE_CONDITIONAL)
-public class DefaultBHttpServerConnectionFactory
-        implements HttpConnectionFactory<DefaultBHttpServerConnection> {
-
-    public static final DefaultBHttpServerConnectionFactory INSTANCE = new DefaultBHttpServerConnectionFactory();
+public class DefaultBHttpServerConnectionFactory implements HttpConnectionFactory<DefaultBHttpServerConnection> {
 
+    private final String scheme;
     private final H1Config h1Config;
     private final CharCodingConfig charCodingConfig;
     private final ContentLengthStrategy incomingContentStrategy;
@@ -61,6 +59,7 @@ public class DefaultBHttpServerConnectionFactory
     private final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory;
 
     public DefaultBHttpServerConnectionFactory(
+            final String scheme,
             final H1Config h1Config,
             final CharCodingConfig charCodingConfig,
             final ContentLengthStrategy incomingContentStrategy,
@@ -68,6 +67,7 @@ public class DefaultBHttpServerConnectionFactory
             final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory,
             final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
         super();
+        this.scheme = scheme;
         this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
         this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
         this.incomingContentStrategy = incomingContentStrategy;
@@ -77,24 +77,25 @@ public class DefaultBHttpServerConnectionFactory
     }
 
     public DefaultBHttpServerConnectionFactory(
+            final String scheme,
             final H1Config h1Config,
             final CharCodingConfig charCodingConfig,
             final HttpMessageParserFactory<ClassicHttpRequest> requestParserFactory,
             final HttpMessageWriterFactory<ClassicHttpResponse> responseWriterFactory) {
-        this(h1Config, charCodingConfig, null, null, requestParserFactory, responseWriterFactory);
+        this(scheme, h1Config, charCodingConfig, null, null, requestParserFactory, responseWriterFactory);
     }
 
-    public DefaultBHttpServerConnectionFactory(final CharCodingConfig charCodingConfig) {
-        this(null, charCodingConfig, null, null, null, null);
-    }
-
-    public DefaultBHttpServerConnectionFactory() {
-        this(null, null, null, null, null, null);
+    public DefaultBHttpServerConnectionFactory(
+            final String scheme,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig) {
+        this(scheme, h1Config, charCodingConfig, null, null, null, null);
     }
 
     @Override
     public DefaultBHttpServerConnection createConnection(final Socket socket) throws IOException {
         final DefaultBHttpServerConnection conn = new DefaultBHttpServerConnection(
+                this.scheme,
                 this.h1Config,
                 CharCodingSupport.createDecoder(this.charCodingConfig),
                 CharCodingSupport.createEncoder(this.charCodingConfig),

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
index 2f24a54..c7424f7 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1IOEventHandlerFactory.java
@@ -29,6 +29,7 @@ package org.apache.hc.core5.http.impl.nio;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -53,15 +54,20 @@ public class ServerHttp1IOEventHandlerFactory implements IOEventHandlerFactory {
 
     @Override
     public IOEventHandler createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
+        final boolean tlsSecured;
         if (tlsStrategy != null) {
-            tlsStrategy.upgrade(
+            tlsSecured = tlsStrategy.upgrade(
                     ioSession,
                     null,
                     ioSession.getLocalAddress(),
                     ioSession.getRemoteAddress(),
                     attachment);
+        } else {
+            tlsSecured = false;
         }
-        return new ServerHttp1IOEventHandler(streamDuplexerFactory.create(ioSession));
+        return new ServerHttp1IOEventHandler(streamDuplexerFactory.create(
+                tlsSecured ? URIScheme.HTTPS.id : URIScheme.HTTP.id,
+                ioSession));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
index 31b912d..86461d2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
@@ -69,6 +69,7 @@ import org.apache.hc.core5.util.Asserts;
 
 public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpRequest, HttpResponse> {
 
+    private final String scheme;
     private final HttpProcessor httpProcessor;
     private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
     private final H1Config h1Config;
@@ -86,6 +87,7 @@ public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
             final TlsCapableIOSession ioSession,
             final HttpProcessor httpProcessor,
             final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+            final String scheme,
             final H1Config h1Config,
             final CharCodingConfig charCodingConfig,
             final ConnectionReuseStrategy connectionReuseStrategy,
@@ -98,6 +100,7 @@ public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
         super(ioSession, h1Config, charCodingConfig, incomingMessageParser, outgoingMessageWriter, connectionListener);
         this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
         this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
+        this.scheme = scheme;
         this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
         this.connectionReuseStrategy = connectionReuseStrategy != null ? connectionReuseStrategy :
                 DefaultConnectionReuseStrategy.INSTANCE;
@@ -321,6 +324,7 @@ public class ServerHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
                     context);
             pipeline.add(streamHandler);
         }
+        request.setScheme(scheme);
         streamHandler.consumeHeader(request, endStream);
         incoming = streamHandler;
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
index 568390a..f197db8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexerFactory.java
@@ -120,8 +120,9 @@ public final class ServerHttp1StreamDuplexerFactory {
         this(httpProcessor, exchangeHandlerFactory, h1Config, charCodingConfig, null, null ,null, connectionListener, streamListener);
     }
 
-    public ServerHttp1StreamDuplexer create(final TlsCapableIOSession ioSession) {
+    public ServerHttp1StreamDuplexer create(final String scheme, final TlsCapableIOSession ioSession) {
         return new ServerHttp1StreamDuplexer(ioSession, httpProcessor, exchangeHandlerFactory,
+                scheme,
                 h1Config,
                 charCodingConfig,
                 connectionReuseStrategy,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
index 9451bf8..0f99cd2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicClientTlsStrategy.java
@@ -32,6 +32,7 @@ import java.net.SocketAddress;
 import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.URIScheme;
 import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
@@ -85,16 +86,18 @@ public class BasicClientTlsStrategy implements TlsStrategy {
     }
 
     @Override
-    public void upgrade(
+    public boolean upgrade(
             final TransportSecurityLayer tlsSession,
             final HttpHost host,
             final SocketAddress localAddress,
             final SocketAddress remoteAddress,
             final Object attachment) {
         final String scheme = host != null ? host.getSchemeName() : null;
-        if ("https".equalsIgnoreCase(scheme)) {
+        if (URIScheme.HTTPS.same(scheme)) {
             tlsSession.startTls(sslContext, sslBufferManagement, initializer, verifier);
+            return true;
         }
+        return false;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
index 0936ceb..b76911f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/BasicServerTlsStrategy.java
@@ -91,7 +91,7 @@ public class BasicServerTlsStrategy implements TlsStrategy {
     }
 
     @Override
-    public void upgrade(
+    public boolean upgrade(
             final TransportSecurityLayer tlsSession,
             final HttpHost host,
             final SocketAddress localAddress,
@@ -101,9 +101,10 @@ public class BasicServerTlsStrategy implements TlsStrategy {
         for (final int securePort: securePorts) {
             if (port == securePort) {
                 tlsSession.startTls(sslContext, sslBufferManagement, initializer, verifier);
-                break;
+                return true;
             }
         }
+        return false;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
index 24514af..a475510 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/ssl/TlsStrategy.java
@@ -39,7 +39,7 @@ import org.apache.hc.core5.reactor.ssl.TransportSecurityLayer;
  */
 public interface TlsStrategy {
 
-    void upgrade(
+    boolean upgrade(
             TransportSecurityLayer tlsSession,
             HttpHost host,
             SocketAddress localAddress,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e92e3ec8/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
index 8ec7ff1..9898218 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/impl/io/TestDefaultBHttpServerConnection.java
@@ -59,7 +59,7 @@ public class TestDefaultBHttpServerConnection {
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-        conn = new DefaultBHttpServerConnection(H1Config.DEFAULT,
+        conn = new DefaultBHttpServerConnection("http", H1Config.DEFAULT,
             null, null,
             DefaultContentLengthStrategy.INSTANCE,
             DefaultContentLengthStrategy.INSTANCE,


[14/50] [abbrv] httpcomponents-core git commit: Updated release notes for HttpCore 5.0-alpha3 release

Posted by ol...@apache.org.
Updated release notes for HttpCore 5.0-alpha3 release

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792443 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 2bb3e676026c73a3a398d965ffed01a5fe1696dd
Parents: ed4b808
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Apr 24 09:24:02 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Apr 24 09:24:02 2017 +0000

----------------------------------------------------------------------
 RELEASE_NOTES.txt | 78 +++++++++++++++++++++++++++++++++-----------------
 1 file changed, 52 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/2bb3e676/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 1d50811..0579ff5 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -5,29 +5,9 @@ This is a major release that renders HttpCore API incompatible with the stable 4
 and upgrades HTTP/1.1 and HTTP/2 protocol conformance to the requirements and recommendations
 of the latest protocol specification.
 
-Changelog
--------------------
-
-* HTTPCORE-450: Add a Provider parameter in SSLContextBuilder.
-  Contributed by lujianbo <387852424 at qq dot com>, Gary Gregory <ggregory at apache.org>
-
-* HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit.
-  Contributed by Gary Gregory <ggregory at apache.org>
-  
-* HTTPCORE-452: Add a UriRegexMatcher.
-
-* HTTPCORE-453: ServerBootstrap should traverse handler map in insertion order.
-
-Release 5.0-ALPHA2
--------------------
-
-This is a major release that renders HttpCore API incompatible with the stable 4.x branch
-and upgrades HTTP/1.1 and HTTP/2 protocol conformance to the requirements and recommendations
-of the latest protocol specification.
-
 Notable changes and features included in the 5.0 series are:
 
-* Partial support for HTTP/2 protocol and partial conformance to requirements and
+* Partial support for HTTP/2 protocol and conformance to requirements and
   recommendations of the latest HTTP/2 protocol specification (RFC 7540, RFC 7541)
 
   Supported features:
@@ -39,16 +19,15 @@ Notable changes and features included in the 5.0 series are:
     ** message trailers
     ** expect-continue handshake
     ** connection validation (ping)
-    ** TLS 1.2 features
+    ** application-layer protocol negotiation (ALPN) on Java 1.9+
+    ** TLS 1.2 security features
 
    Unsupported features:
 
-    ** application-layer protocol negotiation (ALPN)
     ** padding of outgoing frames
     ** stream priority
     ** plain connection HTTP/1.1 upgrade
     ** CONNECT method
-    ** TLS renegotiation and compression cannot be disabled with Java 1.7 JSSE APIs
 
 * Improved conformance to requirements and recommendations of the latest HTTP/1.1 protocol
   specification (RFC 7230, RFC 7231)
@@ -59,11 +38,11 @@ Notable changes and features included in the 5.0 series are:
 
 * Redesigned connection pool implementation with reduced pool lock contention.
 
-* Support for HTTP/1.1 protocol switch / upgrade.
+* Plug-in mechanism for HTTP/1.1 protocol switch / upgrade.
 
 * Package name space changed to 'org.apache.hc.core5'
 
-* Maven group id changed to 'org.apache.httpcomponents.core5' 
+* Maven group id changed to 'org.apache.httpcomponents.core5'
 
 HttpCore 5.0 releases can be co-located with earlier versions.
 
@@ -76,6 +55,53 @@ expected to change in the coming releases without providing a migration path.
 Changelog
 -------------------
 
+* Support for HTTP protocol version negotiation.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* Support TLS ALPN and disable TLS renegotiation via reflection on Java 1.9+.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* HTTPCORE-452: Add a UriRegexMatcher.
+  Contributed by Gary Gregory <ggregory at apache.org>
+
+* HTTPCORE-453: ServerBootstrap should traverse handler map in insertion order.
+  Contributed by Gary Gregory <ggregory at apache.org>
+
+* HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit.
+  Contributed by Gary Gregory <ggregory at apache.org>
+
+* Fixed HTTP/2 server side response message delineation when replying to HEAD requests.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* Rewrite of non-blocking HTTP/1.1 connection persistence and re-use code.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* API for graceful shutdown of processes or endpoints
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* HTTPCORE-450: Add a Provider parameter in SSLContextBuilder.
+  Contributed by lujianbo <387852424 at qq dot com>, Gary Gregory <ggregory at apache.org>
+
+* Improved handling of premature HTTP/1.1 stream termination by non-blocking
+  protocol handlers.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+* Non-blocking connection initializer to support multi-homed remote endpoints.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+
+
+
+Release 5.0-ALPHA2
+-------------------
+
+This is a major release that renders HttpCore API incompatible with the stable 4.x branch
+and upgrades HTTP/1.1 and HTTP/2 protocol conformance to the requirements and recommendations
+of the latest protocol specification.
+
+Changelog
+-------------------
+
 * HTTPCORE-424: added ConnPool policy parameter to control connection re-use policy.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 


[31/50] [abbrv] httpcomponents-core git commit: Replace @exception with the more modern @throws.

Posted by ol...@apache.org.
Replace @exception with the more modern @throws.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792677 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 7cdac6d8288c7a7eeae060cf353fd9a4fc26a1de
Parents: eb2c139
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 22:55:17 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 22:55:17 2017 +0000

----------------------------------------------------------------------
 .../hc/core5/http/impl/io/SessionInputBufferImpl.java     |  4 ++--
 .../hc/core5/http/impl/io/SessionOutputBufferImpl.java    |  2 +-
 .../org/apache/hc/core5/http/io/SessionInputBuffer.java   |  8 ++++----
 .../org/apache/hc/core5/http/io/SessionOutputBuffer.java  | 10 +++++-----
 .../hc/core5/http/nio/entity/ContentInputBuffer.java      |  2 +-
 .../hc/core5/http/nio/entity/ContentOutputBuffer.java     |  6 +++---
 .../java/org/apache/hc/core5/util/CharArrayBuffer.java    |  4 ++--
 7 files changed, 18 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7cdac6d8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java
index f6e4f7a..d5bd31e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionInputBufferImpl.java
@@ -232,7 +232,7 @@ public class SessionInputBufferImpl implements SessionInputBuffer {
      *
      * @param      charbuffer   the line buffer.
      * @return     one line of characters
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     @Override
     public int readLine(final CharArrayBuffer charbuffer, final InputStream inputStream) throws IOException {
@@ -299,7 +299,7 @@ public class SessionInputBufferImpl implements SessionInputBuffer {
      * to CR-LF required by the HTTP specification.
      *
      * @return HTTP line as a string
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     private int lineFromLineBuffer(final CharArrayBuffer charbuffer)
             throws IOException {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7cdac6d8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java
index 8b9d30f..6a99672 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/io/SessionOutputBufferImpl.java
@@ -183,7 +183,7 @@ public class SessionOutputBufferImpl implements SessionOutputBuffer {
      * This method uses CR-LF as a line delimiter.
      *
      * @param      charbuffer the buffer containing chars of the line.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     @Override
     public void writeLine(final CharArrayBuffer charbuffer, final OutputStream outputStream) throws IOException {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7cdac6d8/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionInputBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionInputBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionInputBuffer.java
index bd033a0..fe68b77 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionInputBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionInputBuffer.java
@@ -85,7 +85,7 @@ public interface SessionInputBuffer {
      * @return     the total number of bytes read into the buffer, or
      *             {@code -1} if there is no more data because the end of
      *             the stream has been reached.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     int read(byte[] b, int off, int len, InputStream inputStream) throws IOException;
 
@@ -100,7 +100,7 @@ public interface SessionInputBuffer {
      * @return     the total number of bytes read into the buffer, or
      *             {@code -1} is there is no more data because the end of
      *             the stream has been reached.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     int read(byte[] b, InputStream inputStream) throws IOException;
 
@@ -115,7 +115,7 @@ public interface SessionInputBuffer {
      * @param      inputStream Input stream
      * @return     the next byte of data, or {@code -1} if the end of the
      *             stream is reached.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     int read(InputStream inputStream) throws IOException;
 
@@ -133,7 +133,7 @@ public interface SessionInputBuffer {
      * @param      buffer   the line buffer.
      * @param      inputStream Input stream
      * @return     one line of characters
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     int readLine(CharArrayBuffer buffer, InputStream inputStream) throws IOException;
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7cdac6d8/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionOutputBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionOutputBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionOutputBuffer.java
index 2e724f5..3245bd4 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionOutputBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionOutputBuffer.java
@@ -74,7 +74,7 @@ public interface SessionOutputBuffer {
      * @param      b     the data.
      * @param      off   the start offset in the data.
      * @param      len   the number of bytes to write.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     void write(byte[] b, int off, int len, OutputStream outputStream) throws IOException;
 
@@ -83,7 +83,7 @@ public interface SessionOutputBuffer {
      * to this session buffer.
      *
      * @param      b   the data.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     void write(byte[] b, OutputStream outputStream) throws IOException;
 
@@ -91,7 +91,7 @@ public interface SessionOutputBuffer {
      * Writes the specified byte to this session buffer.
      *
      * @param      b   the {@code byte}.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     void write(int b, OutputStream outputStream) throws IOException;
 
@@ -103,7 +103,7 @@ public interface SessionOutputBuffer {
      * specific implementations of this interface.
      *
      * @param      buffer   the buffer containing chars of the line.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     void writeLine(CharArrayBuffer buffer, OutputStream outputStream) throws IOException;
 
@@ -115,7 +115,7 @@ public interface SessionOutputBuffer {
      * stream, such bytes should immediately be written to their
      * intended destination.
      *
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     void flush(OutputStream outputStream) throws IOException;
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7cdac6d8/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java
index 16cab96..c730ab8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentInputBuffer.java
@@ -67,7 +67,7 @@ public interface ContentInputBuffer {
      * @return     the total number of bytes read into the buffer, or
      *             {@code -1} if there is no more data because the end of
      *             the stream has been reached.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     int read(byte[] b, int off, int len) throws IOException;
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7cdac6d8/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java
index e4b73e7..905f799 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/ContentOutputBuffer.java
@@ -60,7 +60,7 @@ public interface ContentOutputBuffer {
      * @param      b     the data.
      * @param      off   the start offset in the data.
      * @param      len   the number of bytes to write.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     void write(byte[] b, int off, int len) throws IOException;
 
@@ -68,13 +68,13 @@ public interface ContentOutputBuffer {
      * Writes the specified byte to this buffer.
      *
      * @param      b   the {@code byte}.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     void write(int b) throws IOException;
 
     /**
      * Indicates the content has been fully written.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      */
     void writeCompleted() throws IOException;
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/7cdac6d8/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java b/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java
index d7eeee0..79eab23 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/CharArrayBuffer.java
@@ -410,7 +410,7 @@ public final class CharArrayBuffer implements CharSequence, Serializable {
      * @param      beginIndex   the beginning index, inclusive.
      * @param      endIndex     the ending index, exclusive.
      * @return     the specified substring.
-     * @exception  StringIndexOutOfBoundsException  if the
+     * @throws  StringIndexOutOfBoundsException  if the
      *             {@code beginIndex} is negative, or
      *             {@code endIndex} is larger than the length of this
      *             buffer, or {@code beginIndex} is larger than
@@ -443,7 +443,7 @@ public final class CharArrayBuffer implements CharSequence, Serializable {
      * @param      beginIndex   the beginning index, inclusive.
      * @param      endIndex     the ending index, exclusive.
      * @return     the specified substring.
-     * @exception  IndexOutOfBoundsException  if the
+     * @throws  IndexOutOfBoundsException  if the
      *             {@code beginIndex} is negative, or
      *             {@code endIndex} is larger than the length of this
      *             buffer, or {@code beginIndex} is larger than


[25/50] [abbrv] httpcomponents-core git commit: Sort members.

Posted by ol...@apache.org.
Sort members.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792651 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: cb20293c98e0f954f5c48a621dc492ea41522bce
Parents: fee8ab4
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 20:33:58 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 20:33:58 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/util/Args.java     | 60 ++++++++++----------
 1 file changed, 30 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cb20293c/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
index 479c0da..f6fc05f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Args.java
@@ -31,10 +31,6 @@ import java.util.Collection;
 
 public class Args {
 
-    private Args() {
-        // Do not allow utility class to be instantiated.
-    }
-
     public static void check(final boolean expression, final String message) {
         if (!expression) {
             throw new IllegalArgumentException(message);
@@ -53,20 +49,16 @@ public class Args {
         }
     }
 
-    public static <T> T notNull(final T argument, final String name) {
-        if (argument == null) {
-            throw new IllegalArgumentException(name + " may not be null");
-        }
-        return argument;
-    }
-
-    public static <T extends CharSequence> T notEmpty(final T argument, final String name) {
+    public static <T extends CharSequence> T containsNoBlanks(final T argument, final String name) {
         if (argument == null) {
             throw new IllegalArgumentException(name + " may not be null");
         }
-        if (TextUtils.isEmpty(argument)) {
+        if (argument.length() == 0) {
             throw new IllegalArgumentException(name + " may not be empty");
         }
+        if (TextUtils.containsBlanks(argument)) {
+            throw new IllegalArgumentException(name + " may not contain blanks");
+        }
         return argument;
     }
 
@@ -80,16 +72,13 @@ public class Args {
         return argument;
     }
 
-    public static <T extends CharSequence> T containsNoBlanks(final T argument, final String name) {
+    public static <T extends CharSequence> T notEmpty(final T argument, final String name) {
         if (argument == null) {
             throw new IllegalArgumentException(name + " may not be null");
         }
-        if (argument.length() == 0) {
+        if (TextUtils.isEmpty(argument)) {
             throw new IllegalArgumentException(name + " may not be empty");
         }
-        if (TextUtils.containsBlanks(argument)) {
-            throw new IllegalArgumentException(name + " may not contain blanks");
-        }
         return argument;
     }
 
@@ -103,32 +92,43 @@ public class Args {
         return argument;
     }
 
-    public static int positive(final int n, final String name) {
-        if (n <= 0) {
-            throw new IllegalArgumentException(name + " may not be negative or zero");
+    public static int notNegative(final int n, final String name) {
+        if (n < 0) {
+            throw new IllegalArgumentException(name + " may not be negative");
         }
         return n;
     }
 
-    public static long positive(final long n, final String name) {
-        if (n <= 0) {
-            throw new IllegalArgumentException(name + " may not be negative or zero");
+    public static long notNegative(final long n, final String name) {
+        if (n < 0) {
+            throw new IllegalArgumentException(name + " may not be negative");
         }
         return n;
     }
 
-    public static int notNegative(final int n, final String name) {
-        if (n < 0) {
-            throw new IllegalArgumentException(name + " may not be negative");
+    public static <T> T notNull(final T argument, final String name) {
+        if (argument == null) {
+            throw new IllegalArgumentException(name + " may not be null");
+        }
+        return argument;
+    }
+
+    public static int positive(final int n, final String name) {
+        if (n <= 0) {
+            throw new IllegalArgumentException(name + " may not be negative or zero");
         }
         return n;
     }
 
-    public static long notNegative(final long n, final String name) {
-        if (n < 0) {
-            throw new IllegalArgumentException(name + " may not be negative");
+    public static long positive(final long n, final String name) {
+        if (n <= 0) {
+            throw new IllegalArgumentException(name + " may not be negative or zero");
         }
         return n;
     }
 
+    private Args() {
+        // Do not allow utility class to be instantiated.
+    }
+
 }


[04/50] [abbrv] httpcomponents-core git commit: Support TLS ALPN and disable TLS renegotiation via reflection on Java 1.9+

Posted by ol...@apache.org.
Support TLS ALPN and disable TLS renegotiation via reflection on Java 1.9+

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791944 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 38a2d5d952d48359a4acb4301ef02fd193628b47
Parents: 9ae9ade
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Apr 19 16:40:01 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Apr 19 16:40:01 2017 +0000

----------------------------------------------------------------------
 .../hc/core5/http2/ssl/H2ClientTlsStrategy.java |  3 +-
 .../hc/core5/http2/ssl/H2ServerTlsStrategy.java |  3 +-
 .../apache/hc/core5/http2/ssl/H2TlsSupport.java | 46 ++++++++++++++++++--
 3 files changed, 47 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/38a2d5d9/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
index dd6a0ea..b517459 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
@@ -95,7 +95,8 @@ public class H2ClientTlsStrategy implements TlsStrategy {
         final String scheme = host != null ? host.getSchemeName() : null;
         if ("https".equalsIgnoreCase(scheme)) {
             tlsSession.startTls(sslContext, sslBufferManagement,
-                    H2TlsSupport.decorateInitializer(initializer), verifier);
+                    H2TlsSupport.enforceRequirements(initializer),
+                    verifier);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/38a2d5d9/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
index 19ff0cb..f449767 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
@@ -102,7 +102,8 @@ public class H2ServerTlsStrategy implements TlsStrategy {
         for (final int securePort: securePorts) {
             if (port == securePort) {
                 tlsSession.startTls(sslContext, sslBufferManagement,
-                        H2TlsSupport.decorateInitializer(initializer), verifier);
+                        H2TlsSupport.enforceRequirements(initializer),
+                        verifier);
                 break;
             }
         }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/38a2d5d9/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
index 62a750f..836ccaa 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
@@ -27,6 +27,7 @@
 
 package org.apache.hc.core5.http2.ssl;
 
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
@@ -358,13 +359,52 @@ public final class H2TlsSupport {
         return enabledCiphers != null ? enabledCiphers.toArray(new String[enabledCiphers.size()]) : ciphers;
     }
 
-    public static SSLSessionInitializer decorateInitializer(final SSLSessionInitializer initializer) {
+    static void applyParameter(final SSLParameters sslParameters, final String name, final Class type, final Object value) {
+        try {
+            final Class<? extends SSLParameters> clazz = sslParameters.getClass();
+            final Method method = clazz.getMethod("set" + name, type);
+            method.invoke(sslParameters, value);
+        } catch (final Exception ignore) {
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    static <T> T getParameter(final SSLParameters sslParameters, final String name, final Class<T> resultType) {
+        try {
+            final Class<? extends SSLParameters> clazz = sslParameters.getClass();
+            final Method method = clazz.getMethod("get" + name);
+            return resultType.cast(method.invoke(sslParameters));
+        } catch (final Exception ignore) {
+            return null;
+        }
+    }
+
+    public static void setEnableRetransmissions(final SSLParameters sslParameters, final boolean value) {
+        applyParameter(sslParameters, "EnableRetransmissions", Boolean.TYPE, value);
+    }
+
+    public static void setApplicationProtocols(final SSLParameters sslParameters, final String[] values) {
+        applyParameter(sslParameters, "ApplicationProtocols", String[].class, values);
+    }
+
+    public static Boolean getEnableRetransmissions(final SSLParameters sslParameters) {
+        return getParameter(sslParameters, "EnableRetransmissions", Boolean.class);
+    }
+
+    public static String[] getApplicationProtocols(final SSLParameters sslParameters) {
+        return getParameter(sslParameters, "ApplicationProtocols", String[].class);
+    }
+
+    public static SSLSessionInitializer enforceRequirements(final SSLSessionInitializer initializer) {
         return new SSLSessionInitializer() {
 
             @Override
             public void initialize(final NamedEndpoint endpoint, final SSLParameters sslParameters) {
-                sslParameters.setProtocols(H2TlsSupport.excludeBlacklistedProtocols(sslParameters.getProtocols()));
-                sslParameters.setCipherSuites(H2TlsSupport.excludeBlacklistedCiphers(sslParameters.getCipherSuites()));
+                sslParameters.setProtocols(excludeBlacklistedProtocols(sslParameters.getProtocols()));
+                sslParameters.setCipherSuites(excludeBlacklistedCiphers(sslParameters.getCipherSuites()));
+                setEnableRetransmissions(sslParameters, false);
+                setApplicationProtocols(sslParameters, new String[] { "h2" });
+
                 if (initializer != null) {
                     initializer.initialize(endpoint, sslParameters);
                 }


[13/50] [abbrv] httpcomponents-core git commit: HTTP protocol version negotiation

Posted by ol...@apache.org.
HTTP protocol version negotiation

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792442 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: ed4b808c0d0c6e9754bf5f4e226f055c367b8372
Parents: 3d507fc
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Apr 24 09:23:56 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Apr 24 09:23:56 2017 +0000

----------------------------------------------------------------------
 .../Http2SSLRequestExecutionExample.java        | 196 +++++++++++++
 .../hc/core5/http2/HttpVersionPolicy.java       |  33 +++
 .../nio/AbstractHttp2StreamMultiplexer.java     |   4 +-
 .../impl/nio/ClientHttp2StreamMultiplexer.java  |  16 +-
 .../ClientHttp2StreamMultiplexerFactory.java    |  90 ++++++
 .../impl/nio/ClientHttpProtocolNegotiator.java  | 167 ++++++-----
 .../ClientHttpProtocolNegotiatorFactory.java    |  56 ++--
 .../ServerHttp2StreamMultiplexerFactory.java    |  82 ++++++
 .../impl/nio/ServerHttpProtocolNegotiator.java  | 109 ++++---
 .../ServerHttpProtocolNegotiatorFactory.java    |  52 ++--
 .../nio/bootstrap/H2RequesterBootstrap.java     |  56 +++-
 .../impl/nio/bootstrap/H2ServerBootstrap.java   |  71 ++++-
 .../impl/nio/bootstrap/Http2AsyncRequester.java |  73 +++++
 .../core5/http2/ssl/ApplicationProtocols.java   |  50 ++++
 .../hc/core5/http2/ssl/FixedPortStrategy.java   |  56 ++++
 .../hc/core5/http2/ssl/H2ClientTlsStrategy.java |   4 +-
 .../hc/core5/http2/ssl/H2ServerTlsStrategy.java |  35 +--
 .../apache/hc/core5/http2/ssl/H2TlsSupport.java |  63 ++--
 .../hc/core5/http2/ssl/SecurePortStrategy.java  |  41 +++
 .../hc/core5/testing/nio/Http2TestClient.java   |  21 +-
 .../hc/core5/testing/nio/Http2TestServer.java   |  11 +-
 .../InternalClientHttp1EventHandlerFactory.java |  69 +----
 .../InternalClientHttp2EventHandlerFactory.java |  80 +++---
 .../testing/nio/InternalConnectionListener.java |  67 +++++
 .../nio/InternalHttp1StreamListener.java        |  96 +++++++
 .../InternalServerHttp1EventHandlerFactory.java |  69 +----
 .../InternalServerHttp2EventHandlerFactory.java |  82 +++---
 .../hc/core5/testing/nio/LoggingIOSession.java  |  12 +-
 .../hc/core5/testing/SSLTestContexts.java       |  55 ++++
 .../core5/testing/nio/Http1IntegrationTest.java |   5 +-
 .../core5/testing/nio/Http2IntegrationTest.java |   3 +-
 .../nio/Http2ProtocolNegotiationTest.java       | 251 ++++++++++++++++
 .../nio/Http2ServerAndRequesterTest.java        | 288 +++++++++++++++++++
 .../nio/InternalHttp1ServerTestBase.java        |  25 +-
 .../nio/InternalHttp2ServerTestBase.java        |  25 +-
 .../http/examples/AsyncReverseProxyExample.java |   2 +-
 .../http/impl/bootstrap/AsyncRequester.java     |   5 +-
 .../impl/bootstrap/AsyncRequesterBootstrap.java |  30 +-
 .../impl/bootstrap/AsyncServerBootstrap.java    |  21 +-
 .../http/impl/bootstrap/HttpAsyncRequester.java |  28 +-
 .../impl/nio/AbstractHttp1IOEventHandler.java   |   2 +-
 .../impl/nio/AbstractHttp1StreamDuplexer.java   |  14 +-
 .../nio/ClientHttp1IOEventHandlerFactory.java   |  92 +-----
 .../nio/ClientHttp1StreamDuplexerFactory.java   | 137 +++++++++
 .../nio/ServerHttp1IOEventHandlerFactory.java   | 109 +------
 .../nio/ServerHttp1StreamDuplexerFactory.java   | 136 +++++++++
 .../http/impl/nio/SessionInputBufferImpl.java   |   8 +
 .../http/nio/ssl/BasicClientTlsStrategy.java    |   2 +-
 .../http/nio/ssl/BasicServerTlsStrategy.java    |   2 +-
 .../hc/core5/http/nio/ssl/TlsStrategy.java      |   2 +-
 .../hc/core5/reactor/InternalIOSession.java     |   6 +-
 .../hc/core5/reactor/ssl/SSLIOSession.java      |  20 +-
 .../reactor/ssl/SSLSessionInitializer.java      |   9 +-
 .../core5/reactor/ssl/SSLSessionVerifier.java   |   8 +-
 .../apache/hc/core5/reactor/ssl/TlsDetails.java |  63 ++++
 .../reactor/ssl/TransportSecurityLayer.java     |   3 +-
 .../apache/hc/core5/ssl/ReflectionSupport.java  |  54 ++++
 57 files changed, 2385 insertions(+), 781 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
new file mode 100644
index 0000000..0463420
--- /dev/null
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
@@ -0,0 +1,196 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.examples;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Future;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLException;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
+import org.apache.hc.core5.http.nio.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.BasicResponseConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http2.config.H2Config;
+import org.apache.hc.core5.http2.frame.RawFrame;
+import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap;
+import org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy;
+import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.net.NamedEndpoint;
+import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
+import org.apache.hc.core5.ssl.SSLContexts;
+import org.apache.hc.core5.ssl.TrustStrategy;
+import org.apache.hc.core5.util.TimeValue;
+
+/**
+ * This example demonstrates how to execute HTTP/2 requests over TLS connections.
+ */
+public class Http2SSLRequestExecutionExample {
+
+    public final static void main(final String[] args) throws Exception {
+        // Trust standard CA and those trusted by our custom strategy
+        final SSLContext sslcontext = SSLContexts.custom()
+                .loadTrustMaterial(new TrustStrategy() {
+
+                    @Override
+                    public boolean isTrusted(
+                            final X509Certificate[] chain,
+                            final String authType) throws CertificateException {
+                        final X509Certificate cert = chain[0];
+                        return "CN=http2bin.org".equalsIgnoreCase(cert.getSubjectDN().getName());
+                    }
+
+                })
+                .build();
+
+        // Create and start requester
+        H2Config h2Config = H2Config.custom()
+                .setPushEnabled(false)
+                .build();
+
+        final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
+                .setH2Config(h2Config)
+                .setTlsStrategy(new H2ClientTlsStrategy(sslcontext, new SSLSessionVerifier() {
+
+                    @Override
+                    public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {
+                        // IMPORTANT
+                        // In order for HTTP/2 protocol negotiation to succeed one must allow access
+                        // to Java 9 specific properties of SSLEngine via reflection
+                        // by adding the following line to the JVM arguments
+                        //
+                        // --add-opens java.base/sun.security.ssl=ALL-UNNAMED
+                        //
+                        // or uncomment the method below
+
+                        // return new TlsDetails(sslEngine.getSession(), sslEngine.getApplicationProtocol());
+                        return null;
+                    }
+
+                }))
+                .setStreamListener(new Http2StreamListener() {
+
+                    @Override
+                    public void onHeaderInput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
+                        for (int i = 0; i < headers.size(); i++) {
+                            System.out.println(connection + " (" + streamId + ") << " + headers.get(i));
+                        }
+                    }
+
+                    @Override
+                    public void onHeaderOutput(final HttpConnection connection, final int streamId, final List<? extends Header> headers) {
+                        for (int i = 0; i < headers.size(); i++) {
+                            System.out.println(connection + " (" + streamId + ") >> " + headers.get(i));
+                        }
+                    }
+
+                    @Override
+                    public void onFrameInput(final HttpConnection connection, final int streamId, final RawFrame frame) {
+                    }
+
+                    @Override
+                    public void onFrameOutput(final HttpConnection connection, final int streamId, final RawFrame frame) {
+                    }
+
+                    @Override
+                    public void onInputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
+                    }
+
+                    @Override
+                    public void onOutputFlowControl(final HttpConnection connection, final int streamId, final int delta, final int actualSize) {
+                    }
+
+                })
+                .create();
+        Runtime.getRuntime().addShutdownHook(new Thread() {
+            @Override
+            public void run() {
+                System.out.println("HTTP requester shutting down");
+                requester.shutdown(ShutdownType.GRACEFUL);
+            }
+        });
+        requester.start();
+
+        HttpHost target = new HttpHost("http2bin.org", 443, "https");
+        String[] requestUris = new String[] {"/", "/ip", "/user-agent", "/headers"};
+
+        final CountDownLatch latch = new CountDownLatch(requestUris.length);
+        for (final String requestUri: requestUris) {
+            final Future<AsyncClientEndpoint> future = requester.connect(target, TimeValue.ofSeconds(5));
+            final AsyncClientEndpoint clientEndpoint = future.get();
+            clientEndpoint.execute(
+                    new BasicRequestProducer("GET", target, requestUri),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()),
+                    new FutureCallback<Message<HttpResponse, String>>() {
+
+                        @Override
+                        public void completed(final Message<HttpResponse, String> message) {
+                            clientEndpoint.releaseAndReuse();
+                            HttpResponse response = message.getHead();
+                            String body = message.getBody();
+                            System.out.println(requestUri + "->" + response.getCode() + " " + response.getVersion());
+                            System.out.println(body);
+                            latch.countDown();
+                        }
+
+                        @Override
+                        public void failed(final Exception ex) {
+                            clientEndpoint.releaseAndDiscard();
+                            System.out.println(requestUri + "->" + ex);
+                            latch.countDown();
+                        }
+
+                        @Override
+                        public void cancelled() {
+                            clientEndpoint.releaseAndDiscard();
+                            System.out.println(requestUri + " cancelled");
+                            latch.countDown();
+                        }
+
+                    });
+        }
+
+        latch.await();
+        System.out.println("Shutting down I/O reactor");
+        requester.initiateShutdown();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/HttpVersionPolicy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/HttpVersionPolicy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/HttpVersionPolicy.java
new file mode 100644
index 0000000..237c864
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/HttpVersionPolicy.java
@@ -0,0 +1,33 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2;
+
+public enum HttpVersionPolicy {
+
+    FORCE_HTTP_1, FORCE_HTTP_2, NEGOTIATE
+
+};

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
index 61c7fb9..697560b 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
@@ -84,6 +84,7 @@ import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.net.InetAddressUtils;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.ByteArrayBuffer;
 
@@ -1188,7 +1189,8 @@ abstract class AbstractHttp2StreamMultiplexer implements HttpConnection {
 
     @Override
     public SSLSession getSSLSession() {
-        return ioSession.getSSLSession();
+        final TlsDetails tlsDetails = ioSession.getTlsDetails();
+        return tlsDetails != null ? tlsDetails.getSSLSession() : null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java
index 89e47d5..985fed7 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexer.java
@@ -55,8 +55,8 @@ public class ClientHttp2StreamMultiplexer extends AbstractHttp2StreamMultiplexer
             final FrameFactory frameFactory,
             final HttpProcessor httpProcessor,
             final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
-            final CharCodingConfig charCodingConfig,
             final H2Config h2Config,
+            final CharCodingConfig charCodingConfig,
             final ConnectionListener connectionListener,
             final Http2StreamListener streamListener) {
         super(Mode.CLIENT, ioSession, frameFactory, StreamIdGenerator.ODD, httpProcessor, charCodingConfig,
@@ -68,18 +68,18 @@ public class ClientHttp2StreamMultiplexer extends AbstractHttp2StreamMultiplexer
             final TlsCapableIOSession ioSession,
             final HttpProcessor httpProcessor,
             final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final H2Config h2Config) {
-        this(ioSession, DefaultFrameFactory.INSTANCE, httpProcessor, pushHandlerFactory, charCodingConfig,
-                h2Config, null, null);
+            final H2Config h2Config,
+            final CharCodingConfig charCodingConfig) {
+        this(ioSession, DefaultFrameFactory.INSTANCE, httpProcessor, pushHandlerFactory,
+                h2Config, charCodingConfig, null, null);
     }
 
     public ClientHttp2StreamMultiplexer(
             final TlsCapableIOSession ioSession,
             final HttpProcessor httpProcessor,
-            final CharCodingConfig charCodingConfig,
-            final H2Config h2Config) {
-        this(ioSession, httpProcessor, null, charCodingConfig, h2Config);
+            final H2Config h2Config,
+            final CharCodingConfig charCodingConfig) {
+        this(ioSession, httpProcessor, null, h2Config, charCodingConfig);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexerFactory.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexerFactory.java
new file mode 100644
index 0000000..0f15bc0
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttp2StreamMultiplexerFactory.java
@@ -0,0 +1,90 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.impl.nio;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.nio.AsyncPushConsumer;
+import org.apache.hc.core5.http.nio.HandlerFactory;
+import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.config.H2Config;
+import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public final class ClientHttp2StreamMultiplexerFactory {
+
+    private final HttpProcessor httpProcessor;
+    private final HandlerFactory<AsyncPushConsumer> pushHandlerFactory;
+    private final H2Config h2Config;
+    private final CharCodingConfig charCodingConfig;
+    private final ConnectionListener connectionListener;
+    private final Http2StreamListener streamListener;
+
+    public ClientHttp2StreamMultiplexerFactory(
+            final HttpProcessor httpProcessor,
+            final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
+            final H2Config h2Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionListener connectionListener,
+            final Http2StreamListener streamListener) {
+        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
+        this.pushHandlerFactory = pushHandlerFactory;
+        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
+        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
+        this.connectionListener = connectionListener;
+        this.streamListener = streamListener;
+    }
+
+    public ClientHttp2StreamMultiplexerFactory(
+            final HttpProcessor httpProcessor,
+            final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
+            final ConnectionListener connectionListener,
+            final Http2StreamListener streamListener) {
+        this(httpProcessor, pushHandlerFactory, null, null, connectionListener, streamListener);
+    }
+
+    public ClientHttp2StreamMultiplexerFactory(
+            final HttpProcessor httpProcessor,
+            final ConnectionListener connectionListener,
+            final Http2StreamListener streamListener) {
+        this(httpProcessor, null, connectionListener, streamListener);
+    }
+
+    public ClientHttp2StreamMultiplexer create(final TlsCapableIOSession ioSession) {
+        return new ClientHttp2StreamMultiplexer(ioSession, DefaultFrameFactory.INSTANCE, httpProcessor,
+                pushHandlerFactory, h2Config, charCodingConfig, connectionListener, streamListener);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
index b2f80cc..320b949 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiator.java
@@ -37,23 +37,24 @@ import javax.net.ssl.SSLSession;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.EndpointDetails;
 import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler;
+import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer;
+import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
-import org.apache.hc.core5.http.nio.AsyncPushConsumer;
-import org.apache.hc.core5.http.nio.HandlerFactory;
 import org.apache.hc.core5.http.nio.command.ExecutionCommand;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http2.config.H2Config;
-import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.http2.ssl.ApplicationProtocols;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.reactor.Command;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -69,65 +70,85 @@ public class ClientHttpProtocolNegotiator implements HttpConnectionEventHandler
             0x0d, 0x0a, 0x0d, 0x0a};
 
     private final TlsCapableIOSession ioSession;
-    private final HttpProcessor httpProcessor;
-    private final CharCodingConfig charCodingConfig;
-    private final H2Config h2Config;
-    private final HandlerFactory<AsyncPushConsumer> pushHandlerFactory;
+    private final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory;
+    private final ClientHttp2StreamMultiplexerFactory http2StreamHandlerFactory;
+    private final HttpVersionPolicy versionPolicy;
     private final ConnectionListener connectionListener;
-    private final Http2StreamListener streamListener;
-    private final ByteBuffer preface;
+
+    private volatile ByteBuffer preface;
 
     public ClientHttpProtocolNegotiator(
             final TlsCapableIOSession ioSession,
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final H2Config h2Config,
-            final ConnectionListener connectionListener,
-            final Http2StreamListener streamListener) {
+            final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory,
+            final ClientHttp2StreamMultiplexerFactory http2StreamHandlerFactory,
+            final HttpVersionPolicy versionPolicy,
+            final ConnectionListener connectionListener) {
         this.ioSession = Args.notNull(ioSession, "I/O session");
-        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
-        this.pushHandlerFactory = pushHandlerFactory;
-        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
-        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
-        this.streamListener = streamListener;
+        this.http1StreamHandlerFactory = Args.notNull(http1StreamHandlerFactory, "HTTP/1.1 stream handler factory");
+        this.http2StreamHandlerFactory = Args.notNull(http2StreamHandlerFactory, "HTTP/2 stream handler factory");
+        this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
         this.connectionListener = connectionListener;
-        this.preface = ByteBuffer.wrap(PREFACE);
     }
 
-    protected ClientHttp2StreamMultiplexer createStreamMultiplexer(final TlsCapableIOSession ioSession) {
-        return new ClientHttp2StreamMultiplexer(ioSession, DefaultFrameFactory.INSTANCE, httpProcessor,
-                pushHandlerFactory, charCodingConfig, h2Config, connectionListener, streamListener);
+    @Override
+    public void connected(final IOSession session) {
+        try {
+            switch (versionPolicy) {
+                case NEGOTIATE:
+                    final TlsDetails tlsDetails = ioSession.getTlsDetails();
+                    if (tlsDetails != null) {
+                        if (ApplicationProtocols.HTTP_2.id.equals(tlsDetails.getApplicationProtocol())) {
+                            // Proceed with the H2 preface
+                            preface = ByteBuffer.wrap(PREFACE);
+                        }
+                    }
+                    break;
+                case FORCE_HTTP_2:
+                    preface = ByteBuffer.wrap(PREFACE);
+                    break;
+            }
+            if (preface == null) {
+                final ClientHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
+                session.setHandler(new ClientHttp1IOEventHandler(http1StreamHandler));
+                http1StreamHandler.onConnect(null);
+            } else {
+                writePreface(session);
+            }
+        } catch (final Exception ex) {
+            session.shutdown(ShutdownType.IMMEDIATE);
+            exception(session, ex);
+        }
     }
 
-    @Override
-    public void connected(final IOSession ioSession) {
-        outputReady(ioSession);
+    private void writePreface(final IOSession session) throws IOException  {
+        if (preface.hasRemaining()) {
+            final ByteChannel channel = session.channel();
+            channel.write(preface);
+        }
+        if (!preface.hasRemaining()) {
+            final ClientHttp2StreamMultiplexer streamMultiplexer = http2StreamHandlerFactory.create(ioSession);
+            final IOEventHandler newHandler = new ClientHttp2IOEventHandler(streamMultiplexer);
+            newHandler.connected(session);
+            session.setHandler(newHandler);
+        }
     }
 
     @Override
     public void inputReady(final IOSession session) {
+        outputReady(session);
     }
 
     @Override
     public void outputReady(final IOSession session) {
-        if (preface.hasRemaining()) {
-            try {
-                final ByteChannel channel = ioSession.channel();
-                channel.write(preface);
-            } catch (final IOException ex) {
-                ioSession.shutdown(ShutdownType.IMMEDIATE);
-                if (connectionListener != null) {
-                    connectionListener.onError(this, ex);
-                }
-                return;
+        try {
+            if (preface != null) {
+                writePreface(session);
+            } else {
+                session.shutdown(ShutdownType.IMMEDIATE);
             }
-        }
-        if (!preface.hasRemaining()) {
-            final ClientHttp2StreamMultiplexer streamMultiplexer = createStreamMultiplexer(ioSession);
-            final IOEventHandler newHandler = new ClientHttp2IOEventHandler(streamMultiplexer);
-            newHandler.connected(ioSession);
-            ioSession.setHandler(newHandler);
+        } catch (final IOException ex) {
+            session.shutdown(ShutdownType.IMMEDIATE);
+            exception(session, ex);
         }
     }
 
@@ -136,30 +157,27 @@ public class ClientHttpProtocolNegotiator implements HttpConnectionEventHandler
         exception(session, new SocketTimeoutException());
     }
 
-    private void failPendingCommands(final Exception cause) {
-        for (;;) {
-            final Command command = ioSession.getCommand();
-            if (command != null) {
-                if (command instanceof ExecutionCommand) {
-                    final ExecutionCommand executionCommand = (ExecutionCommand) command;
-                    final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
-                    exchangeHandler.failed(cause);
-                } else {
-                    command.cancel();
-                }
-            } else {
-                break;
-            }
-        }
-    }
-
     @Override
     public void exception(final IOSession session, final Exception cause) {
         if (connectionListener != null) {
             connectionListener.onError(this, new SocketTimeoutException());
         }
         try {
-            failPendingCommands(cause);
+            for (;;) {
+                final Command command = ioSession.getCommand();
+                if (command != null) {
+                    if (command instanceof ExecutionCommand) {
+                        final ExecutionCommand executionCommand = (ExecutionCommand) command;
+                        final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
+                        exchangeHandler.failed(cause);
+                        exchangeHandler.releaseResources();
+                    } else {
+                        command.cancel();
+                    }
+                } else {
+                    break;
+                }
+            }
         } finally {
             session.shutdown(ShutdownType.IMMEDIATE);
         }
@@ -167,11 +185,30 @@ public class ClientHttpProtocolNegotiator implements HttpConnectionEventHandler
 
     @Override
     public void disconnected(final IOSession session) {
+        if (connectionListener != null) {
+            connectionListener.onDisconnect(this);
+        }
+        for (;;) {
+            final Command command = ioSession.getCommand();
+            if (command != null) {
+                if (command instanceof ExecutionCommand) {
+                    final ExecutionCommand executionCommand = (ExecutionCommand) command;
+                    final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
+                    exchangeHandler.failed(new ConnectionClosedException("Connection closed"));
+                    exchangeHandler.releaseResources();
+                } else {
+                    command.cancel();
+                }
+            } else {
+                break;
+            }
+        }
     }
 
     @Override
     public SSLSession getSSLSession() {
-        return ioSession.getSSLSession();
+        final TlsDetails tlsDetails = ioSession.getTlsDetails();
+        return tlsDetails != null ? tlsDetails.getSSLSession() : null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
index d99e46c..9a5d2e1 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ClientHttpProtocolNegotiatorFactory.java
@@ -29,12 +29,9 @@ package org.apache.hc.core5.http2.impl.nio;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.impl.ConnectionListener;
-import org.apache.hc.core5.http.nio.AsyncPushConsumer;
-import org.apache.hc.core5.http.nio.HandlerFactory;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http2.config.H2Config;
+import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.util.Args;
@@ -45,47 +42,30 @@ import org.apache.hc.core5.util.Args;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class ClientHttpProtocolNegotiatorFactory implements IOEventHandlerFactory {
 
-    private final HttpProcessor httpProcessor;
-    private final HandlerFactory<AsyncPushConsumer> pushHandlerFactory;
-    private final CharCodingConfig charCodingConfig;
-    private final H2Config h2Config;
+    private final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory;
+    private final ClientHttp2StreamMultiplexerFactory http2StreamHandlerFactory;
+    private final HttpVersionPolicy versionPolicy;
     private final ConnectionListener connectionListener;
-    private final Http2StreamListener streamListener;
 
     public ClientHttpProtocolNegotiatorFactory(
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final H2Config h2Config,
-            final ConnectionListener connectionListener,
-            final Http2StreamListener streamListener) {
-        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
-        this.pushHandlerFactory = pushHandlerFactory;
-        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
-        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
+            final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory,
+            final ClientHttp2StreamMultiplexerFactory http2StreamHandlerFactory,
+            final HttpVersionPolicy versionPolicy,
+            final ConnectionListener connectionListener) {
+        this.http1StreamHandlerFactory = Args.notNull(http1StreamHandlerFactory, "HTTP/1.1 stream handler factory");
+        this.http2StreamHandlerFactory = Args.notNull(http2StreamHandlerFactory, "HTTP/2 stream handler factory");
+        this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
         this.connectionListener = connectionListener;
-        this.streamListener = streamListener;
-    }
-
-    public ClientHttpProtocolNegotiatorFactory(
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncPushConsumer> pushHandlerFactory,
-            final ConnectionListener connectionListener,
-            final Http2StreamListener streamListener) {
-        this(httpProcessor, pushHandlerFactory, null, null, connectionListener, streamListener);
-    }
-
-    public ClientHttpProtocolNegotiatorFactory(
-            final HttpProcessor httpProcessor,
-            final ConnectionListener connectionListener,
-            final Http2StreamListener streamListener) {
-        this(httpProcessor, null, connectionListener, streamListener);
     }
 
     @Override
     public ClientHttpProtocolNegotiator createHandler(final TlsCapableIOSession ioSession, final Object attachment) {
-        return new ClientHttpProtocolNegotiator(ioSession, httpProcessor, pushHandlerFactory,
-                charCodingConfig, h2Config, connectionListener, streamListener);
+        return new ClientHttpProtocolNegotiator(
+                ioSession,
+                http1StreamHandlerFactory,
+                http2StreamHandlerFactory,
+                attachment instanceof HttpVersionPolicy ? (HttpVersionPolicy) attachment : versionPolicy,
+                connectionListener);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexerFactory.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexerFactory.java
new file mode 100644
index 0000000..0d21874
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttp2StreamMultiplexerFactory.java
@@ -0,0 +1,82 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.impl.nio;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.HandlerFactory;
+import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.config.H2Config;
+import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
+import org.apache.hc.core5.reactor.TlsCapableIOSession;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public final class ServerHttp2StreamMultiplexerFactory {
+
+    private final HttpProcessor httpProcessor;
+    private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
+    private final H2Config h2Config;
+    private final CharCodingConfig charCodingConfig;
+    private final ConnectionListener connectionListener;
+    private final Http2StreamListener streamListener;
+
+    public ServerHttp2StreamMultiplexerFactory(
+            final HttpProcessor httpProcessor,
+            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
+            final H2Config h2Config,
+            final CharCodingConfig charCodingConfig,
+            final ConnectionListener connectionListener,
+            final Http2StreamListener streamListener) {
+        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
+        this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
+        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
+        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
+        this.connectionListener = connectionListener;
+        this.streamListener = streamListener;
+    }
+
+    public ServerHttp2StreamMultiplexer create(final TlsCapableIOSession ioSession) {
+        return new ServerHttp2StreamMultiplexer(
+                ioSession,
+                DefaultFrameFactory.INSTANCE,
+                httpProcessor,
+                exchangeHandlerFactory,
+                charCodingConfig,
+                h2Config,
+                connectionListener,
+                streamListener);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
index 65b1430..50c5f4c 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiator.java
@@ -38,19 +38,19 @@ import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.EndpointDetails;
 import org.apache.hc.core5.http.ProtocolVersion;
-import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.impl.ConnectionListener;
 import org.apache.hc.core5.http.impl.nio.HttpConnectionEventHandler;
-import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
-import org.apache.hc.core5.http.nio.HandlerFactory;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler;
+import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexer;
+import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http2.H2ConnectionException;
 import org.apache.hc.core5.http2.H2Error;
-import org.apache.hc.core5.http2.config.H2Config;
-import org.apache.hc.core5.http2.frame.DefaultFrameFactory;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.http2.ssl.ApplicationProtocols;
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.util.Args;
 
 /**
@@ -62,39 +62,51 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
     final static byte[] PREFACE = ClientHttpProtocolNegotiator.PREFACE;
 
     private final TlsCapableIOSession ioSession;
-    private final HttpProcessor httpProcessor;
-    private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
-    private final CharCodingConfig charCodingConfig;
-    private final H2Config h2Config;
-    private final ByteBuffer bytebuf;
+    private final ServerHttp1StreamDuplexerFactory http1StreamHandlerFactory;
+    private final ServerHttp2StreamMultiplexerFactory http2StreamHandlerFactory;
+    private final HttpVersionPolicy versionPolicy;
     private final ConnectionListener connectionListener;
-    private final Http2StreamListener streamListener;
+    private final ByteBuffer bytebuf;
+
+    private volatile boolean expectValidH2Preface;
 
     public ServerHttpProtocolNegotiator(
             final TlsCapableIOSession ioSession,
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final H2Config h2Config,
-            final ConnectionListener connectionListener,
-            final Http2StreamListener streamListener) {
+            final ServerHttp1StreamDuplexerFactory http1StreamHandlerFactory,
+            final ServerHttp2StreamMultiplexerFactory http2StreamHandlerFactory,
+            final HttpVersionPolicy versionPolicy,
+            final ConnectionListener connectionListener) {
         this.ioSession = Args.notNull(ioSession, "I/O session");
-        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
-        this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
-        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
-        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
-        this.bytebuf = ByteBuffer.allocate(1024);
+        this.http1StreamHandlerFactory = Args.notNull(http1StreamHandlerFactory, "HTTP/1.1 stream handler factory");
+        this.http2StreamHandlerFactory = Args.notNull(http2StreamHandlerFactory, "HTTP/2 stream handler factory");
+        this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
         this.connectionListener = connectionListener;
-        this.streamListener = streamListener;
-    }
-
-    protected ServerHttp2StreamMultiplexer createStreamMultiplexer(final TlsCapableIOSession ioSession) {
-        return new ServerHttp2StreamMultiplexer(ioSession, DefaultFrameFactory.INSTANCE, httpProcessor,
-                exchangeHandlerFactory, charCodingConfig, h2Config, connectionListener, streamListener);
+        this.bytebuf = ByteBuffer.allocate(1024);
     }
 
     @Override
     public void connected(final IOSession session) {
+        try {
+            switch (versionPolicy) {
+                case NEGOTIATE:
+                    final TlsDetails tlsDetails = ioSession.getTlsDetails();
+                    if (tlsDetails != null) {
+                        if (ApplicationProtocols.HTTP_2.id.equals(tlsDetails.getApplicationProtocol())) {
+                            expectValidH2Preface = true;
+                            // Proceed with the H2 preface
+                            break;
+                        }
+                    }
+                    break;
+                case FORCE_HTTP_1:
+                    final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
+                    session.setHandler(new ServerHttp1IOEventHandler(http1StreamHandler));
+                    http1StreamHandler.onConnect(null);
+                    break;
+            }
+        } catch (final Exception ex) {
+            exception(session, ex);
+        }
     }
 
     @Override
@@ -105,21 +117,32 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
             }
             if (bytebuf.position() >= PREFACE.length) {
                 bytebuf.flip();
+
+                boolean validH2Preface = true;
                 for (int i = 0; i < PREFACE.length; i++) {
                     if (bytebuf.get() != PREFACE[i]) {
-                        throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "Unexpected HTTP/2 preface");
+                        if (expectValidH2Preface) {
+                            throw new H2ConnectionException(H2Error.PROTOCOL_ERROR, "Unexpected HTTP/2 preface");
+                        } else {
+                            validH2Preface = false;
+                        }
                     }
                 }
-                final ServerHttp2StreamMultiplexer streamMultiplexer = createStreamMultiplexer(ioSession);
-                streamMultiplexer.onConnect(bytebuf.hasRemaining() ? bytebuf : null);
-                streamMultiplexer.onInput();
-                session.setHandler(new ServerHttp2IOEventHandler(streamMultiplexer));
+                if (validH2Preface) {
+                    final ServerHttp2StreamMultiplexer http2StreamHandler = http2StreamHandlerFactory.create(ioSession);
+                    session.setHandler(new ServerHttp2IOEventHandler(http2StreamHandler));
+                    http2StreamHandler.onConnect(bytebuf.hasRemaining() ? bytebuf : null);
+                    http2StreamHandler.onInput();
+                } else {
+                    final ServerHttp1StreamDuplexer http1StreamHandler = http1StreamHandlerFactory.create(ioSession);
+                    session.setHandler(new ServerHttp1IOEventHandler(http1StreamHandler));
+                    bytebuf.rewind();
+                    http1StreamHandler.onConnect(bytebuf);
+                    http1StreamHandler.onInput();
+                }
             }
         } catch (final Exception ex) {
-            session.close();
-            if (connectionListener != null) {
-                connectionListener.onError(this, ex);
-            }
+            exception(session, ex);
         }
     }
 
@@ -134,19 +157,23 @@ public class ServerHttpProtocolNegotiator implements HttpConnectionEventHandler
 
     @Override
     public void exception(final IOSession session, final Exception cause) {
-        session.close();
+        session.shutdown(ShutdownType.IMMEDIATE);
         if (connectionListener != null) {
-            connectionListener.onError(this, new SocketTimeoutException());
+            connectionListener.onError(this, cause);
         }
     }
 
     @Override
     public void disconnected(final IOSession session) {
+        if (connectionListener != null) {
+            connectionListener.onDisconnect(this);
+        }
     }
 
     @Override
     public SSLSession getSSLSession() {
-        return ioSession.getSSLSession();
+        final TlsDetails tlsDetails = ioSession.getTlsDetails();
+        return tlsDetails != null ? tlsDetails.getSSLSession() : null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
index 7394281..ee2873c 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/ServerHttpProtocolNegotiatorFactory.java
@@ -29,13 +29,10 @@ package org.apache.hc.core5.http2.impl.nio;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.impl.ConnectionListener;
-import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
-import org.apache.hc.core5.http.nio.HandlerFactory;
+import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
-import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http2.config.H2Config;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.util.Args;
@@ -46,38 +43,23 @@ import org.apache.hc.core5.util.Args;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class ServerHttpProtocolNegotiatorFactory implements IOEventHandlerFactory {
 
-    private final HttpProcessor httpProcessor;
-    private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
-    private final CharCodingConfig charCodingConfig;
-    private final H2Config h2Config;
+    private final ServerHttp1StreamDuplexerFactory http1StreamDuplexerFactory;
+    private final ServerHttp2StreamMultiplexerFactory http2StreamMultiplexerFactory;
+    private final HttpVersionPolicy versionPolicy;
     private final TlsStrategy tlsStrategy;
     private final ConnectionListener connectionListener;
-    private final Http2StreamListener streamListener;
 
     public ServerHttpProtocolNegotiatorFactory(
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
-            final CharCodingConfig charCodingConfig,
-            final H2Config h2Config,
+            final ServerHttp1StreamDuplexerFactory http1StreamDuplexerFactory,
+            final ServerHttp2StreamMultiplexerFactory http2StreamMultiplexerFactory,
+            final HttpVersionPolicy versionPolicy,
             final TlsStrategy tlsStrategy,
-            final ConnectionListener connectionListener,
-            final Http2StreamListener streamListener) {
-        this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
-        this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
-        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
-        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
+            final ConnectionListener connectionListener) {
+        this.http1StreamDuplexerFactory = Args.notNull(http1StreamDuplexerFactory, "HTTP/1.1 stream handler factory");
+        this.http2StreamMultiplexerFactory = Args.notNull(http2StreamMultiplexerFactory, "HTTP/2 stream handler factory");
+        this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
         this.tlsStrategy = tlsStrategy;
         this.connectionListener = connectionListener;
-        this.streamListener = streamListener;
-    }
-
-    public ServerHttpProtocolNegotiatorFactory(
-            final HttpProcessor httpProcessor,
-            final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
-            final TlsStrategy tlsStrategy,
-            final ConnectionListener connectionListener,
-            final Http2StreamListener streamListener) {
-        this(httpProcessor, exchangeHandlerFactory, null, null, tlsStrategy, connectionListener, streamListener);
     }
 
     @Override
@@ -87,10 +69,14 @@ public class ServerHttpProtocolNegotiatorFactory implements IOEventHandlerFactor
                     ioSession,
                     null,
                     ioSession.getLocalAddress(),
-                    ioSession.getRemoteAddress());
+                    ioSession.getRemoteAddress(),
+                    attachment != null ? attachment : versionPolicy);
         }
-        return new ServerHttpProtocolNegotiator(ioSession, httpProcessor, exchangeHandlerFactory,
-                charCodingConfig, h2Config, connectionListener, streamListener);
+        return new ServerHttpProtocolNegotiator(ioSession,
+                http1StreamDuplexerFactory,
+                http2StreamMultiplexerFactory,
+                versionPolicy,
+                connectionListener);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
index a6b0b35..e856800 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2RequesterBootstrap.java
@@ -33,13 +33,18 @@ import org.apache.hc.core5.function.Supplier;
 import org.apache.hc.core5.http.ExceptionListener;
 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.impl.ConnectionListener;
-import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
+import org.apache.hc.core5.http.impl.Http1StreamListener;
+import org.apache.hc.core5.http.impl.HttpProcessors;
+import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.impl.Http2Processors;
+import org.apache.hc.core5.http2.impl.nio.ClientHttp2StreamMultiplexerFactory;
 import org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiatorFactory;
 import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
 import org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy;
@@ -62,7 +67,9 @@ public class H2RequesterBootstrap {
     private IOReactorConfig ioReactorConfig;
     private HttpProcessor httpProcessor;
     private CharCodingConfig charCodingConfig;
+    private HttpVersionPolicy versionPolicy;
     private H2Config h2Config;
+    private H1Config h1Config;
     private int defaultMaxPerRoute;
     private int maxTotal;
     private TimeValue timeToLive;
@@ -71,6 +78,7 @@ public class H2RequesterBootstrap {
     private ExceptionListener exceptionListener;
     private ConnectionListener connectionListener;
     private Http2StreamListener streamListener;
+    private Http1StreamListener http1StreamListener;
     private ConnPoolListener<HttpHost> connPoolListener;
 
     private H2RequesterBootstrap() {
@@ -98,6 +106,14 @@ public class H2RequesterBootstrap {
     }
 
     /**
+     * Sets HTTP protocol version policy
+     */
+    public final H2RequesterBootstrap setVersionPolicy(final HttpVersionPolicy versionPolicy) {
+        this.versionPolicy = versionPolicy;
+        return this;
+    }
+
+    /**
      * Sets HTTP/2 protocol parameters
      */
     public final H2RequesterBootstrap setH2Config(final H2Config h2Config) {
@@ -106,7 +122,15 @@ public class H2RequesterBootstrap {
     }
 
     /**
-     * Sets char coding for HTTP/2 messages.
+     * Sets HTTP/1.1 protocol parameters
+     */
+    public final H2RequesterBootstrap setH1Config(final H1Config h1Config) {
+        this.h1Config = h1Config;
+        return this;
+    }
+
+    /**
+     * Sets message char coding.
      */
     public final H2RequesterBootstrap setCharCodingConfig(final CharCodingConfig charCodingConfig) {
         this.charCodingConfig = charCodingConfig;
@@ -169,6 +193,14 @@ public class H2RequesterBootstrap {
     }
 
     /**
+     * Assigns {@link Http1StreamListener} instance.
+     */
+    public final H2RequesterBootstrap setStreamListener(final Http1StreamListener http1StreamListener) {
+        this.http1StreamListener = http1StreamListener;
+        return this;
+    }
+
+    /**
      * Assigns {@link ConnPoolListener} instance.
      */
     public final H2RequesterBootstrap setConnPoolListener(final ConnPoolListener<HttpHost> connPoolListener) {
@@ -191,7 +223,7 @@ public class H2RequesterBootstrap {
         return this;
     }
 
-    public HttpAsyncRequester create() {
+    public Http2AsyncRequester create() {
         final StrictConnPool<HttpHost, IOSession> connPool = new StrictConnPool<>(
                 defaultMaxPerRoute > 0 ? defaultMaxPerRoute : 20,
                 maxTotal > 0 ? maxTotal : 50,
@@ -202,15 +234,27 @@ public class H2RequesterBootstrap {
         for (final PushConsumerEntry entry: pushConsumerList) {
             pushConsumerRegistry.register(entry.hostname, entry.uriPattern, entry.supplier);
         }
-        final ClientHttpProtocolNegotiatorFactory ioEventHandlerFactory = new ClientHttpProtocolNegotiatorFactory(
+        final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(
+                httpProcessor != null ? httpProcessor : HttpProcessors.client(),
+                h1Config != null ? h1Config : H1Config.DEFAULT,
+                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
+                connectionListener,
+                http1StreamListener);
+        final ClientHttp2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientHttp2StreamMultiplexerFactory(
                 httpProcessor != null ? httpProcessor : Http2Processors.client(),
                 pushConsumerRegistry,
-                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
                 h2Config != null ? h2Config : H2Config.DEFAULT,
+                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
                 connectionListener,
                 streamListener);
+        final ClientHttpProtocolNegotiatorFactory ioEventHandlerFactory = new ClientHttpProtocolNegotiatorFactory(
+                http1StreamHandlerFactory,
+                http2StreamHandlerFactory,
+                versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE,
+                connectionListener);
         try {
-            return new HttpAsyncRequester(
+            return new Http2AsyncRequester(
+                    versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE,
                     ioReactorConfig,
                     ioEventHandlerFactory,
                     connPool,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
index 23d62a1..60eff6f 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/H2ServerBootstrap.java
@@ -32,21 +32,32 @@ import java.util.List;
 import org.apache.hc.core5.function.Supplier;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.config.CharCodingConfig;
+import org.apache.hc.core5.http.config.H1Config;
 import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
+import org.apache.hc.core5.http.impl.Http1StreamListener;
+import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.bootstrap.AsyncServerExchangeHandlerRegistry;
 import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncServer;
+import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestParserFactory;
+import org.apache.hc.core5.http.impl.nio.DefaultHttpResponseWriterFactory;
+import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
 import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
 import org.apache.hc.core5.http.nio.support.BasicServerExchangeHandler;
 import org.apache.hc.core5.http.nio.support.RequestConsumerSupplier;
 import org.apache.hc.core5.http.nio.support.ResponseHandler;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.impl.Http2Processors;
 import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
+import org.apache.hc.core5.http2.impl.nio.ServerHttp2StreamMultiplexerFactory;
 import org.apache.hc.core5.http2.impl.nio.ServerHttpProtocolNegotiatorFactory;
 import org.apache.hc.core5.http2.ssl.H2ServerTlsStrategy;
 import org.apache.hc.core5.net.InetAddressUtils;
+import org.apache.hc.core5.reactor.IOEventHandlerFactory;
 import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOReactorException;
 import org.apache.hc.core5.util.Args;
@@ -61,11 +72,14 @@ public class H2ServerBootstrap {
     private IOReactorConfig ioReactorConfig;
     private HttpProcessor httpProcessor;
     private CharCodingConfig charCodingConfig;
+    private HttpVersionPolicy versionPolicy;
     private H2Config h2Config;
+    private H1Config h1Config;
     private TlsStrategy tlsStrategy;
     private ExceptionListener exceptionListener;
     private ConnectionListener connectionListener;
-    private Http2StreamListener streamListener;
+    private Http2StreamListener http2StreamListener;
+    private Http1StreamListener http1StreamListener;
 
     private H2ServerBootstrap() {
         this.handlerList = new ArrayList<>();
@@ -102,6 +116,14 @@ public class H2ServerBootstrap {
     }
 
     /**
+     * Sets HTTP protocol version policy
+     */
+    public final H2ServerBootstrap setVersionPolicy(final HttpVersionPolicy versionPolicy) {
+        this.versionPolicy = versionPolicy;
+        return this;
+    }
+
+    /**
      * Sets HTTP/2 protocol parameters
      */
     public final H2ServerBootstrap setH2Config(final H2Config h2Config) {
@@ -110,7 +132,15 @@ public class H2ServerBootstrap {
     }
 
     /**
-     * Sets char coding for HTTP/2 messages.
+     * Sets HTTP/1.1 protocol parameters
+     */
+    public final H2ServerBootstrap setH1Config(final H1Config h1Config) {
+        this.h1Config = h1Config;
+        return this;
+    }
+
+    /**
+     * Sets message char coding.
      */
     public final H2ServerBootstrap setCharset(final CharCodingConfig charCodingConfig) {
         this.charCodingConfig = charCodingConfig;
@@ -144,8 +174,16 @@ public class H2ServerBootstrap {
     /**
      * Assigns {@link Http2StreamListener} instance.
      */
-    public final H2ServerBootstrap setStreamListener(final Http2StreamListener streamListener) {
-        this.streamListener = streamListener;
+    public final H2ServerBootstrap setStreamListener(final Http2StreamListener http2StreamListener) {
+        this.http2StreamListener = http2StreamListener;
+        return this;
+    }
+
+    /**
+     * Assigns {@link Http1StreamListener} instance.
+     */
+    public final H2ServerBootstrap setStreamListener(final Http1StreamListener http1StreamListener) {
+        this.http1StreamListener = http1StreamListener;
         return this;
     }
 
@@ -201,14 +239,31 @@ public class H2ServerBootstrap {
         for (final HandlerEntry entry: handlerList) {
             exchangeHandlerFactory.register(entry.hostname, entry.uriPattern, entry.supplier);
         }
-        final ServerHttpProtocolNegotiatorFactory ioEventHandlerFactory = new ServerHttpProtocolNegotiatorFactory(
+        final ServerHttp2StreamMultiplexerFactory http2StreamHandlerFactory = new ServerHttp2StreamMultiplexerFactory(
                 httpProcessor != null ? httpProcessor : Http2Processors.server(),
                 exchangeHandlerFactory,
-                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
                 h2Config != null ? h2Config : H2Config.DEFAULT,
-                tlsStrategy != null ? tlsStrategy : new H2ServerTlsStrategy(new int[] {443, 8443}),
+                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
                 connectionListener,
-                streamListener);
+                http2StreamListener);
+        final ServerHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ServerHttp1StreamDuplexerFactory(
+                httpProcessor != null ? httpProcessor : HttpProcessors.server(),
+                exchangeHandlerFactory,
+                h1Config != null ? h1Config : H1Config.DEFAULT,
+                charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT,
+                DefaultConnectionReuseStrategy.INSTANCE,
+                DefaultHttpRequestParserFactory.INSTANCE,
+                DefaultHttpResponseWriterFactory.INSTANCE,
+                DefaultContentLengthStrategy.INSTANCE,
+                DefaultContentLengthStrategy.INSTANCE,
+                connectionListener,
+                http1StreamListener);
+        final IOEventHandlerFactory ioEventHandlerFactory = new ServerHttpProtocolNegotiatorFactory(
+                http1StreamHandlerFactory,
+                http2StreamHandlerFactory,
+                versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE,
+                tlsStrategy != null ? tlsStrategy : new H2ServerTlsStrategy(new int[] {443, 8443}),
+                connectionListener);
         try {
             return new HttpAsyncServer(
                     ioEventHandlerFactory,

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2AsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2AsyncRequester.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2AsyncRequester.java
new file mode 100644
index 0000000..5594fea
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/bootstrap/Http2AsyncRequester.java
@@ -0,0 +1,73 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.impl.nio.bootstrap;
+
+import java.util.concurrent.Future;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ExceptionListener;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
+import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.pool.ControlledConnPool;
+import org.apache.hc.core5.reactor.IOEventHandlerFactory;
+import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.IOReactorException;
+import org.apache.hc.core5.reactor.IOSession;
+import org.apache.hc.core5.util.TimeValue;
+
+/**
+ * @since 5.0
+ */
+public class Http2AsyncRequester extends HttpAsyncRequester {
+
+    private final HttpVersionPolicy versionPolicy;
+
+    public Http2AsyncRequester(
+            final HttpVersionPolicy versionPolicy,
+            final IOReactorConfig ioReactorConfig,
+            final IOEventHandlerFactory eventHandlerFactory,
+            final ControlledConnPool<HttpHost, IOSession> connPool,
+            final TlsStrategy tlsStrategy,
+            final ExceptionListener exceptionListener) throws IOReactorException {
+        super(ioReactorConfig, eventHandlerFactory, connPool, tlsStrategy, exceptionListener);
+        this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
+    }
+
+    @Override
+    protected Future<AsyncClientEndpoint> doConnect(
+            final HttpHost host,
+            final TimeValue timeout,
+            final Object attachment,
+            final FutureCallback<AsyncClientEndpoint> callback) {
+        return super.doConnect(host, timeout, attachment != null ? attachment : versionPolicy, callback);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ApplicationProtocols.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ApplicationProtocols.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ApplicationProtocols.java
new file mode 100644
index 0000000..29f90c9
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/ApplicationProtocols.java
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.ssl;
+
+/**
+ * Supported application protocols.
+ *
+ * @since 5.0
+ */
+public enum ApplicationProtocols {
+
+    HTTP_2("h2"), HTTP_1_1("http/1.1");
+
+    public final String id;
+
+    ApplicationProtocols(final String id) {
+        this.id = id;
+    }
+
+    @Override
+    public String toString() {
+        return id;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/FixedPortStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/FixedPortStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/FixedPortStrategy.java
new file mode 100644
index 0000000..35ebe2b
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/FixedPortStrategy.java
@@ -0,0 +1,56 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.ssl;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import org.apache.hc.core5.util.Args;
+
+/**
+ * @since 5.0
+ */
+public final class FixedPortStrategy implements SecurePortStrategy {
+
+    private final int[] securePorts;
+
+    public FixedPortStrategy(final int[] securePorts) {
+        this.securePorts = Args.notNull(securePorts, "Secure ports");
+    }
+
+    public boolean isSecure(final SocketAddress localAddress) {
+        final int port = ((InetSocketAddress) localAddress).getPort();
+        for (final int securePort: securePorts) {
+            if (port == securePort) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
index b517459..4d3e24b 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ClientTlsStrategy.java
@@ -91,11 +91,11 @@ public class H2ClientTlsStrategy implements TlsStrategy {
             final HttpHost host,
             final SocketAddress localAddress,
             final SocketAddress remoteAddress,
-            final String... parameters) {
+            final Object attachment) {
         final String scheme = host != null ? host.getSchemeName() : null;
         if ("https".equalsIgnoreCase(scheme)) {
             tlsSession.startTls(sslContext, sslBufferManagement,
-                    H2TlsSupport.enforceRequirements(initializer),
+                    H2TlsSupport.enforceRequirements(attachment, initializer),
                     verifier);
         }
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
index f449767..2cceb77 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2ServerTlsStrategy.java
@@ -27,7 +27,6 @@
 
 package org.apache.hc.core5.http2.ssl;
 
-import java.net.InetSocketAddress;
 import java.net.SocketAddress;
 
 import javax.net.ssl.SSLContext;
@@ -49,46 +48,46 @@ import org.apache.hc.core5.util.Args;
  */
 public class H2ServerTlsStrategy implements TlsStrategy {
 
-    private final int[] securePorts;
     private final SSLContext sslContext;
+    private final SecurePortStrategy securePortStrategy;
     private final SSLBufferManagement sslBufferManagement;
     private final SSLSessionInitializer initializer;
     private final SSLSessionVerifier verifier;
 
     public H2ServerTlsStrategy(
-            final int[] securePorts,
             final SSLContext sslContext,
+            final SecurePortStrategy securePortStrategy,
             final SSLBufferManagement sslBufferManagement,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier) {
-        this.securePorts = Args.notNull(securePorts, "Array of ports");
         this.sslContext = Args.notNull(sslContext, "SSL context");
+        this.securePortStrategy = securePortStrategy;
         this.sslBufferManagement = sslBufferManagement;
         this.initializer = initializer;
         this.verifier = verifier;
     }
 
     public H2ServerTlsStrategy(
-            final int[] securePorts,
             final SSLContext sslContext,
+            final SecurePortStrategy securePortStrategy,
             final SSLSessionInitializer initializer,
             final SSLSessionVerifier verifier) {
-        this(securePorts, sslContext, null, initializer, verifier);
+        this(sslContext, securePortStrategy, null, initializer, verifier);
     }
 
     public H2ServerTlsStrategy(
-            final int[] securePorts,
             final SSLContext sslContext,
+            final SecurePortStrategy securePortStrategy,
             final SSLSessionVerifier verifier) {
-        this(securePorts, sslContext, null, null, verifier);
+        this(sslContext, securePortStrategy, null, null, verifier);
     }
 
-    public H2ServerTlsStrategy(final int[] securePorts, final SSLContext sslContext) {
-        this(securePorts, sslContext, null, null, null);
+    public H2ServerTlsStrategy(final SSLContext sslContext, final SecurePortStrategy securePortStrategy) {
+        this(sslContext, securePortStrategy, null, null, null);
     }
 
     public H2ServerTlsStrategy(final int[] securePorts) {
-        this(securePorts, SSLContexts.createSystemDefault());
+        this(SSLContexts.createSystemDefault(), new FixedPortStrategy(securePorts));
     }
 
     @Override
@@ -97,15 +96,11 @@ public class H2ServerTlsStrategy implements TlsStrategy {
             final HttpHost host,
             final SocketAddress localAddress,
             final SocketAddress remoteAddress,
-            final String... parameters) {
-        final int port = ((InetSocketAddress) localAddress).getPort();
-        for (final int securePort: securePorts) {
-            if (port == securePort) {
-                tlsSession.startTls(sslContext, sslBufferManagement,
-                        H2TlsSupport.enforceRequirements(initializer),
-                        verifier);
-                break;
-            }
+            final Object attachment) {
+        if (securePortStrategy != null && securePortStrategy.isSecure(localAddress)) {
+            tlsSession.startTls(sslContext, sslBufferManagement,
+                    H2TlsSupport.enforceRequirements(attachment, initializer),
+                    verifier);
         }
     }
 


[34/50] [abbrv] httpcomponents-core git commit: HTTPCORE-458: Validate port values. Add checks and Javadoc.

Posted by ol...@apache.org.
HTTPCORE-458: Validate port values. Add checks and Javadoc.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792683 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 8faaa62ada27d622f40fc8d5b92b8e2c9ec7adae
Parents: 0ee0338
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 23:22:27 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 23:22:27 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/http/HttpHost.java | 37 ++++++++++++++++++--
 1 file changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/8faaa62a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
index 93cc8fc..405933f 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
@@ -69,12 +69,17 @@ public final class HttpHost implements NamedEndpoint, Serializable {
 
     private final InetAddress address;
 
+    /**
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
+     */
     private HttpHost(final String hostname, final int port, final String scheme, final boolean internal) {
         super();
         this.hostname = hostname;
         this.lcHostname = hostname;
         this.schemeName = scheme;
-        this.port = port;
+        this.port = Ports.check(port);
         this.address = null;
     }
 
@@ -87,6 +92,10 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @param scheme    the name of the scheme.
      *                  {@code null} indicates the
      *                  {@link #DEFAULT_SCHEME_NAME default scheme}
+     *
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      */
     public HttpHost(final String hostname, final int port, final String scheme) {
         super();
@@ -97,7 +106,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
         } else {
             this.schemeName = DEFAULT_SCHEME_NAME;
         }
-        this.port = port;
+        this.port = Ports.check(port);
         this.address = null;
     }
 
@@ -107,6 +116,10 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @param hostname  the hostname (IP or DNS name)
      * @param port      the port number.
      *                  {@code -1} indicates the scheme default port.
+     *
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      */
     public HttpHost(final String hostname, final int port) {
         this(hostname, port, null);
@@ -119,6 +132,10 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @param scheme    the name of the scheme.
      *                  {@code null} indicates the
      *                  {@link #DEFAULT_SCHEME_NAME default scheme}
+     *
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      */
     public HttpHost(final String hostname, final String scheme) {
         this(hostname, -1, scheme);
@@ -164,6 +181,10 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * Creates {@code HttpHost} instance with the default scheme and port and the given hostname.
      *
      * @param hostname  the hostname (IP or DNS name)
+     *
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      */
     public HttpHost(final String hostname) {
         this(hostname, -1, null);
@@ -182,6 +203,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @throws IllegalArgumentException
      *             If the port parameter is outside the specified range of valid port values, which is between 0 and
      *             65535, inclusive. {@code -1} indicates the scheme default port.
+     *
      * @since 4.3
      */
     public HttpHost(final InetAddress address, final int port, final String scheme) {
@@ -202,6 +224,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @throws IllegalArgumentException
      *             If the port parameter is outside the specified range of valid port values, which is between 0 and
      *             65535, inclusive. {@code -1} indicates the scheme default port.
+     *
      * @since 4.4
      */
     public HttpHost(final InetAddress address, final String hostname, final int port, final String scheme) {
@@ -228,6 +251,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @throws IllegalArgumentException
      *             If the port parameter is outside the specified range of valid port values, which is between 0 and
      *             65535, inclusive. {@code -1} indicates the scheme default port.
+     *
      * @since 4.3
      */
     public HttpHost(final InetAddress address, final int port) {
@@ -243,6 +267,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @throws IllegalArgumentException
      *             If the port parameter is outside the specified range of valid port values, which is between 0 and
      *             65535, inclusive. {@code -1} indicates the scheme default port.
+     *
      * @since 4.3
      */
     public HttpHost(final InetAddress address) {
@@ -250,6 +275,10 @@ public final class HttpHost implements NamedEndpoint, Serializable {
     }
 
     /**
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
+     *
      * @since 5.0
      */
     public HttpHost(final NamedEndpoint namedEndpoint, final String scheme) {
@@ -257,6 +286,10 @@ public final class HttpHost implements NamedEndpoint, Serializable {
     }
 
     /**
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
+     *
      * @since 5.0
      */
     public HttpHost(final URIAuthority authority) {


[23/50] [abbrv] httpcomponents-core git commit: Javaodc: Remove extra blank line.

Posted by ol...@apache.org.
Javaodc: Remove extra blank line.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792541 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: e2bdb5abbe4b86290caee147b7ebc71d2a73f54b
Parents: 6f1173c
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon Apr 24 20:05:54 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon Apr 24 20:05:54 2017 +0000

----------------------------------------------------------------------
 httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e2bdb5ab/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
index dcce101..5c74d91 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
@@ -44,7 +44,6 @@ import org.apache.hc.core5.util.TextUtils;
  * Holds all of the variables needed to describe an HTTP connection to a host.
  * This includes remote host name, port and scheme.
  *
- *
  * @since 4.0
  */
 @Contract(threading = ThreadingBehavior.IMMUTABLE)


[49/50] [abbrv] httpcomponents-core git commit: Fixed delineation of 200 status message in response to CONNECT method

Posted by ol...@apache.org.
Fixed delineation of 200 status message in response to CONNECT method

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1794176 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: e1c42bf35bb9e6291d212648876c926002525211
Parents: 96b9e84
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Sat May 6 19:33:22 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Sat May 6 19:33:22 2017 +0000

----------------------------------------------------------------------
 .../http/impl/DefaultConnectionReuseStrategy.java | 16 ++++------------
 .../http/impl/nio/ClientHttp1StreamDuplexer.java  |  9 ++-------
 .../http/impl/nio/ClientHttp1StreamHandler.java   |  4 ++--
 .../hc/core5/http/message/MessageSupport.java     | 18 ++++++++++++++++++
 4 files changed, 26 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e1c42bf3/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
index 8aaa4f5..27c2fe2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/DefaultConnectionReuseStrategy.java
@@ -37,10 +37,10 @@ import org.apache.hc.core5.http.HeaderElements;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.HttpVersion;
 import org.apache.hc.core5.http.ProtocolVersion;
 import org.apache.hc.core5.http.message.BasicTokenIterator;
+import org.apache.hc.core5.http.message.MessageSupport;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.util.Args;
 
@@ -97,7 +97,9 @@ public class DefaultConnectionReuseStrategy implements ConnectionReuseStrategy {
                 return false;
             }
         } else {
-            if (canResponseHaveBody(request, response) && response.containsHeaders(HttpHeaders.CONTENT_LENGTH) != 1) {
+            final String method = request != null ? request.getMethod() : null;
+            if (MessageSupport.canResponseHaveBody(method, response)
+                    && response.containsHeaders(HttpHeaders.CONTENT_LENGTH) != 1) {
                 return false;
             }
         }
@@ -134,14 +136,4 @@ public class DefaultConnectionReuseStrategy implements ConnectionReuseStrategy {
         return ver.greaterEquals(HttpVersion.HTTP_1_1);
     }
 
-    private boolean canResponseHaveBody(final HttpRequest request, final HttpResponse response) {
-        if (request != null && request.getMethod().equalsIgnoreCase("HEAD")) {
-            return false;
-        }
-        final int status = response.getCode();
-        return status >= HttpStatus.SC_SUCCESS
-            && status != HttpStatus.SC_NO_CONTENT
-            && status != HttpStatus.SC_NOT_MODIFIED;
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e1c42bf3/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
index 32100a2..f5a55fc 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
@@ -42,7 +42,6 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
-import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.LengthRequiredException;
 import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
@@ -52,6 +51,7 @@ import org.apache.hc.core5.http.impl.ConnectionListener;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.DefaultContentLengthStrategy;
 import org.apache.hc.core5.http.impl.Http1StreamListener;
+import org.apache.hc.core5.http.message.MessageSupport;
 import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.nio.CapacityChannel;
 import org.apache.hc.core5.http.nio.ContentDecoder;
@@ -268,12 +268,7 @@ public class ClientHttp1StreamDuplexer extends AbstractHttp1StreamDuplexer<HttpR
         if (incoming == null) {
             throw new HttpException("Unexpected response");
         }
-
-        if (incoming.isHeadRequest()) {
-            return null;
-        }
-        final int status = response.getCode();
-        if (status < HttpStatus.SC_SUCCESS || status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_NOT_MODIFIED) {
+        if (!MessageSupport.canResponseHaveBody(incoming.getRequestMethod(), response)) {
             return null;
         }
         final long len = incomingContentStrategy.determineLength(response);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e1c42bf3/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
index b5eb490..c5394a2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
@@ -125,8 +125,8 @@ class ClientHttp1StreamHandler implements ResourceHolder {
         return requestState == MessageState.COMPLETE && responseState == MessageState.COMPLETE;
     }
 
-    boolean isHeadRequest() {
-        return committedRequest != null && "HEAD".equalsIgnoreCase(committedRequest.getMethod());
+    String getRequestMethod() {
+        return committedRequest != null ? committedRequest.getMethod() : null;
     }
 
     boolean isOutputReady() {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e1c42bf3/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java b/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
index 2d24b26..91226bd 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java
@@ -39,6 +39,8 @@ import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HeaderElement;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpMessage;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.MessageHeaders;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.CharArrayBuffer;
@@ -169,4 +171,20 @@ public class MessageSupport {
         return BasicHeaderValueParser.INSTANCE.parseElements(value, cursor);
     }
 
+    /**
+     * @since  5.0
+     */
+    public static boolean canResponseHaveBody(final String method, final HttpResponse response) {
+        if ("HEAD".equalsIgnoreCase(method)) {
+            return false;
+        }
+        final int status = response.getCode();
+        if ("CONNECT".equalsIgnoreCase(method) && status == HttpStatus.SC_OK) {
+            return false;
+        }
+        return status >= HttpStatus.SC_SUCCESS
+                && status != HttpStatus.SC_NO_CONTENT
+                && status != HttpStatus.SC_NOT_MODIFIED;
+    }
+
 }


[21/50] [abbrv] httpcomponents-core git commit: Fix Javadoc.

Posted by ol...@apache.org.
Fix Javadoc.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792539 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 4c3fd51a05de974abfa08bd0e37dca1c9997a3e4
Parents: 401ab24
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon Apr 24 19:46:20 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon Apr 24 19:46:20 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/http/protocol/LookupRegistry.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/4c3fd51a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/LookupRegistry.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/LookupRegistry.java b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/LookupRegistry.java
index 17b0021..d37b2c0 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/LookupRegistry.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/LookupRegistry.java
@@ -44,10 +44,10 @@ public interface LookupRegistry<T> {
     /**
      * Looks up an object matching the given request path.
      *
-     * @param path the request path
+     * @param value the request path
      * @return object or {@code null} if no match is found.
      */
-    T lookup(String string);
+    T lookup(String value);
 
     /**
      * Removes registered object, if exists, for the given pattern.


[42/50] [abbrv] httpcomponents-core git commit: Add parse methods in TimeValue and Timeout to consume what toString() produces. Also allow a TimeValue to be easily converted to a Timeout with the new toTimeout() method.

Posted by ol...@apache.org.
Add parse methods in TimeValue and Timeout to consume what toString() produces. Also allow a TimeValue to be easily converted to a Timeout with the new toTimeout() method.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793400 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: aa9928dcddcf32c947c0e0ed2e960a9f9bd9aec9
Parents: 3ee0f67
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon May 1 19:13:18 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon May 1 19:13:18 2017 +0000

----------------------------------------------------------------------
 .../org/apache/hc/core5/util/TimeValue.java     | 32 ++++++++++++++++++--
 .../java/org/apache/hc/core5/util/Timeout.java  | 19 +++++++++++-
 .../org/apache/hc/core5/util/TestTimeValue.java | 10 ++++++
 .../org/apache/hc/core5/util/TestTimeout.java   | 16 ++++++++++
 4 files changed, 73 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aa9928dc/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
index d0ef665..877a92b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
@@ -27,6 +27,9 @@
 
 package org.apache.hc.core5.util;
 
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Locale;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.core5.annotation.Contract;
@@ -105,7 +108,8 @@ public class TimeValue {
     }
 
     /**
-     * Returns the given {@code timeValue} if it is not {@code null}, if {@code null} then returns {@link #ZERO_MILLISECONDS}.
+     * Returns the given {@code timeValue} if it is not {@code null}, if {@code null} then returns
+     * {@link #ZERO_MILLISECONDS}.
      *
      * @param timeValue
      *            may be {@code null}
@@ -164,6 +168,24 @@ public class TimeValue {
         return of(seconds, TimeUnit.SECONDS);
     }
 
+    /**
+     * Parses a TimeValue in the format {@code <Integer><SPACE><TimeUnit>}, for example {@code "1,200 MILLISECONDS"}
+     * 
+     * @param value
+     *            the TimeValue to parse
+     * @return a new TimeValue
+     * @throws ParseException
+     *             if the number cannot be parsed
+     */
+    public static TimeValue parse(String value) throws ParseException {
+        String split[] = value.split("\\s+");
+        if (split.length < 2) {
+            throw new IllegalArgumentException(String.format("Expected format for <Integer><SPACE><TimeUnit>: ", value));
+        }
+        return TimeValue.of(NumberFormat.getInstance().parse(split[0]).longValue(),
+                TimeUnit.valueOf(split[1].trim().toUpperCase(Locale.ROOT)));
+    }
+
     private final long duration;
 
     private final TimeUnit timeUnit;
@@ -185,8 +207,7 @@ public class TimeValue {
         }
         if (obj instanceof TimeValue) {
             final TimeValue that = (TimeValue) obj;
-            return this.duration == that.duration &&
-                    LangUtils.equals(this.timeUnit, that.timeUnit);
+            return this.duration == that.duration && LangUtils.equals(this.timeUnit, that.timeUnit);
         }
         return false;
     }
@@ -259,4 +280,9 @@ public class TimeValue {
     public String toString() {
         return String.format("%,d %s", Long.valueOf(duration), timeUnit);
     }
+
+    public Timeout toTimeout() {
+        return Timeout.of(duration, timeUnit);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aa9928dc/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
index 4cb3c38..5b1f3b8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
@@ -27,6 +27,9 @@
 
 package org.apache.hc.core5.util;
 
+import java.text.NumberFormat;
+import java.text.ParseException;
+import java.util.Locale;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.core5.annotation.Contract;
@@ -40,6 +43,8 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class Timeout extends TimeValue {
 
+    public static final Timeout ZERO_MILLISECONDS = Timeout.of(0, TimeUnit.MILLISECONDS);
+
     /**
      * A disabled timeout represented as 0 {@code MILLISECONDS}.
      */
@@ -145,7 +150,19 @@ public class Timeout extends TimeValue {
         return of(seconds, TimeUnit.SECONDS);
     }
 
-
+    /**
+     * Parses a Timeout in the format {@code <Integer><SPACE><TimeUnit>}, for example {@code "1,200 MILLISECONDS"}
+     * 
+     * @param value
+     *            the TimeValue to parse
+     * @return a new TimeValue
+     * @throws ParseException
+     *             if the number cannot be parsed
+     */
+    public static Timeout parse(String value) throws ParseException {
+        return TimeValue.parse(value).toTimeout();
+    }
+    
     private static long validateDuration(final long duration) {
         if (duration < INT_UNDEFINED) {
             throw new IllegalArgumentException("Duration may not be less than " + INT_UNDEFINED);

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aa9928dc/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
index 21200bf..7b08112 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
@@ -27,6 +27,7 @@
 
 package org.apache.hc.core5.util;
 
+import java.text.ParseException;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.Assert;
@@ -144,4 +145,13 @@ public class TestTimeValue {
         Assert.assertEquals("0 MILLISECONDS", TimeValue.ZERO_MILLISECONDS.toString());
     }
 
+    @Test
+    public void testFromString() throws ParseException {
+        Assert.assertEquals(TimeValue.ofSeconds(Long.MAX_VALUE), TimeValue.parse("9,223,372,036,854,775,807 SECONDS"));
+        Assert.assertEquals(TimeValue.ofSeconds(Long.MAX_VALUE), TimeValue.parse("9,223,372,036,854,775,807 Seconds"));
+        Assert.assertEquals(TimeValue.ofSeconds(Long.MAX_VALUE), TimeValue.parse("9,223,372,036,854,775,807  Seconds"));
+        Assert.assertEquals(TimeValue.ofSeconds(Long.MAX_VALUE), TimeValue.parse("9,223,372,036,854,775,807\tSeconds"));
+        Assert.assertEquals(TimeValue.ZERO_MILLISECONDS, TimeValue.parse("0 MILLISECONDS"));
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/aa9928dc/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
index 0fc3740..9dec674 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
@@ -27,6 +27,7 @@
 
 package org.apache.hc.core5.util;
 
+import java.text.ParseException;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.Assert;
@@ -165,4 +166,19 @@ public class TestTimeout {
         Assert.assertFalse(Timeout.UNDEFINED_SECONDS.isDisabled());
     }
 
+    @Test
+    public void testToString() {
+        Assert.assertEquals("9,223,372,036,854,775,807 SECONDS", Timeout.ofSeconds(Long.MAX_VALUE).toString());
+        Assert.assertEquals("0 MILLISECONDS", Timeout.ZERO_MILLISECONDS.toString());
+    }
+
+    @Test
+    public void testFromString() throws ParseException {
+        Assert.assertEquals(Timeout.ofSeconds(Long.MAX_VALUE), Timeout.parse("9,223,372,036,854,775,807 SECONDS"));
+        Assert.assertEquals(Timeout.ofSeconds(Long.MAX_VALUE), Timeout.parse("9,223,372,036,854,775,807 Seconds"));
+        Assert.assertEquals(Timeout.ofSeconds(Long.MAX_VALUE), Timeout.parse("9,223,372,036,854,775,807  Seconds"));
+        Assert.assertEquals(Timeout.ofSeconds(Long.MAX_VALUE), Timeout.parse("9,223,372,036,854,775,807\tSeconds"));
+        Assert.assertEquals(Timeout.ZERO_MILLISECONDS, Timeout.parse("0 MILLISECONDS"));
+    }
+
 }


[03/50] [abbrv] httpcomponents-core git commit: Corrected termination of pending commands by HTTP/1.1 stream duplexer

Posted by ol...@apache.org.
Corrected termination of pending commands by HTTP/1.1 stream duplexer

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791943 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 9ae9ade8931014e10f3cdb8677507f3d274c357e
Parents: 572bbd3
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Apr 19 16:39:53 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Apr 19 16:39:53 2017 +0000

----------------------------------------------------------------------
 .../nio/AbstractHttp2StreamMultiplexer.java     |  1 +
 .../impl/nio/AbstractHttp1StreamDuplexer.java   | 30 +++++++++++++-------
 2 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9ae9ade8/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
index 7a53353..61c7fb9 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/nio/AbstractHttp2StreamMultiplexer.java
@@ -647,6 +647,7 @@ abstract class AbstractHttp2StreamMultiplexer implements HttpConnection {
                         final ExecutionCommand executionCommand = (ExecutionCommand) command;
                         final AsyncClientExchangeHandler exchangeHandler = executionCommand.getExchangeHandler();
                         exchangeHandler.failed(cause);
+                        exchangeHandler.releaseResources();
                     } else {
                         command.cancel();
                     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9ae9ade8/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
index 176350c..bbda5c8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
@@ -57,6 +57,7 @@ import org.apache.hc.core5.http.impl.BasicHttpConnectionMetrics;
 import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
 import org.apache.hc.core5.http.impl.CharCodingSupport;
 import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.nio.AsyncClientExchangeHandler;
 import org.apache.hc.core5.http.nio.CapacityChannel;
 import org.apache.hc.core5.http.nio.ContentDecoder;
 import org.apache.hc.core5.http.nio.ContentEncoder;
@@ -366,14 +367,13 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
         }
         if (connState.compareTo(ConnectionState.SHUTDOWN) >= 0) {
             ioSession.close();
-            cancelPendingCommands();
             releaseResources();
         }
     }
 
     public final void onTimeout() throws IOException, HttpException {
         if (!handleTimeout()) {
-            shutdownSession(new SocketTimeoutException());
+            onException(new SocketTimeoutException());
         }
     }
 
@@ -383,6 +383,20 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
         }
         try {
             shutdownSession(ex);
+            for (;;) {
+                final Command command = ioSession.getCommand();
+                if (command != null) {
+                    if (command instanceof ExecutionCommand) {
+                        final AsyncClientExchangeHandler exchangeHandler = ((ExecutionCommand) command).getExchangeHandler();
+                        exchangeHandler.failed(ex);
+                        exchangeHandler.releaseResources();
+                    } else {
+                        command.cancel();
+                    }
+                } else {
+                    break;
+                }
+            }
         } catch (IOException ex2) {
             if (connectionListener != null) {
                 connectionListener.onError(this, ex2);
@@ -391,15 +405,7 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
     }
 
     public final void onDisconnect() {
-        cancelPendingCommands();
         disconnected();
-        releaseResources();
-        if (connectionListener != null) {
-            connectionListener.onDisconnect(this);
-        }
-    }
-
-    private void cancelPendingCommands() {
         for (;;) {
             final Command command = ioSession.getCommand();
             if (command != null) {
@@ -408,6 +414,10 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
                 break;
             }
         }
+        releaseResources();
+        if (connectionListener != null) {
+            connectionListener.onDisconnect(this);
+        }
     }
 
     void requestShutdown(final ShutdownType shutdownType) {


[18/50] [abbrv] httpcomponents-core git commit: Added annotation of internal APIs

Posted by ol...@apache.org.
Added annotation of internal APIs

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792527 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 4d7fb34fb3cfe4c952b51a047112ce85a1ca18de
Parents: af44438
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Apr 24 18:11:03 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Apr 24 18:11:03 2017 +0000

----------------------------------------------------------------------
 .../apache/hc/core5/annotation/Internal.java    | 43 ++++++++++++++++++++
 1 file changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/4d7fb34f/httpcore5/src/main/java/org/apache/hc/core5/annotation/Internal.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/annotation/Internal.java b/httpcore5/src/main/java/org/apache/hc/core5/annotation/Internal.java
new file mode 100644
index 0000000..d212748
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/annotation/Internal.java
@@ -0,0 +1,43 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The package, class or method to which this annotation is applied is marked as internal
+ * and its use ought to be avoided.
+ */
+@Documented
+@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.PACKAGE})
+@Retention(RetentionPolicy.CLASS)
+public @interface Internal {
+}


[48/50] [abbrv] httpcomponents-core git commit: [HTTPCORE-450] Add a Provider parameter in SSLContextBuilder. Add SSLContextBuilder.setProvider(String).

Posted by ol...@apache.org.
[HTTPCORE-450] Add a Provider parameter in SSLContextBuilder. Add SSLContextBuilder.setProvider(String).

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793920 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 96b9e847ae1106cc5e316af854ed192e6bbda657
Parents: 1484c67
Author: Gary D. Gregory <gg...@apache.org>
Authored: Thu May 4 22:43:15 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Thu May 4 22:43:15 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/ssl/SSLContextBuilder.java |  6 ++++++
 .../org/apache/hc/core5/ssl/TestSSLContextBuilder.java  | 12 ++++++++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/96b9e847/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
index 5797fd2..0b5cd78 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
@@ -41,6 +41,7 @@ import java.security.Principal;
 import java.security.PrivateKey;
 import java.security.Provider;
 import java.security.SecureRandom;
+import java.security.Security;
 import java.security.UnrecoverableKeyException;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
@@ -118,6 +119,11 @@ public class SSLContextBuilder {
         return this;
     }
 
+    public SSLContextBuilder setProvider(final String name) {
+        this.provider = Security.getProvider(name);
+        return this;
+    }
+
     public SSLContextBuilder setSecureRandom(final SecureRandom secureRandom) {
         this.secureRandom = secureRandom;
         return this;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/96b9e847/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java b/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
index 5ceeaa9..38b1a74 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/ssl/TestSSLContextBuilder.java
@@ -623,4 +623,16 @@ public class TestSSLContextBuilder {
         Assert.assertTrue(sslContext.getProvider().getName().equals("SunJSSE"));
     }
 
+    @Test
+    public void testBuildWithProviderName() throws Exception {
+        final URL resource1 = getClass().getResource("/test-server.keystore");
+        final String storePassword = "nopassword";
+        final String keyPassword = "nopassword";
+        final SSLContext sslContext=SSLContextBuilder.create()
+                .setProvider("SunJSSE")
+                .loadKeyMaterial(resource1, storePassword.toCharArray(), keyPassword.toCharArray())
+                .build();
+        Assert.assertTrue(sslContext.getProvider().getName().equals("SunJSSE"));
+    }
+
 }


[09/50] [abbrv] httpcomponents-core git commit: Fix Checkstyle errors.

Posted by ol...@apache.org.
Fix Checkstyle errors.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792145 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: fe9b6f4dec5a65e03478aac42f80005610586b81
Parents: 7377147
Author: Gary D. Gregory <gg...@apache.org>
Authored: Thu Apr 20 20:21:53 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Thu Apr 20 20:21:53 2017 +0000

----------------------------------------------------------------------
 .../org/apache/hc/core5/util/TimeValue.java     |  2 +-
 .../java/org/apache/hc/core5/util/Timeout.java  | 20 ++++++++++----------
 2 files changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fe9b6f4d/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
index cd7a271..1ba6c70 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
@@ -117,7 +117,7 @@ public class TimeValue {
 
     /**
      * Creates a TimeValue.
-     * 
+     *
      * @param duration
      *            the time duration in the given {@code timeUnit}.
      * @param timeUnit

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fe9b6f4d/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
index f7a4d5d..a7ee542 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
@@ -57,7 +57,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Creates a Timeout.
-     * 
+     *
      * @param duration
      *            the time duration in the given {@code timeUnit}.
      * @param timeUnit
@@ -70,7 +70,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Creates a Timeout.
-     * 
+     *
      * @param days
      *            the duration in days and the given {@code timeUnit}.
      * @return a Timeout
@@ -81,7 +81,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Creates a Timeout.
-     * 
+     *
      * @param hours
      *            the duration in hours and the given {@code timeUnit}.
      * @return a Timeout
@@ -92,7 +92,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Creates a Timeout.
-     * 
+     *
      * @param milliseconds
      *            the duration in milliseconds and the given {@code timeUnit}.
      * @return a Timeout
@@ -103,7 +103,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Creates a Timeout.
-     * 
+     *
      * @param minutes
      *            the duration in minutes and the given {@code timeUnit}.
      * @return a Timeout
@@ -114,7 +114,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Creates a Timeout.
-     * 
+     *
      * @param seconds
      *            the duration in seconds and the given {@code timeUnit}.
      * @return a Timeout
@@ -136,7 +136,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Whether this timeout is disabled.
-     * 
+     *
      * @return Whether this timeout is disabled.
      */
     public boolean isDisabled() {
@@ -145,7 +145,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Whether this timeout is enabled.
-     * 
+     *
      * @return Whether this timeout is disabled.
      */
     public boolean isEnabled() {
@@ -154,7 +154,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Whether this timeout is undefined.
-     * 
+     *
      * @return Whether this timeout is undefined.
      */
     public boolean isUndefinedMilliseconds() {
@@ -163,7 +163,7 @@ public class Timeout extends TimeValue {
 
     /**
      * Whether this timeout is undefined.
-     * 
+     *
      * @return Whether this timeout is undefined.
      */
     public boolean isUndefinedSeconds() {


[24/50] [abbrv] httpcomponents-core git commit: Less verbose.

Posted by ol...@apache.org.
Less verbose.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792549 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: fee8ab47645cea49c93e8879bd2058989f1bcbc1
Parents: e2bdb5a
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon Apr 24 21:38:58 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon Apr 24 21:38:58 2017 +0000

----------------------------------------------------------------------
 .../org/apache/hc/core5/http/protocol/RequestTargetHost.java  | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fee8ab47/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java
index a0743b9..87f957e 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/protocol/RequestTargetHost.java
@@ -74,10 +74,9 @@ public class RequestTargetHost implements HttpRequestInterceptor {
                     return;
                 }
                 throw new ProtocolException("Target host is unknown");
-            } else {
-                if (authority.getUserInfo() != null) {
-                    authority = new URIAuthority(authority.getHostName(), authority.getPort());
-                }
+            }
+            if (authority.getUserInfo() != null) {
+                authority = new URIAuthority(authority.getHostName(), authority.getPort());
             }
             request.addHeader(HttpHeaders.HOST, authority);
         }


[30/50] [abbrv] httpcomponents-core git commit: HTTPCORE-458: Validate port values. First use case.

Posted by ol...@apache.org.
HTTPCORE-458: Validate port values. First use case.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792674 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: eb2c139390c5ff69cfc36f083c6760c5e38b2db0
Parents: f29e5fe
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 22:50:15 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 22:50:15 2017 +0000

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               |  5 +-
 .../java/org/apache/hc/core5/http/HttpHost.java |  3 +-
 .../java/org/apache/hc/core5/net/Ports.java     | 68 ++++++++++++++++++++
 3 files changed, 73 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/eb2c1393/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 0579ff5..7c1c829 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -89,8 +89,9 @@ Changelog
 * Non-blocking connection initializer to support multi-homed remote endpoints.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 
-
-
+* HTTPCORE-458: Validate port values
+  Contributed by Gary Gregory <ggregory at apache.org>
+  
 
 Release 5.0-ALPHA2
 -------------------

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/eb2c1393/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
index 5c74d91..94d37c7 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
@@ -35,6 +35,7 @@ import java.util.Locale;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.net.NamedEndpoint;
+import org.apache.hc.core5.net.Ports;
 import org.apache.hc.core5.net.URIAuthority;
 import org.apache.hc.core5.util.Args;
 import org.apache.hc.core5.util.LangUtils;
@@ -207,7 +208,7 @@ public final class HttpHost implements NamedEndpoint, Serializable {
         } else {
             this.schemeName = DEFAULT_SCHEME_NAME;
         }
-        this.port = port;
+        this.port = Ports.check(port);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/eb2c1393/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java b/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java
new file mode 100644
index 0000000..156c40f
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java
@@ -0,0 +1,68 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.net;
+
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Port helper methods.
+ *
+ * @since 5.0
+ */
+public class Ports {
+
+    /**
+     * The scheme default port.
+     */
+    public final static int SCHEME_DEFAULT = -1;
+
+    /**
+     * The minimum port value per https://tools.ietf.org/html/rfc6335.
+     */
+    public final static int MIN_VALUE = 0;
+
+    /**
+     * The maxium port value per https://tools.ietf.org/html/rfc6335.
+     */
+    public final static int MAX_VALUE = 65535;
+
+    /**
+     * Checks a port number where {@code -1} indicates the scheme default port.
+     *
+     * @param port
+     *            The port to check where {@code -1} indicates the scheme default port.
+     * @return the port
+     *
+     * @throws IllegalArgumentException
+     *             if the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive.
+     */
+    public static int check(final int port) {
+        return Args.checkRange(port, SCHEME_DEFAULT, MAX_VALUE,
+                "Port number(Use -1 to specify the scheme default port)");
+    }
+}


[44/50] [abbrv] httpcomponents-core git commit: Javadocs.

Posted by ol...@apache.org.
Javadocs.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793821 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: bc75d33a5c879a6bf315517e4fa38d03acc0c117
Parents: 981ad57
Author: Gary D. Gregory <gg...@apache.org>
Authored: Thu May 4 15:12:30 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Thu May 4 15:12:30 2017 +0000

----------------------------------------------------------------------
 .../org/apache/hc/core5/ssl/SSLContextBuilder.java    | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bc75d33a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
index 7fe6120..4300ac7 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
@@ -94,6 +94,20 @@ public class SSLContextBuilder {
         this.trustmanagers = new LinkedHashSet<>();
     }
 
+    /**
+     * Sets the SSLContext algorithm name.
+     * 
+     * @param protocol
+     *            the SSLContext algorithm name of the requested protocol. See
+     *            the SSLContext section in the <a href=
+     *            "https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#SSLContext">Java
+     *            Cryptography Architecture Standard Algorithm Name
+     *            Documentation</a> for more information.
+     * @return this builder
+     * @see <a href=
+     *      "https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#SSLContext">Java
+     *      Cryptography Architecture Standard Algorithm Name Documentation</a>
+     */
     public SSLContextBuilder setProtocol(final String protocol) {
         this.protocol = protocol;
         return this;


[19/50] [abbrv] httpcomponents-core git commit: HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Add missing methods for MICROSECONDS and NANOSECONDS TimeUnits.

Posted by ol...@apache.org.
HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Add missing methods for MICROSECONDS and NANOSECONDS TimeUnits.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792537 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 586bfb7efd41ad3d3d718dfed1c36b1601f03cf6
Parents: 4d7fb34
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon Apr 24 19:39:31 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon Apr 24 19:39:31 2017 +0000

----------------------------------------------------------------------
 .../org/apache/hc/core5/util/TimeValue.java     | 94 +++++++++++---------
 .../org/apache/hc/core5/util/TestTimeValue.java | 79 +++++++++++-----
 2 files changed, 110 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/586bfb7e/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
index 1ba6c70..d0ef665 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
@@ -40,9 +40,9 @@ import org.apache.hc.core5.annotation.ThreadingBehavior;
 @Contract(threading = ThreadingBehavior.IMMUTABLE)
 public class TimeValue {
 
-    static final int UNDEFINED = -1;
-    public static final TimeValue NEG_ONE_MILLISECONDS = TimeValue.of(UNDEFINED, TimeUnit.MILLISECONDS);
-    public static final TimeValue NEG_ONE_SECONDS = TimeValue.of(UNDEFINED, TimeUnit.SECONDS);
+    static final int INT_UNDEFINED = -1;
+    public static final TimeValue NEG_ONE_MILLISECONDS = TimeValue.of(INT_UNDEFINED, TimeUnit.MILLISECONDS);
+    public static final TimeValue NEG_ONE_SECONDS = TimeValue.of(INT_UNDEFINED, TimeUnit.SECONDS);
     public static final TimeValue ZERO_MILLISECONDS = TimeValue.of(0, TimeUnit.MILLISECONDS);
 
     /**
@@ -81,17 +81,6 @@ public class TimeValue {
     }
 
     /**
-     * Returns the given {@code timeValue} if it is not {@code null}, if {@code null} then returns {@link #ZERO_MILLISECONDS}.
-     *
-     * @param timeValue
-     *            may be {@code null}
-     * @return {@code timeValue} or {@link #ZERO_MILLISECONDS}
-     */
-    public static TimeValue defaultsToZeroMillis(final TimeValue timeValue) {
-        return defaultsTo(timeValue, ZERO_MILLISECONDS);
-    }
-
-    /**
      * Returns the given {@code timeValue} if it is not {@code null}, if {@code null} then returns
      * {@link #NEG_ONE_SECONDS}.
      *
@@ -116,6 +105,25 @@ public class TimeValue {
     }
 
     /**
+     * Returns the given {@code timeValue} if it is not {@code null}, if {@code null} then returns {@link #ZERO_MILLISECONDS}.
+     *
+     * @param timeValue
+     *            may be {@code null}
+     * @return {@code timeValue} or {@link #ZERO_MILLISECONDS}
+     */
+    public static TimeValue defaultsToZeroMillis(final TimeValue timeValue) {
+        return defaultsTo(timeValue, ZERO_MILLISECONDS);
+    }
+
+    public static boolean isNonNegative(final TimeValue timeValue) {
+        return timeValue != null && timeValue.getDuration() >= 0;
+    }
+
+    public static boolean isPositive(final TimeValue timeValue) {
+        return timeValue != null && timeValue.getDuration() > 0;
+    }
+
+    /**
      * Creates a TimeValue.
      *
      * @param duration
@@ -136,6 +144,10 @@ public class TimeValue {
         return of(hours, TimeUnit.HOURS);
     }
 
+    public static TimeValue ofMicroseconds(final long microseconds) {
+        return of(microseconds, TimeUnit.MICROSECONDS);
+    }
+
     public static TimeValue ofMillis(final long millis) {
         return of(millis, TimeUnit.MILLISECONDS);
     }
@@ -144,16 +156,12 @@ public class TimeValue {
         return of(minutes, TimeUnit.MINUTES);
     }
 
-    public static TimeValue ofSeconds(final long seconds) {
-        return of(seconds, TimeUnit.SECONDS);
-    }
-
-    public static boolean isPositive(final TimeValue timeValue) {
-        return timeValue != null && timeValue.getDuration() > 0;
+    public static TimeValue ofNanoseconds(final long nanoseconds) {
+        return of(nanoseconds, TimeUnit.NANOSECONDS);
     }
 
-    public static boolean isNonNegative(final TimeValue timeValue) {
-        return timeValue != null && timeValue.getDuration() >= 0;
+    public static TimeValue ofSeconds(final long seconds) {
+        return of(seconds, TimeUnit.SECONDS);
     }
 
     private final long duration;
@@ -170,6 +178,19 @@ public class TimeValue {
         return timeUnit.convert(duration, sourceUnit);
     }
 
+    @Override
+    public boolean equals(final Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof TimeValue) {
+            final TimeValue that = (TimeValue) obj;
+            return this.duration == that.duration &&
+                    LangUtils.equals(this.timeUnit, that.timeUnit);
+        }
+        return false;
+    }
+
     public long getDuration() {
         return duration;
     }
@@ -178,6 +199,14 @@ public class TimeValue {
         return timeUnit;
     }
 
+    @Override
+    public int hashCode() {
+        int hash = LangUtils.HASH_SEED;
+        hash = LangUtils.hashCode(hash, Long.valueOf(duration));
+        hash = LangUtils.hashCode(hash, timeUnit);
+        return hash;
+    }
+
     public void sleep() throws InterruptedException {
         timeUnit.sleep(duration);
     }
@@ -227,27 +256,6 @@ public class TimeValue {
     }
 
     @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof TimeValue) {
-            final TimeValue that = (TimeValue) obj;
-            return this.duration == that.duration &&
-                    LangUtils.equals(this.timeUnit, that.timeUnit);
-        }
-        return false;
-    }
-
-    @Override
-    public int hashCode() {
-        int hash = LangUtils.HASH_SEED;
-        hash = LangUtils.hashCode(hash, Long.valueOf(duration));
-        hash = LangUtils.hashCode(hash, timeUnit);
-        return hash;
-    }
-
-    @Override
     public String toString() {
         return String.format("%,d %s", Long.valueOf(duration), timeUnit);
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/586bfb7e/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
index 9a34e40..87b27b8 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
@@ -34,10 +34,6 @@ import org.junit.Test;
 
 public class TestTimeValue {
 
-    private void checkToSeconds(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toSeconds(value), TimeValue.of(value, timeUnit).toSeconds());
-    }
-
     private void checkToDays(final long value, final TimeUnit timeUnit) {
         Assert.assertEquals(timeUnit.toDays(value), TimeValue.of(value, timeUnit).toDays());
     }
@@ -46,22 +42,38 @@ public class TestTimeValue {
         Assert.assertEquals(timeUnit.toHours(value), TimeValue.of(value, timeUnit).toHours());
     }
 
-    private void checkToMinutes(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toMinutes(value), TimeValue.of(value, timeUnit).toMinutes());
+    private void checkToMicros(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toMicros(value), TimeValue.of(value, timeUnit).toMicros());
     }
 
     private void checkToMillis(final long value, final TimeUnit timeUnit) {
         Assert.assertEquals(timeUnit.toMillis(value), TimeValue.of(value, timeUnit).toMillis());
     }
 
-    private void checkToMicros(final long value, final TimeUnit timeUnit) {
-        Assert.assertEquals(timeUnit.toMicros(value), TimeValue.of(value, timeUnit).toMicros());
+    private void checkToMinutes(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toMinutes(value), TimeValue.of(value, timeUnit).toMinutes());
     }
 
     private void checkToNanos(final long value, final TimeUnit timeUnit) {
         Assert.assertEquals(timeUnit.toNanos(value), TimeValue.of(value, timeUnit).toNanos());
     }
 
+    private void checkToSeconds(final long value, final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit.toSeconds(value), TimeValue.of(value, timeUnit).toSeconds());
+    }
+
+    private void test(final long value) {
+        for (final TimeUnit timeUnit : TimeUnit.values()) {
+            checkToDays(value, timeUnit);
+            checkToHours(value, timeUnit);
+            checkToMinutes(value, timeUnit);
+            checkToSeconds(value, timeUnit);
+            checkToMillis(value, timeUnit);
+            checkToMicros(value, timeUnit);
+            checkToNanos(value, timeUnit);
+        }
+    }
+
     @Test
     public void test0() {
         test(0);
@@ -72,9 +84,43 @@ public class TestTimeValue {
         test(1);
     }
 
+    private void testFactory(final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit, TimeValue.of(1, timeUnit).getTimeUnit());
+    }
+
     @Test
-    public void testNegative1() {
-        test(-1);
+    public void testFactoryForDays() {
+        testFactory(TimeUnit.DAYS);
+    }
+
+    @Test
+    public void testFactoryForHours() {
+        testFactory(TimeUnit.HOURS);
+    }
+
+    @Test
+    public void testFactoryForMicroseconds() {
+        testFactory(TimeUnit.MICROSECONDS);
+    }
+
+    @Test
+    public void testFactoryForMillisseconds() {
+        testFactory(TimeUnit.MILLISECONDS);
+    }
+
+    @Test
+    public void testFactoryForMinutes() {
+        testFactory(TimeUnit.MINUTES);
+    }
+
+    @Test
+    public void testFactoryForNanoseconds() {
+        testFactory(TimeUnit.NANOSECONDS);
+    }
+
+    @Test
+    public void testFactoryForSeconds() {
+        testFactory(TimeUnit.SECONDS);
     }
 
     @Test
@@ -87,16 +133,9 @@ public class TestTimeValue {
         test(Long.MAX_VALUE);
     }
 
-    private void test(final long value) {
-        for (final TimeUnit timeUnit : TimeUnit.values()) {
-            checkToDays(value, timeUnit);
-            checkToHours(value, timeUnit);
-            checkToMinutes(value, timeUnit);
-            checkToSeconds(value, timeUnit);
-            checkToMillis(value, timeUnit);
-            checkToMicros(value, timeUnit);
-            checkToNanos(value, timeUnit);
-        }
+    @Test
+    public void testNegative1() {
+        test(-1);
     }
 
 }


[27/50] [abbrv] httpcomponents-core git commit: Fix Checkstyle error.

Posted by ol...@apache.org.
Fix Checkstyle error.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792664 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 0346029b0cd79b4d4e3e42f92f6fc69cbecc1a6e
Parents: ffaafb7
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 21:57:13 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 21:57:13 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/0346029b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java
index 78f07a9..21f12f5 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java
@@ -211,7 +211,7 @@ public class TestEntityUtils {
             final String s = EntityUtils.toString(httpentity, "ISO-8859-1");
             Assert.assertEquals(content, s);
         }}
-    
+
     @Test
     public void testContentWithInvalidContentTypeToString() throws Exception {
         final String content = constructString(RUSSIAN_HELLO);


[20/50] [abbrv] httpcomponents-core git commit: [HTTPCORE-454] Add a Timeout class that extends TimeValue. Add missing methods for MICROSECONDS and NANOSECONDS TimeUnits.

Posted by ol...@apache.org.
[HTTPCORE-454] Add a Timeout class that extends TimeValue. Add missing methods for MICROSECONDS and NANOSECONDS TimeUnits.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792538 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 401ab2497bee953f988138d1ab0d493b29930fd3
Parents: 586bfb7
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon Apr 24 19:39:59 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon Apr 24 19:39:59 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/util/Timeout.java  | 35 +++++++++++++++---
 .../org/apache/hc/core5/util/TestTimeout.java   | 39 ++++++++++++++++++++
 2 files changed, 68 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/401ab249/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
index a7ee542..4cb3c38 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
@@ -48,12 +48,12 @@ public class Timeout extends TimeValue {
     /**
      * An undefined timeout represented as -1 {@code MILLISECONDS}.
      */
-    public static final Timeout UNDEFINED_MILLISECONDS = new Timeout(UNDEFINED, TimeUnit.MILLISECONDS);
+    public static final Timeout UNDEFINED_MILLISECONDS = new Timeout(INT_UNDEFINED, TimeUnit.MILLISECONDS);
 
     /**
      * An undefined timeout represented as -1 {@code SECONDS}.
      */
-    public static final Timeout UNDEFINED_SECONDS = new Timeout(UNDEFINED, TimeUnit.SECONDS);
+    public static final Timeout UNDEFINED_SECONDS = new Timeout(INT_UNDEFINED, TimeUnit.SECONDS);
 
     /**
      * Creates a Timeout.
@@ -93,6 +93,17 @@ public class Timeout extends TimeValue {
     /**
      * Creates a Timeout.
      *
+     * @param microseconds
+     *            the duration in seconds and the given {@code timeUnit}.
+     * @return a Timeout
+     */
+    public static Timeout ofMicroseconds(final long microseconds) {
+        return of(microseconds, TimeUnit.MICROSECONDS);
+    }
+
+    /**
+     * Creates a Timeout.
+     *
      * @param milliseconds
      *            the duration in milliseconds and the given {@code timeUnit}.
      * @return a Timeout
@@ -115,6 +126,17 @@ public class Timeout extends TimeValue {
     /**
      * Creates a Timeout.
      *
+     * @param nanoseconds
+     *            the duration in seconds and the given {@code timeUnit}.
+     * @return a Timeout
+     */
+    public static Timeout ofNanoseconds(final long nanoseconds) {
+        return of(nanoseconds, TimeUnit.NANOSECONDS);
+    }
+
+    /**
+     * Creates a Timeout.
+     *
      * @param seconds
      *            the duration in seconds and the given {@code timeUnit}.
      * @return a Timeout
@@ -123,9 +145,10 @@ public class Timeout extends TimeValue {
         return of(seconds, TimeUnit.SECONDS);
     }
 
+
     private static long validateDuration(final long duration) {
-        if (duration < UNDEFINED) {
-            throw new IllegalArgumentException("Duration may not be less than " + UNDEFINED);
+        if (duration < INT_UNDEFINED) {
+            throw new IllegalArgumentException("Duration may not be less than " + INT_UNDEFINED);
         }
         return duration;
     }
@@ -158,7 +181,7 @@ public class Timeout extends TimeValue {
      * @return Whether this timeout is undefined.
      */
     public boolean isUndefinedMilliseconds() {
-        return getDuration() == UNDEFINED && getTimeUnit() == TimeUnit.MILLISECONDS;
+        return getDuration() == INT_UNDEFINED && getTimeUnit() == TimeUnit.MILLISECONDS;
     }
 
     /**
@@ -167,7 +190,7 @@ public class Timeout extends TimeValue {
      * @return Whether this timeout is undefined.
      */
     public boolean isUndefinedSeconds() {
-        return getDuration() == UNDEFINED && getTimeUnit() == TimeUnit.SECONDS;
+        return getDuration() == INT_UNDEFINED && getTimeUnit() == TimeUnit.SECONDS;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/401ab249/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
index 271a348..0fc3740 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeout.java
@@ -92,6 +92,45 @@ public class TestTimeout {
         Assert.assertFalse(Timeout.DISABLED.isUndefinedSeconds());
     }
 
+    private void testFactory(final TimeUnit timeUnit) {
+        Assert.assertEquals(timeUnit, Timeout.of(1, timeUnit).getTimeUnit());
+    }
+
+    @Test
+    public void testFactoryForDays() {
+        testFactory(TimeUnit.DAYS);
+    }
+
+    @Test
+    public void testFactoryForHours() {
+        testFactory(TimeUnit.HOURS);
+    }
+
+    @Test
+    public void testFactoryForMicroseconds() {
+        testFactory(TimeUnit.MICROSECONDS);
+    }
+
+    @Test
+    public void testFactoryForMillisseconds() {
+        testFactory(TimeUnit.MILLISECONDS);
+    }
+
+    @Test
+    public void testFactoryForMinutes() {
+        testFactory(TimeUnit.MINUTES);
+    }
+
+    @Test
+    public void testFactoryForNanoseconds() {
+        testFactory(TimeUnit.NANOSECONDS);
+    }
+
+    @Test
+    public void testFactoryForSeconds() {
+        testFactory(TimeUnit.SECONDS);
+    }
+
     @Test
     public void testMaxInt() {
         test(Integer.MAX_VALUE);


[33/50] [abbrv] httpcomponents-core git commit: HTTPCORE-458: Validate port values. Javadoc.

Posted by ol...@apache.org.
HTTPCORE-458: Validate port values. Javadoc.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792682 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 0ee0338dc091022ce59a33fd5242f250f1436450
Parents: 874ada9
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 23:12:31 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 23:12:31 2017 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/hc/core5/http/HttpHost.java    | 12 ++++++++++++
 1 file changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/0ee0338d/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
index 94d37c7..93cc8fc 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/HttpHost.java
@@ -179,6 +179,9 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      *                  {@code null} indicates the
      *                  {@link #DEFAULT_SCHEME_NAME default scheme}
      *
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      * @since 4.3
      */
     public HttpHost(final InetAddress address, final int port, final String scheme) {
@@ -196,6 +199,9 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      *                  {@code null} indicates the
      *                  {@link #DEFAULT_SCHEME_NAME default scheme}
      *
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      * @since 4.4
      */
     public HttpHost(final InetAddress address, final String hostname, final int port, final String scheme) {
@@ -219,6 +225,9 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      * @param port      the port number.
      *                  {@code -1} indicates the scheme default port.
      *
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      * @since 4.3
      */
     public HttpHost(final InetAddress address, final int port) {
@@ -231,6 +240,9 @@ public final class HttpHost implements NamedEndpoint, Serializable {
      *
      * @param address   the inet address.
      *
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      * @since 4.3
      */
     public HttpHost(final InetAddress address) {


[12/50] [abbrv] httpcomponents-core git commit: HTTP protocol version negotiation

Posted by ol...@apache.org.
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
index 836ccaa..d4333ad 100644
--- a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/H2TlsSupport.java
@@ -27,17 +27,19 @@
 
 package org.apache.hc.core5.http2.ssl;
 
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
 
+import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLParameters;
 
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.net.NamedEndpoint;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
+import org.apache.hc.core5.ssl.ReflectionSupport;
 
 public final class H2TlsSupport {
 
@@ -359,54 +361,43 @@ public final class H2TlsSupport {
         return enabledCiphers != null ? enabledCiphers.toArray(new String[enabledCiphers.size()]) : ciphers;
     }
 
-    static void applyParameter(final SSLParameters sslParameters, final String name, final Class type, final Object value) {
-        try {
-            final Class<? extends SSLParameters> clazz = sslParameters.getClass();
-            final Method method = clazz.getMethod("set" + name, type);
-            method.invoke(sslParameters, value);
-        } catch (final Exception ignore) {
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    static <T> T getParameter(final SSLParameters sslParameters, final String name, final Class<T> resultType) {
-        try {
-            final Class<? extends SSLParameters> clazz = sslParameters.getClass();
-            final Method method = clazz.getMethod("get" + name);
-            return resultType.cast(method.invoke(sslParameters));
-        } catch (final Exception ignore) {
-            return null;
-        }
-    }
-
     public static void setEnableRetransmissions(final SSLParameters sslParameters, final boolean value) {
-        applyParameter(sslParameters, "EnableRetransmissions", Boolean.TYPE, value);
+        ReflectionSupport.callSetter(sslParameters, "EnableRetransmissions", Boolean.TYPE, value);
     }
 
     public static void setApplicationProtocols(final SSLParameters sslParameters, final String[] values) {
-        applyParameter(sslParameters, "ApplicationProtocols", String[].class, values);
+        ReflectionSupport.callSetter(sslParameters, "ApplicationProtocols", String[].class, values);
     }
 
-    public static Boolean getEnableRetransmissions(final SSLParameters sslParameters) {
-        return getParameter(sslParameters, "EnableRetransmissions", Boolean.class);
-    }
-
-    public static String[] getApplicationProtocols(final SSLParameters sslParameters) {
-        return getParameter(sslParameters, "ApplicationProtocols", String[].class);
-    }
-
-    public static SSLSessionInitializer enforceRequirements(final SSLSessionInitializer initializer) {
+    public static SSLSessionInitializer enforceRequirements(
+            final Object attachment,
+            final SSLSessionInitializer initializer) {
         return new SSLSessionInitializer() {
 
             @Override
-            public void initialize(final NamedEndpoint endpoint, final SSLParameters sslParameters) {
+            public void initialize(final NamedEndpoint endpoint, final SSLEngine sslEngine) {
+                final SSLParameters sslParameters = sslEngine.getSSLParameters();
                 sslParameters.setProtocols(excludeBlacklistedProtocols(sslParameters.getProtocols()));
                 sslParameters.setCipherSuites(excludeBlacklistedCiphers(sslParameters.getCipherSuites()));
                 setEnableRetransmissions(sslParameters, false);
-                setApplicationProtocols(sslParameters, new String[] { "h2" });
-
+                final HttpVersionPolicy versionPolicy = attachment instanceof HttpVersionPolicy ?
+                        (HttpVersionPolicy) attachment : HttpVersionPolicy.NEGOTIATE;
+                final String[] appProtocols;
+                switch (versionPolicy) {
+                    case FORCE_HTTP_1:
+                        appProtocols = new String[] { ApplicationProtocols.HTTP_1_1.id };
+                        break;
+                    case FORCE_HTTP_2:
+                        appProtocols = new String[] { ApplicationProtocols.HTTP_2.id };
+                        break;
+                    default:
+                        appProtocols = new String[] { ApplicationProtocols.HTTP_2.id, ApplicationProtocols.HTTP_1_1.id };
+                        break;
+                }
+                setApplicationProtocols(sslParameters, appProtocols);
+                sslEngine.setSSLParameters(sslParameters);
                 if (initializer != null) {
-                    initializer.initialize(endpoint, sslParameters);
+                    initializer.initialize(endpoint, sslEngine);
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/SecurePortStrategy.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/SecurePortStrategy.java b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/SecurePortStrategy.java
new file mode 100644
index 0000000..3a4538d
--- /dev/null
+++ b/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/ssl/SecurePortStrategy.java
@@ -0,0 +1,41 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.ssl;
+
+import java.net.SocketAddress;
+
+/**
+ * Side-side strategy to determine if local endpoint should be secured with TLS.
+ *
+ * @since 5.0
+ */
+public interface SecurePortStrategy {
+
+    boolean isSecure(SocketAddress localAddress);
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestClient.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestClient.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestClient.java
index f846498..b956aa0 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestClient.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestClient.java
@@ -38,8 +38,10 @@ import org.apache.hc.core5.concurrent.FutureCallback;
 import org.apache.hc.core5.function.Supplier;
 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.nio.AsyncPushConsumer;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.impl.Http2Processors;
 import org.apache.hc.core5.http2.impl.nio.bootstrap.AsyncPushConsumerRegistry;
@@ -80,8 +82,21 @@ public class Http2TestClient extends AsyncRequester {
         start(new InternalClientHttp2EventHandlerFactory(
                 httpProcessor,
                 pushConsumerRegistry,
-                CharCodingConfig.DEFAULT,
+                HttpVersionPolicy.FORCE_HTTP_2,
                 h2Config,
+                H1Config.DEFAULT,
+                CharCodingConfig.DEFAULT,
+                sslContext));
+    }
+
+    public void start(final HttpProcessor httpProcessor, final H1Config h1Config) throws IOException {
+        start(new InternalClientHttp2EventHandlerFactory(
+                httpProcessor,
+                pushConsumerRegistry,
+                HttpVersionPolicy.FORCE_HTTP_1,
+                H2Config.DEFAULT,
+                h1Config,
+                CharCodingConfig.DEFAULT,
                 sslContext));
     }
 
@@ -89,6 +104,10 @@ public class Http2TestClient extends AsyncRequester {
         start(Http2Processors.client(), h2Config);
     }
 
+    public void start(final H1Config h1Config) throws IOException {
+        start(Http2Processors.client(), h1Config);
+    }
+
     public void start() throws Exception {
         start(H2Config.DEFAULT);
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestServer.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestServer.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestServer.java
index cbc0f7f..3264cb6 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestServer.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/Http2TestServer.java
@@ -35,7 +35,6 @@ import javax.net.ssl.SSLContext;
 import org.apache.hc.core5.function.Supplier;
 import org.apache.hc.core5.http.config.CharCodingConfig;
 import org.apache.hc.core5.http.config.H1Config;
-import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.bootstrap.AsyncServerExchangeHandlerRegistry;
 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
@@ -43,6 +42,7 @@ import org.apache.hc.core5.http.nio.support.BasicServerExchangeHandler;
 import org.apache.hc.core5.http.nio.support.RequestConsumerSupplier;
 import org.apache.hc.core5.http.nio.support.ResponseHandler;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
 import org.apache.hc.core5.http2.impl.Http2Processors;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -90,8 +90,10 @@ public class Http2TestServer extends AsyncServer {
         start(new InternalServerHttp2EventHandlerFactory(
                 httpProcessor,
                 handlerRegistry,
-                CharCodingConfig.DEFAULT,
+                HttpVersionPolicy.FORCE_HTTP_2,
                 h2Config,
+                H1Config.DEFAULT,
+                CharCodingConfig.DEFAULT,
                 sslContext));
         final ListenerEndpoint listener = listen(new InetSocketAddress(0));
         listener.waitFor();
@@ -99,12 +101,13 @@ public class Http2TestServer extends AsyncServer {
     }
 
     public InetSocketAddress start(final HttpProcessor httpProcessor, final H1Config h1Config) throws Exception {
-        start(new InternalServerHttp1EventHandlerFactory(
+        start(new InternalServerHttp2EventHandlerFactory(
                 httpProcessor,
                 handlerRegistry,
+                HttpVersionPolicy.FORCE_HTTP_1,
+                H2Config.DEFAULT,
                 h1Config,
                 CharCodingConfig.DEFAULT,
-                DefaultConnectionReuseStrategy.INSTANCE,
                 sslContext));
         final ListenerEndpoint listener = listen(new InetSocketAddress(0));
         listener.waitFor();

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java
index 75a2f62..e32cee7 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp1EventHandlerFactory.java
@@ -27,17 +27,12 @@
 
 package org.apache.hc.core5.testing.nio;
 
-import java.util.Iterator;
-
 import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.ContentLengthStrategy;
-import org.apache.hc.core5.http.Header;
-import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.config.CharCodingConfig;
@@ -50,8 +45,6 @@ import org.apache.hc.core5.http.impl.nio.ClientHttp1IOEventHandler;
 import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexer;
 import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestWriterFactory;
 import org.apache.hc.core5.http.impl.nio.DefaultHttpResponseParserFactory;
-import org.apache.hc.core5.http.message.RequestLine;
-import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.nio.NHttpMessageParser;
 import org.apache.hc.core5.http.nio.NHttpMessageParserFactory;
 import org.apache.hc.core5.http.nio.NHttpMessageWriter;
@@ -120,7 +113,6 @@ class InternalClientHttp1EventHandlerFactory implements IOEventHandlerFactory {
         }
         final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
         final Logger wireLog = LogManager.getLogger("org.apache.hc.core5.http.wire");
-        final Logger headerLog = LogManager.getLogger("org.apache.hc.core5.http.headers");
         final ClientHttp1StreamDuplexer streamDuplexer = createClientHttp1StreamDuplexer(
                 new LoggingIOSession(ioSession, sessionLog, wireLog),
                 httpProcessor,
@@ -131,65 +123,8 @@ class InternalClientHttp1EventHandlerFactory implements IOEventHandlerFactory {
                 requestWriterFactory.create(),
                 DefaultContentLengthStrategy.INSTANCE,
                 DefaultContentLengthStrategy.INSTANCE,
-                new ConnectionListener() {
-
-                    @Override
-                    public void onConnect(final HttpConnection connection) {
-                        if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + " "  + connection + " connected");
-                        }
-                    }
-
-                    @Override
-                    public void onDisconnect(final HttpConnection connection) {
-                        if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + " "  + connection + " disconnected");
-                        }
-                    }
-
-                    @Override
-                    public void onError(final HttpConnection connection, final Exception ex) {
-                        if (ex instanceof ConnectionClosedException) {
-                            return;
-                        }
-                        sessionLog.error(id + " "  + ex.getMessage(), ex);
-                    }
-
-                },
-                new Http1StreamListener() {
-
-                    @Override
-                    public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
-                        if (headerLog.isDebugEnabled()) {
-                            headerLog.debug(id + " >> " + new RequestLine(request));
-                            for (final Iterator<Header> it = request.headerIterator(); it.hasNext(); ) {
-                                headerLog.debug(id + " >> " + it.next());
-                            }
-                        }
-                    }
-
-                    @Override
-                    public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
-                        if (headerLog.isDebugEnabled()) {
-                            headerLog.debug(id + " << " + new StatusLine(response));
-                            for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
-                                headerLog.debug(id + " << " + it.next());
-                            }
-                        }
-                    }
-
-                    @Override
-                    public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
-                        if (sessionLog.isDebugEnabled()) {
-                            if (keepAlive) {
-                                sessionLog.debug(id + " Connection is kept alive");
-                            } else {
-                                sessionLog.debug(id + " Connection is not kept alive");
-                            }
-                        }
-                    }
-
-                });
+                new InternalConnectionListener(id, sessionLog),
+                new InternalHttp1StreamListener(id, InternalHttp1StreamListener.Type.CLIENT, sessionLog));
         return new LoggingIOEventHandler(new ClientHttp1IOEventHandler(streamDuplexer), id, sessionLog);
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java
index 8f50052..fcbaf8a 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalClientHttp2EventHandlerFactory.java
@@ -29,15 +29,17 @@ package org.apache.hc.core5.testing.nio;
 
 import javax.net.ssl.SSLContext;
 
-import org.apache.hc.core5.http.ConnectionClosedException;
-import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.HttpProcessors;
+import org.apache.hc.core5.http.impl.nio.ClientHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http.nio.AsyncPushConsumer;
 import org.apache.hc.core5.http.nio.HandlerFactory;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
-import org.apache.hc.core5.http2.impl.nio.ClientHttp2StreamMultiplexer;
+import org.apache.hc.core5.http2.impl.Http2Processors;
+import org.apache.hc.core5.http2.impl.nio.ClientHttp2StreamMultiplexerFactory;
 import org.apache.hc.core5.http2.impl.nio.ClientHttpProtocolNegotiator;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -50,20 +52,26 @@ class InternalClientHttp2EventHandlerFactory implements IOEventHandlerFactory {
 
     private final HttpProcessor httpProcessor;
     private final HandlerFactory<AsyncPushConsumer> exchangeHandlerFactory;
-    private final CharCodingConfig charCodingConfig;
+    private final HttpVersionPolicy versionPolicy;
     private final H2Config h2Config;
+    private final H1Config h1Config;
+    private final CharCodingConfig charCodingConfig;
     private final SSLContext sslContext;
 
     InternalClientHttp2EventHandlerFactory(
             final HttpProcessor httpProcessor,
             final HandlerFactory<AsyncPushConsumer> exchangeHandlerFactory,
-            final CharCodingConfig charCodingConfig,
+            final HttpVersionPolicy versionPolicy,
             final H2Config h2Config,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
             final SSLContext sslContext) {
         this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
         this.exchangeHandlerFactory = exchangeHandlerFactory;
-        this.charCodingConfig = charCodingConfig;
-        this.h2Config = h2Config;
+        this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
+        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
+        this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
+        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
         this.sslContext = sslContext;
     }
 
@@ -74,40 +82,28 @@ class InternalClientHttp2EventHandlerFactory implements IOEventHandlerFactory {
             ioSession.startTls(sslContext, null ,null, null);
         }
         final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
-        return new LoggingIOEventHandler(new ClientHttpProtocolNegotiator(
-                ioSession, httpProcessor, exchangeHandlerFactory, charCodingConfig, h2Config,
-                new ConnectionListener() {
-
-                    @Override
-                    public void onConnect(final HttpConnection connection) {
-                        if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + " "  + connection + " connected");
-                        }
-                    }
-
-                    @Override
-                    public void onDisconnect(final HttpConnection connection) {
-                        if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + " "  + connection + " disconnected");
-                        }
-                    }
-
-                    @Override
-                    public void onError(final HttpConnection connection, final Exception ex) {
-                        if (ex instanceof ConnectionClosedException) {
-                            return;
-                        }
-                        sessionLog.error(id + " "  + ex.getMessage(), ex);
-                    }
-
-                }, new InternalHttp2StreamListener(id)) {
-
-            @Override
-            protected ClientHttp2StreamMultiplexer createStreamMultiplexer(final TlsCapableIOSession ioSession) {
-                return super.createStreamMultiplexer(new LoggingIOSession(ioSession, sessionLog));
-            }
-        }, id, sessionLog);
-
+        final LoggingIOSession loggingIOSession = new LoggingIOSession(ioSession, sessionLog);
+        final ClientHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ClientHttp1StreamDuplexerFactory(
+                httpProcessor != null ? httpProcessor : HttpProcessors.client(),
+                h1Config,
+                charCodingConfig,
+                new InternalConnectionListener(id, sessionLog),
+                new InternalHttp1StreamListener(id, InternalHttp1StreamListener.Type.CLIENT, sessionLog));
+        final ClientHttp2StreamMultiplexerFactory http2StreamHandlerFactory = new ClientHttp2StreamMultiplexerFactory(
+                httpProcessor != null ? httpProcessor : Http2Processors.client(),
+                exchangeHandlerFactory,
+                h2Config,
+                charCodingConfig,
+                new InternalConnectionListener(id, sessionLog),
+                new InternalHttp2StreamListener(id));
+        return new LoggingIOEventHandler(
+                new ClientHttpProtocolNegotiator(
+                        loggingIOSession,
+                        http1StreamHandlerFactory,
+                        http2StreamHandlerFactory,
+                        versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE,
+                        new InternalConnectionListener(id, sessionLog)),
+                id, sessionLog);
    }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalConnectionListener.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalConnectionListener.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalConnectionListener.java
new file mode 100644
index 0000000..5c0ef96
--- /dev/null
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalConnectionListener.java
@@ -0,0 +1,67 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.testing.nio;
+
+import org.apache.hc.core5.http.ConnectionClosedException;
+import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.logging.log4j.Logger;
+
+class InternalConnectionListener implements ConnectionListener {
+
+    private final String id;
+    private final Logger log;
+
+    public InternalConnectionListener(final String id, final Logger log) {
+        this.log = log;
+        this.id = id;
+    }
+
+    @Override
+    public void onConnect(final HttpConnection connection) {
+        if (log.isDebugEnabled()) {
+            log.debug(id + " " + connection + " connected");
+        }
+    }
+
+    @Override
+    public void onDisconnect(final HttpConnection connection) {
+        if (log.isDebugEnabled()) {
+            log.debug(id + " " + connection + " disconnected");
+        }
+    }
+
+    @Override
+    public void onError(final HttpConnection connection, final Exception ex) {
+        if (ex instanceof ConnectionClosedException) {
+            return;
+        }
+        log.error(id + " " + ex.getMessage(), ex);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalHttp1StreamListener.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalHttp1StreamListener.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalHttp1StreamListener.java
new file mode 100644
index 0000000..48b9608
--- /dev/null
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalHttp1StreamListener.java
@@ -0,0 +1,96 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.testing.nio;
+
+import java.util.Iterator;
+
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpConnection;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.impl.Http1StreamListener;
+import org.apache.hc.core5.http.message.RequestLine;
+import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+class InternalHttp1StreamListener implements Http1StreamListener {
+
+    enum Type { CLIENT, SERVER }
+
+    private final String id;
+    private final Type type;
+    private final Logger sessionLog;
+    private final Logger headerLog = LogManager.getLogger("org.apache.hc.core5.http.headers");
+
+    public InternalHttp1StreamListener(final String id, final Type type, final Logger sessionLog) {
+        this.id = id;
+        this.type = type;
+        this.sessionLog = sessionLog;
+    }
+
+    private String requestDirection() {
+        return type == Type.CLIENT ? " >> " : " << ";
+    }
+
+    private String responseDirection() {
+        return type == Type.CLIENT ? " << " : " >> ";
+    }
+
+    @Override
+    public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
+        if (headerLog.isDebugEnabled()) {
+            headerLog.debug(id + requestDirection() + new RequestLine(request));
+            for (final Iterator<Header> it = request.headerIterator(); it.hasNext(); ) {
+                headerLog.debug(id + requestDirection() + it.next());
+            }
+        }
+    }
+
+    @Override
+    public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
+        if (headerLog.isDebugEnabled()) {
+            headerLog.debug(id + responseDirection() + new StatusLine(response));
+            for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
+                headerLog.debug(id + responseDirection() + it.next());
+            }
+        }
+    }
+
+    @Override
+    public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
+        if (sessionLog.isDebugEnabled()) {
+            if (keepAlive) {
+                sessionLog.debug(id + " Connection is kept alive");
+            } else {
+                sessionLog.debug(id + " Connection is not kept alive");
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
index a051d51..bf1ad15 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp1EventHandlerFactory.java
@@ -27,17 +27,12 @@
 
 package org.apache.hc.core5.testing.nio;
 
-import java.util.Iterator;
-
 import javax.net.ssl.SSLContext;
 
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
-import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.ContentLengthStrategy;
-import org.apache.hc.core5.http.Header;
-import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.http.HttpRequest;
 import org.apache.hc.core5.http.HttpResponse;
 import org.apache.hc.core5.http.config.CharCodingConfig;
@@ -50,8 +45,6 @@ import org.apache.hc.core5.http.impl.nio.DefaultHttpRequestParserFactory;
 import org.apache.hc.core5.http.impl.nio.DefaultHttpResponseWriterFactory;
 import org.apache.hc.core5.http.impl.nio.ServerHttp1IOEventHandler;
 import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexer;
-import org.apache.hc.core5.http.message.RequestLine;
-import org.apache.hc.core5.http.message.StatusLine;
 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
 import org.apache.hc.core5.http.nio.HandlerFactory;
 import org.apache.hc.core5.http.nio.NHttpMessageParser;
@@ -125,7 +118,6 @@ class InternalServerHttp1EventHandlerFactory implements IOEventHandlerFactory {
         }
         final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
         final Logger wireLog = LogManager.getLogger("org.apache.hc.core5.http.wire");
-        final Logger headerLog = LogManager.getLogger("org.apache.hc.core5.http.headers");
 
         final ServerHttp1StreamDuplexer streamDuplexer = createServerHttp1StreamDuplexer(
                 new LoggingIOSession(ioSession, sessionLog, wireLog),
@@ -138,65 +130,8 @@ class InternalServerHttp1EventHandlerFactory implements IOEventHandlerFactory {
                 responseWriterFactory.create(),
                 DefaultContentLengthStrategy.INSTANCE,
                 DefaultContentLengthStrategy.INSTANCE,
-                new ConnectionListener() {
-
-                    @Override
-                    public void onConnect(final HttpConnection connection) {
-                        if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + " "  + connection + " connected");
-                        }
-                    }
-
-                    @Override
-                    public void onDisconnect(final HttpConnection connection) {
-                        if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + " "  + connection + " disconnected");
-                        }
-                    }
-
-                    @Override
-                    public void onError(final HttpConnection connection, final Exception ex) {
-                        if (ex instanceof ConnectionClosedException) {
-                            return;
-                        }
-                        sessionLog.error(id + " "  + ex.getMessage(), ex);
-                    }
-
-                },
-                new Http1StreamListener() {
-
-                    @Override
-                    public void onRequestHead(final HttpConnection connection, final HttpRequest request) {
-                        if (headerLog.isDebugEnabled()) {
-                            headerLog.debug(id + " << " + new RequestLine(request));
-                            for (final Iterator<Header> it = request.headerIterator(); it.hasNext(); ) {
-                                headerLog.debug(id + " << " + it.next());
-                            }
-                        }
-                    }
-
-                    @Override
-                    public void onResponseHead(final HttpConnection connection, final HttpResponse response) {
-                        if (headerLog.isDebugEnabled()) {
-                            headerLog.debug(id + " >> " + new StatusLine(response));
-                            for (final Iterator<Header> it = response.headerIterator(); it.hasNext(); ) {
-                                headerLog.debug(id + " >> " + it.next());
-                            }
-                        }
-                    }
-
-                    @Override
-                    public void onExchangeComplete(final HttpConnection connection, final boolean keepAlive) {
-                        if (sessionLog.isDebugEnabled()) {
-                            if (keepAlive) {
-                                sessionLog.debug(id + " Connection is kept alive");
-                            } else {
-                                sessionLog.debug(id + " Connection is not kept alive");
-                            }
-                        }
-                    }
-
-                });
+                new InternalConnectionListener(id, sessionLog),
+                new InternalHttp1StreamListener(id, InternalHttp1StreamListener.Type.SERVER, sessionLog));
         return new LoggingIOEventHandler(new ServerHttp1IOEventHandler(streamDuplexer), id, sessionLog);
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java
index bed94ed..4a69374 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/InternalServerHttp2EventHandlerFactory.java
@@ -29,15 +29,17 @@ package org.apache.hc.core5.testing.nio;
 
 import javax.net.ssl.SSLContext;
 
-import org.apache.hc.core5.http.ConnectionClosedException;
-import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.http.config.CharCodingConfig;
-import org.apache.hc.core5.http.impl.ConnectionListener;
+import org.apache.hc.core5.http.config.H1Config;
+import org.apache.hc.core5.http.impl.HttpProcessors;
+import org.apache.hc.core5.http.impl.nio.ServerHttp1StreamDuplexerFactory;
 import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
 import org.apache.hc.core5.http.nio.HandlerFactory;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
 import org.apache.hc.core5.http2.config.H2Config;
-import org.apache.hc.core5.http2.impl.nio.ServerHttp2StreamMultiplexer;
+import org.apache.hc.core5.http2.impl.Http2Processors;
+import org.apache.hc.core5.http2.impl.nio.ServerHttp2StreamMultiplexerFactory;
 import org.apache.hc.core5.http2.impl.nio.ServerHttpProtocolNegotiator;
 import org.apache.hc.core5.reactor.IOEventHandler;
 import org.apache.hc.core5.reactor.IOEventHandlerFactory;
@@ -50,20 +52,26 @@ class InternalServerHttp2EventHandlerFactory implements IOEventHandlerFactory {
 
     private final HttpProcessor httpProcessor;
     private final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory;
-    private final CharCodingConfig charCodingConfig;
+    private final HttpVersionPolicy versionPolicy;
     private final H2Config h2Config;
+    private final H1Config h1Config;
+    private final CharCodingConfig charCodingConfig;
     private final SSLContext sslContext;
 
     public InternalServerHttp2EventHandlerFactory(
             final HttpProcessor httpProcessor,
             final HandlerFactory<AsyncServerExchangeHandler> exchangeHandlerFactory,
-            final CharCodingConfig charCodingConfig,
+            final HttpVersionPolicy versionPolicy,
             final H2Config h2Config,
+            final H1Config h1Config,
+            final CharCodingConfig charCodingConfig,
             final SSLContext sslContext) {
         this.httpProcessor = Args.notNull(httpProcessor, "HTTP processor");
         this.exchangeHandlerFactory = Args.notNull(exchangeHandlerFactory, "Exchange handler factory");
-        this.charCodingConfig = charCodingConfig;
-        this.h2Config = h2Config;
+        this.versionPolicy = versionPolicy != null ? versionPolicy : HttpVersionPolicy.NEGOTIATE;
+        this.h2Config = h2Config != null ? h2Config : H2Config.DEFAULT;
+        this.h1Config = h1Config != null ? h1Config : H1Config.DEFAULT;
+        this.charCodingConfig = charCodingConfig != null ? charCodingConfig : CharCodingConfig.DEFAULT;
         this.sslContext = sslContext;
     }
 
@@ -74,39 +82,29 @@ class InternalServerHttp2EventHandlerFactory implements IOEventHandlerFactory {
             ioSession.startTls(sslContext, null ,null, null);
         }
         final Logger sessionLog = LogManager.getLogger(ioSession.getClass());
-        return new LoggingIOEventHandler(new ServerHttpProtocolNegotiator(
-                ioSession, httpProcessor, exchangeHandlerFactory, charCodingConfig, h2Config,
-                new ConnectionListener() {
-
-                    @Override
-                    public void onConnect(final HttpConnection connection) {
-                        if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + " "  + connection + " connected");
-                        }
-                    }
-
-                    @Override
-                    public void onDisconnect(final HttpConnection connection) {
-                        if (sessionLog.isDebugEnabled()) {
-                            sessionLog.debug(id + " "  + connection + " disconnected");
-                        }
-                    }
-
-                    @Override
-                    public void onError(final HttpConnection connection, final Exception ex) {
-                        if (ex instanceof ConnectionClosedException) {
-                            return;
-                        }
-                        sessionLog.error(id + " "  + ex.getMessage(), ex);
-                    }
-
-                }, new InternalHttp2StreamListener(id)) {
-
-            @Override
-            protected ServerHttp2StreamMultiplexer createStreamMultiplexer(final TlsCapableIOSession ioSession) {
-                return super.createStreamMultiplexer(new LoggingIOSession(ioSession, sessionLog));
-            }
-        }, id, sessionLog);
-
+        final LoggingIOSession loggingIOSession = new LoggingIOSession(ioSession, sessionLog);
+        final ServerHttp1StreamDuplexerFactory http1StreamHandlerFactory = new ServerHttp1StreamDuplexerFactory(
+                httpProcessor != null ? httpProcessor : HttpProcessors.server(),
+                exchangeHandlerFactory,
+                h1Config,
+                charCodingConfig,
+                new InternalConnectionListener(id, sessionLog),
+                new InternalHttp1StreamListener(id, InternalHttp1StreamListener.Type.SERVER, sessionLog));
+        final ServerHttp2StreamMultiplexerFactory http2StreamHandlerFactory = new ServerHttp2StreamMultiplexerFactory(
+                httpProcessor != null ? httpProcessor : Http2Processors.server(),
+                exchangeHandlerFactory,
+                h2Config,
+                charCodingConfig,
+                new InternalConnectionListener(id, sessionLog),
+                new InternalHttp2StreamListener(id));
+        return new LoggingIOEventHandler(
+                new ServerHttpProtocolNegotiator(
+                        loggingIOSession,
+                        http1StreamHandlerFactory,
+                        http2StreamHandlerFactory,
+                        versionPolicy,
+                        new InternalConnectionListener(id, sessionLog)),
+                id, sessionLog);
     }
+
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
index 096c03f..5ddefe0 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/testing/nio/LoggingIOSession.java
@@ -34,7 +34,6 @@ import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
 
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
 
 import org.apache.hc.core5.io.ShutdownType;
 import org.apache.hc.core5.reactor.Command;
@@ -43,6 +42,7 @@ import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.reactor.ssl.SSLBufferManagement;
 import org.apache.hc.core5.reactor.ssl.SSLSessionInitializer;
 import org.apache.hc.core5.reactor.ssl.SSLSessionVerifier;
+import org.apache.hc.core5.reactor.ssl.TlsDetails;
 import org.apache.hc.core5.testing.classic.Wire;
 import org.apache.logging.log4j.Logger;
 public class LoggingIOSession implements TlsCapableIOSession {
@@ -197,6 +197,11 @@ public class LoggingIOSession implements TlsCapableIOSession {
     }
 
     @Override
+    public TlsDetails getTlsDetails() {
+        return session.getTlsDetails();
+    }
+
+    @Override
     public void startTls(
             final SSLContext sslContext,
             final SSLBufferManagement sslBufferManagement,
@@ -206,11 +211,6 @@ public class LoggingIOSession implements TlsCapableIOSession {
     }
 
     @Override
-    public SSLSession getSSLSession() {
-        return session.getSSLSession();
-    }
-
-    @Override
     public String toString() {
         return this.session.toString();
     }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/SSLTestContexts.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/SSLTestContexts.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/SSLTestContexts.java
new file mode 100644
index 0000000..6668f7a
--- /dev/null
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/SSLTestContexts.java
@@ -0,0 +1,55 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.testing;
+
+import java.net.URL;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.hc.core5.ssl.SSLContextBuilder;
+
+public final class SSLTestContexts {
+
+    public static SSLContext createServerSSLContext() throws Exception {
+        final URL keyStoreURL = SSLTestContexts.class.getResource("/test.keystore");
+        final String storePassword = "nopassword";
+        return SSLContextBuilder.create()
+                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
+                .loadKeyMaterial(keyStoreURL, storePassword.toCharArray(), storePassword.toCharArray())
+                .build();
+    }
+
+    public static SSLContext createClientSSLContext() throws Exception {
+        final URL keyStoreURL = SSLTestContexts.class.getResource("/test.keystore");
+        final String storePassword = "nopassword";
+        return SSLContextBuilder.create()
+                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
+                .build();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
index 6e0af70..2d0430a 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http1IntegrationTest.java
@@ -124,6 +124,7 @@ import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.reactor.TlsCapableIOSession;
 import org.apache.hc.core5.testing.ProtocolScheme;
+import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.CharArrayBuffer;
 import org.apache.hc.core5.util.TextUtils;
 import org.apache.hc.core5.util.TimeValue;
@@ -158,7 +159,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
     public void setup() throws Exception {
         client = new Http1TestClient(
                 IOReactorConfig.DEFAULT,
-                scheme == ProtocolScheme.HTTPS ? createClientSSLContext() : null);
+                scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
     }
 
     @After
@@ -1353,7 +1354,7 @@ public class Http1IntegrationTest extends InternalHttp1ServerTestBase {
                 H1Config.DEFAULT,
                 CharCodingConfig.DEFAULT,
                 DefaultConnectionReuseStrategy.INSTANCE,
-                scheme == ProtocolScheme.HTTPS ? createServerSSLContext() : null) {
+                scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null) {
 
             @Override
             protected ServerHttp1StreamDuplexer createServerHttp1StreamDuplexer(

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
index b67f8d9..438e6db 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2IntegrationTest.java
@@ -111,6 +111,7 @@ import org.apache.hc.core5.reactor.IOReactorConfig;
 import org.apache.hc.core5.reactor.IOSession;
 import org.apache.hc.core5.reactor.SessionRequest;
 import org.apache.hc.core5.testing.ProtocolScheme;
+import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.TextUtils;
 import org.apache.hc.core5.util.TimeValue;
 import org.hamcrest.CoreMatchers;
@@ -144,7 +145,7 @@ public class Http2IntegrationTest extends InternalHttp2ServerTestBase {
     @Before
     public void setup() throws Exception {
         client = new Http2TestClient(IOReactorConfig.DEFAULT,
-                scheme == ProtocolScheme.HTTPS ? createClientSSLContext() : null);
+                scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createClientSSLContext() : null);
     }
 
     @After

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
new file mode 100644
index 0000000..4fe5b0e
--- /dev/null
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ProtocolNegotiationTest.java
@@ -0,0 +1,251 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.testing.nio;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.util.concurrent.Future;
+
+import org.apache.hc.core5.function.Supplier;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.HttpVersion;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncServer;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.BasicResponseConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.H2ServerBootstrap;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.Http2AsyncRequester;
+import org.apache.hc.core5.http2.ssl.H2ClientTlsStrategy;
+import org.apache.hc.core5.http2.ssl.H2ServerTlsStrategy;
+import org.apache.hc.core5.http2.ssl.SecurePortStrategy;
+import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.ListenerEndpoint;
+import org.apache.hc.core5.testing.SSLTestContexts;
+import org.apache.hc.core5.util.TimeValue;
+import org.apache.logging.log4j.LogManager;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExternalResource;
+
+public class Http2ProtocolNegotiationTest {
+
+    private static final TimeValue TIMEOUT = TimeValue.ofSeconds(30);
+
+    private HttpAsyncServer server;
+
+    @Rule
+    public ExternalResource serverResource = new ExternalResource() {
+
+        @Override
+        protected void before() throws Throwable {
+            server = H2ServerBootstrap.bootstrap()
+                    .setTlsStrategy(new H2ServerTlsStrategy(SSLTestContexts.createServerSSLContext(), new SecurePortStrategy() {
+
+                        @Override
+                        public boolean isSecure(final SocketAddress localAddress) {
+                            return true;
+                        }
+
+                    }))
+                    .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
+                    .setIOReactorConfig(
+                            IOReactorConfig.custom()
+                                    .setSoTimeout(TIMEOUT)
+                                    .build())
+                    .register("*", new Supplier<AsyncServerExchangeHandler>() {
+
+                        @Override
+                        public AsyncServerExchangeHandler get() {
+                            return new EchoHandler(2048);
+                        }
+
+                    })
+                    .setConnectionListener(new InternalConnectionListener("test", LogManager.getLogger(getClass())))
+                    .create();
+        }
+
+        @Override
+        protected void after() {
+            if (server != null) {
+                try {
+                    server.shutdown(ShutdownType.IMMEDIATE);
+                    server = null;
+                } catch (final Exception ignore) {
+                }
+            }
+        }
+
+    };
+
+    private Http2AsyncRequester requester;
+
+    @Rule
+    public ExternalResource clientResource = new ExternalResource() {
+
+        @Override
+        protected void before() throws Throwable {
+            requester = H2RequesterBootstrap.bootstrap()
+                    .setTlsStrategy(new H2ClientTlsStrategy(SSLTestContexts.createClientSSLContext()))
+                    .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
+                    .setIOReactorConfig(IOReactorConfig.custom()
+                            .setSoTimeout(TIMEOUT)
+                            .build())
+                    .create();
+        }
+
+        @Override
+        protected void after() {
+            if (requester != null) {
+                try {
+                    requester.shutdown(ShutdownType.IMMEDIATE);
+                    requester = null;
+                } catch (final Exception ignore) {
+                }
+            }
+        }
+
+    };
+
+    private static int version;
+
+    @BeforeClass
+    public static void determineJavaVersion() {
+        version = 7;
+        final String s = System.getProperty("java.version");
+        if (s.equals("9-ea")) {
+            version = 9;
+        }
+        final String[] parts = s.split("\\.");
+        if (parts.length >= 2) {
+            if (parts[0].equals("1")) {
+                try {
+                    version = Integer.parseInt(parts[1]);
+                } catch (NumberFormatException ignore) {
+                }
+            }
+        }
+    }
+
+    @Before
+    public void checkVersion() {
+        Assume.assumeTrue("Java version must be 1.8 or greater", version > 7);
+    }
+
+    @Test
+    public void testForceHttp1() throws Exception {
+        server.start();
+        final ListenerEndpoint listener = server.listen(new InetSocketAddress(0));
+        listener.waitFor();
+        final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
+        requester.start();
+
+        final HttpHost target = new HttpHost("localhost", address.getPort(), "https");
+        final Future<AsyncClientEndpoint> connectFuture = requester.connect(target, TIMEOUT, HttpVersionPolicy.FORCE_HTTP_1, null);
+        final AsyncClientEndpoint endpoint = connectFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+
+        final Future<Message<HttpResponse, String>> resultFuture1 = endpoint.execute(
+                new BasicRequestProducer("POST", target, "/stuff",
+                        new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)),
+                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+        final Message<HttpResponse, String> message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        Assert.assertThat(message1, CoreMatchers.notNullValue());
+        final HttpResponse response1 = message1.getHead();
+        Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+        Assert.assertThat(response1.getVersion(), CoreMatchers.<ProtocolVersion>equalTo(HttpVersion.HTTP_1_1));
+    }
+
+    @Test
+    public void testForceHttp2() throws Exception {
+        server.start();
+        final ListenerEndpoint listener = server.listen(new InetSocketAddress(0));
+        listener.waitFor();
+        final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
+        requester.start();
+
+        final HttpHost target = new HttpHost("localhost", address.getPort(), "https");
+        final Future<AsyncClientEndpoint> connectFuture = requester.connect(target, TIMEOUT, HttpVersionPolicy.FORCE_HTTP_2, null);
+        final AsyncClientEndpoint endpoint = connectFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+
+        final Future<Message<HttpResponse, String>> resultFuture1 = endpoint.execute(
+                new BasicRequestProducer("POST", target, "/stuff",
+                        new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)),
+                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+        final Message<HttpResponse, String> message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        Assert.assertThat(message1, CoreMatchers.notNullValue());
+        final HttpResponse response1 = message1.getHead();
+        Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+        Assert.assertThat(response1.getVersion(), CoreMatchers.<ProtocolVersion>equalTo(HttpVersion.HTTP_2));
+    }
+
+    @Test
+    public void testNegotiateProtocol() throws Exception {
+        server.start();
+        final ListenerEndpoint listener = server.listen(new InetSocketAddress(0));
+        listener.waitFor();
+        final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
+        requester.start();
+
+        final HttpHost target = new HttpHost("localhost", address.getPort(), "https");
+        final Future<AsyncClientEndpoint> connectFuture = requester.connect(target, TIMEOUT, HttpVersionPolicy.NEGOTIATE, null);
+        final AsyncClientEndpoint endpoint = connectFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+
+        final Future<Message<HttpResponse, String>> resultFuture1 = endpoint.execute(
+                new BasicRequestProducer("POST", target, "/stuff",
+                        new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)),
+                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+        final Message<HttpResponse, String> message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        Assert.assertThat(message1, CoreMatchers.notNullValue());
+        final HttpResponse response1 = message1.getHead();
+        Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+
+        if (version < 9) {
+            Assert.assertThat(response1.getVersion(), CoreMatchers.<ProtocolVersion>equalTo(HttpVersion.HTTP_1_1));
+        } else {
+//            Assert.assertThat("Requires --add-opens java.base/sun.security.ssl=ALL-UNNAMED with Java 1.9+ " +
+//                    " in order to enable reflective access to SSLEngine",
+//                    response1.getVersion(), CoreMatchers.<ProtocolVersion>equalTo(HttpVersion.HTTP_2));
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
new file mode 100644
index 0000000..1b01ee8
--- /dev/null
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/Http2ServerAndRequesterTest.java
@@ -0,0 +1,288 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.testing.nio;
+
+import java.net.InetSocketAddress;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.concurrent.Future;
+
+import org.apache.hc.core5.function.Supplier;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
+import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncServer;
+import org.apache.hc.core5.http.nio.AsyncClientEndpoint;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.BasicResponseConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap;
+import org.apache.hc.core5.http2.impl.nio.bootstrap.H2ServerBootstrap;
+import org.apache.hc.core5.io.ShutdownType;
+import org.apache.hc.core5.reactor.IOReactorConfig;
+import org.apache.hc.core5.reactor.ListenerEndpoint;
+import org.apache.hc.core5.util.TimeValue;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExternalResource;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class Http2ServerAndRequesterTest {
+
+    @Parameterized.Parameters(name = "{0}")
+    public static Collection<Object[]> protocols() {
+        return Arrays.asList(new Object[][]{
+                { HttpVersionPolicy.NEGOTIATE },
+                { HttpVersionPolicy.FORCE_HTTP_1 },
+                { HttpVersionPolicy.FORCE_HTTP_2 }
+        });
+    }
+
+    private static final TimeValue TIMEOUT = TimeValue.ofSeconds(30);
+
+    private final HttpVersionPolicy versionPolicy;
+
+    public Http2ServerAndRequesterTest(final HttpVersionPolicy versionPolicy) {
+        this.versionPolicy = versionPolicy;
+    }
+
+    private HttpAsyncServer server;
+
+    @Rule
+    public ExternalResource serverResource = new ExternalResource() {
+
+        @Override
+        protected void before() throws Throwable {
+            server = H2ServerBootstrap.bootstrap()
+                    .setVersionPolicy(versionPolicy)
+                    .setIOReactorConfig(
+                            IOReactorConfig.custom()
+                                    .setSoTimeout(TIMEOUT)
+                                    .build())
+                    .register("*", new Supplier<AsyncServerExchangeHandler>() {
+
+                        @Override
+                        public AsyncServerExchangeHandler get() {
+                            return new EchoHandler(2048);
+                        }
+
+                    })
+                    .create();
+        }
+
+        @Override
+        protected void after() {
+            if (server != null) {
+                try {
+                    server.shutdown(ShutdownType.IMMEDIATE);
+                    server = null;
+                } catch (final Exception ignore) {
+                }
+            }
+        }
+
+    };
+
+    private HttpAsyncRequester requester;
+
+    @Rule
+    public ExternalResource clientResource = new ExternalResource() {
+
+        @Override
+        protected void before() throws Throwable {
+            requester = H2RequesterBootstrap.bootstrap()
+                    .setVersionPolicy(versionPolicy)
+                    .setIOReactorConfig(IOReactorConfig.custom()
+                            .setSoTimeout(TIMEOUT)
+                            .build())
+                    .create();
+        }
+
+        @Override
+        protected void after() {
+            if (requester != null) {
+                try {
+                    requester.shutdown(ShutdownType.IMMEDIATE);
+                    requester = null;
+                } catch (final Exception ignore) {
+                }
+            }
+        }
+
+    };
+
+    @Test
+    public void testSequentialRequests() throws Exception {
+        server.start();
+        final ListenerEndpoint listener = server.listen(new InetSocketAddress(0));
+        listener.waitFor();
+        final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
+        requester.start();
+
+        final HttpHost target = new HttpHost("localhost", address.getPort());
+        final Future<Message<HttpResponse, String>> resultFuture1 = requester.execute(
+                new BasicRequestProducer("POST", target, "/stuff",
+                        new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)),
+                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null);
+        final Message<HttpResponse, String> message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        Assert.assertThat(message1, CoreMatchers.notNullValue());
+        final HttpResponse response1 = message1.getHead();
+        Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+        final String body1 = message1.getBody();
+        Assert.assertThat(body1, CoreMatchers.equalTo("some stuff"));
+
+        final Future<Message<HttpResponse, String>> resultFuture2 = requester.execute(
+                new BasicRequestProducer("POST", target, "/other-stuff",
+                        new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)),
+                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null);
+        final Message<HttpResponse, String> message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        Assert.assertThat(message2, CoreMatchers.notNullValue());
+        final HttpResponse response2 = message2.getHead();
+        Assert.assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+        final String body2 = message2.getBody();
+        Assert.assertThat(body2, CoreMatchers.equalTo("some other stuff"));
+
+        final Future<Message<HttpResponse, String>> resultFuture3 = requester.execute(
+                new BasicRequestProducer("POST", target, "/more-stuff",
+                        new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)),
+                new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), TIMEOUT, null);
+        final Message<HttpResponse, String> message3 = resultFuture3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        Assert.assertThat(message3, CoreMatchers.notNullValue());
+        final HttpResponse response3 = message3.getHead();
+        Assert.assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+        final String body3 = message3.getBody();
+        Assert.assertThat(body3, CoreMatchers.equalTo("some more stuff"));
+    }
+
+    @Test
+    public void testSequentialRequestsSameEndpoint() throws Exception {
+        server.start();
+        final ListenerEndpoint listener = server.listen(new InetSocketAddress(0));
+        listener.waitFor();
+        final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
+        requester.start();
+
+        final HttpHost target = new HttpHost("localhost", address.getPort());
+        final Future<AsyncClientEndpoint> endpointFuture = requester.connect(target, TimeValue.ofSeconds(5));
+        final AsyncClientEndpoint endpoint = endpointFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        try {
+
+            final Future<Message<HttpResponse, String>> resultFuture1 = endpoint.execute(
+                    new BasicRequestProducer("POST", target, "/stuff",
+                            new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+            final Message<HttpResponse, String> message1 = resultFuture1.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+            Assert.assertThat(message1, CoreMatchers.notNullValue());
+            final HttpResponse response1 = message1.getHead();
+            Assert.assertThat(response1.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+            final String body1 = message1.getBody();
+            Assert.assertThat(body1, CoreMatchers.equalTo("some stuff"));
+
+            final Future<Message<HttpResponse, String>> resultFuture2 = endpoint.execute(
+                    new BasicRequestProducer("POST", target, "/other-stuff",
+                            new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+            final Message<HttpResponse, String> message2 = resultFuture2.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+            Assert.assertThat(message2, CoreMatchers.notNullValue());
+            final HttpResponse response2 = message2.getHead();
+            Assert.assertThat(response2.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+            final String body2 = message2.getBody();
+            Assert.assertThat(body2, CoreMatchers.equalTo("some other stuff"));
+
+            final Future<Message<HttpResponse, String>> resultFuture3 = endpoint.execute(
+                    new BasicRequestProducer("POST", target, "/more-stuff",
+                            new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
+            final Message<HttpResponse, String> message3 = resultFuture3.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+            Assert.assertThat(message3, CoreMatchers.notNullValue());
+            final HttpResponse response3 = message3.getHead();
+            Assert.assertThat(response3.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+            final String body3 = message3.getBody();
+            Assert.assertThat(body3, CoreMatchers.equalTo("some more stuff"));
+
+        } finally {
+            endpoint.releaseAndReuse();
+        }
+    }
+
+    @Test
+    public void testPipelinedRequests() throws Exception {
+        server.start();
+        final ListenerEndpoint listener = server.listen(new InetSocketAddress(0));
+        listener.waitFor();
+        final InetSocketAddress address = (InetSocketAddress) listener.getAddress();
+        requester.start();
+
+        final HttpHost target = new HttpHost("localhost", address.getPort());
+        final Future<AsyncClientEndpoint> endpointFuture = requester.connect(target, TimeValue.ofSeconds(5));
+        final AsyncClientEndpoint endpoint = endpointFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+        try {
+
+            final Queue<Future<Message<HttpResponse, String>>> queue = new LinkedList<>();
+
+            queue.add(endpoint.execute(
+                    new BasicRequestProducer("POST", target, "/stuff",
+                            new StringAsyncEntityProducer("some stuff", ContentType.TEXT_PLAIN)),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null));
+            queue.add(endpoint.execute(
+                    new BasicRequestProducer("POST", target, "/other-stuff",
+                            new StringAsyncEntityProducer("some other stuff", ContentType.TEXT_PLAIN)),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null));
+            queue.add(endpoint.execute(
+                    new BasicRequestProducer("POST", target, "/more-stuff",
+                            new StringAsyncEntityProducer("some more stuff", ContentType.TEXT_PLAIN)),
+                    new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null));
+
+            while (!queue.isEmpty()) {
+                final Future<Message<HttpResponse, String>> resultFuture = queue.remove();
+                final Message<HttpResponse, String> message = resultFuture.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
+                Assert.assertThat(message, CoreMatchers.notNullValue());
+                final HttpResponse response = message.getHead();
+                Assert.assertThat(response.getCode(), CoreMatchers.equalTo(HttpStatus.SC_OK));
+                final String body = message.getBody();
+                Assert.assertThat(body, CoreMatchers.containsString("stuff"));
+            }
+
+        } finally {
+            endpoint.releaseAndReuse();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
index c63f510..94081f6 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp1ServerTestBase.java
@@ -27,13 +27,9 @@
 
 package org.apache.hc.core5.testing.nio;
 
-import java.net.URL;
-
-import javax.net.ssl.SSLContext;
-
 import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.ssl.SSLContextBuilder;
 import org.apache.hc.core5.testing.ProtocolScheme;
+import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.TimeValue;
 import org.junit.Rule;
 import org.junit.rules.ExternalResource;
@@ -59,7 +55,7 @@ public abstract class InternalHttp1ServerTestBase {
         protected void before() throws Throwable {
             server = new Http1TestServer(
                     IOReactorConfig.DEFAULT,
-                    scheme == ProtocolScheme.HTTPS ? createServerSSLContext() : null);
+                    scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
         }
 
         @Override
@@ -75,21 +71,4 @@ public abstract class InternalHttp1ServerTestBase {
 
     };
 
-    protected SSLContext createServerSSLContext() throws Exception {
-        final URL keyStoreURL = getClass().getResource("/test.keystore");
-        final String storePassword = "nopassword";
-        return SSLContextBuilder.create()
-                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
-                .loadKeyMaterial(keyStoreURL, storePassword.toCharArray(), storePassword.toCharArray())
-                .build();
-    }
-
-    protected SSLContext createClientSSLContext() throws Exception {
-        final URL keyStoreURL = getClass().getResource("/test.keystore");
-        final String storePassword = "nopassword";
-        return SSLContextBuilder.create()
-                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
-                .build();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
index 7d49753..c2f0e28 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/InternalHttp2ServerTestBase.java
@@ -27,13 +27,9 @@
 
 package org.apache.hc.core5.testing.nio;
 
-import java.net.URL;
-
-import javax.net.ssl.SSLContext;
-
 import org.apache.hc.core5.reactor.IOReactorConfig;
-import org.apache.hc.core5.ssl.SSLContextBuilder;
 import org.apache.hc.core5.testing.ProtocolScheme;
+import org.apache.hc.core5.testing.SSLTestContexts;
 import org.apache.hc.core5.util.TimeValue;
 import org.junit.Rule;
 import org.junit.rules.ExternalResource;
@@ -58,7 +54,7 @@ public abstract class InternalHttp2ServerTestBase {
         @Override
         protected void before() throws Throwable {
             server = new Http2TestServer(IOReactorConfig.DEFAULT,
-                    scheme == ProtocolScheme.HTTPS ? createServerSSLContext() : null);
+                    scheme == ProtocolScheme.HTTPS ? SSLTestContexts.createServerSSLContext() : null);
         }
 
         @Override
@@ -74,21 +70,4 @@ public abstract class InternalHttp2ServerTestBase {
 
     };
 
-    protected SSLContext createServerSSLContext() throws Exception {
-        final URL keyStoreURL = getClass().getResource("/test.keystore");
-        final String storePassword = "nopassword";
-        return SSLContextBuilder.create()
-                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
-                .loadKeyMaterial(keyStoreURL, storePassword.toCharArray(), storePassword.toCharArray())
-                .build();
-    }
-
-    protected SSLContext createClientSSLContext() throws Exception {
-        final URL keyStoreURL = getClass().getResource("/test.keystore");
-        final String storePassword = "nopassword";
-        return SSLContextBuilder.create()
-                .loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
-                .build();
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
index 42d12ff..0f0c787 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
@@ -313,7 +313,7 @@ public class AsyncReverseProxyExample {
 
             System.out.println("[proxy->origin] " + exchangeState.id + " request connection to " + targetHost);
 
-            requester.connect(targetHost, TimeValue.ofSeconds(30), new FutureCallback<AsyncClientEndpoint>() {
+            requester.connect(targetHost, TimeValue.ofSeconds(30), null, new FutureCallback<AsyncClientEndpoint>() {
 
                 @Override
                 public void completed(final AsyncClientEndpoint clientEndpoint) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ed4b808c/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
index 94c92d5..f0da106 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/bootstrap/AsyncRequester.java
@@ -72,13 +72,14 @@ public class AsyncRequester extends IOReactorExecutor<DefaultConnectingIOReactor
         return new InetSocketAddress(hostName, port);
     }
 
-    protected SessionRequest requestSession(
+    public SessionRequest requestSession(
             final HttpHost host,
             final TimeValue timeout,
+            final Object attachment,
             final SessionRequestCallback callback) {
         Args.notNull(host, "Host");
         Args.notNull(timeout, "Timeout");
-        final SessionRequest  sessionRequest = reactor().connect(host, toSocketAddress(host), null, null, callback);
+        final SessionRequest  sessionRequest = reactor().connect(host, toSocketAddress(host), null, attachment, callback);
         sessionRequest.setConnectTimeout(timeout.toMillisIntBound());
         return sessionRequest;
     }


[36/50] [abbrv] httpcomponents-core git commit: Added some basic convenience request/response producers/consumers

Posted by ol...@apache.org.
Added some basic convenience request/response producers/consumers

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792795 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: fe88c7b31bbde15853257402dffbeff7c117a2ff
Parents: f89ce93
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Wed Apr 26 19:20:57 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Wed Apr 26 19:20:57 2017 +0000

----------------------------------------------------------------------
 .../support/AbstractAsyncRequesterConsumer.java | 126 +++++++++++++++++++
 .../support/AbstractAsyncResponseConsumer.java  | 126 +++++++++++++++++++
 .../nio/support/BasicAsyncRequestProducer.java  |  83 ++++++++++++
 .../nio/support/BasicAsyncResponseProducer.java |  83 ++++++++++++
 4 files changed, 418 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fe88c7b3/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractAsyncRequesterConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractAsyncRequesterConsumer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractAsyncRequesterConsumer.java
new file mode 100644
index 0000000..b164e6b
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractAsyncRequesterConsumer.java
@@ -0,0 +1,126 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.nio.support;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.List;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.AsyncRequestConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+import org.apache.hc.core5.util.Args;
+
+public abstract class AbstractAsyncRequesterConsumer<T, E> implements AsyncRequestConsumer<T> {
+
+    private final AsyncEntityConsumer<E> entityConsumer;
+
+    private volatile T result;
+
+    public AbstractAsyncRequesterConsumer(final AsyncEntityConsumer<E> entityConsumer) {
+        Args.notNull(entityConsumer, "Entity consumer");
+        this.entityConsumer = entityConsumer;
+    }
+
+    protected abstract T buildResult(HttpRequest request, E entity, ContentType contentType);
+
+    @Override
+    public final void consumeRequest(
+            final HttpRequest request,
+            final EntityDetails entityDetails,
+            final FutureCallback<T> resultCallback) throws HttpException, IOException {
+        if (entityDetails != null) {
+            entityConsumer.streamStart(entityDetails, new FutureCallback<E>() {
+
+                @Override
+                public void completed(final E entity) {
+                    final ContentType contentType;
+                    try {
+                        contentType = ContentType.parse(entityDetails.getContentType());
+                        result = buildResult(request, entity, contentType);
+                        resultCallback.completed(result);
+                    } catch (final UnsupportedCharsetException ex) {
+                        resultCallback.failed(ex);
+                    }
+                }
+
+                @Override
+                public void failed(final Exception ex) {
+                    resultCallback.failed(ex);
+                }
+
+                @Override
+                public void cancelled() {
+                    resultCallback.cancelled();
+                }
+
+            });
+        } else {
+            resultCallback.completed(buildResult(request, null, null));
+            entityConsumer.releaseResources();
+        }
+
+    }
+
+    @Override
+    public final void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
+        entityConsumer.updateCapacity(capacityChannel);
+    }
+
+    @Override
+    public final int consume(final ByteBuffer src) throws IOException {
+        return entityConsumer.consume(src);
+    }
+
+    @Override
+    public final void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException {
+        entityConsumer.streamEnd(trailers);
+    }
+
+    @Override
+    public T getResult() {
+        return result;
+    }
+
+    @Override
+    public final void failed(final Exception cause) {
+        releaseResources();
+    }
+
+    @Override
+    public final void releaseResources() {
+        entityConsumer.releaseResources();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fe88c7b3/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractAsyncResponseConsumer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractAsyncResponseConsumer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractAsyncResponseConsumer.java
new file mode 100644
index 0000000..02c5662
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/AbstractAsyncResponseConsumer.java
@@ -0,0 +1,126 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.nio.support;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.List;
+
+import org.apache.hc.core5.concurrent.FutureCallback;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.Header;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.AsyncResponseConsumer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+import org.apache.hc.core5.util.Args;
+
+public abstract class AbstractAsyncResponseConsumer<T, E> implements AsyncResponseConsumer<T> {
+
+    private final AsyncEntityConsumer<E> entityConsumer;
+
+    private volatile T result;
+
+    public AbstractAsyncResponseConsumer(final AsyncEntityConsumer<E> entityConsumer) {
+        Args.notNull(entityConsumer, "Entity consumer");
+        this.entityConsumer = entityConsumer;
+    }
+
+    protected abstract T buildResult(HttpResponse response, E entity, ContentType contentType);
+
+    @Override
+    public final void consumeResponse(
+            final HttpResponse response,
+            final EntityDetails entityDetails,
+            final FutureCallback<T> resultCallback) throws HttpException, IOException {
+        if (entityDetails != null) {
+            entityConsumer.streamStart(entityDetails, new FutureCallback<E>() {
+
+                @Override
+                public void completed(final E entity) {
+                    final ContentType contentType;
+                    try {
+                        contentType = ContentType.parse(entityDetails.getContentType());
+                        result = buildResult(response, entity, contentType);
+                        resultCallback.completed(result);
+                    } catch (final UnsupportedCharsetException ex) {
+                        resultCallback.failed(ex);
+                    }
+                }
+
+                @Override
+                public void failed(final Exception ex) {
+                    resultCallback.failed(ex);
+                }
+
+                @Override
+                public void cancelled() {
+                    resultCallback.cancelled();
+                }
+
+            });
+        } else {
+            resultCallback.completed(buildResult(response, null, null));
+            entityConsumer.releaseResources();
+        }
+
+    }
+
+    @Override
+    public final void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
+        entityConsumer.updateCapacity(capacityChannel);
+    }
+
+    @Override
+    public final int consume(final ByteBuffer src) throws IOException {
+        return entityConsumer.consume(src);
+    }
+
+    @Override
+    public final void streamEnd(final List<? extends Header> trailers) throws HttpException, IOException {
+        entityConsumer.streamEnd(trailers);
+    }
+
+    @Override
+    public T getResult() {
+        return result;
+    }
+
+    @Override
+    public final void failed(final Exception cause) {
+        releaseResources();
+    }
+
+    @Override
+    public final void releaseResources() {
+        entityConsumer.releaseResources();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fe88c7b3/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncRequestProducer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncRequestProducer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncRequestProducer.java
new file mode 100644
index 0000000..4bfce2f
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncRequestProducer.java
@@ -0,0 +1,83 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.nio.support;
+
+import java.io.IOException;
+
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.AsyncRequestProducer;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.util.Args;
+
+public class BasicAsyncRequestProducer implements AsyncRequestProducer {
+
+    private final HttpRequest request;
+    private final AsyncEntityProducer entityProducer;
+
+    public BasicAsyncRequestProducer(final HttpRequest request, final AsyncEntityProducer entityProducer) {
+        Args.notNull(request, "Request");
+        this.request = request;
+        this.entityProducer = entityProducer;
+    }
+
+    @Override
+    public final HttpRequest produceRequest() {
+        return request;
+    }
+
+    @Override
+    public final EntityDetails getEntityDetails() {
+        return entityProducer;
+    }
+
+    @Override
+    public final int available() {
+        return entityProducer != null ? entityProducer.available() : 0;
+    }
+
+    @Override
+    public final void produce(final DataStreamChannel channel) throws IOException {
+        if (entityProducer != null) {
+            entityProducer.produce(channel);
+        }
+    }
+
+    @Override
+    public final void failed(final Exception cause) {
+        releaseResources();
+    }
+
+    @Override
+    public final void releaseResources() {
+        if (entityProducer != null) {
+            entityProducer.releaseResources();
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/fe88c7b3/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncResponseProducer.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncResponseProducer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncResponseProducer.java
new file mode 100644
index 0000000..9d4ca52
--- /dev/null
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/nio/support/BasicAsyncResponseProducer.java
@@ -0,0 +1,83 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.nio.support;
+
+import java.io.IOException;
+
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.nio.AsyncEntityProducer;
+import org.apache.hc.core5.http.nio.AsyncResponseProducer;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.util.Args;
+
+public class BasicAsyncResponseProducer implements AsyncResponseProducer {
+
+    private final HttpResponse response;
+    private final AsyncEntityProducer entityProducer;
+
+    public BasicAsyncResponseProducer(final HttpResponse response, final AsyncEntityProducer entityProducer) {
+        Args.notNull(response, "Response");
+        this.response = response;
+        this.entityProducer = entityProducer;
+    }
+
+    @Override
+    public HttpResponse produceResponse() {
+        return response;
+    }
+
+    @Override
+    public final EntityDetails getEntityDetails() {
+        return entityProducer;
+    }
+
+    @Override
+    public final int available() {
+        return entityProducer != null ? entityProducer.available() : 0;
+    }
+
+    @Override
+    public final void produce(final DataStreamChannel channel) throws IOException {
+        if (entityProducer != null) {
+            entityProducer.produce(channel);
+        }
+    }
+
+    @Override
+    public final void failed(final Exception cause) {
+        releaseResources();
+    }
+
+    @Override
+    public final void releaseResources() {
+        if (entityProducer != null) {
+            entityProducer.releaseResources();
+        }
+    }
+
+}


[46/50] [abbrv] httpcomponents-core git commit: Rename variables "sslcontext" to "sslContext".

Posted by ol...@apache.org.
Rename variables "sslcontext" to "sslContext".

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793839 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 993ee4d5835a69777cfd59cfe5ad21dd4e86568e
Parents: f392d69
Author: Gary D. Gregory <gg...@apache.org>
Authored: Thu May 4 17:52:27 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Thu May 4 17:52:27 2017 +0000

----------------------------------------------------------------------
 .../examples/Http2SSLRequestExecutionExample.java     |  4 ++--
 .../core5/http/examples/ClassicFileServerExample.java |  6 +++---
 .../org/apache/hc/core5/ssl/SSLContextBuilder.java    | 14 +++++++-------
 .../java/org/apache/hc/core5/ssl/SSLContexts.java     |  6 +++---
 4 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/993ee4d5/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
index 0463420..00ef85f 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2SSLRequestExecutionExample.java
@@ -67,7 +67,7 @@ public class Http2SSLRequestExecutionExample {
 
     public final static void main(final String[] args) throws Exception {
         // Trust standard CA and those trusted by our custom strategy
-        final SSLContext sslcontext = SSLContexts.custom()
+        final SSLContext sslContext = SSLContexts.custom()
                 .loadTrustMaterial(new TrustStrategy() {
 
                     @Override
@@ -88,7 +88,7 @@ public class Http2SSLRequestExecutionExample {
 
         final HttpAsyncRequester requester = H2RequesterBootstrap.bootstrap()
                 .setH2Config(h2Config)
-                .setTlsStrategy(new H2ClientTlsStrategy(sslcontext, new SSLSessionVerifier() {
+                .setTlsStrategy(new H2ClientTlsStrategy(sslContext, new SSLSessionVerifier() {
 
                     @Override
                     public TlsDetails verify(final NamedEndpoint endpoint, final SSLEngine sslEngine) throws SSLException {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/993ee4d5/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
index d590e38..1720658 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
@@ -78,7 +78,7 @@ public class ClassicFileServerExample {
             port = Integer.parseInt(args[1]);
         }
 
-        SSLContext sslcontext = null;
+        SSLContext sslContext = null;
         if (port == 8443) {
             // Initialize SSL context
             URL url = ClassicFileServerExample.class.getResource("/my.keystore");
@@ -86,7 +86,7 @@ public class ClassicFileServerExample {
                 System.out.println("Keystore not found");
                 System.exit(1);
             }
-            sslcontext = SSLContexts.custom()
+            sslContext = SSLContexts.custom()
                     .loadKeyMaterial(url, "secret".toCharArray(), "secret".toCharArray())
                     .build();
         }
@@ -99,7 +99,7 @@ public class ClassicFileServerExample {
         final HttpServer server = ServerBootstrap.bootstrap()
                 .setListenerPort(port)
                 .setSocketConfig(socketConfig)
-                .setSslContext(sslcontext)
+                .setSslContext(sslContext)
                 .setExceptionListener(new ExceptionListener() {
 
                     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/993ee4d5/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
index d06d526..5797fd2 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
@@ -265,26 +265,26 @@ public class SSLContextBuilder {
     }
 
     protected void initSSLContext(
-            final SSLContext sslcontext,
+            final SSLContext sslContext,
             final Collection<KeyManager> keyManagers,
             final Collection<TrustManager> trustManagers,
             final SecureRandom secureRandom) throws KeyManagementException {
-        sslcontext.init(
+        sslContext.init(
                 !keyManagers.isEmpty() ? keyManagers.toArray(new KeyManager[keyManagers.size()]) : null,
                 !trustManagers.isEmpty() ? trustManagers.toArray(new TrustManager[trustManagers.size()]) : null,
                 secureRandom);
     }
 
     public SSLContext build() throws NoSuchAlgorithmException, KeyManagementException {
-        final SSLContext sslcontext;
+        final SSLContext sslContext;
         final String protocolStr = this.protocol != null ? this.protocol : TLS;
         if (this.provider != null) {
-            sslcontext = SSLContext.getInstance(protocolStr, this.provider);
+            sslContext = SSLContext.getInstance(protocolStr, this.provider);
         } else {
-            sslcontext = SSLContext.getInstance(protocolStr);
+            sslContext = SSLContext.getInstance(protocolStr);
         }
-        initSSLContext(sslcontext, keymanagers, trustmanagers, secureRandom);
-        return sslcontext;
+        initSSLContext(sslContext, keymanagers, trustmanagers, secureRandom);
+        return sslContext;
     }
 
     static class TrustManagerDelegate implements X509TrustManager {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/993ee4d5/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java
index 6b7de0d..213026b 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContexts.java
@@ -63,9 +63,9 @@ public final class SSLContexts {
      */
     public static SSLContext createDefault() throws SSLInitializationException {
         try {
-            final SSLContext sslcontext = SSLContext.getInstance(SSLContextBuilder.TLS);
-            sslcontext.init(null, null, null);
-            return sslcontext;
+            final SSLContext sslContext = SSLContext.getInstance(SSLContextBuilder.TLS);
+            sslContext.init(null, null, null);
+            return sslContext;
         } catch (final NoSuchAlgorithmException | KeyManagementException ex) {
             throw new SSLInitializationException(ex.getMessage(), ex);
         }


[07/50] [abbrv] httpcomponents-core git commit: HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Fix test method name.

Posted by ol...@apache.org.
HTTPCORE-451: Add a TimeValue class to wrap a long and a TimeUnit. Fix test method name.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791980 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: c704b3a6bd9ede5c1ddd673aa9072d7e7da3f690
Parents: 5f87041
Author: Gary D. Gregory <gg...@apache.org>
Authored: Wed Apr 19 21:25:06 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Wed Apr 19 21:25:06 2017 +0000

----------------------------------------------------------------------
 .../src/test/java/org/apache/hc/core5/util/TestTimeValue.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/c704b3a6/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
index 559b11a..9a34e40 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/util/TestTimeValue.java
@@ -73,7 +73,7 @@ public class TestTimeValue {
     }
 
     @Test
-    public void test1Negative1() {
+    public void testNegative1() {
         test(-1);
     }
 


[22/50] [abbrv] httpcomponents-core git commit: Fix generics compiler warning.

Posted by ol...@apache.org.
Fix generics compiler warning.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792540 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 6f1173c36816e14cff9626238f654642685ef7d9
Parents: 4c3fd51
Author: Gary D. Gregory <gg...@apache.org>
Authored: Mon Apr 24 19:46:46 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Mon Apr 24 19:46:46 2017 +0000

----------------------------------------------------------------------
 .../src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/6f1173c3/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
index 333d5f0..308bbab 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/ReflectionSupport.java
@@ -31,7 +31,7 @@ import java.lang.reflect.Method;
 
 public final class ReflectionSupport {
 
-    public static void callSetter(final Object object, final String setterName, final Class type, final Object value) {
+    public static void callSetter(final Object object, final String setterName, final Class<?> type, final Object value) {
         try {
             final Class<?> clazz = object.getClass();
             final Method method = clazz.getMethod("set" + setterName, type);


[43/50] [abbrv] httpcomponents-core git commit: Checkstyle fixes.

Posted by ol...@apache.org.
Checkstyle fixes.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1793427 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 981ad57f041d25195b79982c3bcc507a8efed839
Parents: aa9928d
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 2 01:08:31 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 2 01:08:31 2017 +0000

----------------------------------------------------------------------
 .../src/main/java/org/apache/hc/core5/util/TimeValue.java   | 9 +++++----
 .../src/main/java/org/apache/hc/core5/util/Timeout.java     | 8 +++-----
 2 files changed, 8 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/981ad57f/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
index 877a92b..d81253a 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/TimeValue.java
@@ -170,17 +170,18 @@ public class TimeValue {
 
     /**
      * Parses a TimeValue in the format {@code <Integer><SPACE><TimeUnit>}, for example {@code "1,200 MILLISECONDS"}
-     * 
+     *
      * @param value
      *            the TimeValue to parse
      * @return a new TimeValue
      * @throws ParseException
      *             if the number cannot be parsed
      */
-    public static TimeValue parse(String value) throws ParseException {
-        String split[] = value.split("\\s+");
+    public static TimeValue parse(final String value) throws ParseException {
+        final String split[] = value.split("\\s+");
         if (split.length < 2) {
-            throw new IllegalArgumentException(String.format("Expected format for <Integer><SPACE><TimeUnit>: ", value));
+            throw new IllegalArgumentException(
+                    String.format("Expected format for <Integer><SPACE><TimeUnit>: ", value));
         }
         return TimeValue.of(NumberFormat.getInstance().parse(split[0]).longValue(),
                 TimeUnit.valueOf(split[1].trim().toUpperCase(Locale.ROOT)));

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/981ad57f/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
index 5b1f3b8..04b40e0 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/util/Timeout.java
@@ -27,9 +27,7 @@
 
 package org.apache.hc.core5.util;
 
-import java.text.NumberFormat;
 import java.text.ParseException;
-import java.util.Locale;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.hc.core5.annotation.Contract;
@@ -152,17 +150,17 @@ public class Timeout extends TimeValue {
 
     /**
      * Parses a Timeout in the format {@code <Integer><SPACE><TimeUnit>}, for example {@code "1,200 MILLISECONDS"}
-     * 
+     *
      * @param value
      *            the TimeValue to parse
      * @return a new TimeValue
      * @throws ParseException
      *             if the number cannot be parsed
      */
-    public static Timeout parse(String value) throws ParseException {
+    public static Timeout parse(final String value) throws ParseException {
         return TimeValue.parse(value).toTimeout();
     }
-    
+
     private static long validateDuration(final long duration) {
         if (duration < INT_UNDEFINED) {
             throw new IllegalArgumentException("Duration may not be less than " + INT_UNDEFINED);


[32/50] [abbrv] httpcomponents-core git commit: HTTPCORE-458: Validate port values. Javadoc.

Posted by ol...@apache.org.
HTTPCORE-458: Validate port values. Javadoc.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792681 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 874ada92596a5c1c866587bc9b07748dcee43e40
Parents: 7cdac6d
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 23:11:00 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 23:11:00 2017 +0000

----------------------------------------------------------------------
 httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/874ada92/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java b/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java
index 156c40f..51b7bf6 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/net/Ports.java
@@ -58,8 +58,8 @@ public class Ports {
      * @return the port
      *
      * @throws IllegalArgumentException
-     *             if the port parameter is outside the specified range of valid port values, which is between 0 and
-     *             65535, inclusive.
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
      */
     public static int check(final int port) {
         return Args.checkRange(port, SCHEME_DEFAULT, MAX_VALUE,


[10/50] [abbrv] httpcomponents-core git commit: Fixed examples

Posted by ol...@apache.org.
Fixed examples

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792441 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 3d507fc452e909354574bf91c1b6a90bc1cefefa
Parents: fe9b6f4
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Apr 24 09:23:19 2017 +0000
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Apr 24 09:23:19 2017 +0000

----------------------------------------------------------------------
 .../org/apache/hc/core5/http/examples/Http2FileServerExample.java  | 2 +-
 .../org/apache/hc/core5/http/examples/AsyncFileServerExample.java  | 2 +-
 .../apache/hc/core5/http/examples/AsyncReverseProxyExample.java    | 2 +-
 .../apache/hc/core5/http/examples/ClassicFileServerExample.java    | 2 +-
 .../apache/hc/core5/http/examples/ClassicReverseProxyExample.java  | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3d507fc4/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
index 3477eef..d95afbb 100644
--- a/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
+++ b/httpcore5-h2/src/examples/org/apache/hc/core5/http/examples/Http2FileServerExample.java
@@ -237,7 +237,7 @@ public class Http2FileServerExample {
         ListenerEndpoint listenerEndpoint = server.listen(new InetSocketAddress(port));
         listenerEndpoint.waitFor();
         System.out.print("Listening on " + listenerEndpoint.getAddress());
-        server.awaitShutdown(TimeValue.MAX_VALUE);
+        server.awaitShutdown(TimeValue.ofDays(Long.MAX_VALUE));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3d507fc4/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
index bef7217..610c959 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncFileServerExample.java
@@ -200,7 +200,7 @@ public class AsyncFileServerExample {
         ListenerEndpoint listenerEndpoint = server.listen(new InetSocketAddress(port));
         listenerEndpoint.waitFor();
         System.out.print("Listening on " + listenerEndpoint.getAddress());
-        server.awaitShutdown(TimeValue.MAX_VALUE);
+        server.awaitShutdown(TimeValue.ofDays(Long.MAX_VALUE));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3d507fc4/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
index 4a7109c..42d12ff 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/AsyncReverseProxyExample.java
@@ -222,7 +222,7 @@ public class AsyncReverseProxyExample {
         server.listen(new InetSocketAddress(port));
         System.out.println("Listening on port " + port);
 
-        server.awaitShutdown(TimeValue.MAX_VALUE);
+        server.awaitShutdown(TimeValue.ofDays(Long.MAX_VALUE));
     }
 
     private static class ProxyBuffer extends ExpandableBuffer {

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3d507fc4/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
index 45fd44c..d590e38 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicFileServerExample.java
@@ -126,7 +126,7 @@ public class ClassicFileServerExample {
         });
         System.out.println("Listening on port " + port);
 
-        server.awaitTermination(TimeValue.MAX_VALUE);
+        server.awaitTermination(TimeValue.ofDays(Long.MAX_VALUE));
 
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/3d507fc4/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
index 4fa7c06..ca4723f 100644
--- a/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
+++ b/httpcore5/src/examples/org/apache/hc/core5/http/examples/ClassicReverseProxyExample.java
@@ -178,7 +178,7 @@ public class ClassicReverseProxyExample {
         });
 
         System.out.println("Listening on port " + port);
-        server.awaitTermination(TimeValue.MAX_VALUE);
+        server.awaitTermination(TimeValue.ofDays(Long.MAX_VALUE));
     }
 
     private final static Set<String> HOP_BY_HOP = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(


[26/50] [abbrv] httpcomponents-core git commit: Use try-with-resources to fix compiler warnings.

Posted by ol...@apache.org.
Use try-with-resources to fix compiler warnings.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792662 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: ffaafb73fb92ffa2fd51b79fdcf994c417843dd5
Parents: cb20293
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 21:32:47 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 21:32:47 2017 +0000

----------------------------------------------------------------------
 .../core5/http/io/entity/TestEntityUtils.java   | 260 ++++++++++---------
 1 file changed, 132 insertions(+), 128 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/ffaafb73/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java
index b8ab519..78f07a9 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/http/io/entity/TestEntityUtils.java
@@ -60,52 +60,54 @@ public class TestEntityUtils {
 
     @Test
     public void testEmptyContentToByteArray() throws Exception {
-        final NullHttpEntity httpentity = new NullHttpEntity();
-        final byte[] bytes = EntityUtils.toByteArray(httpentity);
-        Assert.assertNull(bytes);
+        try (final NullHttpEntity httpentity = new NullHttpEntity()) {
+            final byte[] bytes = EntityUtils.toByteArray(httpentity);
+            Assert.assertNull(bytes);
+        }
     }
 
     @Test
     public void testMaxIntContentToByteArray() throws Exception {
         final byte[] content = "Message content".getBytes(StandardCharsets.ISO_8859_1);
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(content));
-        httpentity.setContentLength(Integer.MAX_VALUE + 100L);
-        try {
-            EntityUtils.toByteArray(httpentity);
-            Assert.fail("IllegalArgumentException should have been thrown");
-        } catch (final IllegalArgumentException ex) {
-            // expected
-        }
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(content));
+            httpentity.setContentLength(Integer.MAX_VALUE + 100L);
+            try {
+                EntityUtils.toByteArray(httpentity);
+                Assert.fail("IllegalArgumentException should have been thrown");
+            } catch (final IllegalArgumentException ex) {
+                // expected
+            }
+        }}
 
     @Test
     public void testUnknownLengthContentToByteArray() throws Exception {
         final byte[] bytes = "Message content".getBytes(StandardCharsets.ISO_8859_1);
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(bytes));
-        httpentity.setContentLength(-1L);
-        final byte[] bytes2 = EntityUtils.toByteArray(httpentity);
-        Assert.assertNotNull(bytes2);
-        Assert.assertEquals(bytes.length, bytes2.length);
-        for (int i = 0; i < bytes.length; i++) {
-            Assert.assertEquals(bytes[i], bytes2[i]);
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(bytes));
+            httpentity.setContentLength(-1L);
+            final byte[] bytes2 = EntityUtils.toByteArray(httpentity);
+            Assert.assertNotNull(bytes2);
+            Assert.assertEquals(bytes.length, bytes2.length);
+            for (int i = 0; i < bytes.length; i++) {
+                Assert.assertEquals(bytes[i], bytes2[i]);
+            }
         }
     }
 
     @Test
     public void testKnownLengthContentToByteArray() throws Exception {
         final byte[] bytes = "Message content".getBytes(StandardCharsets.ISO_8859_1);
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(bytes));
-        httpentity.setContentLength(bytes.length);
-        final byte[] bytes2 = EntityUtils.toByteArray(httpentity);
-        Assert.assertNotNull(bytes2);
-        Assert.assertEquals(bytes.length, bytes2.length);
-        for (int i = 0; i < bytes.length; i++) {
-            Assert.assertEquals(bytes[i], bytes2[i]);
-        }
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(bytes));
+            httpentity.setContentLength(bytes.length);
+            final byte[] bytes2 = EntityUtils.toByteArray(httpentity);
+            Assert.assertNotNull(bytes2);
+            Assert.assertEquals(bytes.length, bytes2.length);
+            for (int i = 0; i < bytes.length; i++) {
+                Assert.assertEquals(bytes[i], bytes2[i]);
+            }
+        }}
 
     @Test
     public void testNullEntityToString() throws Exception {
@@ -119,44 +121,44 @@ public class TestEntityUtils {
 
     @Test
     public void testEmptyContentToString() throws Exception {
-        final NullHttpEntity httpentity = new NullHttpEntity();
-        final String s = EntityUtils.toString(httpentity);
-        Assert.assertNull(s);
-    }
+        try (final NullHttpEntity httpentity = new NullHttpEntity()) {
+            final String s = EntityUtils.toString(httpentity);
+            Assert.assertNull(s);
+        }}
 
     @Test
     public void testMaxIntContentToString() throws Exception {
         final byte[] content = "Message content".getBytes(StandardCharsets.ISO_8859_1);
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(content));
-        httpentity.setContentLength(Integer.MAX_VALUE + 100L);
-        try {
-            EntityUtils.toString(httpentity);
-            Assert.fail("IllegalArgumentException should have been thrown");
-        } catch (final IllegalArgumentException ex) {
-            // expected
-        }
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(content));
+            httpentity.setContentLength(Integer.MAX_VALUE + 100L);
+            try {
+                EntityUtils.toString(httpentity);
+                Assert.fail("IllegalArgumentException should have been thrown");
+            } catch (final IllegalArgumentException ex) {
+                // expected
+            }
+        }}
 
     @Test
     public void testUnknownLengthContentToString() throws Exception {
         final byte[] bytes = "Message content".getBytes(StandardCharsets.ISO_8859_1);
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(bytes));
-        httpentity.setContentLength(-1L);
-        final String s = EntityUtils.toString(httpentity, "ISO-8859-1");
-        Assert.assertEquals("Message content", s);
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(bytes));
+            httpentity.setContentLength(-1L);
+            final String s = EntityUtils.toString(httpentity, "ISO-8859-1");
+            Assert.assertEquals("Message content", s);
+        }}
 
     @Test
     public void testKnownLengthContentToString() throws Exception {
         final byte[] bytes = "Message content".getBytes(StandardCharsets.ISO_8859_1);
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(bytes));
-        httpentity.setContentLength(bytes.length);
-        final String s = EntityUtils.toString(httpentity, "ISO-8859-1");
-        Assert.assertEquals("Message content", s);
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(bytes));
+            httpentity.setContentLength(bytes.length);
+            final String s = EntityUtils.toString(httpentity, "ISO-8859-1");
+            Assert.assertEquals("Message content", s);
+        }}
 
     static final int SWISS_GERMAN_HELLO [] = {
         0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4
@@ -181,44 +183,45 @@ public class TestEntityUtils {
     public void testNoCharsetContentToString() throws Exception {
         final String content = constructString(SWISS_GERMAN_HELLO);
         final byte[] bytes = content.getBytes(StandardCharsets.ISO_8859_1);
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(bytes));
-        httpentity.setContentType("text/plain");
-        final String s = EntityUtils.toString(httpentity);
-        Assert.assertEquals(content, s);
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(bytes));
+            httpentity.setContentType("text/plain");
+            final String s = EntityUtils.toString(httpentity);
+            Assert.assertEquals(content, s);
+        }}
 
     @Test
     public void testDefaultCharsetContentToString() throws Exception {
         final String content = constructString(RUSSIAN_HELLO);
         final byte[] bytes = content.getBytes(Charset.forName("KOI8-R"));
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(bytes));
-        httpentity.setContentType("text/plain");
-        final String s = EntityUtils.toString(httpentity, "KOI8-R");
-        Assert.assertEquals(content, s);
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(bytes));
+            httpentity.setContentType("text/plain");
+            final String s = EntityUtils.toString(httpentity, "KOI8-R");
+            Assert.assertEquals(content, s);
+        }}
 
     @Test
     public void testContentWithContentTypeToString() throws Exception {
         final String content = constructString(RUSSIAN_HELLO);
         final byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(bytes));
-        httpentity.setContentType("text/plain; charset=UTF-8");
-        final String s = EntityUtils.toString(httpentity, "ISO-8859-1");
-        Assert.assertEquals(content, s);
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(bytes));
+            httpentity.setContentType("text/plain; charset=UTF-8");
+            final String s = EntityUtils.toString(httpentity, "ISO-8859-1");
+            Assert.assertEquals(content, s);
+        }}
+    
     @Test
     public void testContentWithInvalidContentTypeToString() throws Exception {
         final String content = constructString(RUSSIAN_HELLO);
         final byte[] bytes = content.getBytes("UTF-8");
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContent(new ByteArrayInputStream(bytes));
-        httpentity.setContentType("text/plain; charset=nosuchcharset");
-        final String s = EntityUtils.toString(httpentity, "UTF-8");
-        Assert.assertEquals(content, s);
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContent(new ByteArrayInputStream(bytes));
+            httpentity.setContentType("text/plain; charset=nosuchcharset");
+            final String s = EntityUtils.toString(httpentity, "UTF-8");
+            Assert.assertEquals(content, s);
+        }}
 
     @Test
     public void testExtractNullInput() throws Exception {
@@ -227,37 +230,37 @@ public class TestEntityUtils {
 
     @Test
     public void testExtractNullContentType() throws Exception {
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContentType(null);
-        Assert.assertNull(EntityUtils.getContentType(httpentity));
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContentType(null);
+            Assert.assertNull(EntityUtils.getContentType(httpentity));
+        }}
 
     @Test
     public void testExtract() throws Exception {
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContentType("text/plain; charset = UTF-8");
-        final ContentType contentType = EntityUtils.getContentType(httpentity);
-        Assert.assertNotNull(contentType);
-        Assert.assertEquals("text/plain", contentType.getMimeType());
-        Assert.assertEquals(StandardCharsets.UTF_8, contentType.getCharset());
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContentType("text/plain; charset = UTF-8");
+            final ContentType contentType = EntityUtils.getContentType(httpentity);
+            Assert.assertNotNull(contentType);
+            Assert.assertEquals("text/plain", contentType.getMimeType());
+            Assert.assertEquals(StandardCharsets.UTF_8, contentType.getCharset());
+        }}
 
     @Test
     public void testExtractNoCharset() throws Exception {
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContentType("text/plain; param=yadayada");
-        final ContentType contentType = EntityUtils.getContentType(httpentity);
-        Assert.assertNotNull(contentType);
-        Assert.assertEquals("text/plain", contentType.getMimeType());
-        Assert.assertNull(contentType.getCharset());
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContentType("text/plain; param=yadayada");
+            final ContentType contentType = EntityUtils.getContentType(httpentity);
+            Assert.assertNotNull(contentType);
+            Assert.assertEquals("text/plain", contentType.getMimeType());
+            Assert.assertNull(contentType.getCharset());
+        }}
 
     @Test(expected = UnsupportedCharsetException.class)
     public void testExtractInvalidCharset() throws Exception {
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContentType("text/plain; charset = stuff");
-        EntityUtils.getContentType(httpentity);
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContentType("text/plain; charset = stuff");
+            EntityUtils.getContentType(httpentity);
+        }}
 
     @Test
     public void testExtracLenienttNullInput() throws Exception {
@@ -266,20 +269,20 @@ public class TestEntityUtils {
 
     @Test
     public void testExtractLenientNullContentType() throws Exception {
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContentType(null);
-        Assert.assertNull(EntityUtils.getContentTypeLenient(httpentity));
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContentType(null);
+            Assert.assertNull(EntityUtils.getContentTypeLenient(httpentity));
+        }}
 
     @Test
     public void testLenientExtractInvalidCharset() throws Exception {
-        final BasicHttpEntity httpentity = new BasicHttpEntity();
-        httpentity.setContentType("text/plain; charset = stuff");
-        final ContentType contentType = EntityUtils.getContentTypeLenient(httpentity);
-        Assert.assertNotNull(contentType);
-        Assert.assertEquals("text/plain", contentType.getMimeType());
-        Assert.assertEquals(null, contentType.getCharset());
-    }
+        try (final BasicHttpEntity httpentity = new BasicHttpEntity()) {
+            httpentity.setContentType("text/plain; charset = stuff");
+            final ContentType contentType = EntityUtils.getContentTypeLenient(httpentity);
+            Assert.assertNotNull(contentType);
+            Assert.assertEquals("text/plain", contentType.getMimeType());
+            Assert.assertEquals(null, contentType.getCharset());
+        }}
 
     private static void assertNameValuePair (
             final NameValuePair parameter,
@@ -291,16 +294,16 @@ public class TestEntityUtils {
 
     @Test
     public void testParseEntity() throws Exception {
-        final StringEntity entity = new StringEntity("Name1=Value1");
+        try (final StringEntity entity = new StringEntity("Name1=Value1")) {
 
-        entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
-        final List<NameValuePair> result = EntityUtils.parse(entity);
-        Assert.assertEquals(1, result.size());
-        assertNameValuePair(result.get(0), "Name1", "Value1");
+            entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
+            final List<NameValuePair> result = EntityUtils.parse(entity);
+            Assert.assertEquals(1, result.size());
+            assertNameValuePair(result.get(0), "Name1", "Value1");
 
-        entity.setContentType("text/test");
-        Assert.assertTrue(EntityUtils.parse(entity).isEmpty());
-    }
+            entity.setContentType("text/test");
+            Assert.assertTrue(EntityUtils.parse(entity).isEmpty());
+        }}
 
     @Test
     public void testParseUTF8Entity() throws Exception {
@@ -315,12 +318,13 @@ public class TestEntityUtils {
         Assert.assertEquals("russian=%D0%92%D1%81%D0%B5%D0%BC_%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" +
                 "&swiss=Gr%C3%BCezi_z%C3%A4m%C3%A4", s);
 
-        final StringEntity entity = new StringEntity(s, ContentType.create(
-                URLEncodedUtils.CONTENT_TYPE, StandardCharsets.UTF_8));
-        final List <NameValuePair> result = EntityUtils.parse(entity);
-        Assert.assertEquals(2, result.size());
-        assertNameValuePair(result.get(0), "russian", ru_hello);
-        assertNameValuePair(result.get(1), "swiss", ch_hello);
+        try (final StringEntity entity = new StringEntity(s,
+                ContentType.create(URLEncodedUtils.CONTENT_TYPE, StandardCharsets.UTF_8))) {
+            final List<NameValuePair> result = EntityUtils.parse(entity);
+            Assert.assertEquals(2, result.size());
+            assertNameValuePair(result.get(0), "russian", ru_hello);
+            assertNameValuePair(result.get(1), "swiss", ch_hello);
+        }
     }
 
     /**


[50/50] [abbrv] httpcomponents-core git commit: Use camel case for instance variable names (which are all private and final.) Add toString().

Posted by ol...@apache.org.
Use camel case for instance variable names (which are all private and final.) Add toString().

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1794495 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: 9c362d4a2e7724495fb48523431286857766ba6f
Parents: e1c42bf
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue May 9 03:01:04 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue May 9 03:01:04 2017 +0000

----------------------------------------------------------------------
 .../apache/hc/core5/ssl/SSLContextBuilder.java  | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/9c362d4a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
index 0b5cd78..6bfc7c6 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/ssl/SSLContextBuilder.java
@@ -80,8 +80,8 @@ public class SSLContextBuilder {
     static final String TLS   = "TLS";
 
     private String protocol;
-    private final Set<KeyManager> keymanagers;
-    private final Set<TrustManager> trustmanagers;
+    private final Set<KeyManager> keyManagers;
+    private final Set<TrustManager> trustManagers;
     private SecureRandom secureRandom;
     private Provider provider;
 
@@ -91,8 +91,8 @@ public class SSLContextBuilder {
 
     public SSLContextBuilder() {
         super();
-        this.keymanagers = new LinkedHashSet<>();
-        this.trustmanagers = new LinkedHashSet<>();
+        this.keyManagers = new LinkedHashSet<>();
+        this.trustManagers = new LinkedHashSet<>();
     }
 
     /**
@@ -147,7 +147,7 @@ public class SSLContextBuilder {
                 }
             }
             for (final TrustManager tm : tms) {
-                this.trustmanagers.add(tm);
+                this.trustManagers.add(tm);
             }
         }
         return this;
@@ -218,7 +218,7 @@ public class SSLContextBuilder {
                 }
             }
             for (final KeyManager km : kms) {
-                keymanagers.add(km);
+                keyManagers.add(km);
             }
         }
         return this;
@@ -289,7 +289,7 @@ public class SSLContextBuilder {
         } else {
             sslContext = SSLContext.getInstance(protocolStr);
         }
-        initSSLContext(sslContext, keymanagers, trustmanagers, secureRandom);
+        initSSLContext(sslContext, keyManagers, trustManagers, secureRandom);
         return sslContext;
     }
 
@@ -418,4 +418,10 @@ public class SSLContextBuilder {
 
     }
 
+    @Override
+    public String toString() {
+        return "[provider=" + provider + ", protocol=" + protocol + ", keyManagers=" + keyManagers
+                + ", trustManagers=" + trustManagers + ", secureRandom=" + secureRandom + "]";
+    }
+
 }


[05/50] [abbrv] httpcomponents-core git commit: Update Log4j from 2.8 to 2.8.2.

Posted by ol...@apache.org.
Update Log4j from 2.8 to 2.8.2.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1791955 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: e7043b524f6b5e3946ccb32e943d508ca3e8f493
Parents: 38a2d5d
Author: Gary D. Gregory <gg...@apache.org>
Authored: Wed Apr 19 19:29:36 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Wed Apr 19 19:29:36 2017 +0000

----------------------------------------------------------------------
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/e7043b52/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 3386352..1756c8e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -79,7 +79,7 @@
     <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
     <junit.version>4.12</junit.version>
     <mockito.version>2.7.22</mockito.version>
-    <log4j.version>2.8</log4j.version>
+    <log4j.version>2.8.2</log4j.version>
     <hc.stylecheck.version>1</hc.stylecheck.version>
   </properties>
 


[35/50] [abbrv] httpcomponents-core git commit: HTTPCORE-458: Validate port values. Add checks and Javadoc.

Posted by ol...@apache.org.
HTTPCORE-458: Validate port values. Add checks and Javadoc.

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1792684 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/trunk
Commit: f89ce937c8aff5fe0423e2239e6d1afde877e66a
Parents: 8faaa62
Author: Gary D. Gregory <gg...@apache.org>
Authored: Tue Apr 25 23:26:07 2017 +0000
Committer: Gary D. Gregory <gg...@apache.org>
Committed: Tue Apr 25 23:26:07 2017 +0000

----------------------------------------------------------------------
 .../java/org/apache/hc/core5/net/URIAuthority.java    | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/f89ce937/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java b/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
index 2dbba21..74d7ab6 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/net/URIAuthority.java
@@ -49,13 +49,23 @@ public final class URIAuthority implements NamedEndpoint, Serializable {
     private final String hostname;
     private final int port;
 
+    /**
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
+     */
     private URIAuthority(final String userInfo, final String hostname, final int port, final boolean internal) {
         super();
         this.userInfo = userInfo;
         this.hostname = hostname;
-        this.port = port;
+        this.port = Ports.check(port);
     }
 
+    /**
+     * @throws IllegalArgumentException
+     *             If the port parameter is outside the specified range of valid port values, which is between 0 and
+     *             65535, inclusive. {@code -1} indicates the scheme default port.
+     */
     public URIAuthority(final String userInfo, final String hostname, final int port) {
         super();
         Args.containsNoBlanks(hostname, "Host name");
@@ -64,7 +74,7 @@ public final class URIAuthority implements NamedEndpoint, Serializable {
         }
         this.userInfo = userInfo;
         this.hostname = hostname.toLowerCase(Locale.ROOT);
-        this.port = port;
+        this.port = Ports.check(port);
     }
 
     public URIAuthority(final String hostname, final int port) {