hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1767339 [5/14] - in /httpcomponents/httpcore/trunk: ./ httpcore5-ab/src/main/java/org/apache/hc/core5/http/benchmark/ httpcore5-ab/src/test/java/org/apache/hc/core5/http/benchmark/ httpcore5-h2/src/main/java/org/apache/hc/core5/http2/boots...
Date Mon, 31 Oct 2016 17:33:33 GMT
Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/Http1IntegrationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/InternalServerTestBase.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/integration/RndTestPatternGenerator.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/InternalServerTestBase.java?p2=httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/InternalServerTestBase.java&p1=httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/integration/RndTestPatternGenerator.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/integration/RndTestPatternGenerator.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/InternalServerTestBase.java Mon Oct 31 17:33:27 2016
@@ -25,30 +25,36 @@
  *
  */
 
-package org.apache.hc.core5.http.integration;
+package org.apache.hc.core5.testing.nio.http;
 
-import java.util.Random;
+import java.util.concurrent.TimeUnit;
 
-final class RndTestPatternGenerator {
+import org.junit.Rule;
+import org.junit.rules.ExternalResource;
 
-    private static final Random RND = new Random();
-    private static final String TEST_CHARS = "0123456789ABCDEF";
+public abstract class InternalServerTestBase {
 
-    public static String generateText() {
-        final StringBuilder buffer = new StringBuilder();
-        for (int i = 0; i < 5; i++) {
-            final char rndchar = TEST_CHARS.charAt(RND.nextInt(TEST_CHARS.length() - 1));
-            buffer.append(rndchar);
+    protected Http1TestServer server;
+
+    @Rule
+    public ExternalResource serverResource = new ExternalResource() {
+
+        @Override
+        protected void before() throws Throwable {
+            server = new Http1TestServer();
+        }
+
+        @Override
+        protected void after() {
+            if (server != null) {
+                try {
+                    server.shutdown(3, TimeUnit.SECONDS);
+                    server = null;
+                } catch (Exception ignore) {
+                }
+            }
         }
-        return buffer.toString();
-    }
 
-    public static int generateCount(final int max) {
-        return RND.nextInt(max - 1) + 1;
-    }
-
-    public static boolean generateBoolean() {
-        return RND.nextBoolean();
-    }
+    };
 
 }

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/InternalServerTestBase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/InternalServerTestBase.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/InternalServerTestBase.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MessageExchangeHandler.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/HandlerFactory.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MessageExchangeHandler.java?p2=httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MessageExchangeHandler.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/HandlerFactory.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/HandlerFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MessageExchangeHandler.java Mon Oct 31 17:33:27 2016
@@ -24,23 +24,38 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio;
-
-import java.io.IOException;
+package org.apache.hc.core5.testing.nio.http;
 
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.AsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.AsyncRequestConsumer;
+import org.apache.hc.core5.http.nio.BasicRequestConsumer;
+import org.apache.hc.core5.http.nio.support.AbstractServerExchangeHandler;
 import org.apache.hc.core5.http.protocol.HttpContext;
 
 /**
- * Abstract handler factory.
- *
- * @param <T> resource holder
- *
  * @since 5.0
  */
-public interface HandlerFactory<T extends ResourceHolder> {
+public abstract class MessageExchangeHandler<T> extends AbstractServerExchangeHandler<Message<HttpRequest, T>> {
+
+    private final AsyncRequestConsumer<Message<HttpRequest, T>> requestConsumer;
+
+    public MessageExchangeHandler(final AsyncRequestConsumer<Message<HttpRequest, T>> requestConsumer) {
+        super();
+        this.requestConsumer = requestConsumer;
+    }
+
+    public MessageExchangeHandler(final AsyncEntityConsumer<T> entityConsumer) {
+        this(new BasicRequestConsumer<>(entityConsumer));
+    }
 
-    T create(HttpRequest request, HttpContext context) throws HttpException, IOException;
+    @Override
+    protected AsyncRequestConsumer<Message<HttpRequest, T>> supplyConsumer(
+            final HttpRequest request,
+            final HttpContext context) throws HttpException {
+        return requestConsumer;
+    }
 
 }

Copied: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineEntityProducer.java (from r1765384, httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/ByteArrayAsyncEntityProducer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineEntityProducer.java?p2=httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineEntityProducer.java&p1=httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/ByteArrayAsyncEntityProducer.java&r1=1765384&r2=1767339&rev=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/nio/entity/ByteArrayAsyncEntityProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineEntityProducer.java Mon Oct 31 17:33:27 2016
@@ -24,38 +24,34 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.hc.core5.http2.nio.entity;
+package org.apache.hc.core5.testing.nio.http;
 
 import java.io.IOException;
-import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
 
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http2.nio.StreamChannel;
-import org.apache.hc.core5.util.Args;
-import org.apache.hc.core5.util.Asserts;
-
-/**
- * @since 5.0
- */
-public class ByteArrayAsyncEntityProducer extends AbstractBinAsyncEntityProducer {
-
-    private final ByteBuffer content;
-    private final int len;
-
-    public ByteArrayAsyncEntityProducer(final byte[] content, final int bufferSize, final ContentType contentType) {
-        super(bufferSize, contentType);
-        Args.notNull(content, "Byte array");
-        this.content = ByteBuffer.wrap(content);
-        this.len = this.content.remaining();
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.nio.StreamChannel;
+import org.apache.hc.core5.http.nio.entity.AbstractCharAsyncEntityProducer;
+
+public class MultiLineEntityProducer extends AbstractCharAsyncEntityProducer {
+
+    private final String text;
+    private final int total;
+    private final CharBuffer charbuf;
+
+    private int count;
+
+    public MultiLineEntityProducer(final String text, final int total) {
+        super(1024, -1, ContentType.TEXT_PLAIN);
+        this.text = text;
+        this.total = total;
+        this.charbuf = CharBuffer.allocate(4096);
+        this.count = 0;
     }
 
     @Override
     public long getContentLength() {
-        return len;
-    }
-
-    @Override
-    protected void dataStart() throws IOException {
+        return -1;
     }
 
     @Override
@@ -64,15 +60,26 @@ public class ByteArrayAsyncEntityProduce
     }
 
     @Override
-    protected void produceData(final StreamChannel<ByteBuffer> channel) throws IOException {
-        Asserts.notNull(channel, "StreamChannel");
-        channel.write(content);
-        if (!content.hasRemaining()) {
+    protected void produceData(final StreamChannel<CharBuffer> channel) throws IOException {
+        while (charbuf.remaining() > text.length() + 2 && count < total) {
+            charbuf.put(text + "\r\n");
+            count++;
+        }
+        if (charbuf.position() > 0) {
+            charbuf.flip();
+            channel.write(charbuf);
+            charbuf.compact();
+        }
+        if (count >= total && charbuf.position() == 0) {
             channel.endStream();
         }
     }
 
     @Override
+    public void failed(final Exception cause) {
+    }
+
+    @Override
     public void releaseResources() {
     }
 

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineEntityProducer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineEntityProducer.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineEntityProducer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineResponseHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineResponseHandler.java?rev=1767339&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineResponseHandler.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineResponseHandler.java Mon Oct 31 17:33:27 2016
@@ -0,0 +1,75 @@
+/*
+ * ====================================================================
+ * 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.http;
+
+import java.io.IOException;
+
+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.Message;
+import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.nio.AsyncRequestConsumer;
+import org.apache.hc.core5.http.nio.BasicRequestConsumer;
+import org.apache.hc.core5.http.nio.BasicResponseProducer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+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.nio.support.ResponseTrigger;
+import org.apache.hc.core5.http.protocol.HttpContext;
+
+public class MultiLineResponseHandler extends BasicServerExchangeHandler<Message<HttpRequest, String>> {
+
+    public MultiLineResponseHandler(final String message, final int count) {
+        super(new RequestConsumerSupplier<Message<HttpRequest, String>>() {
+
+                  @Override
+                  public AsyncRequestConsumer<Message<HttpRequest, String>> get(
+                          final HttpRequest request,
+                          final HttpContext context) throws HttpException {
+                      return new BasicRequestConsumer<>(new StringAsyncEntityConsumer());
+                  }
+
+              }, new ResponseHandler<Message<HttpRequest, String>>() {
+
+                  @Override
+                  public void handle(
+                          final Message<HttpRequest, String> requestMessage,
+                          final ResponseTrigger responseTrigger,
+                          final HttpContext context) throws HttpException, IOException {
+                      final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
+                      responseTrigger.submitResponse(new BasicResponseProducer(
+                              response,
+                              new MultiLineEntityProducer(message, count)));
+                  }
+              }
+        );
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineResponseHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineResponseHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/MultiLineResponseHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/SingleLineResponseHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/SingleLineResponseHandler.java?rev=1767339&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/SingleLineResponseHandler.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/SingleLineResponseHandler.java Mon Oct 31 17:33:27 2016
@@ -0,0 +1,72 @@
+/*
+ * ====================================================================
+ * 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.http;
+
+import java.io.IOException;
+
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpStatus;
+import org.apache.hc.core5.http.Message;
+import org.apache.hc.core5.http.nio.AsyncRequestConsumer;
+import org.apache.hc.core5.http.nio.BasicRequestConsumer;
+import org.apache.hc.core5.http.nio.BasicResponseProducer;
+import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityProducer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+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.nio.support.ResponseTrigger;
+import org.apache.hc.core5.http.protocol.HttpContext;
+
+public class SingleLineResponseHandler extends BasicServerExchangeHandler<Message<HttpRequest, String>> {
+
+    public SingleLineResponseHandler(final String message) {
+        super(new RequestConsumerSupplier<Message<HttpRequest, String>>() {
+
+                  @Override
+                  public AsyncRequestConsumer<Message<HttpRequest, String>> get(
+                          final HttpRequest request,
+                          final HttpContext context) throws HttpException {
+                      return new BasicRequestConsumer<>(new StringAsyncEntityConsumer());
+                  }
+
+              }, new ResponseHandler<Message<HttpRequest, String>>() {
+
+                  @Override
+                  public void handle(
+                          final Message<HttpRequest, String> requestMessage,
+                          final ResponseTrigger responseTrigger,
+                          final HttpContext context) throws HttpException, IOException {
+                      responseTrigger.submitResponse(new BasicResponseProducer(
+                              HttpStatus.SC_OK, new BasicAsyncEntityProducer(message)));
+                  }
+              }
+        );
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/SingleLineResponseHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/SingleLineResponseHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http/SingleLineResponseHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5-testing/src/test/java/org/apache/hc/core5/testing/nio/http2/Http2IntegrationTest.java Mon Oct 31 17:33:27 2016
@@ -39,7 +39,6 @@ import java.net.InetSocketAddress;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.LinkedList;
@@ -51,7 +50,6 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.LinkedBlockingDeque;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.hc.core5.http.EntityDetails;
@@ -62,36 +60,38 @@ import org.apache.hc.core5.http.HttpRequ
 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.entity.ContentType;
+import org.apache.hc.core5.http.impl.nio.AbstractClassicServerExchangeHandler;
+import org.apache.hc.core5.http.impl.nio.bootstrap.ClientEndpoint;
+import org.apache.hc.core5.http.impl.nio.entity.AbstractClassicEntityConsumer;
+import org.apache.hc.core5.http.impl.nio.entity.AbstractClassicEntityProducer;
+import org.apache.hc.core5.http.io.entity.ContentType;
 import org.apache.hc.core5.http.message.BasicHttpRequest;
-import org.apache.hc.core5.http.message.BasicHttpResponse;
+import org.apache.hc.core5.http.nio.AsyncPushConsumer;
+import org.apache.hc.core5.http.nio.AsyncResponseProducer;
+import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
+import org.apache.hc.core5.http.nio.BasicPushProducer;
+import org.apache.hc.core5.http.nio.BasicRequestProducer;
+import org.apache.hc.core5.http.nio.BasicResponseConsumer;
+import org.apache.hc.core5.http.nio.BasicResponseProducer;
+import org.apache.hc.core5.http.nio.CapacityChannel;
+import org.apache.hc.core5.http.nio.DataStreamChannel;
+import org.apache.hc.core5.http.nio.ExpectationChannel;
+import org.apache.hc.core5.http.nio.ResponseChannel;
+import org.apache.hc.core5.http.nio.Supplier;
+import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityProducer;
+import org.apache.hc.core5.http.nio.entity.NoopEntityConsumer;
+import org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer;
+import org.apache.hc.core5.http.nio.support.BasicAsyncPushHandler;
+import org.apache.hc.core5.http.nio.support.ResponseTrigger;
+import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http2.H2Error;
 import org.apache.hc.core5.http2.H2StreamResetException;
 import org.apache.hc.core5.http2.config.H2Config;
-import org.apache.hc.core5.http2.nio.BasicAsyncPushHandler;
-import org.apache.hc.core5.http2.nio.BasicServerExchangeHandler;
-import org.apache.hc.core5.http2.impl.nio.AbstractClassicServerExchangeHandler;
-import org.apache.hc.core5.http2.nio.AsyncPushConsumer;
-import org.apache.hc.core5.http2.nio.AsyncResponseProducer;
-import org.apache.hc.core5.http2.nio.AsyncResponseTrigger;
-import org.apache.hc.core5.http2.nio.AsyncServerExchangeHandler;
-import org.apache.hc.core5.http2.nio.BasicPushProducer;
-import org.apache.hc.core5.http2.nio.BasicRequestProducer;
-import org.apache.hc.core5.http2.nio.BasicResponseConsumer;
-import org.apache.hc.core5.http2.nio.BasicResponseProducer;
-import org.apache.hc.core5.http2.nio.CapacityChannel;
-import org.apache.hc.core5.http2.nio.DataStreamChannel;
-import org.apache.hc.core5.http2.nio.ExpectationChannel;
-import org.apache.hc.core5.http2.nio.ResponseChannel;
-import org.apache.hc.core5.http2.nio.StreamChannel;
-import org.apache.hc.core5.http2.nio.Supplier;
-import org.apache.hc.core5.http2.nio.command.ClientCommandEndpoint;
-import org.apache.hc.core5.http2.nio.entity.AbstractCharAsyncEntityProducer;
-import org.apache.hc.core5.http2.impl.nio.entity.AbstractClassicEntityConsumer;
-import org.apache.hc.core5.http2.impl.nio.entity.AbstractClassicEntityProducer;
-import org.apache.hc.core5.http2.nio.entity.NoopEntityConsumer;
-import org.apache.hc.core5.http2.nio.entity.StringAsyncEntityConsumer;
-import org.apache.hc.core5.http2.nio.entity.StringAsyncEntityProducer;
+import org.apache.hc.core5.testing.nio.http.EchoHandler;
+import org.apache.hc.core5.testing.nio.http.MessageExchangeHandler;
+import org.apache.hc.core5.testing.nio.http.MultiLineEntityProducer;
+import org.apache.hc.core5.testing.nio.http.MultiLineResponseHandler;
+import org.apache.hc.core5.testing.nio.http.SingleLineResponseHandler;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -99,6 +99,8 @@ import org.junit.Test;
 
 public class Http2IntegrationTest extends InternalServerTestBase {
 
+    private static final long TIMEOUT = 5;
+
     private Http2TestClient client;
 
     @Before
@@ -121,36 +123,9 @@ public class Http2IntegrationTest extend
         }
     }
 
-    static class SingleLineEntityProducer extends StringAsyncEntityProducer {
-
-        SingleLineEntityProducer(final String message) {
-            super(message, ContentType.TEXT_PLAIN);
-        }
-
-    }
-
-    static class SingleLineResponseHandler extends BasicServerExchangeHandler<String> {
-
-        private final String message;
-
-        SingleLineResponseHandler(final String message) {
-            super(new StringAsyncEntityConsumer());
-            this.message = message;
-        }
-
-        @Override
-        protected void handle(
-                final Message<HttpRequest, String> request,
-                final AsyncResponseTrigger responseTrigger) throws IOException, HttpException {
-            responseTrigger.submitResponse(new BasicResponseProducer(
-                    HttpStatus.SC_OK, new SingleLineEntityProducer(message)));
-        }
-
-    }
-
     @Test
     public void testSimpleGet() throws Exception {
-        server.registerHandler("/hello", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("/hello", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
@@ -161,14 +136,14 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start();
 
         client.start();
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
-        final HttpRequest request1 = new BasicHttpRequest("GET", createRequestURI(serverEndpoint, "/hello"));
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
-                new BasicRequestProducer(request1, null),
+                new BasicRequestProducer("GET", createRequestURI(serverEndpoint, "/hello")),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         final String entity1 = result1.getBody();
@@ -177,85 +152,9 @@ public class Http2IntegrationTest extend
         Assert.assertEquals("Hi there", entity1);
     }
 
-    static class MultiLineEntityProducer extends AbstractCharAsyncEntityProducer {
-
-        private final String text;
-        private final int total;
-        private final CharBuffer charbuf;
-
-        private int count;
-
-        MultiLineEntityProducer(final String text, final int total) {
-            super(1024, ContentType.TEXT_PLAIN);
-            this.text = text;
-            this.total = total;
-            this.charbuf = CharBuffer.allocate(4096);
-            this.count = 0;
-        }
-
-        @Override
-        public long getContentLength() {
-            return -1;
-        }
-
-        @Override
-        protected void dataStart(final StreamChannel<CharBuffer> channel) throws IOException {
-            produceData(channel);
-        }
-
-        @Override
-        public int available() {
-            return Integer.MAX_VALUE;
-        }
-
-        @Override
-        protected void produceData(final StreamChannel<CharBuffer> channel) throws IOException {
-            while (charbuf.remaining() > text.length() + 2 && count < total) {
-                charbuf.put(text + "\r\n");
-                count++;
-            }
-            if (charbuf.position() > 0) {
-                charbuf.flip();
-                channel.write(charbuf);
-                charbuf.compact();
-            }
-            if (count >= total && charbuf.position() == 0) {
-                channel.endStream();
-            }
-        }
-
-        @Override
-        public void releaseResources() {
-        }
-
-    }
-
-    static class MultiLineResponseHandler extends BasicServerExchangeHandler<String> {
-
-        private final String message;
-        private final int count;
-
-        MultiLineResponseHandler(final String message, final int count) {
-            super(new StringAsyncEntityConsumer());
-            this.message = message;
-            this.count = count;
-        }
-
-        @Override
-        protected void handle(
-                final Message<HttpRequest, String> request,
-                final AsyncResponseTrigger responseTrigger) throws IOException, HttpException {
-            final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
-            responseTrigger.submitResponse(new BasicResponseProducer(
-                    response,
-                    new MultiLineEntityProducer(message, count)));
-        }
-
-    }
-
     @Test
     public void testLargeGet() throws Exception {
-        server.registerHandler("/", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("/", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
@@ -266,20 +165,19 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start();
 
         client.start();
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
-        final HttpRequest request1 = new BasicHttpRequest("GET", createRequestURI(serverEndpoint, "/"));
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
-                new BasicRequestProducer(request1, null),
+                new BasicRequestProducer("GET", createRequestURI(serverEndpoint, "/"), null),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
 
-        final HttpRequest request2 = new BasicHttpRequest("GET", createRequestURI(serverEndpoint, "/"));
         final Future<Message<HttpResponse, String>> future2 = streamEndpoint.execute(
-                new BasicRequestProducer(request2, null),
+                new BasicRequestProducer("GET", createRequestURI(serverEndpoint, "/")),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer(512)), null);
 
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         Assert.assertNotNull(response1);
@@ -291,7 +189,7 @@ public class Http2IntegrationTest extend
             Assert.assertEquals("0123456789abcdef", t1.nextToken());
         }
 
-        final Message<HttpResponse, String> result2 = future2.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result2 = future2.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result2);
         final HttpResponse response2 = result2.getHead();
         Assert.assertNotNull(response2);
@@ -306,7 +204,7 @@ public class Http2IntegrationTest extend
 
     @Test
     public void testBasicPost() throws Exception {
-        server.registerHandler("/hello", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("/hello", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
@@ -317,14 +215,15 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start();
 
         client.start();
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
         final HttpRequest request1 = new BasicHttpRequest("POST", createRequestURI(serverEndpoint, "/hello"));
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
-                new BasicRequestProducer(request1, new SingleLineEntityProducer("Hi there")),
+                new BasicRequestProducer(request1, new BasicAsyncEntityProducer("Hi there")),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         final String entity1 = result1.getBody();
@@ -333,123 +232,9 @@ public class Http2IntegrationTest extend
         Assert.assertEquals("Hi back", entity1);
     }
 
-    static class EchoHandler implements AsyncServerExchangeHandler {
-
-        private volatile ByteBuffer buffer;
-        private volatile CapacityChannel inputCapacityChannel;
-        private volatile DataStreamChannel outputDataChannel;
-        private volatile boolean endStream;
-
-        EchoHandler(final int bufferSize) {
-            this.buffer = ByteBuffer.allocate(bufferSize);
-        }
-
-        private void ensureCapacity(final int chunk) {
-            if (buffer.remaining() < chunk) {
-                final ByteBuffer oldBuffer = buffer;
-                oldBuffer.flip();
-                buffer = ByteBuffer.allocate(oldBuffer.remaining() + (chunk > 2048 ? chunk : 2048));
-                buffer.put(oldBuffer);
-            }
-        }
-
-        @Override
-        public void verify(
-                final HttpRequest request,
-                final EntityDetails entityDetails,
-                final ExpectationChannel expectationChannel) throws HttpException, IOException {
-            expectationChannel.sendContinue();
-        }
-
-        @Override
-        public void handleRequest(
-                final HttpRequest request,
-                final EntityDetails entityDetails,
-                final ResponseChannel responseChannel) throws HttpException, IOException {
-            final HttpResponse response = new BasicHttpResponse(HttpStatus.SC_OK);
-            responseChannel.sendResponse(response, entityDetails);
-        }
-
-        @Override
-        public void consume(final ByteBuffer src) throws IOException {
-            if (buffer.position() == 0) {
-                if (outputDataChannel != null) {
-                    outputDataChannel.write(src);
-                }
-            }
-            if (src.hasRemaining()) {
-                ensureCapacity(src.remaining());
-                buffer.put(src);
-                if (outputDataChannel != null) {
-                    outputDataChannel.requestOutput();
-                }
-            }
-        }
-
-        @Override
-        public int capacity() {
-            return buffer.remaining();
-        }
-
-        @Override
-        public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
-            if (buffer.hasRemaining()) {
-                capacityChannel.update(buffer.remaining());
-                inputCapacityChannel = null;
-            } else {
-                inputCapacityChannel = capacityChannel;
-            }
-        }
-
-        @Override
-        public void streamEnd(final List<Header> trailers) throws HttpException, IOException {
-            endStream = true;
-            if (buffer.position() == 0) {
-                if (outputDataChannel != null) {
-                    outputDataChannel.endStream();
-                }
-            } else {
-                if (outputDataChannel != null) {
-                    outputDataChannel.requestOutput();
-                }
-            }
-        }
-
-        @Override
-        public int available() {
-            return buffer.position();
-        }
-
-        @Override
-        public void produce(final DataStreamChannel channel) throws IOException {
-            outputDataChannel = channel;
-            buffer.flip();
-            if (buffer.hasRemaining()) {
-                channel.write(buffer);
-            }
-            buffer.compact();
-            if (buffer.position() == 0 && endStream) {
-                channel.endStream();
-            }
-            final CapacityChannel capacityChannel = inputCapacityChannel;
-            if (capacityChannel != null && buffer.hasRemaining()) {
-                capacityChannel.update(buffer.remaining());
-            }
-        }
-
-        @Override
-        public void failed(final Exception cause) {
-        }
-
-        @Override
-        public void releaseResources() {
-        }
-
-    }
-
     @Test
     public void testLargePost() throws Exception {
-        server.registerHandler("*", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("*", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
@@ -460,14 +245,15 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start();
 
         client.start();
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
-        final HttpRequest request1 = new BasicHttpRequest("POST", createRequestURI(serverEndpoint, "/echo"));
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
-                new BasicRequestProducer(request1, new MultiLineEntityProducer("0123456789abcdef", 5000)),
+                new BasicRequestProducer("POST", createRequestURI(serverEndpoint, "/echo"),
+                        new MultiLineEntityProducer("0123456789abcdef", 5000)),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         Assert.assertNotNull(response1);
@@ -482,7 +268,7 @@ public class Http2IntegrationTest extend
 
     @Test
     public void testSlowResponseConsumer() throws Exception {
-        server.registerHandler("/", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("/", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
@@ -493,12 +279,12 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start();
 
         client.start(H2Config.custom().setInitialWindowSize(16).build());
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
-        final HttpRequest request1 = new BasicHttpRequest("GET", createRequestURI(serverEndpoint, "/"));
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
-                new BasicRequestProducer(request1, null),
+                new BasicRequestProducer("GET", createRequestURI(serverEndpoint, "/"), null),
                 new BasicResponseConsumer<>(new AbstractClassicEntityConsumer<String>(16, Executors.newSingleThreadExecutor()) {
 
                     @Override
@@ -509,7 +295,7 @@ public class Http2IntegrationTest extend
                             charset = StandardCharsets.US_ASCII;
                         }
 
-                        final StringBuffer buffer = new StringBuffer();
+                        final StringBuilder buffer = new StringBuilder();
                         try {
                             final byte[] tmp = new byte[16];
                             int l;
@@ -526,7 +312,7 @@ public class Http2IntegrationTest extend
                 }),
                 null);
 
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         Assert.assertNotNull(response1);
@@ -541,7 +327,7 @@ public class Http2IntegrationTest extend
 
     @Test
     public void testSlowRequestProducer() throws Exception {
-        server.registerHandler("*", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("*", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
@@ -552,8 +338,9 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start();
 
         client.start();
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
         final HttpRequest request1 = new BasicHttpRequest("POST", createRequestURI(serverEndpoint, "/echo"));
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
@@ -581,7 +368,7 @@ public class Http2IntegrationTest extend
 
                 }),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         Assert.assertNotNull(response1);
@@ -596,7 +383,7 @@ public class Http2IntegrationTest extend
 
     @Test
     public void testSlowResponseProducer() throws Exception {
-        server.registerHandler("*", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("*", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
@@ -607,7 +394,8 @@ public class Http2IntegrationTest extend
                             final HttpRequest request,
                             final InputStream requestStream,
                             final HttpResponse response,
-                            final OutputStream responseStream) throws IOException, HttpException {
+                            final OutputStream responseStream,
+                            final HttpContext context) throws IOException, HttpException {
 
                         if (!"/hello".equals(request.getPath())) {
                             response.setCode(HttpStatus.SC_NOT_FOUND);
@@ -658,14 +446,15 @@ public class Http2IntegrationTest extend
                 .setInitialWindowSize(512)
                 .build());
 
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
         final HttpRequest request1 = new BasicHttpRequest("POST", createRequestURI(serverEndpoint, "/hello"));
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
                 new BasicRequestProducer(request1, new MultiLineEntityProducer("0123456789abcd", 2000)),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         Assert.assertNotNull(response1);
@@ -681,25 +470,23 @@ public class Http2IntegrationTest extend
     @Test
     public void testPush() throws Exception {
         final InetSocketAddress serverEndpoint = server.start();
-        server.registerHandler("/hello", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("/hello", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
-                return new BasicServerExchangeHandler<Void>(new NoopEntityConsumer()) {
-
-
+                return new MessageExchangeHandler<Void>(new NoopEntityConsumer()) {
 
                     @Override
                     protected void handle(
                             final Message<HttpRequest, Void> request,
-                            final AsyncResponseTrigger responseTrigger) throws IOException, HttpException {
-
+                            final ResponseTrigger responseTrigger,
+                            final HttpContext context) throws IOException, HttpException {
                         responseTrigger.pushPromise(
                                 new BasicHttpRequest("GET", createRequestURI(serverEndpoint, "/stuff")),
                                 new BasicPushProducer(new MultiLineEntityProducer("Pushing lots of stuff", 500)));
                         responseTrigger.submitResponse(new BasicResponseProducer(
                                 HttpStatus.SC_OK,
-                                new SingleLineEntityProducer("Hi there")));
+                                new BasicAsyncEntityProducer("Hi there")));
                     }
                 };
             }
@@ -709,7 +496,7 @@ public class Http2IntegrationTest extend
         client.start(H2Config.custom().setPushEnabled(true).build());
 
         final BlockingQueue<Message<HttpResponse, String>> pushMessageQueue = new LinkedBlockingDeque<>();
-        client.registerHandler("*", new Supplier<AsyncPushConsumer>() {
+        client.register("*", new Supplier<AsyncPushConsumer>() {
 
             @Override
             public AsyncPushConsumer get() {
@@ -732,13 +519,14 @@ public class Http2IntegrationTest extend
 
         });
 
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
                 new BasicRequestProducer("GET", createRequestURI(serverEndpoint, "/hello")),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         final String entity1 = result1.getBody();
@@ -762,20 +550,21 @@ public class Http2IntegrationTest extend
     public void testPushRefused() throws Exception {
         final BlockingQueue<Exception> pushResultQueue = new LinkedBlockingDeque<>();
         final InetSocketAddress serverEndpoint = server.start();
-        server.registerHandler("/hello", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("/hello", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
-                return new BasicServerExchangeHandler<Void>(new NoopEntityConsumer()) {
+                return new MessageExchangeHandler<Void>(new NoopEntityConsumer()) {
 
                     @Override
                     protected void handle(
                             final Message<HttpRequest, Void> request,
-                            final AsyncResponseTrigger responseTrigger) throws IOException, HttpException {
+                            final ResponseTrigger responseTrigger,
+                            final HttpContext context) throws IOException, HttpException {
 
                         responseTrigger.pushPromise(
                                 new BasicHttpRequest("GET", createRequestURI(serverEndpoint, "/stuff")),
-                                new BasicPushProducer(new SingleLineEntityProducer("Pushing all sorts of stuff")) {
+                                new BasicPushProducer(new BasicAsyncEntityProducer("Pushing all sorts of stuff")) {
 
                             @Override
                             public void failed(final Exception cause) {
@@ -797,7 +586,7 @@ public class Http2IntegrationTest extend
                         });
                         responseTrigger.submitResponse(new BasicResponseProducer(
                                 HttpStatus.SC_OK,
-                                new SingleLineEntityProducer("Hi there")));
+                                new BasicAsyncEntityProducer("Hi there")));
                     }
                 };
             }
@@ -806,13 +595,14 @@ public class Http2IntegrationTest extend
 
         client.start(H2Config.custom().setPushEnabled(true).build());
 
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
                 new BasicRequestProducer("GET", createRequestURI(serverEndpoint, "/hello")),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         final String entity1 = result1.getBody();
@@ -833,7 +623,7 @@ public class Http2IntegrationTest extend
 
     @Test
     public void testExcessOfConcurrentStreams() throws Exception {
-        server.registerHandler("/", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("/", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
@@ -844,8 +634,9 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start(H2Config.custom().setMaxConcurrentStreams(20).build());
 
         client.start(H2Config.custom().setMaxConcurrentStreams(20).build());
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
         final Queue<Future<Message<HttpResponse, Void>>> queue = new LinkedList<>();
         for (int i = 0; i < 2000; i++) {
@@ -858,7 +649,7 @@ public class Http2IntegrationTest extend
 
         while (!queue.isEmpty()) {
             final Future<Message<HttpResponse, Void>> future = queue.remove();
-            final Message<HttpResponse, Void> result = future.get(5, TimeUnit.SECONDS);
+            final Message<HttpResponse, Void> result = future.get(TIMEOUT, TimeUnit.SECONDS);
             Assert.assertNotNull(result);
             final HttpResponse response = result.getHead();
             Assert.assertNotNull(response);
@@ -867,15 +658,17 @@ public class Http2IntegrationTest extend
     }
 
     @Test
-    public void testExpecationFailed() throws Exception {
-        server.registerHandler("*", new Supplier<AsyncServerExchangeHandler>() {
+    public void testExpectationFailed() throws Exception {
+        server.register("*", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
-                return new BasicServerExchangeHandler<String>(new StringAsyncEntityConsumer()) {
+                return new MessageExchangeHandler<Void>(new NoopEntityConsumer()) {
 
                     @Override
-                    protected AsyncResponseProducer verify(final HttpRequest request) throws IOException, HttpException {
+                    protected AsyncResponseProducer verify(
+                            final HttpRequest request,
+                            final HttpContext context) throws IOException, HttpException {
                         final Header h = request.getFirstHeader("password");
                         if (h != null && "secret".equals(h.getValue())) {
                             return null;
@@ -886,8 +679,9 @@ public class Http2IntegrationTest extend
 
                     @Override
                     protected void handle(
-                            final Message<HttpRequest, String> request,
-                            final AsyncResponseTrigger responseTrigger) throws IOException, HttpException {
+                            final Message<HttpRequest, Void> request,
+                            final ResponseTrigger responseTrigger,
+                            final HttpContext context) throws IOException, HttpException {
                         responseTrigger.submitResponse(
                                 new BasicResponseProducer(HttpStatus.SC_OK, "All is well"));
 
@@ -899,15 +693,16 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start();
 
         client.start();
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
         final HttpRequest request1 = new BasicHttpRequest("POST", createRequestURI(serverEndpoint, "/echo"));
         request1.addHeader("password", "secret");
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
                 new BasicRequestProducer(request1, new MultiLineEntityProducer("0123456789abcdef", 5000)),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         Assert.assertNotNull(response1);
@@ -918,7 +713,7 @@ public class Http2IntegrationTest extend
         final Future<Message<HttpResponse, String>> future2 = streamEndpoint.execute(
                 new BasicRequestProducer(request2, new MultiLineEntityProducer("0123456789abcdef", 5000)),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result2 = future2.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result2 = future2.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result2);
         final HttpResponse response2 = result2.getHead();
         Assert.assertNotNull(response2);
@@ -928,14 +723,17 @@ public class Http2IntegrationTest extend
 
     @Test
     public void testPrematureResponse() throws Exception {
-        server.registerHandler("*", new Supplier<AsyncServerExchangeHandler>() {
+        server.register("*", new Supplier<AsyncServerExchangeHandler>() {
 
             @Override
             public AsyncServerExchangeHandler get() {
                 return new AsyncServerExchangeHandler() {
 
                     private final AtomicReference<AsyncResponseProducer> responseProducer = new AtomicReference<>(null);
-                    private final AtomicBoolean dataStarted = new AtomicBoolean(false);
+
+                    @Override
+                    public void setContext(final HttpContext context) {
+                    }
 
                     @Override
                     public void verify(
@@ -946,17 +744,13 @@ public class Http2IntegrationTest extend
                     }
 
                     @Override
-                    public int capacity() {
-                        return Integer.MAX_VALUE;
-                    }
-
-                    @Override
                     public void updateCapacity(final CapacityChannel capacityChannel) throws IOException {
                         capacityChannel.update(Integer.MAX_VALUE);
                     }
 
                     @Override
-                    public void consume(final ByteBuffer src) throws IOException {
+                    public int consume(final ByteBuffer src) throws IOException {
+                        return Integer.MAX_VALUE;
                     }
 
                     @Override
@@ -988,9 +782,6 @@ public class Http2IntegrationTest extend
                     @Override
                     public void produce(final DataStreamChannel channel) throws IOException {
                         final AsyncResponseProducer producer = this.responseProducer.get();
-                        if (dataStarted.compareAndSet(false, true)) {
-                            producer.dataStart(channel);
-                        }
                         producer.produce(channel);
                     }
 
@@ -1008,14 +799,15 @@ public class Http2IntegrationTest extend
         final InetSocketAddress serverEndpoint = server.start();
 
         client.start();
-        final Future<ClientCommandEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), 5000);
-        final ClientCommandEndpoint streamEndpoint = connectFuture.get();
+        final Future<ClientEndpoint> connectFuture = client.connect(
+                "localhost", serverEndpoint.getPort(), TIMEOUT, TimeUnit.SECONDS);
+        final ClientEndpoint streamEndpoint = connectFuture.get();
 
         final HttpRequest request1 = new BasicHttpRequest("POST", createRequestURI(serverEndpoint, "/echo"));
         final Future<Message<HttpResponse, String>> future1 = streamEndpoint.execute(
                 new BasicRequestProducer(request1, new MultiLineEntityProducer("0123456789abcdef", 5000)),
                 new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
-        final Message<HttpResponse, String> result1 = future1.get(5, TimeUnit.SECONDS);
+        final Message<HttpResponse, String> result1 = future1.get(TIMEOUT, TimeUnit.SECONDS);
         Assert.assertNotNull(result1);
         final HttpResponse response1 = result1.getHead();
         Assert.assertNotNull(response1);

Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpGet.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpGet.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpGet.java Mon Oct 31 17:33:27 2016
@@ -33,19 +33,14 @@ import org.apache.hc.core5.http.ClassicH
 import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.entity.EntityUtils;
+import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
-import org.apache.hc.core5.http.protocol.RequestConnControl;
-import org.apache.hc.core5.http.protocol.RequestContent;
-import org.apache.hc.core5.http.protocol.RequestExpectContinue;
-import org.apache.hc.core5.http.protocol.RequestTargetHost;
-import org.apache.hc.core5.http.protocol.RequestUserAgent;
 
 /**
  * Elemental example for executing multiple GET requests sequentially.
@@ -53,13 +48,7 @@ import org.apache.hc.core5.http.protocol
 public class ElementalHttpGet {
 
     public static void main(String[] args) throws Exception {
-        HttpProcessor httpproc = HttpProcessorBuilder.create()
-            .add(new RequestContent())
-            .add(new RequestTargetHost())
-            .add(new RequestConnControl())
-            .add(new RequestUserAgent("Test/1.1"))
-            .add(new RequestExpectContinue()).build();
-
+        HttpProcessor httpproc = HttpProcessors.client();
         HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
 
         HttpCoreContext coreContext = HttpCoreContext.create();

Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpPost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpPost.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpPost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpPost.java Mon Oct 31 17:33:27 2016
@@ -31,28 +31,23 @@ import java.io.ByteArrayInputStream;
 import java.net.Socket;
 import java.nio.charset.StandardCharsets;
 
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.entity.ByteArrayEntity;
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http.entity.EntityUtils;
-import org.apache.hc.core5.http.entity.InputStreamEntity;
-import org.apache.hc.core5.http.entity.StringEntity;
+import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.io.entity.ByteArrayEntity;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.InputStreamEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
-import org.apache.hc.core5.http.protocol.RequestConnControl;
-import org.apache.hc.core5.http.protocol.RequestContent;
-import org.apache.hc.core5.http.protocol.RequestExpectContinue;
-import org.apache.hc.core5.http.protocol.RequestTargetHost;
-import org.apache.hc.core5.http.protocol.RequestUserAgent;
 
 /**
  * Elemental example for executing multiple POST requests sequentially.
@@ -60,13 +55,7 @@ import org.apache.hc.core5.http.protocol
 public class ElementalHttpPost {
 
     public static void main(String[] args) throws Exception {
-        HttpProcessor httpproc = HttpProcessorBuilder.create()
-            .add(new RequestContent())
-            .add(new RequestTargetHost())
-            .add(new RequestConnControl())
-            .add(new RequestUserAgent("Test/1.1"))
-            .add(new RequestExpectContinue()).build();
-
+        HttpProcessor httpproc = HttpProcessors.client();
         HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
 
         HttpCoreContext coreContext = HttpCoreContext.create();

Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpPostTrailers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpPostTrailers.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpPostTrailers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalHttpPostTrailers.java Mon Oct 31 17:33:27 2016
@@ -30,36 +30,27 @@ package org.apache.hc.core5.http.example
 import java.net.Socket;
 
 import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http.entity.EntityUtils;
-import org.apache.hc.core5.http.entity.HttpEntityWithTrailers;
-import org.apache.hc.core5.http.entity.StringEntity;
+import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
-import org.apache.hc.core5.http.message.BasicHeader;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.HttpEntityWithTrailers;
+import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
+import org.apache.hc.core5.http.message.BasicHeader;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
-import org.apache.hc.core5.http.protocol.RequestConnControl;
-import org.apache.hc.core5.http.protocol.RequestContent;
-import org.apache.hc.core5.http.protocol.RequestTargetHost;
-import org.apache.hc.core5.http.protocol.RequestUserAgent;
 
 /**
  * Elemental example for executing POST request with trailing headers
  */
 public class ElementalHttpPostTrailers {
     public static void main(String[] args) throws Exception {
-        HttpProcessor httpproc = HttpProcessorBuilder.create()
-                .add(new RequestContent())
-                .add(new RequestTargetHost())
-                .add(new RequestConnControl())
-                .add(new RequestUserAgent("Test/1.1"))
-                .build();
+        HttpProcessor httpproc = HttpProcessors.client();
         HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
         HttpCoreContext coreContext = HttpCoreContext.create();
         HttpHost host = new HttpHost("localhost", 8080);

Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalPoolingHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalPoolingHttpGet.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalPoolingHttpGet.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalPoolingHttpGet.java Mon Oct 31 17:33:27 2016
@@ -35,22 +35,17 @@ import org.apache.hc.core5.http.ClassicH
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.entity.EntityUtils;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.impl.io.pool.BasicConnFactory;
+import org.apache.hc.core5.http.impl.io.pool.BasicConnPool;
+import org.apache.hc.core5.http.impl.io.pool.BasicPoolEntry;
 import org.apache.hc.core5.http.io.HttpClientConnection;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
 import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
-import org.apache.hc.core5.http.pool.io.BasicConnFactory;
-import org.apache.hc.core5.http.pool.io.BasicConnPool;
-import org.apache.hc.core5.http.pool.io.BasicPoolEntry;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
-import org.apache.hc.core5.http.protocol.RequestConnControl;
-import org.apache.hc.core5.http.protocol.RequestContent;
-import org.apache.hc.core5.http.protocol.RequestExpectContinue;
-import org.apache.hc.core5.http.protocol.RequestTargetHost;
-import org.apache.hc.core5.http.protocol.RequestUserAgent;
 
 /**
  * Elemental example for executing multiple GET requests from different threads using a connection
@@ -59,13 +54,7 @@ import org.apache.hc.core5.http.protocol
 public class ElementalPoolingHttpGet {
 
     public static void main(String[] args) throws Exception {
-        final HttpProcessor httpproc = HttpProcessorBuilder.create()
-            .add(new RequestContent())
-            .add(new RequestTargetHost())
-            .add(new RequestConnControl())
-            .add(new RequestUserAgent("Test/1.1"))
-            .add(new RequestExpectContinue()).build();
-
+        final HttpProcessor httpproc = HttpProcessors.client();
         final HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
 
         final BasicConnPool pool = new BasicConnPool(new BasicConnFactory());

Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalReverseProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalReverseProxy.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalReverseProxy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/ElementalReverseProxy.java Mon Oct 31 17:33:27 2016
@@ -31,16 +31,22 @@ import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Set;
 
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.ConnectionReuseStrategy;
+import org.apache.hc.core5.http.Header;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHeaders;
 import org.apache.hc.core5.http.HttpHost;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.HttpRequestInterceptor;
-import org.apache.hc.core5.http.ClassicHttpResponse;
-import org.apache.hc.core5.http.HttpResponseInterceptor;
+import org.apache.hc.core5.http.impl.HttpProcessors;
 import org.apache.hc.core5.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpClientConnection;
 import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection;
@@ -50,20 +56,11 @@ import org.apache.hc.core5.http.io.HttpC
 import org.apache.hc.core5.http.io.HttpRequestHandler;
 import org.apache.hc.core5.http.io.HttpServerConnection;
 import org.apache.hc.core5.http.io.UriHttpRequestHandlerMapper;
+import org.apache.hc.core5.http.message.BasicClassicHttpRequest;
 import org.apache.hc.core5.http.protocol.BasicHttpContext;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.http.protocol.HttpProcessor;
-import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
-import org.apache.hc.core5.http.protocol.RequestConnControl;
-import org.apache.hc.core5.http.protocol.RequestContent;
-import org.apache.hc.core5.http.protocol.RequestExpectContinue;
-import org.apache.hc.core5.http.protocol.RequestTargetHost;
-import org.apache.hc.core5.http.protocol.RequestUserAgent;
-import org.apache.hc.core5.http.protocol.ResponseConnControl;
-import org.apache.hc.core5.http.protocol.ResponseContent;
-import org.apache.hc.core5.http.protocol.ResponseDate;
-import org.apache.hc.core5.http.protocol.ResponseServer;
 
 /**
  * Elemental HTTP/1.1 reverse proxy.
@@ -91,19 +88,27 @@ public class ElementalReverseProxy {
         t.start();
     }
 
+    private final static Set<String> HOP_BY_HOP = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
+            HttpHeaders.CONTENT_LENGTH.toLowerCase(Locale.ROOT),
+            HttpHeaders.TRANSFER_ENCODING.toLowerCase(Locale.ROOT),
+            HttpHeaders.CONNECTION.toLowerCase(Locale.ROOT),
+            "Keep-Alive".toLowerCase(Locale.ROOT),
+            "Proxy-Authenticate".toLowerCase(Locale.ROOT),
+            HttpHeaders.TE.toLowerCase(Locale.ROOT),
+            HttpHeaders.TRAILER.toLowerCase(Locale.ROOT),
+            HttpHeaders.UPGRADE.toLowerCase(Locale.ROOT))));
+
+
     static class ProxyHandler implements HttpRequestHandler  {
 
-        private final HttpHost target;
         private final HttpProcessor httpproc;
         private final HttpRequestExecutor httpexecutor;
         private final ConnectionReuseStrategy connStrategy;
 
         public ProxyHandler(
-                final HttpHost target,
                 final HttpProcessor httpproc,
                 final HttpRequestExecutor httpexecutor) {
             super();
-            this.target = target;
             this.httpproc = httpproc;
             this.httpexecutor = httpexecutor;
             this.connStrategy = DefaultConnectionReuseStrategy.INSTANCE;
@@ -111,8 +116,8 @@ public class ElementalReverseProxy {
 
         @Override
         public void handle(
-                final ClassicHttpRequest request,
-                final ClassicHttpResponse response,
+                final ClassicHttpRequest incomingRequest,
+                final ClassicHttpResponse outgoingResponse,
                 final HttpContext context) throws HttpException, IOException {
 
             final HttpClientConnection conn = (HttpClientConnection) context.getAttribute(
@@ -120,38 +125,31 @@ public class ElementalReverseProxy {
 
             context.setAttribute(HttpCoreContext.HTTP_CONNECTION, conn);
 
-            System.out.println(">> Request URI: " + request.getPath());
+            System.out.println(">> Request URI: " + incomingRequest.getPath());
 
-            // Remove hop-by-hop headers
-            request.removeHeaders(HttpHeaders.CONTENT_LENGTH);
-            request.removeHeaders(HttpHeaders.TRANSFER_ENCODING);
-            request.removeHeaders(HttpHeaders.CONNECTION);
-            request.removeHeaders("Keep-Alive");
-            request.removeHeaders("Proxy-Authenticate");
-            request.removeHeaders(HttpHeaders.TE);
-            request.removeHeaders(HttpHeaders.TRAILER);
-            request.removeHeaders(HttpHeaders.UPGRADE);
-
-            this.httpexecutor.preProcess(request, this.httpproc, context);
-            final ClassicHttpResponse targetResponse = this.httpexecutor.execute(request, conn, context);
-            this.httpexecutor.postProcess(response, this.httpproc, context);
-
-            // Remove hop-by-hop headers
-            targetResponse.removeHeaders(HttpHeaders.CONTENT_LENGTH);
-            targetResponse.removeHeaders(HttpHeaders.TRANSFER_ENCODING);
-            targetResponse.removeHeaders(HttpHeaders.CONNECTION);
-            targetResponse.removeHeaders("Keep-Alive");
-            targetResponse.removeHeaders("TE");
-            targetResponse.removeHeaders("Trailers");
-            targetResponse.removeHeaders("Upgrade");
-
-            response.setCode(targetResponse.getCode());
-            response.setHeaders(targetResponse.getAllHeaders());
-            response.setEntity(targetResponse.getEntity());
+            ClassicHttpRequest outgoingRequest = new BasicClassicHttpRequest(incomingRequest.getMethod(), incomingRequest.getPath());
+            for (Iterator<Header> it = incomingRequest.headerIterator(); it.hasNext(); ) {
+                Header header = it.next();
+                if (!HOP_BY_HOP.contains(header.getName().toLowerCase(Locale.ROOT))) {
+                    outgoingRequest.addHeader(header);
+                }
+            }
+            this.httpexecutor.preProcess(outgoingRequest, this.httpproc, context);
+            final ClassicHttpResponse incomingResponse = this.httpexecutor.execute(outgoingRequest, conn, context);
+            this.httpexecutor.postProcess(incomingResponse, this.httpproc, context);
+
+            outgoingResponse.setCode(incomingResponse.getCode());
+            for (Iterator<Header> it = incomingResponse.headerIterator(); it.hasNext(); ) {
+                Header header = it.next();
+                if (!HOP_BY_HOP.contains(header.getName().toLowerCase(Locale.ROOT))) {
+                    outgoingResponse.addHeader(header);
+                }
+            }
+            outgoingResponse.setEntity(incomingResponse.getEntity());
 
-            System.out.println("<< Response: " + response.getCode());
+            System.out.println("<< Response: " + outgoingResponse.getCode());
 
-            final boolean keepalive = this.connStrategy.keepAlive(request, response, context);
+            final boolean keepalive = this.connStrategy.keepAlive(incomingRequest, outgoingResponse, context);
             context.setAttribute(HTTP_CONN_KEEPALIVE, new Boolean(keepalive));
         }
 
@@ -168,33 +166,17 @@ public class ElementalReverseProxy {
             this.serversocket = new ServerSocket(port);
 
             // Set up HTTP protocol processor for incoming connections
-            final HttpProcessor inhttpproc = new DefaultHttpProcessor(
-                    new HttpRequestInterceptor[] {
-                            new RequestContent(),
-                            new RequestTargetHost(),
-                            new RequestConnControl(),
-                            new RequestUserAgent("Test/1.1"),
-                            new RequestExpectContinue()
-             });
+            final HttpProcessor inhttpproc = HttpProcessors.client();
 
             // Set up HTTP protocol processor for outgoing connections
-            final HttpProcessor outhttpproc = new DefaultHttpProcessor(
-                    new HttpResponseInterceptor[] {
-                            new ResponseDate(),
-                            new ResponseServer("Test/1.1"),
-                            new ResponseContent(),
-                            new ResponseConnControl()
-            });
+            final HttpProcessor outhttpproc = HttpProcessors.server();
 
             // Set up outgoing request executor
             final HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
 
             // Set up incoming request handler
             final UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper();
-            reqistry.register("*", new ProxyHandler(
-                    this.target,
-                    outhttpproc,
-                    httpexecutor));
+            reqistry.register("*", new ProxyHandler(outhttpproc, httpexecutor));
 
             // Set up the HTTP service
             this.httpService = new HttpService(inhttpproc, reqistry);

Modified: httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/HttpFileServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/HttpFileServer.java?rev=1767339&r1=1767338&r2=1767339&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/HttpFileServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/examples/org/apache/hc/core5/http/examples/HttpFileServer.java Mon Oct 31 17:33:27 2016
@@ -38,23 +38,23 @@ import java.util.concurrent.TimeUnit;
 
 import javax.net.ssl.SSLContext;
 
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.ConnectionClosedException;
 import org.apache.hc.core5.http.ExceptionListener;
 import org.apache.hc.core5.http.HttpConnection;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
-import org.apache.hc.core5.http.ClassicHttpRequest;
-import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpStatus;
 import org.apache.hc.core5.http.MethodNotSupportedException;
-import org.apache.hc.core5.http.bootstrap.io.HttpServer;
-import org.apache.hc.core5.http.bootstrap.io.ServerBootstrap;
 import org.apache.hc.core5.http.config.SocketConfig;
-import org.apache.hc.core5.http.entity.ContentType;
-import org.apache.hc.core5.http.entity.EntityUtils;
-import org.apache.hc.core5.http.entity.FileEntity;
-import org.apache.hc.core5.http.entity.StringEntity;
+import org.apache.hc.core5.http.impl.io.bootstrap.HttpServer;
+import org.apache.hc.core5.http.impl.io.bootstrap.ServerBootstrap;
 import org.apache.hc.core5.http.io.HttpRequestHandler;
+import org.apache.hc.core5.http.io.entity.ContentType;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.io.entity.FileEntity;
+import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.apache.hc.core5.http.protocol.HttpContext;
 import org.apache.hc.core5.http.protocol.HttpCoreContext;
 import org.apache.hc.core5.ssl.SSLContexts;
@@ -96,7 +96,6 @@ public class HttpFileServer {
 
         final HttpServer server = ServerBootstrap.bootstrap()
                 .setListenerPort(port)
-                .setServerInfo("Test/1.1")
                 .setSocketConfig(socketConfig)
                 .setSslContext(sslcontext)
                 .setExceptionListener(new StdErrorExceptionListener())



Mime
View raw message