You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2015/06/03 20:20:41 UTC
svn commit: r1683403 - in /httpcomponents/httpcore/branches/4.4.x:
httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/
httpcore-nio/src/test/java/org/apache/http/nio/integration/
httpcore-nio/src/test/java/org/apache/http/nio/testserver/ httpc...
Author: olegk
Date: Wed Jun 3 18:20:41 2015
New Revision: 1683403
URL: http://svn.apache.org/r1683403
Log:
Refactored async integration testing framework and integration tests
Removed:
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactors.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/SimpleIOReactorExceptionHandler.java
Modified:
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestServerSidePipelining.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpClientNio.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java
httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpServerNio.java
httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestCustomSSL.java Wed Jun 3 18:20:41 2015
@@ -46,8 +46,6 @@ import org.apache.http.impl.nio.pool.Bas
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.nio.NHttpConnection;
import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
-import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
-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.ssl.SSLSetupHandler;
@@ -55,7 +53,6 @@ import org.apache.http.nio.testserver.Cl
import org.apache.http.nio.testserver.HttpClientNio;
import org.apache.http.nio.testserver.HttpServerNio;
import org.apache.http.nio.testserver.ServerConnectionFactory;
-import org.apache.http.nio.testserver.SimpleIOReactorExceptionHandler;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpCoreContext;
import org.apache.http.protocol.HttpRequestHandler;
@@ -125,29 +122,25 @@ public class TestCustomSSL {
.loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
.loadKeyMaterial(keyStoreURL, storePassword.toCharArray(), storePassword.toCharArray())
.build();
- this.server = new HttpServerNio(new ServerConnectionFactory(serverSSLContext, sslSetupHandler));
- this.server.setExceptionHandler(new SimpleIOReactorExceptionHandler());
+ this.server = new HttpServerNio();
+ this.server.setConnectionFactory(new ServerConnectionFactory(serverSSLContext, sslSetupHandler));
this.server.setTimeout(5000);
final SSLContext clientSSLContext = SSLContextBuilder.create()
.loadTrustMaterial(keyStoreURL, storePassword.toCharArray())
.build();
- this.client = new HttpClientNio(
- new BasicNIOConnFactory(new ClientConnectionFactory(clientSSLContext), null));
- this.client.setExceptionHandler(new SimpleIOReactorExceptionHandler());
+ this.client = new HttpClientNio(new BasicNIOConnFactory(new ClientConnectionFactory(clientSSLContext), null));
this.client.setTimeout(5000);
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(requestHandler));
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(requestHandler));
- this.server.start(HttpServerNio.DEFAULT_HTTP_PROC, registry, null);
- this.client.start(HttpClientNio.DEFAULT_HTTP_PROC);
+ this.server.start();
+ this.client.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
final HttpHost target = new HttpHost("localhost", address.getPort());
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlerCancellable.java Wed Jun 3 18:20:41 2015
@@ -51,8 +51,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.UriHttpAsyncRequestHandlerMapper;
-import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.nio.testserver.HttpCoreNIOTestBase;
import org.apache.http.protocol.HttpContext;
@@ -111,8 +109,7 @@ public class TestHttpAsyncHandlerCancell
};
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
+ this.server.registerHandler("*", new HttpAsyncRequestHandler<HttpRequest>() {
@Override
public HttpAsyncRequestConsumer<HttpRequest> processRequest(
@@ -131,12 +128,11 @@ public class TestHttpAsyncHandlerCancell
}
});
- this.server.start(registry);
+ this.server.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
final Socket socket = new Socket("localhost", address.getPort());
try {
@@ -170,8 +166,7 @@ public class TestHttpAsyncHandlerCancell
}
};
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
+ this.server.registerHandler("*", new HttpAsyncRequestHandler<HttpRequest>() {
@Override
public HttpAsyncRequestConsumer<HttpRequest> processRequest(
@@ -191,12 +186,11 @@ public class TestHttpAsyncHandlerCancell
}
});
- this.server.start(registry);
+ this.server.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
final Socket socket = new Socket("localhost", address.getPort());
try {
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlers.java Wed Jun 3 18:20:41 2015
@@ -55,15 +55,11 @@ import org.apache.http.nio.protocol.Http
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
-import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
-import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
-import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.nio.testserver.HttpCoreNIOTestBase;
import org.apache.http.protocol.BasicHttpContext;
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;
@@ -108,28 +104,17 @@ public class TestHttpAsyncHandlers exten
shutDownServer();
}
- private HttpHost start(
- final HttpProcessor clientProtocolProcessor,
- final HttpProcessor serverProtocolProcessor,
- final HttpAsyncRequestHandlerMapper requestHandlerResolver,
- final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- this.server.start(serverProtocolProcessor, requestHandlerResolver, expectationVerifier);
- this.client.start(clientProtocolProcessor);
+ private HttpHost start() throws IOException, InterruptedException {
+ this.server.start();
+ this.client.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
return new HttpHost("localhost", address.getPort(), getScheme().name());
}
- private HttpHost start(
- final HttpAsyncRequestHandlerMapper requestHandlerResolver,
- final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- return start(null, null, requestHandlerResolver, expectationVerifier);
- }
-
private static String createRequestUri(final String pattern, final int count) {
return pattern + "x" + count;
}
@@ -144,9 +129,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpGets() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -173,9 +157,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpHeads() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -200,9 +183,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostsWithContentLength() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -232,9 +214,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostsChunked() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -265,9 +246,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostsHTTP10() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -297,9 +277,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostsNoEntity() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -326,16 +305,15 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostNoContentLength() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpProcessor clientHttpProc = new ImmutableHttpProcessor(
+ this.client.setHttpProcessor(new ImmutableHttpProcessor(
new RequestTargetHost(),
new RequestConnControl(),
new RequestUserAgent(),
- new RequestExpectContinue(true));
+ new RequestExpectContinue(true)));
- final HttpHost target = start(clientHttpProc, null, registry, null);
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -356,10 +334,9 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostIdentity() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpProcessor clientHttpProc = new ImmutableHttpProcessor(
+ this.client.setHttpProcessor(new ImmutableHttpProcessor(
new HttpRequestInterceptor() {
@Override
@@ -373,9 +350,9 @@ public class TestHttpAsyncHandlers exten
new RequestTargetHost(),
new RequestConnControl(),
new RequestUserAgent(),
- new RequestExpectContinue(true));
+ new RequestExpectContinue(true)));
- final HttpHost target = start(clientHttpProc, null, registry, null);
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -396,9 +373,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostsWithExpectContinue() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -430,7 +406,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostsWithExpectationVerification() throws Exception {
- final HttpAsyncExpectationVerifier expectationVerifier = new HttpAsyncExpectationVerifier() {
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ this.server.setExpectationVerifier(new HttpAsyncExpectationVerifier() {
@Override
public void verify(
@@ -452,11 +429,9 @@ public class TestHttpAsyncHandlers exten
}
}
- };
+ });
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, expectationVerifier);
+ final HttpHost target = start();
final BasicHttpEntityEnclosingRequest request1 = new BasicHttpEntityEnclosingRequest(
"POST", createRequestUri("AAAAA", 10));
@@ -537,9 +512,8 @@ public class TestHttpAsyncHandlers exten
}
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new DelayedRequestHandler());
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new DelayedRequestHandler());
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -564,7 +538,8 @@ public class TestHttpAsyncHandlers exten
@Test
public void testHttpPostsWithExpectationVerificationDelayedResponse() throws Exception {
- final HttpAsyncExpectationVerifier expectationVerifier = new HttpAsyncExpectationVerifier() {
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ this.server.setExpectationVerifier(new HttpAsyncExpectationVerifier() {
@Override
public void verify(
@@ -574,7 +549,10 @@ public class TestHttpAsyncHandlers exten
@Override
public void run() {
// Wait a bit, to make sure this is delayed.
- try { Thread.sleep(100); } catch(final InterruptedException ie) {}
+ try {
+ Thread.sleep(100);
+ } catch (final InterruptedException ie) {
+ }
// Set the entity after delaying...
final HttpRequest request = httpexchange.getRequest();
ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
@@ -594,11 +572,8 @@ public class TestHttpAsyncHandlers exten
}.start();
}
- };
-
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, expectationVerifier);
+ });
+ final HttpHost target = start();
final BasicHttpEntityEnclosingRequest request1 = new BasicHttpEntityEnclosingRequest(
"POST", createRequestUri("AAAAA", 10));
@@ -658,9 +633,8 @@ public class TestHttpAsyncHandlers exten
}
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new FailingRequestHandler());
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new FailingRequestHandler());
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -685,8 +659,7 @@ public class TestHttpAsyncHandlers exten
@Test
public void testNoServiceHandler() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- final HttpHost target = start(registry, null);
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -711,8 +684,7 @@ public class TestHttpAsyncHandlers exten
@Test
public void testResponseNoContent() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new HttpRequestHandler() {
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new HttpRequestHandler() {
@Override
public void handle(
@@ -723,7 +695,7 @@ public class TestHttpAsyncHandlers exten
}
}));
- final HttpHost target = start(registry, null);
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncHandlersPipelining.java Wed Jun 3 18:20:41 2015
@@ -59,14 +59,10 @@ import org.apache.http.nio.protocol.Basi
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.HttpAsyncRequestHandler;
-import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
-import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
-import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.nio.testserver.HttpCoreNIOTestBase;
import org.apache.http.protocol.HttpContext;
@@ -122,28 +118,18 @@ public class TestHttpAsyncHandlersPipeli
shutDownServer();
}
- private HttpHost start(
- final HttpProcessor clientProtocolProcessor,
- final HttpProcessor serverProtocolProcessor,
- final HttpAsyncRequestHandlerMapper requestHandlerResolver,
- final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- this.server.start(serverProtocolProcessor, requestHandlerResolver, expectationVerifier);
- this.client.start(clientProtocolProcessor);
+ private HttpHost start() throws Exception {
+ this.server.start();
+ this.client.setHttpProcessor(DEFAULT_HTTP_PROC);
+ this.client.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
return new HttpHost("localhost", address.getPort(), getScheme().name());
}
- private HttpHost start(
- final HttpAsyncRequestHandlerMapper requestHandlerResolver,
- final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- return start(DEFAULT_HTTP_PROC, null, requestHandlerResolver, expectationVerifier);
- }
-
private static String createRequestUri(final String pattern, final int count) {
return pattern + "x" + count;
}
@@ -158,9 +144,8 @@ public class TestHttpAsyncHandlersPipeli
@Test
public void testHttpGets() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -194,9 +179,8 @@ public class TestHttpAsyncHandlersPipeli
@Test
public void testHttpHeads() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -227,9 +211,8 @@ public class TestHttpAsyncHandlersPipeli
@Test
public void testHttpPosts() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler()));
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -314,9 +297,8 @@ public class TestHttpAsyncHandlersPipeli
}
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new DelayedRequestHandler());
- final HttpHost target = start(registry, null);
+ this.server.registerHandler("*", new DelayedRequestHandler());
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
@@ -364,8 +346,7 @@ public class TestHttpAsyncHandlersPipeli
@Test @Ignore
public void testUnexpectedConnectionClosure() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new HttpRequestHandler() {
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new HttpRequestHandler() {
@Override
public void handle(
@@ -377,7 +358,7 @@ public class TestHttpAsyncHandlersPipeli
}
}));
- registry.register("/boom", new BasicAsyncRequestHandler(new HttpRequestHandler() {
+ this.server.registerHandler("/boom", new BasicAsyncRequestHandler(new HttpRequestHandler() {
@Override
public void handle(
@@ -390,7 +371,7 @@ public class TestHttpAsyncHandlersPipeli
}
}));
- final HttpHost target = start(registry, null);
+ final HttpHost target = start();
this.client.setMaxPerRoute(3);
this.client.setMaxTotal(3);
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpAsyncPrematureTermination.java Wed Jun 3 18:20:41 2015
@@ -49,12 +49,8 @@ import org.apache.http.nio.entity.NStrin
import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
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.HttpAsyncRequestHandler;
-import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
-import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
-import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
import org.apache.http.nio.testserver.HttpCoreNIOTestBase;
import org.apache.http.protocol.BasicHttpContext;
@@ -79,23 +75,19 @@ public class TestHttpAsyncPrematureTermi
shutDownServer();
}
- private InetSocketAddress start(
- final HttpAsyncRequestHandlerMapper requestHandlerResolver,
- final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
- this.server.start(requestHandlerResolver, expectationVerifier);
+ private InetSocketAddress start() throws Exception {
+ this.server.start();
this.client.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
return (InetSocketAddress) endpoint.getAddress();
}
@Test
public void testConnectionTerminatedProcessingRequest() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
+ this.server.registerHandler("*", new HttpAsyncRequestHandler<HttpRequest>() {
@Override
public HttpAsyncRequestConsumer<HttpRequest> processRequest(
@@ -118,7 +110,7 @@ public class TestHttpAsyncPrematureTermi
}
});
- final InetSocketAddress address = start(registry, null);
+ final InetSocketAddress address = start();
final HttpHost target = new HttpHost("localhost", address.getPort());
final CountDownLatch latch = new CountDownLatch(1);
@@ -151,7 +143,6 @@ public class TestHttpAsyncPrematureTermi
@Test
public void testConnectionTerminatedHandlingRequest() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
final CountDownLatch responseStreamClosed = new CountDownLatch(1);
final InputStream testInputStream = new ByteArrayInputStream(
"all is well".getBytes(Consts.ASCII)) {
@@ -161,7 +152,7 @@ public class TestHttpAsyncPrematureTermi
super.close();
}
};
- registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
+ this.server.registerHandler("*", new HttpAsyncRequestHandler<HttpRequest>() {
@Override
public HttpAsyncRequestConsumer<HttpRequest> processRequest(
@@ -184,7 +175,7 @@ public class TestHttpAsyncPrematureTermi
}
});
- final InetSocketAddress address = start(registry, null);
+ final InetSocketAddress address = start();
final HttpHost target = new HttpHost("localhost", address.getPort());
final CountDownLatch latch = new CountDownLatch(1);
@@ -218,8 +209,7 @@ public class TestHttpAsyncPrematureTermi
@Test
public void testConnectionTerminatedSendingResponse() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
+ this.server.registerHandler("*", new HttpAsyncRequestHandler<HttpRequest>() {
@Override
public HttpAsyncRequestConsumer<HttpRequest> processRequest(
@@ -248,7 +238,7 @@ public class TestHttpAsyncPrematureTermi
}
});
- final InetSocketAddress address = start(registry, null);
+ final InetSocketAddress address = start();
final HttpHost target = new HttpHost("localhost", address.getPort());
final CountDownLatch latch = new CountDownLatch(1);
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncTimeout.java Wed Jun 3 18:20:41 2015
@@ -40,7 +40,6 @@ import org.apache.http.concurrent.Future
import org.apache.http.message.BasicHttpRequest;
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.testserver.HttpCoreNIOTestBase;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
@@ -70,8 +69,7 @@ public class TestHttpsAsyncTimeout exten
private InetSocketAddress start() throws Exception {
- final HttpAsyncRequestExecutor clientHandler = new HttpAsyncRequestExecutor();
- this.client.start(clientHandler);
+ this.client.start();
serverSocket = new ServerSocket(0);
return new InetSocketAddress(serverSocket.getInetAddress(), serverSocket.getLocalPort());
}
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestServerSidePipelining.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestServerSidePipelining.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestServerSidePipelining.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestServerSidePipelining.java Wed Jun 3 18:20:41 2015
@@ -46,14 +46,11 @@ import org.apache.http.entity.ContentTyp
import org.apache.http.nio.entity.NByteArrayEntity;
import org.apache.http.nio.entity.NStringEntity;
import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
-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;
import org.apache.http.nio.testserver.HttpCoreNIOTestBase;
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.ResponseConnControl;
@@ -70,16 +67,13 @@ import org.junit.Test;
*/
public class TestServerSidePipelining extends HttpCoreNIOTestBase {
- protected HttpProcessor serverHttpProc;
- protected HttpAsyncService serviceHandler;
-
@Before
public void setUp() throws Exception {
initServer();
- this.serverHttpProc = new ImmutableHttpProcessor(
- new ResponseServer("TEST-SERVER/1.1"), new ResponseContent(), new ResponseConnControl());
+ this.server.setHttpProcessor(new ImmutableHttpProcessor(
+ new ResponseServer("TEST-SERVER/1.1"), new ResponseContent(), new ResponseConnControl()));
final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new HttpRequestHandler() {
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new HttpRequestHandler() {
@Override
public void handle(
@@ -92,7 +86,7 @@ public class TestServerSidePipelining ex
}
}));
- registry.register("/goodbye", new BasicAsyncRequestHandler(new HttpRequestHandler() {
+ this.server.registerHandler("/goodbye", new BasicAsyncRequestHandler(new HttpRequestHandler() {
@Override
public void handle(
@@ -106,7 +100,7 @@ public class TestServerSidePipelining ex
}
}));
- registry.register("/echo", new BasicAsyncRequestHandler(new HttpRequestHandler() {
+ this.server.registerHandler("/echo", new BasicAsyncRequestHandler(new HttpRequestHandler() {
@Override
public void handle(
@@ -126,7 +120,6 @@ public class TestServerSidePipelining ex
}
}));
- this.serviceHandler = new HttpAsyncService(this.serverHttpProc, registry);
}
@After
@@ -136,13 +129,11 @@ public class TestServerSidePipelining ex
@Test
public void testGetRequestPipelining() throws Exception {
- this.server.start(this.serviceHandler);
+ this.server.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
-
final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
final Socket socket = new Socket("localhost", address.getPort());
try {
@@ -208,13 +199,11 @@ public class TestServerSidePipelining ex
@Test
public void testPostRequestPipelining() throws Exception {
- this.server.start(this.serviceHandler);
+ this.server.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
-
final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
final Socket socket = new Socket("localhost", address.getPort());
try {
@@ -289,13 +278,11 @@ public class TestServerSidePipelining ex
@Test
public void testPostRequestPipeliningExpectContinue() throws Exception {
- this.server.start(this.serviceHandler);
+ this.server.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
-
final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
final Socket socket = new Socket("localhost", address.getPort());
try {
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestTruncatedChunks.java Wed Jun 3 18:20:41 2015
@@ -55,8 +55,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.UriHttpAsyncRequestHandlerMapper;
-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.SessionOutputBuffer;
@@ -170,16 +168,13 @@ public class TestTruncatedChunks extends
@Test
public void testTruncatedChunkException() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler(true)));
- this.server.start(registry);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler(true)));
+ this.server.start();
this.client.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
-
final String pattern = RndTestPatternGenerator.generateText();
final int count = RndTestPatternGenerator.generateCount(1000);
@@ -246,16 +241,13 @@ public class TestTruncatedChunks extends
@Test
public void testIgnoreTruncatedChunkException() throws Exception {
- final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
- registry.register("*", new BasicAsyncRequestHandler(new SimpleRequestHandler(true)));
- this.server.start(registry);
+ this.server.registerHandler("*", new BasicAsyncRequestHandler(new SimpleRequestHandler(true)));
+ this.server.start();
this.client.start();
final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
endpoint.waitFor();
- Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
-
final String pattern = RndTestPatternGenerator.generateText();
final int count = RndTestPatternGenerator.generateCount(1000);
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpClientNio.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpClientNio.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpClientNio.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpClientNio.java Wed Jun 3 18:20:41 2015
@@ -37,8 +37,8 @@ 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.OoopsieRuntimeException;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.config.ConnectionConfig;
import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
@@ -77,17 +77,17 @@ import org.apache.http.protocol.RequestU
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(true)});
+ new RequestContent(),
+ new RequestTargetHost(),
+ new RequestConnControl(),
+ new RequestUserAgent("TEST-CLIENT/1.1"),
+ new RequestExpectContinue(true));
private final DefaultConnectingIOReactor ioReactor;
private final BasicNIOConnPool connpool;
- private volatile HttpAsyncRequester executor;
+ private volatile HttpProcessor httpProcessor;
+ private volatile HttpAsyncRequester executor;
private volatile IOReactorThread thread;
private volatile int timeout;
@@ -95,6 +95,7 @@ public class HttpClientNio {
final NIOConnFactory<HttpHost, NHttpClientConnection> connFactory) throws IOException {
super();
this.ioReactor = new DefaultConnectingIOReactor();
+ this.ioReactor.setExceptionHandler(new SimpleIOReactorExceptionHandler());
this.connpool = new BasicNIOConnPool(this.ioReactor, new NIOConnFactory<HttpHost, NHttpClientConnection>() {
@Override
@@ -124,6 +125,10 @@ public class HttpClientNio {
this.connpool.setDefaultMaxPerRoute(max);
}
+ public void setHttpProcessor(final HttpProcessor httpProcessor) {
+ this.httpProcessor = httpProcessor;
+ }
+
public Future<BasicNIOPoolEntry> lease(
final HttpHost host,
final FutureCallback<BasicNIOPoolEntry> callback) {
@@ -208,10 +213,6 @@ public class HttpClientNio {
return executePipelined(target, Arrays.asList(requests), null, null);
}
- public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
- this.ioReactor.setExceptionHandler(exceptionHandler);
- }
-
private void execute(final NHttpClientEventHandler clientHandler) throws IOException {
final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(clientHandler,
new DefaultNHttpClientConnectionFactory(ConnectionConfig.DEFAULT)) {
@@ -233,27 +234,10 @@ public class HttpClientNio {
return sessionRequest;
}
- 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());
+ this.executor = new HttpAsyncRequester(this.httpProcessor != null ? this.httpProcessor : DEFAULT_HTTP_PROC);
+ this.thread = new IOReactorThread(new HttpAsyncRequestExecutor());
+ this.thread.start();
}
public ConnectingIOReactor getIoReactor() {
@@ -315,5 +299,23 @@ public class HttpClientNio {
}
}
+
+ static class SimpleIOReactorExceptionHandler implements IOReactorExceptionHandler {
+
+ @Override
+ public boolean handle(final RuntimeException ex) {
+ if (!(ex instanceof OoopsieRuntimeException)) {
+ ex.printStackTrace(System.out);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean handle(final IOException ex) {
+ ex.printStackTrace(System.out);
+ return false;
+ }
+
+ }
}
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpCoreNIOTestBase.java Wed Jun 3 18:20:41 2015
@@ -90,14 +90,13 @@ public abstract class HttpCoreNIOTestBas
}
public void initServer() throws Exception {
- this.server = new HttpServerNio(createServerConnectionFactory());
- this.server.setExceptionHandler(new SimpleIOReactorExceptionHandler());
+ this.server = new HttpServerNio();
+ this.server.setConnectionFactory(createServerConnectionFactory());
this.server.setTimeout(5000);
}
public void initClient() throws Exception {
this.client = new HttpClientNio(createClientConnectionFactory());
- this.client.setExceptionHandler(new SimpleIOReactorExceptionHandler());
this.client.setTimeout(5000);
}
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpServerNio.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpServerNio.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpServerNio.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/testserver/HttpServerNio.java Wed Jun 3 18:20:41 2015
@@ -28,53 +28,38 @@
package org.apache.http.nio.testserver;
import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.List;
+import java.net.SocketException;
+import java.util.concurrent.TimeUnit;
-import org.apache.http.HttpResponseInterceptor;
-import org.apache.http.impl.nio.DefaultHttpServerIODispatch;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.http.ConnectionClosedException;
+import org.apache.http.ExceptionLogger;
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
-import org.apache.http.impl.nio.reactor.DefaultListeningIOReactor;
-import org.apache.http.impl.nio.reactor.ExceptionEvent;
+import org.apache.http.impl.nio.bootstrap.HttpServer;
+import org.apache.http.impl.nio.bootstrap.ServerBootstrap;
+import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerEventHandler;
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.protocol.HttpAsyncRequestHandler;
+import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
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;
+import org.apache.http.util.Asserts;
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;
-
- private volatile IOReactorThread thread;
- private volatile ListenerEndpoint endpoint;
+ private final UriHttpAsyncRequestHandlerMapper reqistry;
+ private volatile HttpAsyncExpectationVerifier expectationVerifier;
+ private volatile NHttpConnectionFactory<DefaultNHttpServerConnection> connectionFactory;
+ private volatile HttpProcessor httpProcessor;
private volatile int timeout;
- public HttpServerNio(
- final NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory) throws IOException {
+ private volatile HttpServer server;
+
+ public HttpServerNio() throws IOException {
super();
- this.ioReactor = new DefaultListeningIOReactor();
- this.connFactory = connFactory;
+ this.reqistry = new UriHttpAsyncRequestHandlerMapper();
}
public int getTimeout() {
@@ -85,114 +70,71 @@ public class HttpServerNio {
this.timeout = timeout;
}
- public void setExceptionHandler(final IOReactorExceptionHandler exceptionHandler) {
- this.ioReactor.setExceptionHandler(exceptionHandler);
- }
-
- private void execute(final NHttpServerEventHandler serviceHandler) throws IOException {
- final IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(serviceHandler, this.connFactory) {
-
- @Override
- protected DefaultNHttpServerConnection createConnection(final IOSession session) {
- final DefaultNHttpServerConnection conn = super.createConnection(session);
- conn.setSocketTimeout(timeout);
- return conn;
- }
-
- };
- this.ioReactor.execute(ioEventDispatch);
- }
-
- public ListenerEndpoint getListenerEndpoint() {
- return this.endpoint;
- }
-
- public void setEndpoint(final ListenerEndpoint endpoint) {
- this.endpoint = endpoint;
- }
-
- public void start(final NHttpServerEventHandler serviceHandler) {
- this.endpoint = this.ioReactor.listen(new InetSocketAddress(0));
- this.thread = new IOReactorThread(serviceHandler);
- this.thread.start();
+ public void registerHandler(
+ final String pattern,
+ final HttpAsyncRequestHandler handler) {
+ this.reqistry.register(pattern, handler);
}
- 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 setExpectationVerifier(final HttpAsyncExpectationVerifier expectationVerifier) {
+ this.expectationVerifier = expectationVerifier;
}
- public void start(
- final HttpAsyncRequestHandlerMapper handlerMapper,
- final HttpAsyncExpectationVerifier expectationVerifier) {
- start(null, handlerMapper, expectationVerifier);
+ public void setConnectionFactory(final NHttpConnectionFactory<DefaultNHttpServerConnection> connectionFactory) {
+ this.connectionFactory = connectionFactory;
}
- public void start(final HttpAsyncRequestHandlerMapper handlerMapper) {
- start(null, handlerMapper, null);
+ public void setHttpProcessor(final HttpProcessor httpProcessor) {
+ this.httpProcessor = httpProcessor;
}
- public ListeningIOReactor getIoReactor() {
- return this.ioReactor;
- }
-
- public IOReactorStatus getStatus() {
- return this.ioReactor.getStatus();
- }
-
- public List<ExceptionEvent> getAuditLog() {
- return this.ioReactor.getAuditLog();
- }
-
- public void join(final long timeout) throws InterruptedException {
- if (this.thread != null) {
- this.thread.join(timeout);
+ public ListenerEndpoint getListenerEndpoint() {
+ final HttpServer local = this.server;
+ if (local != null) {
+ return this.server.getEndpoint();
+ } else {
+ throw new IllegalStateException("Server not running");
}
}
- public Exception getException() {
- if (this.thread != null) {
- return this.thread.getException();
- } else {
- return null;
- }
+ public void start() throws IOException {
+ Asserts.check(this.server == null, "Server already running");
+ this.server = ServerBootstrap.bootstrap()
+ .setIOReactorConfig(IOReactorConfig.custom()
+ .setSoTimeout(this.timeout)
+ .build())
+ .setServerInfo("TEST-SERVER/1.1")
+ .setConnectionFactory(connectionFactory)
+ .setExceptionLogger(new SimpleExceptionLogger())
+ .setExpectationVerifier(this.expectationVerifier)
+ .setHttpProcessor(this.httpProcessor)
+ .setHandlerMapper(this.reqistry)
+ .create();
+ this.server.start();
}
- public void shutdown() throws IOException {
- this.ioReactor.shutdown();
- try {
- join(500);
- } catch (final InterruptedException ignore) {
+ public void shutdown() {
+ final HttpServer local = this.server;
+ this.server = null;
+ if (local != null) {
+ local.shutdown(5, TimeUnit.SECONDS);
}
}
- private class IOReactorThread extends Thread {
-
- private final NHttpServerEventHandler serviceHandler;
+ static class SimpleExceptionLogger implements ExceptionLogger {
- private volatile Exception ex;
-
- public IOReactorThread(final NHttpServerEventHandler serviceHandler) {
- super();
- this.serviceHandler = serviceHandler;
- }
+ private final Log log = LogFactory.getLog(HttpServer.class);
@Override
- public void run() {
- try {
- execute(this.serviceHandler);
- } catch (final Exception ex) {
- this.ex = ex;
+ public void log(final Exception ex) {
+ if (ex instanceof ConnectionClosedException) {
+ this.log.debug(ex.getMessage());
+ } else if (ex instanceof SocketException) {
+ this.log.debug(ex.getMessage());
+ } else {
+ this.log.error(ex.getMessage(), ex);
}
}
-
- public Exception getException() {
- return this.ex;
- }
-
}
}
Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java?rev=1683403&r1=1683402&r2=1683403&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java (original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/testserver/HttpClient.java Wed Jun 3 18:20:41 2015
@@ -36,7 +36,6 @@ import org.apache.http.HttpClientConnect
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
-import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.impl.DefaultBHttpClientConnection;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
@@ -70,13 +69,11 @@ public class HttpClient {
public HttpClient() {
this(new ImmutableHttpProcessor(
- new HttpRequestInterceptor[] {
- new RequestContent(),
- new RequestTargetHost(),
- new RequestConnControl(),
- new RequestUserAgent("TEST-CLIENT/1.1"),
- new RequestExpectContinue(true)
- }));
+ new RequestContent(),
+ new RequestTargetHost(),
+ new RequestConnControl(),
+ new RequestUserAgent("TEST-CLIENT/1.1"),
+ new RequestExpectContinue(true)));
}
public HttpContext getContext() {