hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1395631 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/protocol/ test/java/org/apache/http/impl/nio/reactor/ test/java/org/apache/http/nio/integration/ test/java/org/apache/http/testserver/
Date Mon, 08 Oct 2012 15:57:26 GMT
Author: olegk
Date: Mon Oct  8 15:57:25 2012
New Revision: 1395631

URL: http://svn.apache.org/viewvc?rev=1395631&view=rev
Log:
Simplified HttpCore NIO integration testing framework

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestAsyncNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestPipelining.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpCoreNIOTestBase.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java Mon Oct  8 15:57:25 2012
@@ -126,11 +126,11 @@ public class HttpAsyncRequester {
         BasicAsyncRequestExecutionHandler<T> handler = new BasicAsyncRequestExecutionHandler<T>(
                 requestProducer, responseConsumer, callback, context,
                 this.httppocessor, this.reuseStrategy);
-        doExecute(handler, conn);
+        initExection(handler, conn);
         return handler.getFuture();
     }
 
-    private <T> void doExecute(
+    private <T> void initExection(
             final HttpAsyncRequestExecutionHandler<T> handler, final NHttpClientConnection conn) {
         conn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, handler);
         conn.requestOutput();
@@ -208,6 +208,46 @@ public class HttpAsyncRequester {
     }
 
     /**
+     * Initiates asynchronous HTTP request execution. This method automatically releases
+     * the given pool entry once request execution is completed (successfully or unsuccessfully).
+     *
+     * @param <T> the result type of request execution.
+     * @param <E> the connection pool entry type.
+     * @param requestProducer request producer callback.
+     * @param responseConsumer response consumer callaback.
+     * @param poolEntry leased pool entry. It will be automatically released
+     *   back to the pool when execution is completed.
+     * @param connPool pool of persistent reusable connections.
+     * @param context HTTP context
+     * @param callback future callback.
+     * @return future representing pending completion of the operation.
+     *
+     * @since 4.3
+     */
+    public <T, E extends PoolEntry<HttpHost, NHttpClientConnection>> Future<T> execute(
+            final HttpAsyncRequestProducer requestProducer,
+            final HttpAsyncResponseConsumer<T> responseConsumer,
+            final E poolEntry,
+            final ConnPool<HttpHost, E> connPool,
+            final HttpContext context,
+            final FutureCallback<T> callback) {
+        Args.notNull(requestProducer, "HTTP request producer");
+        Args.notNull(responseConsumer, "HTTP response consumer");
+        Args.notNull(connPool, "HTTP connection pool");
+        Args.notNull(poolEntry, "Pool entry");
+        Args.notNull(context, "HTTP context");
+        BasicFuture<T> future = new BasicFuture<T>(callback);
+        NHttpClientConnection conn = poolEntry.getConnection();
+        BasicAsyncRequestExecutionHandler<T> handler = new BasicAsyncRequestExecutionHandler<T>(
+                requestProducer, responseConsumer,
+                new RequestExecutionCallback<T, E>(future, poolEntry, connPool),
+                context,
+                this.httppocessor, this.reuseStrategy);
+        initExection(handler, conn);
+        return future;
+    }
+
+    /**
      * Initiates asynchronous HTTP request execution.
      *
      * @param <T> the result type of request execution.
@@ -275,7 +315,7 @@ public class HttpAsyncRequester {
                     this.requestProducer, this.responseConsumer,
                     new RequestExecutionCallback<T, E>(this.requestFuture, result, this.connPool),
                     this.context, httppocessor, reuseStrategy);
-            doExecute(handler, conn);
+            initExection(handler, conn);
         }
 
         public void failed(final Exception ex) {

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java Mon Oct  8 15:57:25 2012
@@ -56,6 +56,7 @@ import org.apache.http.protocol.HttpCont
 import org.apache.http.protocol.HttpExpectationVerifier;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.testserver.HttpCoreNIOTestBase;
+import org.apache.http.testserver.HttpServerNio;
 import org.apache.http.testserver.LoggingSSLClientConnectionFactory;
 import org.apache.http.testserver.LoggingSSLServerConnectionFactory;
 import org.apache.http.testserver.SSLTestContexts;
@@ -93,7 +94,7 @@ public class TestBaseIOReactorSSL extend
             final HttpExpectationVerifier expectationVerifier,
             final EventListener eventListener) {
         BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
-                this.serverHttpProc,
+                HttpServerNio.DEFAULT_HTTP_PROC,
                 DefaultHttpResponseFactory.INSTANCE,
                 DefaultConnectionReuseStrategy.INSTANCE,
                 new BasicHttpParams());

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java Mon Oct  8 15:57:25 2012
@@ -50,8 +50,6 @@ import org.apache.http.nio.NHttpClientCo
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.NHttpServerConnection;
 import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
-import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
-import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
 import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
 import org.apache.http.nio.protocol.HttpAsyncService;
 import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
@@ -62,6 +60,7 @@ import org.apache.http.nio.reactor.Liste
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.testserver.HttpCoreNIOTestBase;
+import org.apache.http.testserver.HttpServerNio;
 import org.apache.http.testserver.LoggingClientConnectionFactory;
 import org.apache.http.testserver.LoggingServerConnectionFactory;
 import org.junit.After;
@@ -108,7 +107,8 @@ public class TestDefaultIOReactors exten
         this.client.setMaxTotal(connNo);
 
         UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
-        HttpAsyncService serviceHandler = new HttpAsyncService(this.serverHttpProc, registry) {
+        HttpAsyncService serviceHandler = new HttpAsyncService(
+                HttpServerNio.DEFAULT_HTTP_PROC, registry) {
 
             @Override
             public void connected(final NHttpServerConnection conn) {
@@ -189,7 +189,8 @@ public class TestDefaultIOReactors exten
 
         UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
         registry.register("*", new BasicAsyncRequestHandler(requestHandler));
-        HttpAsyncService serviceHandler = new HttpAsyncService(this.serverHttpProc, registry) {
+        HttpAsyncService serviceHandler = new HttpAsyncService(
+                HttpServerNio.DEFAULT_HTTP_PROC, registry) {
 
                     @Override
                     public void exception(
@@ -202,9 +203,8 @@ public class TestDefaultIOReactors exten
                     }
 
         };
-        HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor();
         this.server.start(serviceHandler);
-        this.client.start(clientHandler);
+        this.client.start();
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
@@ -214,10 +214,7 @@ public class TestDefaultIOReactors exten
         Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
 
         BasicHttpRequest request = new BasicHttpRequest("GET", "/");
-        this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool());
+        this.client.execute(target, request);
 
         this.server.join(20000);
 
@@ -268,7 +265,8 @@ public class TestDefaultIOReactors exten
 
         UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
         registry.register("*", new BasicAsyncRequestHandler(requestHandler));
-        HttpAsyncService serviceHandler = new HttpAsyncService(this.serverHttpProc, registry) {
+        HttpAsyncService serviceHandler = new HttpAsyncService(
+                HttpServerNio.DEFAULT_HTTP_PROC, registry) {
 
             @Override
             public void exception(
@@ -281,10 +279,9 @@ public class TestDefaultIOReactors exten
             }
 
         };
-        HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor();
         this.server.setExceptionHandler(exceptionHandler);
         this.server.start(serviceHandler);
-        this.client.start(clientHandler);
+        this.client.start();
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
@@ -294,10 +291,7 @@ public class TestDefaultIOReactors exten
         Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
 
         BasicHttpRequest request = new BasicHttpRequest("GET", "/");
-        this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool());
+        this.client.execute(target, request);
 
         this.server.join(20000);
 
@@ -348,7 +342,8 @@ public class TestDefaultIOReactors exten
 
         UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
         registry.register("*", new BasicAsyncRequestHandler(requestHandler));
-        HttpAsyncService serviceHandler = new HttpAsyncService(this.serverHttpProc, registry) {
+        HttpAsyncService serviceHandler = new HttpAsyncService(
+                HttpServerNio.DEFAULT_HTTP_PROC, registry) {
 
             @Override
             public void exception(
@@ -361,10 +356,9 @@ public class TestDefaultIOReactors exten
             }
 
         };
-        HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor();
         this.server.setExceptionHandler(exceptionHandler);
         this.server.start(serviceHandler);
-        this.client.start(clientHandler);
+        this.client.start();
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
@@ -374,10 +368,7 @@ public class TestDefaultIOReactors exten
         Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
 
         BasicHttpRequest request = new BasicHttpRequest("GET", "/");
-        this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool());
+        this.client.execute(target, request);
 
         requestConns.await();
         Assert.assertEquals(0, requestConns.getCount());

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestAsyncNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestAsyncNHttpHandlers.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestAsyncNHttpHandlers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestAsyncNHttpHandlers.java Mon Oct  8 15:57:25 2012
@@ -77,7 +77,9 @@ import org.apache.http.protocol.Response
 import org.apache.http.protocol.ResponseContent;
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
+import org.apache.http.testserver.HttpClientNio;
 import org.apache.http.testserver.HttpCoreNIOTestBase;
+import org.apache.http.testserver.HttpServerNio;
 import org.apache.http.testserver.LoggingClientConnectionFactory;
 import org.apache.http.testserver.LoggingServerConnectionFactory;
 import org.apache.http.testserver.SimpleEventListener;
@@ -134,7 +136,7 @@ public class TestAsyncNHttpHandlers exte
         }
 
         AsyncNHttpServiceHandler serviceHandler = new AsyncNHttpServiceHandler(
-                this.serverHttpProc,
+                HttpServerNio.DEFAULT_HTTP_PROC,
                 DefaultHttpResponseFactory.INSTANCE,
                 DefaultConnectionReuseStrategy.INSTANCE,
                 this.params);
@@ -145,7 +147,7 @@ public class TestAsyncNHttpHandlers exte
                 new SimpleEventListener());
 
         AsyncNHttpClientHandler clientHandler = new AsyncNHttpClientHandler(
-                this.clientHttpProc,
+                HttpClientNio.DEFAULT_HTTP_PROC,
                 requestExecutionHandler,
                 DefaultConnectionReuseStrategy.INSTANCE,
                 this.params);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java Mon Oct  8 15:57:25 2012
@@ -54,7 +54,6 @@ import org.apache.http.nio.protocol.Http
 import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
 import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
 import org.apache.http.nio.protocol.HttpAsyncResponseProducer;
-import org.apache.http.nio.protocol.HttpAsyncService;
 import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
@@ -140,8 +139,7 @@ public class TestHttpAsyncHandlerCancell
             }
             
         });
-        HttpAsyncService serviceHandler = new HttpAsyncService(this.serverHttpProc, registry);
-        this.server.start(serviceHandler);
+        this.server.start(registry);
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
@@ -198,8 +196,7 @@ public class TestHttpAsyncHandlerCancell
             }
             
         });
-        HttpAsyncService serviceHandler = new HttpAsyncService(this.serverHttpProc, registry);
-        this.server.start(serviceHandler);
+        this.server.start(registry);
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java Mon Oct  8 15:57:25 2012
@@ -42,8 +42,6 @@ import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.entity.ContentType;
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.nio.DefaultNHttpClientConnection;
 import org.apache.http.impl.nio.DefaultNHttpServerConnection;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
@@ -53,17 +51,12 @@ import org.apache.http.nio.NHttpConnecti
 import org.apache.http.nio.entity.NStringEntity;
 import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
 import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
-import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
-import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
 import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
 import org.apache.http.nio.protocol.HttpAsyncExchange;
 import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
 import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
-import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
 import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
 import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
-import org.apache.http.nio.protocol.HttpAsyncRequester;
-import org.apache.http.nio.protocol.HttpAsyncService;
 import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
@@ -71,6 +64,7 @@ import org.apache.http.protocol.BasicHtt
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.protocol.ImmutableHttpProcessor;
 import org.apache.http.protocol.RequestConnControl;
@@ -114,17 +108,12 @@ public class TestHttpAsyncHandlers exten
     }
 
     private InetSocketAddress start(
+            final HttpProcessor clientProtocolProcessor,
+            final HttpProcessor serverProtocolProcessor,
             final HttpAsyncRequestHandlerMapper requestHandlerResolver,
             final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
-        HttpAsyncService serviceHandler = new HttpAsyncService(
-                this.serverHttpProc,
-                DefaultConnectionReuseStrategy.INSTANCE,
-                DefaultHttpResponseFactory.INSTANCE,
-                requestHandlerResolver,
-                expectationVerifier);
-        HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor();
-        this.server.start(serviceHandler);
-        this.client.start(clientHandler);
+        this.server.start(serverProtocolProcessor, requestHandlerResolver, expectationVerifier);
+        this.client.start(clientProtocolProcessor);
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
@@ -133,6 +122,12 @@ public class TestHttpAsyncHandlers exten
         return (InetSocketAddress) endpoint.getAddress();
     }
 
+    private InetSocketAddress start(
+            final HttpAsyncRequestHandlerMapper requestHandlerResolver,
+            final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
+        return start(null, null, requestHandlerResolver, expectationVerifier);
+    }
+
     private static String createRequestUri(final String pattern, int count) {
         return pattern + "x" + count;
     }
@@ -163,10 +158,7 @@ public class TestHttpAsyncHandlers exten
         Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
         for (int i = 0; i < 30; i++) {
             BasicHttpRequest request = new BasicHttpRequest("GET", createRequestUri(pattern, count));
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -195,10 +187,7 @@ public class TestHttpAsyncHandlers exten
         Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
         for (int i = 0; i < 30; i++) {
             BasicHttpRequest request = new BasicHttpRequest("HEAD", createRequestUri(pattern, count));
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -231,10 +220,7 @@ public class TestHttpAsyncHandlers exten
                     "POST", createRequestUri(pattern, count));
             NStringEntity entity = new NStringEntity(expectedPattern, ContentType.DEFAULT_TEXT);
             request.setEntity(entity);
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -268,10 +254,7 @@ public class TestHttpAsyncHandlers exten
             NStringEntity entity = new NStringEntity(expectedPattern, ContentType.DEFAULT_TEXT);
             entity.setChunked(true);
             request.setEntity(entity);
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -304,10 +287,7 @@ public class TestHttpAsyncHandlers exten
                     "POST", createRequestUri(pattern, count), HttpVersion.HTTP_1_0);
             NStringEntity entity = new NStringEntity(expectedPattern, ContentType.DEFAULT_TEXT);
             request.setEntity(entity);
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -338,10 +318,7 @@ public class TestHttpAsyncHandlers exten
             BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(
                     "POST", createRequestUri(pattern, count));
             request.setEntity(null);
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -358,15 +335,13 @@ public class TestHttpAsyncHandlers exten
         UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
         registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
 
-        this.clientHttpProc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
+        HttpProcessor clientHttpProc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
                 new RequestTargetHost(),
                 new RequestConnControl(),
                 new RequestUserAgent(),
                 new RequestExpectContinue()});
 
-        this.executor = new HttpAsyncRequester(this.clientHttpProc);
-
-        InetSocketAddress address = start(registry, null);
+        InetSocketAddress address = start(clientHttpProc, null, registry, null);
 
         this.client.setMaxPerRoute(3);
         this.client.setMaxTotal(3);
@@ -380,10 +355,7 @@ public class TestHttpAsyncHandlers exten
                 "POST", createRequestUri(pattern, count));
         request.setEntity(null);
 
-        Future<HttpResponse> future = this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool());
+        Future<HttpResponse> future = this.client.execute(target, request);
 
         HttpResponse response = future.get();
         Assert.assertNotNull(response);
@@ -395,7 +367,7 @@ public class TestHttpAsyncHandlers exten
         UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
         registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
 
-        this.clientHttpProc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
+        HttpProcessor clientHttpProc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
                 new HttpRequestInterceptor() {
 
                     public void process(
@@ -410,9 +382,7 @@ public class TestHttpAsyncHandlers exten
                 new RequestUserAgent(),
                 new RequestExpectContinue()});
 
-        this.executor = new HttpAsyncRequester(this.clientHttpProc);
-
-        InetSocketAddress address = start(registry, null);
+        InetSocketAddress address = start(clientHttpProc, null, registry, null);
 
         this.client.setMaxPerRoute(3);
         this.client.setMaxTotal(3);
@@ -426,10 +396,7 @@ public class TestHttpAsyncHandlers exten
                 "POST", createRequestUri(pattern, count));
         request.setEntity(null);
 
-        Future<HttpResponse> future = this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool());
+        Future<HttpResponse> future = this.client.execute(target, request);
 
         HttpResponse response = future.get();
         Assert.assertNotNull(response);
@@ -461,11 +428,7 @@ public class TestHttpAsyncHandlers exten
             HttpContext context = new BasicHttpContext();
             context.setAttribute(ExecutionContext.HTTP_EXPECT_CONT, true);
 
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool(),
-                    context);
+            Future<HttpResponse> future = this.client.execute(target, request, context);
             queue.add(future);
         }
 
@@ -525,11 +488,7 @@ public class TestHttpAsyncHandlers exten
             HttpContext context = new BasicHttpContext();
             context.setAttribute(ExecutionContext.HTTP_EXPECT_CONT, true);
 
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, requests[i]),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool(),
-                    context);
+            Future<HttpResponse> future = this.client.execute(target, requests[i], context);
             queue.add(future);
         }
 
@@ -606,10 +565,7 @@ public class TestHttpAsyncHandlers exten
         Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
         for (int i = 0; i < 30; i++) {
             BasicHttpRequest request = new BasicHttpRequest("HEAD", createRequestUri(pattern, count));
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -677,11 +633,7 @@ public class TestHttpAsyncHandlers exten
             HttpContext context = new BasicHttpContext();
             context.setAttribute(ExecutionContext.HTTP_EXPECT_CONT, true);
 
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, requests[i]),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool(),
-                    context);
+            Future<HttpResponse> future = this.client.execute(target, requests[i], context);
             queue.add(future);
         }
 
@@ -737,10 +689,7 @@ public class TestHttpAsyncHandlers exten
         Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
         for (int i = 0; i < 1; i++) {
             BasicHttpRequest request = new BasicHttpRequest("GET", createRequestUri(pattern, count));
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -768,10 +717,7 @@ public class TestHttpAsyncHandlers exten
         Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
         for (int i = 0; i < 30; i++) {
             BasicHttpRequest request = new BasicHttpRequest("GET", createRequestUri(pattern, count));
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 
@@ -806,10 +752,7 @@ public class TestHttpAsyncHandlers exten
         Queue<Future<HttpResponse>> queue = new ConcurrentLinkedQueue<Future<HttpResponse>>();
         for (int i = 0; i < 30; i++) {
             BasicHttpRequest request = new BasicHttpRequest("GET", "/");
-            Future<HttpResponse> future = this.executor.execute(
-                    new BasicAsyncRequestProducer(target, request),
-                    new BasicAsyncResponseConsumer(),
-                    this.client.getConnPool());
+            Future<HttpResponse> future = this.client.execute(target, request);
             queue.add(future);
         }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java Mon Oct  8 15:57:25 2012
@@ -38,8 +38,6 @@ import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.entity.ContentType;
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.nio.DefaultNHttpClientConnection;
 import org.apache.http.impl.nio.DefaultNHttpServerConnection;
 import org.apache.http.message.BasicHttpRequest;
@@ -48,16 +46,12 @@ import org.apache.http.nio.IOControl;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.entity.NStringEntity;
 import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
-import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
-import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
 import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
 import org.apache.http.nio.protocol.HttpAsyncExchange;
 import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
 import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
-import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
 import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
 import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
-import org.apache.http.nio.protocol.HttpAsyncService;
 import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
@@ -99,15 +93,8 @@ public class TestHttpAsyncPrematureTermi
     private InetSocketAddress start(
             final HttpAsyncRequestHandlerMapper requestHandlerResolver,
             final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
-        HttpAsyncService serviceHandler = new HttpAsyncService(
-                this.serverHttpProc,
-                DefaultConnectionReuseStrategy.INSTANCE,
-                DefaultHttpResponseFactory.INSTANCE,
-                requestHandlerResolver,
-                expectationVerifier);
-        HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor();
-        this.server.start(serviceHandler);
-        this.client.start(clientHandler);
+        this.server.start(requestHandlerResolver, expectationVerifier);
+        this.client.start();
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
@@ -163,10 +150,7 @@ public class TestHttpAsyncPrematureTermi
 
         HttpRequest request = new BasicHttpRequest("GET", "/");
         HttpContext context = new BasicHttpContext();
-        this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool(), context, callback);
+        this.client.execute(target, request, context, callback);
 
         Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
     }
@@ -218,10 +202,7 @@ public class TestHttpAsyncPrematureTermi
 
         HttpRequest request = new BasicHttpRequest("GET", "/");
         HttpContext context = new BasicHttpContext();
-        this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool(), context, callback);
+        this.client.execute(target, request, context, callback);
 
         Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
     }
@@ -279,10 +260,7 @@ public class TestHttpAsyncPrematureTermi
 
         HttpRequest request = new BasicHttpRequest("GET", "/");
         HttpContext context = new BasicHttpContext();
-        this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool(), context, callback);
+        this.client.execute(target, request, context, callback);
 
         Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
     }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestPipelining.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestPipelining.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestPipelining.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestPipelining.java Mon Oct  8 15:57:25 2012
@@ -59,6 +59,7 @@ import org.apache.http.nio.protocol.UriH
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestHandler;
 import org.apache.http.protocol.ImmutableHttpProcessor;
 import org.apache.http.protocol.ResponseConnControl;
@@ -77,6 +78,8 @@ import org.junit.Test;
  */
 public class TestPipelining extends HttpCoreNIOTestBase {
 
+    protected HttpProcessor serverHttpProc;
+
     @Before
     public void setUp() throws Exception {
         initServer();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestThrottlingNHttpHandlers.java Mon Oct  8 15:57:25 2012
@@ -83,7 +83,9 @@ import org.apache.http.protocol.Response
 import org.apache.http.protocol.ResponseContent;
 import org.apache.http.protocol.ResponseDate;
 import org.apache.http.protocol.ResponseServer;
+import org.apache.http.testserver.HttpClientNio;
 import org.apache.http.testserver.HttpCoreNIOTestBase;
+import org.apache.http.testserver.HttpServerNio;
 import org.apache.http.testserver.LoggingClientConnectionFactory;
 import org.apache.http.testserver.LoggingServerConnectionFactory;
 import org.apache.http.testserver.SimpleEventListener;
@@ -153,7 +155,7 @@ public class TestThrottlingNHttpHandlers
         }
 
         ThrottlingHttpServiceHandler serviceHandler = new ThrottlingHttpServiceHandler(
-                this.serverHttpProc,
+                HttpServerNio.DEFAULT_HTTP_PROC,
                 DefaultHttpResponseFactory.INSTANCE,
                 DefaultConnectionReuseStrategy.INSTANCE,
                 this.execService,
@@ -165,7 +167,7 @@ public class TestThrottlingNHttpHandlers
                 new SimpleEventListener());
 
         ThrottlingHttpClientHandler clientHandler = new ThrottlingHttpClientHandler(
-                this.clientHttpProc,
+                HttpClientNio.DEFAULT_HTTP_PROC,
                 requestExecutionHandler,
                 DefaultConnectionReuseStrategy.INSTANCE,
                 this.execService,

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java Mon Oct  8 15:57:25 2012
@@ -57,9 +57,6 @@ import org.apache.http.nio.entity.Conten
 import org.apache.http.nio.protocol.AbstractAsyncResponseConsumer;
 import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
 import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
-import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
-import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
-import org.apache.http.nio.protocol.HttpAsyncService;
 import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.IOSession;
@@ -180,10 +177,8 @@ public class TestTruncatedChunks extends
     public void testTruncatedChunkException() throws Exception {
         UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
         registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler(true)));
-        HttpAsyncService serviceHandler = new HttpAsyncService(this.serverHttpProc, registry);
-        HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor();
-        this.server.start(serviceHandler);
-        this.client.start(clientHandler);
+        this.server.start(registry);
+        this.client.start();
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
@@ -195,10 +190,7 @@ public class TestTruncatedChunks extends
 
         HttpHost target = new HttpHost("localhost", ((InetSocketAddress)endpoint.getAddress()).getPort());
         BasicHttpRequest request = new BasicHttpRequest("GET", pattern + "x" + count);
-        Future<HttpResponse> future = this.executor.execute(
-                new BasicAsyncRequestProducer(target, request),
-                new BasicAsyncResponseConsumer(),
-                this.client.getConnPool());
+        Future<HttpResponse> future = this.client.execute(target, request);
         try {
             future.get();
             Assert.fail("ExecutionException should have been thrown");
@@ -261,10 +253,8 @@ public class TestTruncatedChunks extends
     public void testIgnoreTruncatedChunkException() throws Exception {
         UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
         registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler(true)));
-        HttpAsyncService serviceHandler = new HttpAsyncService(this.serverHttpProc, registry);
-        HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor();
-        this.server.start(serviceHandler);
-        this.client.start(clientHandler);
+        this.server.start(registry);
+        this.client.start();
 
         ListenerEndpoint endpoint = this.server.getListenerEndpoint();
         endpoint.waitFor();
@@ -276,10 +266,10 @@ public class TestTruncatedChunks extends
 
         HttpHost target = new HttpHost("localhost", ((InetSocketAddress)endpoint.getAddress()).getPort());
         BasicHttpRequest request = new BasicHttpRequest("GET", pattern + "x" + count);
-        Future<HttpResponse> future = this.executor.execute(
+        Future<HttpResponse> future = this.client.execute(
                 new BasicAsyncRequestProducer(target, request),
                 new LenientAsyncResponseConsumer(),
-                this.client.getConnPool());
+                null, null);
 
         HttpResponse response = future.get();
         Assert.assertNotNull(response);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpClientNio.java Mon Oct  8 15:57:25 2012
@@ -34,6 +34,10 @@ import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponse;
+import org.apache.http.concurrent.BasicFuture;
 import org.apache.http.concurrent.FutureCallback;
 import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
 import org.apache.http.impl.nio.DefaultNHttpClientConnection;
@@ -45,20 +49,44 @@ import org.apache.http.impl.nio.reactor.
 import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.NHttpClientEventHandler;
 import org.apache.http.nio.NHttpConnectionFactory;
+import org.apache.http.nio.protocol.BasicAsyncRequestProducer;
+import org.apache.http.nio.protocol.BasicAsyncResponseConsumer;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
+import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
+import org.apache.http.nio.protocol.HttpAsyncRequester;
+import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.SessionRequest;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
+import org.apache.http.protocol.RequestConnControl;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestExpectContinue;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
 
 @SuppressWarnings("deprecation")
 public class HttpClientNio {
 
+    public static final HttpProcessor DEFAULT_HTTP_PROC = new ImmutableHttpProcessor(
+            new HttpRequestInterceptor[] {
+                    new RequestContent(),
+                    new RequestTargetHost(),
+                    new RequestConnControl(),
+                    new RequestUserAgent("TEST-CLIENT/1.1"),
+                    new RequestExpectContinue()});
+
     private final DefaultConnectingIOReactor ioReactor;
     private final NHttpConnectionFactory<DefaultNHttpClientConnection> connFactory;
     private final BasicNIOConnPool connpool;
 
+    private volatile  HttpAsyncRequester executor;
     private volatile IOReactorThread thread;
     private volatile int timeout;
 
@@ -96,8 +124,73 @@ public class HttpClientNio {
         this.connpool.release(poolEntry, reusable);
     }
 
-    public BasicNIOConnPool getConnPool() {
-        return this.connpool;
+    public <T> Future<T> execute(
+            final HttpAsyncRequestProducer requestProducer,
+            final HttpAsyncResponseConsumer<T> responseConsumer,
+            final HttpContext context,
+            final FutureCallback<T> callback) {
+        final HttpHost target = requestProducer.getTarget();
+        final BasicFuture<T> future = new BasicFuture<T>(callback);
+        this.connpool.lease(target, null, this.timeout, TimeUnit.MILLISECONDS,
+            new FutureCallback<BasicNIOPoolEntry>() {
+
+                public void completed(final BasicNIOPoolEntry result) {
+                    executor.execute(
+                            requestProducer, responseConsumer,
+                            result, connpool,
+                            context != null ? context : new BasicHttpContext(),
+                            new FutureCallback<T>() {
+
+                                public void completed(final T result) {
+                                    future.completed(result);
+                                }
+
+                                public void failed(final Exception ex) {
+                                    future.failed(ex);
+                                }
+
+                                public void cancelled() {
+                                    future.cancel();
+                                }
+
+                            });
+                }
+
+                public void failed(final Exception ex) {
+                    future.failed(ex);
+                }
+
+                public void cancelled() {
+                    future.cancel();
+                }
+
+            });
+        return future;
+    }
+
+    public Future<HttpResponse> execute(
+            final HttpHost target,
+            final HttpRequest request,
+            final HttpContext context,
+            final FutureCallback<HttpResponse> callback) {
+        return execute(
+                new BasicAsyncRequestProducer(target, request),
+                new BasicAsyncResponseConsumer(),
+                context != null ? context : new BasicHttpContext(),
+                callback);
+    }
+
+    public Future<HttpResponse> execute(
+            final HttpHost target,
+            final HttpRequest request,
+            final HttpContext context) {
+        return execute(target, request, context, null);
+    }
+
+    public Future<HttpResponse> execute(
+            final HttpHost target,
+            final HttpRequest request) {
+        return execute(target, request, null, null);
     }
 
     public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
@@ -124,11 +217,29 @@ public class HttpClientNio {
         return sessionRequest;
     }
 
-    public void start(final NHttpClientEventHandler clientHandler) {
+    public void start(
+            final HttpProcessor protocolProcessor,
+            final NHttpClientEventHandler clientHandler) {
+        this.executor = new HttpAsyncRequester(protocolProcessor != null ? protocolProcessor :
+            DEFAULT_HTTP_PROC);
         this.thread = new IOReactorThread(clientHandler);
         this.thread.start();
     }
 
+    public void start(
+            final HttpProcessor protocolProcessor) {
+        start(protocolProcessor, new HttpAsyncRequestExecutor());
+    }
+
+    public void start(
+            final NHttpClientEventHandler clientHandler) {
+        start(null, clientHandler);
+    }
+
+    public void start() {
+        start(null, new HttpAsyncRequestExecutor());
+    }
+
     public void start(final NHttpClientHandler handler) {
         this.thread = new IOReactorThread(new NHttpClientEventHandlerAdaptor(handler));
         this.thread.start();

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpCoreNIOTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpCoreNIOTestBase.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpCoreNIOTestBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpCoreNIOTestBase.java Mon Oct  8 15:57:25 2012
@@ -27,23 +27,9 @@
 
 package org.apache.http.testserver;
 
-import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.impl.nio.DefaultNHttpClientConnection;
 import org.apache.http.impl.nio.DefaultNHttpServerConnection;
 import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.protocol.HttpAsyncRequester;
-import org.apache.http.protocol.HttpProcessor;
-import org.apache.http.protocol.ImmutableHttpProcessor;
-import org.apache.http.protocol.RequestConnControl;
-import org.apache.http.protocol.RequestContent;
-import org.apache.http.protocol.RequestExpectContinue;
-import org.apache.http.protocol.RequestTargetHost;
-import org.apache.http.protocol.RequestUserAgent;
-import org.apache.http.protocol.ResponseConnControl;
-import org.apache.http.protocol.ResponseContent;
-import org.apache.http.protocol.ResponseDate;
-import org.apache.http.protocol.ResponseServer;
 import org.junit.After;
 
 /**
@@ -54,9 +40,6 @@ public abstract class HttpCoreNIOTestBas
 
     protected HttpServerNio server;
     protected HttpClientNio client;
-    protected HttpProcessor serverHttpProc;
-    protected HttpProcessor clientHttpProc;
-    protected HttpAsyncRequester executor;
 
     protected abstract NHttpConnectionFactory<DefaultNHttpServerConnection>
         createServerConnectionFactory() throws Exception;
@@ -67,26 +50,13 @@ public abstract class HttpCoreNIOTestBas
     public void initServer() throws Exception {
         this.server = new HttpServerNio(createServerConnectionFactory());
         this.server.setExceptionHandler(new SimpleIOReactorExceptionHandler());
-        this.serverHttpProc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
-                new ResponseDate(),
-                new ResponseServer("TEST-SERVER/1.1"),
-                new ResponseContent(),
-                new ResponseConnControl()
-        });
         this.server.setTimeout(5000);
     }
 
     public void initClient() throws Exception {
         this.client = new HttpClientNio(createClientConnectionFactory());
         this.client.setExceptionHandler(new SimpleIOReactorExceptionHandler());
-        this.clientHttpProc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
-                new RequestContent(),
-                new RequestTargetHost(),
-                new RequestConnControl(),
-                new RequestUserAgent("TEST-CLIENT/1.1"),
-                new RequestExpectContinue()});
         this.client.setTimeout(5000);
-        this.executor = new HttpAsyncRequester(this.clientHttpProc);
     }
 
     @After

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java?rev=1395631&r1=1395630&r2=1395631&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java Mon Oct  8 15:57:25 2012
@@ -31,6 +31,7 @@ import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.List;
 
+import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.impl.nio.DefaultNHttpServerConnection;
 import org.apache.http.impl.nio.DefaultHttpServerIODispatch;
 import org.apache.http.impl.nio.reactor.DefaultListeningIOReactor;
@@ -38,16 +39,32 @@ import org.apache.http.impl.nio.reactor.
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.NHttpServerEventHandler;
 import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
+import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
+import org.apache.http.nio.protocol.HttpAsyncService;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOReactorExceptionHandler;
 import org.apache.http.nio.reactor.IOReactorStatus;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.ListenerEndpoint;
 import org.apache.http.nio.reactor.ListeningIOReactor;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
+import org.apache.http.protocol.ResponseConnControl;
+import org.apache.http.protocol.ResponseContent;
+import org.apache.http.protocol.ResponseDate;
+import org.apache.http.protocol.ResponseServer;
 
 @SuppressWarnings("deprecation")
 public class HttpServerNio {
 
+    public static final HttpProcessor DEFAULT_HTTP_PROC = new ImmutableHttpProcessor(
+            new HttpResponseInterceptor[] {
+                    new ResponseDate(),
+                    new ResponseServer("TEST-SERVER/1.1"),
+                    new ResponseContent(),
+                    new ResponseConnControl()});
+
     private final DefaultListeningIOReactor ioReactor;
     private final NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory;
 
@@ -102,6 +119,24 @@ public class HttpServerNio {
         this.thread.start();
     }
 
+    public void start(
+            final HttpProcessor protocolProcessor,
+            final HttpAsyncRequestHandlerMapper handlerMapper,
+            final HttpAsyncExpectationVerifier expectationVerifier) {
+        start(new HttpAsyncService(protocolProcessor != null ? protocolProcessor :
+            DEFAULT_HTTP_PROC, null, null, handlerMapper, expectationVerifier));
+    }
+
+    public void start(
+            final HttpAsyncRequestHandlerMapper handlerMapper,
+            final HttpAsyncExpectationVerifier expectationVerifier) {
+        start(null, handlerMapper, expectationVerifier);
+    }
+
+    public void start(final HttpAsyncRequestHandlerMapper handlerMapper) {
+        start(null, handlerMapper, null);
+    }
+
     public void start(final NHttpServiceHandler handler) {
         this.endpoint = this.ioReactor.listen(new InetSocketAddress(0));
         this.thread = new IOReactorThread(new NHttpServerEventHandlerAdaptor(handler));



Mime
View raw message