HTTPASYNC-87: ability to provide a custom request executor
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/trunk@1659391 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/httpasyncclient/src/main/java-deprecated/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java b/httpasyncclient/src/main/java-deprecated/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java
index 7c3e52d..78aee8b 100644
--- a/httpasyncclient/src/main/java-deprecated/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java
+++ b/httpasyncclient/src/main/java-deprecated/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java
@@ -85,6 +85,7 @@
import org.apache.http.nio.client.methods.HttpAsyncMethods;
import org.apache.http.nio.conn.ClientAsyncConnectionManager;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.nio.reactor.IOEventDispatch;
@@ -459,7 +460,7 @@
}
private void doExecute() {
- final LoggingAsyncRequestExecutor handler = new LoggingAsyncRequestExecutor();
+ final InternalRequestExecutor handler = new InternalRequestExecutor(this.log, new HttpAsyncRequestExecutor());
try {
final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(handler, getParams());
this.connmgr.execute(ioEventDispatch);
diff --git a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java
index 8d24844..fe1db37 100644
--- a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java
+++ b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java
@@ -98,6 +98,7 @@
import org.apache.http.nio.conn.NoopIOSessionStrategy;
import org.apache.http.nio.conn.SchemeIOSessionStrategy;
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpProcessorBuilder;
@@ -854,7 +855,7 @@
}
eventHandler = this.eventHandler;
if (eventHandler == null) {
- eventHandler = new LoggingAsyncRequestExecutor();
+ eventHandler = new HttpAsyncRequestExecutor();
}
}
return new InternalHttpAsyncClient(
diff --git a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
index cfdd4dc..fa04c6b 100644
--- a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
+++ b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIODispatch.java
@@ -29,6 +29,8 @@
import java.io.IOException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.http.impl.nio.DefaultNHttpClientConnection;
import org.apache.http.impl.nio.reactor.AbstractIODispatch;
import org.apache.http.nio.NHttpClientEventHandler;
@@ -36,11 +38,17 @@
class InternalIODispatch extends AbstractIODispatch<DefaultNHttpClientConnection> {
+ private final Log log = LogFactory.getLog(InternalIODispatch.class);
+
private final NHttpClientEventHandler handler;
public InternalIODispatch(final NHttpClientEventHandler handler) {
super();
- this.handler = handler;
+ if (this.log.isDebugEnabled()) {
+ this.handler = new InternalRequestExecutor(this.log, handler);
+ } else {
+ this.handler = handler;
+ }
}
@Override
diff --git a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutor.java
similarity index 79%
rename from httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
rename to httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutor.java
index 966563c..fae3ab9 100644
--- a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
+++ b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalRequestExecutor.java
@@ -30,24 +30,20 @@
import java.io.IOException;
import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpException;
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.NHttpClientConnection;
-import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
+import org.apache.http.nio.NHttpClientEventHandler;
-class LoggingAsyncRequestExecutor extends HttpAsyncRequestExecutor {
+class InternalRequestExecutor implements NHttpClientEventHandler {
- private final Log log = LogFactory.getLog(HttpAsyncRequestExecutor.class);
+ private final Log log;
+ private final NHttpClientEventHandler handler;
- public LoggingAsyncRequestExecutor() {
- super();
- }
-
- @Override
- protected void log(final Exception ex) {
- this.log.debug(ex.getMessage(), ex);
+ public InternalRequestExecutor(final Log log, final NHttpClientEventHandler handler) {
+ this.log = log;
+ this.handler = handler;
}
@Override
@@ -57,7 +53,7 @@
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Connected");
}
- super.connected(conn, attachment);
+ this.handler.connected(conn, attachment);
}
@Override
@@ -65,7 +61,7 @@
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Disconnected");
}
- super.closed(conn);
+ this.handler.closed(conn);
}
@Override
@@ -74,7 +70,7 @@
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Request ready");
}
- super.requestReady(conn);
+ this.handler.requestReady(conn);
}
@Override
@@ -84,7 +80,7 @@
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Input ready");
}
- super.inputReady(conn, decoder);
+ this.handler.inputReady(conn, decoder);
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " " + decoder);
}
@@ -97,7 +93,7 @@
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Output ready");
}
- super.outputReady(conn, encoder);
+ this.handler.outputReady(conn, encoder);
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " " + encoder);
}
@@ -109,15 +105,23 @@
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Response received");
}
- super.responseReceived(conn);
+ this.handler.responseReceived(conn);
}
@Override
- public void timeout(final NHttpClientConnection conn) throws IOException {
+ public void timeout(final NHttpClientConnection conn) throws HttpException, IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Timeout");
}
- super.timeout(conn);
+ this.handler.timeout(conn);
+ }
+
+ @Override
+ public void exception(final NHttpClientConnection conn, final Exception ex) {
+ if (this.log.isDebugEnabled()) {
+ this.log.debug(conn + " Exception", ex);
+ }
+ this.handler.exception(conn, ex);
}
@Override
@@ -125,7 +129,7 @@
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " End of input");
}
- super.endOfInput(conn);
+ this.handler.endOfInput(conn);
}
}
diff --git a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
index 0a01d68..4898eec 100644
--- a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
+++ b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
@@ -43,6 +43,7 @@
import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
import org.apache.http.nio.NHttpClientEventHandler;
import org.apache.http.nio.conn.NHttpClientConnectionManager;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.protocol.BasicHttpContext;
@@ -77,7 +78,7 @@
final HttpProcessor httpProcessor) {
this(connmgr,
Executors.defaultThreadFactory(),
- new LoggingAsyncRequestExecutor(),
+ new HttpAsyncRequestExecutor(),
httpProcessor,
DefaultConnectionReuseStrategy.INSTANCE,
DefaultConnectionKeepAliveStrategy.INSTANCE);
diff --git a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java
index e44ea16..a865dc7 100644
--- a/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java
+++ b/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClientBuilder.java
@@ -42,6 +42,7 @@
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.nio.NHttpClientEventHandler;
import org.apache.http.nio.conn.NHttpClientConnectionManager;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpProcessorBuilder;
import org.apache.http.protocol.RequestContent;
@@ -151,7 +152,7 @@
if (threadFactory == null) {
threadFactory = Executors.defaultThreadFactory();
}
- eventHandler = new LoggingAsyncRequestExecutor();
+ eventHandler = new HttpAsyncRequestExecutor();
}
return new MinimalHttpAsyncClient(
connManager,