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 2011/12/01 18:20:37 UTC

svn commit: r1209158 [1/3] - in /httpcomponents/httpcore/trunk/httpcore-nio/src: examples/org/apache/http/examples/nio/ main/java/org/apache/http/impl/nio/ main/java/org/apache/http/nio/ main/java/org/apache/http/nio/protocol/ test/java/org/apache/http...

Author: olegk
Date: Thu Dec  1 17:20:25 2011
New Revision: 1209158

URL: http://svn.apache.org/viewvc?rev=1209158&view=rev
Log:
* Major simplification of the exception handling API and a complete rewrite of the exception handling code in the async protocol handlers; this also required deprecation of NHttpClientHandler and NHttpServiceHandler interfaces superseded by NHttpClientProtocolHandler and NHttpServerProtocolHandler interfaces; the new interfaces are largely identical to old ones, however, unlike the old interfaces methods of new interfaces throw IOException and HttpException to the caller relieving the handles from having to handle those exceptions in each and every method; This change was largely inspired by HTTPCORE-283.
* Fixed broken examples.

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpClientProtocolHandlerAdaptor.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpServerProtocolHandlerAdaptor.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientProtocolHandler.java
      - copied, changed from r1209156, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerProtocolHandler.java
      - copied, changed from r1209156, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/NHttpClientProtocolHandlerAdaptor.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/NHttpServerProtocolHandlerAdaptor.java   (with props)
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIODispatch.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIODispatch.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncServiceHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/HttpCoreNIOTestBase.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/LoggingClientConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/LoggingNHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/LoggingNHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/LoggingSSLClientConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/LoggingSSLServerConnectionFactory.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/LoggingServerConnectionFactory.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/impl/nio/reactor/TestDefaultIOReactorsSSL.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/TestHttpAsyncHandlers.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncHandlers.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/nio/protocol/TestHttpAsyncClientProtocolHandler.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncServiceHandler.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/HttpServerNio.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java Thu Dec  1 17:20:25 2011
@@ -76,7 +76,7 @@ import org.apache.http.nio.protocol.Http
 import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
 import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
 import org.apache.http.nio.protocol.HttpAsyncResponseProducer;
-import org.apache.http.nio.protocol.HttpAsyncResponseTrigger;
+import org.apache.http.nio.protocol.HttpAsyncServiceExchange;
 import org.apache.http.nio.protocol.HttpAsyncServiceHandler;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
@@ -168,7 +168,7 @@ public class NHttpReverseProxy {
         handlerRegistry.register("*", new ProxyRequestHandler(targetHost, executor, connPool));
 
         ProxyServiceHandler serviceHandler = new ProxyServiceHandler(
-                handlerRegistry, inhttpproc, new ProxyIncomingConnectionReuseStrategy(), params);
+                inhttpproc, new ProxyIncomingConnectionReuseStrategy(), handlerRegistry, params);
 
         final IOEventDispatch connectingEventDispatch = new DefaultClientIODispatch(
                 clientHandler, params);
@@ -219,7 +219,7 @@ public class NHttpReverseProxy {
 
         private volatile String id;
         private volatile HttpHost target;
-        private volatile HttpAsyncResponseTrigger responseTrigger;
+        private volatile HttpAsyncServiceExchange responseTrigger;
         private volatile IOControl originIOControl;
         private volatile IOControl clientIOControl;
         private volatile HttpRequest request;
@@ -274,11 +274,11 @@ public class NHttpReverseProxy {
             this.response = response;
         }
 
-        public HttpAsyncResponseTrigger getResponseTrigger() {
+        public HttpAsyncServiceExchange getResponseTrigger() {
             return this.responseTrigger;
         }
 
-        public void setResponseTrigger(final HttpAsyncResponseTrigger responseTrigger) {
+        public void setResponseTrigger(final HttpAsyncServiceExchange responseTrigger) {
             this.responseTrigger = responseTrigger;
         }
 
@@ -376,7 +376,7 @@ public class NHttpReverseProxy {
 
         public Cancellable handle(
                 final ProxyHttpExchange httpExchange,
-                final HttpAsyncResponseTrigger responseTrigger,
+                final HttpAsyncServiceExchange responseTrigger,
                 final HttpContext context) throws HttpException, IOException {
             synchronized (httpExchange) {
                 Exception ex = httpExchange.getException();
@@ -492,6 +492,10 @@ public class NHttpReverseProxy {
             return this.completed;
         }
 
+        public void failed(final Exception ex) {
+            System.out.println("[client->proxy] " + ex.toString());
+        }
+
     }
 
     static class ProxyRequestProducer implements HttpAsyncRequestProducer {
@@ -573,6 +577,10 @@ public class NHttpReverseProxy {
         public void resetRequest() {
         }
 
+        public void failed(final Exception ex) {
+            System.out.println("[proxy->origin] " + ex.toString());
+        }
+
     }
 
     static class ProxyResponseConsumer implements HttpAsyncResponseConsumer<ProxyHttpExchange> {
@@ -593,8 +601,8 @@ public class NHttpReverseProxy {
             synchronized (this.httpExchange) {
                 System.out.println("[proxy<-origin] " + this.httpExchange.getId() + " " + response.getStatusLine());
                 this.httpExchange.setResponse(response);
-                HttpAsyncResponseTrigger responseTrigger = this.httpExchange.getResponseTrigger();
-                if (responseTrigger != null && !responseTrigger.isTriggered()) {
+                HttpAsyncServiceExchange responseTrigger = this.httpExchange.getResponseTrigger();
+                if (responseTrigger != null && !responseTrigger.isCompleted()) {
                     System.out.println("[client<-proxy] " + this.httpExchange.getId() + " response triggered");
                     responseTrigger.submitResponse(new ProxyResponseProducer(this.httpExchange));
                 }
@@ -644,15 +652,15 @@ public class NHttpReverseProxy {
             }
         }
 
-        public void failed(Exception ex) {
+        public void failed(final Exception ex) {
             synchronized (this.httpExchange) {
                 if (this.completed) {
                     return;
                 }
                 this.completed = true;
                 this.httpExchange.setException(ex);
-                HttpAsyncResponseTrigger responseTrigger = this.httpExchange.getResponseTrigger();
-                if (responseTrigger != null && !responseTrigger.isTriggered()) {
+                HttpAsyncServiceExchange responseTrigger = this.httpExchange.getResponseTrigger();
+                if (responseTrigger != null && !responseTrigger.isCompleted()) {
                     System.out.println("[client<-proxy] " + this.httpExchange.getId() + " " + ex);
                     int status = HttpStatus.SC_INTERNAL_SERVER_ERROR;
                     HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_0, status,
@@ -753,6 +761,10 @@ public class NHttpReverseProxy {
             }
         }
 
+        public void failed(final Exception ex) {
+            System.out.println("[client<-proxy] " + ex.toString());
+        }
+
     }
 
     static class ProxyIncomingConnectionReuseStrategy extends DefaultConnectionReuseStrategy {
@@ -788,15 +800,15 @@ public class NHttpReverseProxy {
     static class ProxyServiceHandler extends HttpAsyncServiceHandler {
 
         public ProxyServiceHandler(
-                final HttpAsyncRequestHandlerResolver handlerResolver,
                 final HttpProcessor httpProcessor,
                 final ConnectionReuseStrategy reuseStrategy,
+                final HttpAsyncRequestHandlerResolver handlerResolver,
                 final HttpParams params) {
-            super(handlerResolver, httpProcessor, reuseStrategy, params);
+            super(httpProcessor, reuseStrategy, handlerResolver, params);
         }
 
         @Override
-        protected void onException(final Exception ex) {
+        protected void log(final Exception ex) {
             ex.printStackTrace();
         }
 
@@ -821,12 +833,13 @@ public class NHttpReverseProxy {
         }
 
         @Override
-        protected void onException(final Exception ex) {
+        protected void log(final Exception ex) {
             ex.printStackTrace();
         }
 
         @Override
-        public void connected(final NHttpClientConnection conn, final Object attachment) {
+        public void connected(final NHttpClientConnection conn,
+                final Object attachment) throws IOException, HttpException {
             System.out.println("[proxy->origin] connection open " + conn);
             super.connected(conn, attachment);
         }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpServer.java Thu Dec  1 17:20:25 2011
@@ -42,16 +42,13 @@ import javax.net.ssl.SSLContext;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
-import org.apache.http.HttpResponseFactory;
 import org.apache.http.HttpResponseInterceptor;
 import org.apache.http.HttpStatus;
-import org.apache.http.HttpVersion;
 import org.apache.http.MethodNotSupportedException;
-import org.apache.http.ProtocolVersion;
 import org.apache.http.concurrent.Cancellable;
 import org.apache.http.entity.ContentType;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.DefaultNHttpServerConnection;
 import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
 import org.apache.http.impl.nio.DefaultServerIODispatch;
 import org.apache.http.impl.nio.SSLNHttpServerConnectionFactory;
@@ -59,7 +56,6 @@ import org.apache.http.impl.nio.reactor.
 import org.apache.http.nio.NHttpConnection;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.NHttpServerConnection;
-import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.entity.NFileEntity;
 import org.apache.http.nio.entity.NStringEntity;
 import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
@@ -67,7 +63,7 @@ import org.apache.http.nio.protocol.Basi
 import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
 import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
 import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
-import org.apache.http.nio.protocol.HttpAsyncResponseTrigger;
+import org.apache.http.nio.protocol.HttpAsyncServiceExchange;
 import org.apache.http.nio.protocol.HttpAsyncServiceHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.ListeningIOReactor;
@@ -122,7 +118,7 @@ public class NHttpServer {
         reqistry.register("*", new HttpFileHandler(docRoot));
         // Create server-side HTTP protocol handler
         HttpAsyncServiceHandler protocolHandler = new HttpAsyncServiceHandler(
-                reqistry, httpproc, new DefaultConnectionReuseStrategy(), params) {
+                httpproc, new DefaultConnectionReuseStrategy(), reqistry, params) {
 
             @Override
             public void connected(final NHttpServerConnection conn) {
@@ -138,7 +134,7 @@ public class NHttpServer {
 
         };
         // Create HTTP connection factory
-        NHttpConnectionFactory<NHttpServerIOTarget> connFactory;
+        NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory;
         if (port == 8443) {
             // Initialize SSL context
             ClassLoader cl = NHttpServer.class.getClassLoader();
@@ -179,12 +175,10 @@ public class NHttpServer {
     static class HttpFileHandler implements HttpAsyncRequestHandler<HttpRequest> {
 
         private final File docRoot;
-        private final HttpResponseFactory responseFactory;
 
         public HttpFileHandler(final File docRoot) {
             super();
             this.docRoot = docRoot;
-            this.responseFactory = new DefaultHttpResponseFactory();
         }
 
         public HttpAsyncRequestConsumer<HttpRequest> processRequest(
@@ -196,15 +190,11 @@ public class NHttpServer {
 
         public Cancellable handle(
                 final HttpRequest request,
-                final HttpAsyncResponseTrigger trigger,
+                final HttpAsyncServiceExchange httpexchange,
                 final HttpContext context) throws HttpException, IOException {
-            ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
-            if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
-                ver = HttpVersion.HTTP_1_1;
-            }
-            HttpResponse response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_OK, context);
+            HttpResponse response = httpexchange.getResponse();
             handleInternal(request, response, context);
-            trigger.submitResponse(new BasicAsyncResponseProducer(response));
+            httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
             return null;
         }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIODispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIODispatch.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIODispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultClientIODispatch.java Thu Dec  1 17:20:25 2011
@@ -32,8 +32,7 @@ import java.io.IOException;
 import javax.net.ssl.SSLContext;
 
 import org.apache.http.annotation.Immutable;
-import org.apache.http.nio.NHttpClientHandler;
-import org.apache.http.nio.NHttpClientIOTarget;
+import org.apache.http.nio.NHttpClientProtocolHandler;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
@@ -47,10 +46,11 @@ import org.apache.http.params.HttpParams
  * @since 4.2
  */
 @Immutable // provided injected dependencies are immutable
-public class DefaultClientIODispatch extends AbstractIODispatch<NHttpClientIOTarget> {
+public class DefaultClientIODispatch
+                    extends AbstractIODispatch<DefaultNHttpClientConnection> {
 
-    private final NHttpClientHandler handler;
-    private final NHttpConnectionFactory<NHttpClientIOTarget> connFactory;
+    private final NHttpClientProtocolHandler handler;
+    private final NHttpConnectionFactory<DefaultNHttpClientConnection> connFactory;
 
     /**
      * Creates a new instance of this class to be used for dispatching I/O event
@@ -60,8 +60,8 @@ public class DefaultClientIODispatch ext
      * @param connFactory HTTP client connection factory.
      */
     public DefaultClientIODispatch(
-            final NHttpClientHandler handler,
-            final NHttpConnectionFactory<NHttpClientIOTarget> connFactory) {
+            final NHttpClientProtocolHandler handler,
+            final NHttpConnectionFactory<DefaultNHttpClientConnection> connFactory) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("HTTP client handler may not be null");
@@ -73,12 +73,14 @@ public class DefaultClientIODispatch ext
         this.connFactory = connFactory;
     }
 
-    public DefaultClientIODispatch(final NHttpClientHandler handler, final HttpParams params) {
+    public DefaultClientIODispatch(
+            final NHttpClientProtocolHandler handler,
+            final HttpParams params) {
         this(handler, new DefaultNHttpClientConnectionFactory(params));
     }
 
     public DefaultClientIODispatch(
-            final NHttpClientHandler handler,
+            final NHttpClientProtocolHandler handler,
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler,
             final HttpParams params) {
@@ -86,46 +88,54 @@ public class DefaultClientIODispatch ext
     }
 
     public DefaultClientIODispatch(
-            final NHttpClientHandler handler,
+            final NHttpClientProtocolHandler handler,
             final SSLContext sslcontext,
             final HttpParams params) {
         this(handler, sslcontext, null, params);
     }
 
     @Override
-    protected NHttpClientIOTarget createConnection(final IOSession session) {
+    protected DefaultNHttpClientConnection createConnection(final IOSession session) {
         return this.connFactory.createConnection(session);
     }
 
     @Override
-    protected void onConnected(final NHttpClientIOTarget conn) {
+    protected void onConnected(final DefaultNHttpClientConnection conn) {
         Object attachment = conn.getContext().getAttribute(IOSession.ATTACHMENT_KEY);
-        this.handler.connected(conn, attachment);
+        try {
+            this.handler.connected(conn, attachment);
+        } catch (Exception ex) {
+            this.handler.exception(conn, ex);
+        }
     }
 
     @Override
-    protected void onClosed(final NHttpClientIOTarget conn) {
+    protected void onClosed(final DefaultNHttpClientConnection conn) {
         this.handler.closed(conn);
     }
 
     @Override
-    protected void onException(final NHttpClientIOTarget conn, IOException ex) {
+    protected void onException(final DefaultNHttpClientConnection conn, IOException ex) {
         this.handler.exception(conn, ex);
     }
 
     @Override
-    protected void onInputReady(final NHttpClientIOTarget conn) {
+    protected void onInputReady(final DefaultNHttpClientConnection conn) {
         conn.consumeInput(this.handler);
     }
 
     @Override
-    protected void onOutputReady(final NHttpClientIOTarget conn) {
+    protected void onOutputReady(final DefaultNHttpClientConnection conn) {
         conn.produceOutput(this.handler);
     }
 
     @Override
-    protected void onTimeout(final NHttpClientIOTarget conn) {
-        this.handler.timeout(conn);
+    protected void onTimeout(final DefaultNHttpClientConnection conn) {
+        try {
+            this.handler.timeout(conn);
+        } catch (Exception ex) {
+            this.handler.exception(conn, ex);
+        }
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java Thu Dec  1 17:20:25 2011
@@ -42,6 +42,7 @@ import org.apache.http.impl.nio.codecs.D
 import org.apache.http.nio.NHttpClientConnection;
 import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientProtocolHandler;
 import org.apache.http.nio.NHttpMessageParser;
 import org.apache.http.nio.NHttpMessageWriter;
 import org.apache.http.nio.reactor.EventMask;
@@ -65,6 +66,7 @@ import org.apache.http.params.HttpParams
  *
  * @since 4.0
  */
+@SuppressWarnings("deprecation")
 @NotThreadSafe
 public class DefaultNHttpClientConnection
     extends NHttpConnectionBase implements NHttpClientIOTarget {
@@ -141,7 +143,7 @@ public class DefaultNHttpClientConnectio
         this.requestWriter.reset();
     }
 
-    public void consumeInput(final NHttpClientHandler handler) {
+    public void consumeInput(final NHttpClientProtocolHandler handler) {
         if (this.status != ACTIVE) {
             this.session.clearEvent(EventMask.READ);
             return;
@@ -179,19 +181,18 @@ public class DefaultNHttpClientConnectio
                     resetInput();
                 }
             }
-        } catch (IOException ex) {
-            handler.exception(this, ex);
         } catch (HttpException ex) {
             resetInput();
             handler.exception(this, ex);
+        } catch (Exception ex) {
+            handler.exception(this, ex);
         } finally {
             // Finally set buffered input flag
             this.hasBufferedInput = this.inbuf.hasData();
         }
     }
 
-    public void produceOutput(final NHttpClientHandler handler) {
-
+    public void produceOutput(final NHttpClientProtocolHandler handler) {
         try {
             if (this.outbuf.hasData()) {
                 int bytesWritten = this.outbuf.flush(this.session.channel());
@@ -225,7 +226,7 @@ public class DefaultNHttpClientConnectio
                     }
                 }
             }
-        } catch (IOException ex) {
+        } catch (Exception ex) {
             handler.exception(this, ex);
         } finally {
             // Finally set buffered output flag
@@ -257,4 +258,12 @@ public class DefaultNHttpClientConnectio
         return this.request != null;
     }
 
+    public void consumeInput(final NHttpClientHandler handler) {
+        consumeInput(new NHttpClientProtocolHandlerAdaptor(handler));
+    }
+
+    public void produceOutput(final NHttpClientHandler handler) {
+        produceOutput(new NHttpClientProtocolHandlerAdaptor(handler));
+    }
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnectionFactory.java Thu Dec  1 17:20:25 2011
@@ -30,7 +30,6 @@ import org.apache.http.HttpResponseFacto
 import org.apache.http.annotation.Immutable;
 import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.nio.NHttpClientConnection;
-import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.ByteBufferAllocator;
@@ -54,7 +53,8 @@ import org.apache.http.params.HttpParams
  * @since 4.2
  */
 @Immutable
-public class DefaultNHttpClientConnectionFactory implements NHttpConnectionFactory<NHttpClientIOTarget> {
+public class DefaultNHttpClientConnectionFactory
+    implements NHttpConnectionFactory<DefaultNHttpClientConnection> {
 
     private final HttpResponseFactory responseFactory;
     private final ByteBufferAllocator allocator;
@@ -83,7 +83,7 @@ public class DefaultNHttpClientConnectio
         this(new DefaultHttpResponseFactory(), new HeapByteBufferAllocator(), params);
     }
 
-    protected NHttpClientIOTarget createConnection(
+    protected DefaultNHttpClientConnection createConnection(
             final IOSession session,
             final HttpResponseFactory responseFactory,
             final ByteBufferAllocator allocator,
@@ -91,8 +91,8 @@ public class DefaultNHttpClientConnectio
         return new DefaultNHttpClientConnection(session, responseFactory, allocator, params);
     }
 
-    public NHttpClientIOTarget createConnection(final IOSession session) {
-        NHttpClientIOTarget conn = createConnection(session, this.responseFactory, this.allocator, this.params);
+    public DefaultNHttpClientConnection createConnection(final IOSession session) {
+        DefaultNHttpClientConnection conn = createConnection(session, this.responseFactory, this.allocator, this.params);
         int timeout = HttpConnectionParams.getSoTimeout(this.params);
         conn.setSocketTimeout(timeout);
         return conn;

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java Thu Dec  1 17:20:25 2011
@@ -43,6 +43,7 @@ import org.apache.http.nio.NHttpMessageP
 import org.apache.http.nio.NHttpMessageWriter;
 import org.apache.http.nio.NHttpServerConnection;
 import org.apache.http.nio.NHttpServerIOTarget;
+import org.apache.http.nio.NHttpServerProtocolHandler;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
@@ -65,6 +66,7 @@ import org.apache.http.params.HttpParams
  *
  * @since 4.0
  */
+@SuppressWarnings("deprecation")
 @NotThreadSafe
 public class DefaultNHttpServerConnection
     extends NHttpConnectionBase implements NHttpServerIOTarget {
@@ -139,7 +141,7 @@ public class DefaultNHttpServerConnectio
         this.responseWriter.reset();
     }
 
-    public void consumeInput(final NHttpServiceHandler handler) {
+    public void consumeInput(final NHttpServerProtocolHandler handler) {
         if (this.status != ACTIVE) {
             this.session.clearEvent(EventMask.READ);
             return;
@@ -180,18 +182,18 @@ public class DefaultNHttpServerConnectio
                     resetInput();
                 }
             }
-        } catch (IOException ex) {
-            handler.exception(this, ex);
         } catch (HttpException ex) {
             resetInput();
             handler.exception(this, ex);
+        } catch (Exception ex) {
+            handler.exception(this, ex);
         } finally {
             // Finally set buffered input flag
             this.hasBufferedInput = this.inbuf.hasData();
         }
     }
 
-    public void produceOutput(final NHttpServiceHandler handler) {
+    public void produceOutput(final NHttpServerProtocolHandler handler) {
         try {
             if (this.outbuf.hasData()) {
                 int bytesWritten = this.outbuf.flush(this.session.channel());
@@ -225,7 +227,7 @@ public class DefaultNHttpServerConnectio
                     }
                 }
             }
-        } catch (IOException ex) {
+        } catch (Exception ex) {
             handler.exception(this, ex);
         } finally {
             // Finally set the buffered output flag
@@ -259,4 +261,12 @@ public class DefaultNHttpServerConnectio
         return this.response != null;
     }
 
+    public void consumeInput(final NHttpServiceHandler handler) {
+        consumeInput(new NHttpServerProtocolHandlerAdaptor(handler));
+    }
+
+    public void produceOutput(NHttpServiceHandler handler) {
+        produceOutput(new NHttpServerProtocolHandlerAdaptor(handler));
+    }
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnectionFactory.java Thu Dec  1 17:20:25 2011
@@ -31,7 +31,6 @@ import org.apache.http.annotation.Immuta
 import org.apache.http.impl.DefaultHttpRequestFactory;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.NHttpServerConnection;
-import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
@@ -54,7 +53,8 @@ import org.apache.http.params.HttpParams
  * @since 4.2
  */
 @Immutable
-public class DefaultNHttpServerConnectionFactory implements NHttpConnectionFactory<NHttpServerIOTarget> {
+public class DefaultNHttpServerConnectionFactory
+    implements NHttpConnectionFactory<DefaultNHttpServerConnection> {
 
     private final HttpRequestFactory requestFactory;
     private final ByteBufferAllocator allocator;
@@ -83,7 +83,7 @@ public class DefaultNHttpServerConnectio
         this(new DefaultHttpRequestFactory(), new HeapByteBufferAllocator(), params);
     }
 
-    protected NHttpServerIOTarget createConnection(
+    protected DefaultNHttpServerConnection createConnection(
             final IOSession session,
             final HttpRequestFactory requestFactory,
             final ByteBufferAllocator allocator,
@@ -91,8 +91,8 @@ public class DefaultNHttpServerConnectio
         return new DefaultNHttpServerConnection(session, requestFactory, allocator, params);
     }
 
-    public NHttpServerIOTarget createConnection(final IOSession session) {
-        NHttpServerIOTarget conn = createConnection(
+    public DefaultNHttpServerConnection createConnection(final IOSession session) {
+        DefaultNHttpServerConnection conn = createConnection(
                 session, this.requestFactory, this.allocator, this.params);
         int timeout = HttpConnectionParams.getSoTimeout(this.params);
         conn.setSocketTimeout(timeout);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIODispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIODispatch.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIODispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultServerIODispatch.java Thu Dec  1 17:20:25 2011
@@ -33,8 +33,7 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.http.annotation.Immutable;
 import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.NHttpServerIOTarget;
-import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.NHttpServerProtocolHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.ssl.SSLSetupHandler;
@@ -47,14 +46,15 @@ import org.apache.http.params.HttpParams
  * @since 4.2
  */
 @Immutable // provided injected dependencies are immutable
-public class DefaultServerIODispatch extends AbstractIODispatch<NHttpServerIOTarget> {
+public class DefaultServerIODispatch
+                    extends AbstractIODispatch<DefaultNHttpServerConnection> {
 
-    private final NHttpServiceHandler handler;
-    private final NHttpConnectionFactory<NHttpServerIOTarget> connFactory;
+    private final NHttpServerProtocolHandler handler;
+    private final NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory;
 
     public DefaultServerIODispatch(
-            final NHttpServiceHandler handler,
-            final NHttpConnectionFactory<NHttpServerIOTarget> connFactory) {
+            final NHttpServerProtocolHandler handler,
+            final NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory) {
         super();
         if (handler == null) {
             throw new IllegalArgumentException("HTTP client handler may not be null");
@@ -66,12 +66,14 @@ public class DefaultServerIODispatch ext
         this.connFactory = connFactory;
     }
 
-    public DefaultServerIODispatch(final NHttpServiceHandler handler, final HttpParams params) {
+    public DefaultServerIODispatch(
+            final NHttpServerProtocolHandler handler,
+            final HttpParams params) {
         this(handler, new DefaultNHttpServerConnectionFactory(params));
     }
 
     public DefaultServerIODispatch(
-            final NHttpServiceHandler handler,
+            final NHttpServerProtocolHandler handler,
             final SSLContext sslcontext,
             final SSLSetupHandler sslHandler,
             final HttpParams params) {
@@ -79,45 +81,53 @@ public class DefaultServerIODispatch ext
     }
 
     public DefaultServerIODispatch(
-            final NHttpServiceHandler handler,
+            final NHttpServerProtocolHandler handler,
             final SSLContext sslcontext,
             final HttpParams params) {
         this(handler, sslcontext, null, params);
     }
 
     @Override
-    protected NHttpServerIOTarget createConnection(final IOSession session) {
+    protected DefaultNHttpServerConnection createConnection(final IOSession session) {
         return this.connFactory.createConnection(session);
     }
 
     @Override
-    protected void onConnected(final NHttpServerIOTarget conn) {
-        this.handler.connected(conn);
+    protected void onConnected(final DefaultNHttpServerConnection conn) {
+        try {
+            this.handler.connected(conn);
+        } catch (Exception ex) {
+            this.handler.exception(conn, ex);
+        }
     }
 
     @Override
-    protected void onClosed(final NHttpServerIOTarget conn) {
+    protected void onClosed(final DefaultNHttpServerConnection conn) {
         this.handler.closed(conn);
     }
 
     @Override
-    protected void onException(final NHttpServerIOTarget conn, IOException ex) {
+    protected void onException(final DefaultNHttpServerConnection conn, IOException ex) {
         this.handler.exception(conn, ex);
     }
 
     @Override
-    protected void onInputReady(final NHttpServerIOTarget conn) {
+    protected void onInputReady(final DefaultNHttpServerConnection conn) {
         conn.consumeInput(this.handler);
     }
 
     @Override
-    protected void onOutputReady(final NHttpServerIOTarget conn) {
+    protected void onOutputReady(final DefaultNHttpServerConnection conn) {
         conn.produceOutput(this.handler);
     }
 
     @Override
-    protected void onTimeout(final NHttpServerIOTarget conn) {
-        this.handler.timeout(conn);
+    protected void onTimeout(final DefaultNHttpServerConnection conn) {
+        try {
+            this.handler.timeout(conn);
+        } catch (Exception ex) {
+            this.handler.exception(conn, ex);
+        }
     }
 
 }

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpClientProtocolHandlerAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpClientProtocolHandlerAdaptor.java?rev=1209158&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpClientProtocolHandlerAdaptor.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpClientProtocolHandlerAdaptor.java Thu Dec  1 17:20:25 2011
@@ -0,0 +1,97 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.nio;
+
+import java.io.IOException;
+
+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.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientProtocolHandler;
+
+@Deprecated
+class NHttpClientProtocolHandlerAdaptor implements NHttpClientProtocolHandler {
+
+    private final NHttpClientHandler handler;
+
+    public NHttpClientProtocolHandlerAdaptor(final NHttpClientHandler handler) {
+        super();
+        this.handler = handler;
+    }
+
+    public void connected(final NHttpClientConnection conn, final Object attachment) {
+        this.handler.connected(conn, attachment);
+    }
+
+    public void requestReady(
+            final NHttpClientConnection conn) throws IOException, HttpException {
+        this.handler.requestReady(conn);
+    }
+
+    public void responseReceived(
+            final NHttpClientConnection conn) throws IOException, HttpException {
+        this.handler.responseReceived(conn);
+    }
+
+    public void inputReady(
+            final NHttpClientConnection conn,
+            final ContentDecoder decoder) throws IOException, HttpException {
+        this.handler.inputReady(conn, decoder);
+    }
+
+    public void outputReady(
+            final NHttpClientConnection conn,
+            final ContentEncoder encoder) throws IOException, HttpException {
+        this.handler.outputReady(conn, encoder);
+    }
+
+    public void exception(final NHttpClientConnection conn, final Exception ex) {
+        if (ex instanceof HttpException) {
+            this.handler.exception(conn, (HttpException) ex);
+        } else if (ex instanceof IOException) {
+            this.handler.exception(conn, (IOException) ex);
+        } else {
+            if (ex instanceof RuntimeException) {
+                throw (RuntimeException) ex;
+            } else {
+                throw new Error("Unexpected exception: ", ex);
+            }
+        }
+    }
+
+    public void timeout(final NHttpClientConnection conn) {
+        this.handler.timeout(conn);
+    }
+
+    public void closed(final NHttpClientConnection conn) {
+        this.handler.closed(conn);
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpClientProtocolHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpClientProtocolHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpClientProtocolHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpServerProtocolHandlerAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpServerProtocolHandlerAdaptor.java?rev=1209158&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpServerProtocolHandlerAdaptor.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpServerProtocolHandlerAdaptor.java Thu Dec  1 17:20:25 2011
@@ -0,0 +1,97 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.nio;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.NHttpServerConnection;
+import org.apache.http.nio.NHttpServerProtocolHandler;
+import org.apache.http.nio.NHttpServiceHandler;
+
+@Deprecated
+class NHttpServerProtocolHandlerAdaptor implements NHttpServerProtocolHandler {
+
+    private final NHttpServiceHandler handler;
+
+    public NHttpServerProtocolHandlerAdaptor(final NHttpServiceHandler handler) {
+        super();
+        this.handler = handler;
+    }
+
+    public void connected(final NHttpServerConnection conn) {
+        this.handler.connected(conn);
+    }
+
+    public void responseReady(
+            final NHttpServerConnection conn) throws IOException, HttpException {
+        this.handler.responseReady(conn);
+    }
+
+    public void requestReceived(
+            final NHttpServerConnection conn) throws IOException, HttpException {
+        this.handler.requestReceived(conn);
+    }
+
+    public void inputReady(
+            final NHttpServerConnection conn,
+            final ContentDecoder decoder) throws IOException, HttpException {
+        this.handler.inputReady(conn, decoder);
+    }
+
+    public void outputReady(
+            final NHttpServerConnection conn,
+            final ContentEncoder encoder) throws IOException, HttpException {
+        this.handler.outputReady(conn, encoder);
+    }
+
+    public void exception(final NHttpServerConnection conn, final Exception ex) {
+        if (ex instanceof HttpException) {
+            this.handler.exception(conn, (HttpException) ex);
+        } else if (ex instanceof IOException) {
+            this.handler.exception(conn, (IOException) ex);
+        } else {
+            if (ex instanceof RuntimeException) {
+                throw (RuntimeException) ex;
+            } else {
+                throw new Error("Unexpected exception: ", ex);
+            }
+        }
+    }
+
+    public void timeout(final NHttpServerConnection conn) {
+        this.handler.timeout(conn);
+    }
+
+    public void closed(final NHttpServerConnection conn) {
+        this.handler.closed(conn);
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpServerProtocolHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpServerProtocolHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpServerProtocolHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpClientConnectionFactory.java Thu Dec  1 17:20:25 2011
@@ -32,7 +32,6 @@ import org.apache.http.HttpResponseFacto
 import org.apache.http.annotation.Immutable;
 import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.nio.NHttpClientConnection;
-import org.apache.http.nio.NHttpClientIOTarget;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.ssl.SSLIOSession;
@@ -59,7 +58,8 @@ import org.apache.http.params.HttpParams
  * @since 4.2
  */
 @Immutable
-public class SSLNHttpClientConnectionFactory implements NHttpConnectionFactory<NHttpClientIOTarget> {
+public class SSLNHttpClientConnectionFactory
+    implements NHttpConnectionFactory<DefaultNHttpClientConnection> {
 
     private final HttpResponseFactory responseFactory;
     private final ByteBufferAllocator allocator;
@@ -112,7 +112,7 @@ public class SSLNHttpClientConnectionFac
         return sslcontext;
     }
 
-    protected NHttpClientIOTarget createConnection(
+    protected DefaultNHttpClientConnection createConnection(
             final IOSession session,
             final HttpResponseFactory responseFactory,
             final ByteBufferAllocator allocator,
@@ -120,11 +120,11 @@ public class SSLNHttpClientConnectionFac
         return new DefaultNHttpClientConnection(session, responseFactory, allocator, params);
     }
 
-    public NHttpClientIOTarget createConnection(final IOSession session) {
+    public DefaultNHttpClientConnection createConnection(final IOSession session) {
         SSLContext sslcontext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
         SSLIOSession ssliosession = new SSLIOSession(session, SSLMode.CLIENT, sslcontext, this.sslHandler);
         session.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
-        NHttpClientIOTarget conn = createConnection(
+        DefaultNHttpClientConnection conn = createConnection(
                 ssliosession, this.responseFactory, this.allocator, this.params);
         int timeout = HttpConnectionParams.getSoTimeout(this.params);
         conn.setSocketTimeout(timeout);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLNHttpServerConnectionFactory.java Thu Dec  1 17:20:25 2011
@@ -33,7 +33,6 @@ import org.apache.http.annotation.Immuta
 import org.apache.http.impl.DefaultHttpRequestFactory;
 import org.apache.http.nio.NHttpConnectionFactory;
 import org.apache.http.nio.NHttpServerConnection;
-import org.apache.http.nio.NHttpServerIOTarget;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.ssl.SSLIOSession;
 import org.apache.http.nio.reactor.ssl.SSLMode;
@@ -59,7 +58,8 @@ import org.apache.http.params.HttpParams
  * @since 4.2
  */
 @Immutable
-public class SSLNHttpServerConnectionFactory implements NHttpConnectionFactory<NHttpServerIOTarget> {
+public class SSLNHttpServerConnectionFactory
+    implements NHttpConnectionFactory<DefaultNHttpServerConnection> {
 
     private final HttpRequestFactory requestFactory;
     private final ByteBufferAllocator allocator;
@@ -112,7 +112,7 @@ public class SSLNHttpServerConnectionFac
         return sslcontext;
     }
 
-    protected NHttpServerIOTarget createConnection(
+    protected DefaultNHttpServerConnection createConnection(
             final IOSession session,
             final HttpRequestFactory requestFactory,
             final ByteBufferAllocator allocator,
@@ -120,11 +120,11 @@ public class SSLNHttpServerConnectionFac
         return new DefaultNHttpServerConnection(session, requestFactory, allocator, params);
     }
 
-    public NHttpServerIOTarget createConnection(final IOSession session) {
+    public DefaultNHttpServerConnection createConnection(final IOSession session) {
         SSLContext sslcontext = this.sslcontext != null ? this.sslcontext : getDefaultSSLContext();
         SSLIOSession ssliosession = new SSLIOSession(session, SSLMode.SERVER, sslcontext, this.sslHandler);
         session.setAttribute(SSLIOSession.SESSION_KEY, ssliosession);
-        NHttpServerIOTarget conn =  createConnection(
+        DefaultNHttpServerConnection conn =  createConnection(
                 ssliosession, this.requestFactory, this.allocator, this.params);
         int timeout = HttpConnectionParams.getSoTimeout(this.params);
         conn.setSocketTimeout(timeout);

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java Thu Dec  1 17:20:25 2011
@@ -35,7 +35,10 @@ import org.apache.http.HttpException;
  * Abstract client-side HTTP protocol handler.
  *
  * @since 4.0
+ *
+ * @deprecated use {@link NHttpClientProtocolHandler}
  */
+@Deprecated
 public interface NHttpClientHandler {
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java Thu Dec  1 17:20:25 2011
@@ -35,7 +35,10 @@ import org.apache.http.nio.reactor.IOEve
  * objects of I/O events.
  *
  * @since 4.0
+ *
+ * @deprecated no longer used
  */
+@Deprecated
 public interface NHttpClientIOTarget extends NHttpClientConnection {
 
     /**

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientProtocolHandler.java (from r1209156, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientProtocolHandler.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientProtocolHandler.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java&r1=1209156&r2=1209158&rev=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientProtocolHandler.java Thu Dec  1 17:20:25 2011
@@ -34,9 +34,9 @@ import org.apache.http.HttpException;
 /**
  * Abstract client-side HTTP protocol handler.
  *
- * @since 4.0
+ * @since 4.2
  */
-public interface NHttpClientHandler {
+public interface NHttpClientProtocolHandler {
 
     /**
      * Triggered when a new outgoing connection is created.
@@ -44,7 +44,9 @@ public interface NHttpClientHandler {
      * @param conn new outgoing HTTP connection.
      * @param attachment an object that was attached to the session request
      */
-    void connected(NHttpClientConnection conn, Object attachment);
+    void connected(
+            NHttpClientConnection conn,
+            Object attachment) throws IOException, HttpException;
 
     /**
      * Triggered when the connection is ready to accept a new HTTP request.
@@ -55,7 +57,8 @@ public interface NHttpClientHandler {
      *
      * @param conn HTTP connection that is ready to accept a new HTTP request.
      */
-    void requestReady(NHttpClientConnection conn);
+    void requestReady(
+            NHttpClientConnection conn) throws IOException, HttpException;
 
     /**
      * Triggered when an HTTP response is received. The connection
@@ -71,7 +74,8 @@ public interface NHttpClientHandler {
      *
      * @param conn HTTP connection that contains an HTTP response
      */
-    void responseReceived(NHttpClientConnection conn);
+    void responseReceived(
+            NHttpClientConnection conn) throws IOException, HttpException;
 
     /**
      * Triggered when the underlying channel is ready for reading a
@@ -90,7 +94,9 @@ public interface NHttpClientHandler {
      * incoming response content.
      * @param decoder The content decoder to use to read content.
      */
-    void inputReady(NHttpClientConnection conn, ContentDecoder decoder);
+    void inputReady(
+            NHttpClientConnection conn,
+            ContentDecoder decoder) throws IOException, HttpException;
 
     /**
      * Triggered when the underlying channel is ready for writing a next portion
@@ -108,25 +114,9 @@ public interface NHttpClientHandler {
      * of the outgoing request content.
      * @param encoder The content encoder to use to write content.
      */
-    void outputReady(NHttpClientConnection conn, ContentEncoder encoder);
-
-    /**
-     * Triggered when an I/O error occurs while reading from or writing
-     * to the underlying channel.
-     *
-     * @param conn HTTP connection that caused an I/O error
-     * @param ex I/O exception
-     */
-    void exception(NHttpClientConnection conn, IOException ex);
-
-    /**
-     * Triggered when an HTTP protocol violation occurs while receiving
-     * an HTTP response.
-     *
-     * @param conn HTTP connection that caused an HTTP protocol violation
-     * @param ex HTTP protocol violation exception
-     */
-    void exception(NHttpClientConnection conn, HttpException ex);
+    void outputReady(
+            NHttpClientConnection conn,
+            ContentEncoder encoder) throws IOException, HttpException;
 
     /**
      * Triggered when no input is detected on this connection over the
@@ -134,7 +124,8 @@ public interface NHttpClientHandler {
      *
      * @param conn HTTP connection that caused timeout condition.
      */
-    void timeout(NHttpClientConnection conn);
+    void timeout(
+            NHttpClientConnection conn) throws IOException, HttpException;
 
     /**
      * Triggered when the connection is closed.
@@ -143,4 +134,12 @@ public interface NHttpClientHandler {
      */
     void closed(NHttpClientConnection conn);
 
+    /**
+     * Triggered if an error occurs during the HTTP exchange.
+     *
+     * @param conn HTTP connection that caused an I/O error
+     * @param ex exception
+     */
+    void exception(NHttpClientConnection conn, Exception ex);
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java Thu Dec  1 17:20:25 2011
@@ -35,7 +35,10 @@ import org.apache.http.nio.reactor.IOEve
  * objects of I/O events.
  *
  * @since 4.0
+ *
+ * @deprecated no longer used
  */
+@Deprecated
 public interface NHttpServerIOTarget extends NHttpServerConnection {
 
     /**

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerProtocolHandler.java (from r1209156, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerProtocolHandler.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerProtocolHandler.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java&r1=1209156&r2=1209158&rev=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerProtocolHandler.java Thu Dec  1 17:20:25 2011
@@ -34,16 +34,17 @@ import org.apache.http.HttpException;
 /**
  * Abstract server-side HTTP protocol handler.
  *
- * @since 4.0
+ * @since 4.2
  */
-public interface NHttpServiceHandler {
+public interface NHttpServerProtocolHandler {
 
     /**
      * Triggered when a new incoming connection is created.
      *
      * @param conn new incoming connection HTTP connection.
      */
-    void connected(NHttpServerConnection conn);
+    void connected(
+            NHttpServerConnection conn) throws IOException, HttpException;
 
     /**
      * Triggered when a new HTTP request is received. The connection
@@ -59,7 +60,8 @@ public interface NHttpServiceHandler {
      *
      * @param conn HTTP connection that contains a new HTTP request
      */
-    void requestReceived(NHttpServerConnection conn);
+    void requestReceived(
+            NHttpServerConnection conn) throws IOException, HttpException;
 
     /**
      * Triggered when the underlying channel is ready for reading a
@@ -78,7 +80,9 @@ public interface NHttpServiceHandler {
      * incoming request content.
      * @param decoder The content decoder to use to read content.
      */
-    void inputReady(NHttpServerConnection conn, ContentDecoder decoder);
+    void inputReady(
+            NHttpServerConnection conn,
+            ContentDecoder decoder) throws IOException, HttpException;
 
     /**
      * Triggered when the connection is ready to accept a new HTTP response.
@@ -89,7 +93,8 @@ public interface NHttpServiceHandler {
      *
      * @param conn HTTP connection that contains an HTTP response
      */
-    void responseReady(NHttpServerConnection conn);
+    void responseReady(
+            NHttpServerConnection conn) throws IOException, HttpException;
 
     /**
      * Triggered when the underlying channel is ready for writing a
@@ -108,25 +113,9 @@ public interface NHttpServiceHandler {
      * of the outgoing response content.
      * @param encoder The content encoder to use to write content.
      */
-    void outputReady(NHttpServerConnection conn, ContentEncoder encoder);
-
-    /**
-     * Triggered when an I/O error occurs while reading from or writing
-     * to the underlying channel.
-     *
-     * @param conn HTTP connection that caused an I/O error
-     * @param ex I/O exception
-     */
-    void exception(NHttpServerConnection conn, IOException ex);
-
-    /**
-     * Triggered when an HTTP protocol violation occurs while receiving
-     * an HTTP request.
-     *
-     * @param conn HTTP connection that caused an HTTP protocol violation
-     * @param ex HTTP protocol violation exception
-     */
-    void exception(NHttpServerConnection conn, HttpException ex);
+    void outputReady(
+            NHttpServerConnection conn,
+            ContentEncoder encoder) throws IOException, HttpException;
 
     /**
      * Triggered when no input is detected on this connection over the
@@ -134,7 +123,8 @@ public interface NHttpServiceHandler {
      *
      * @param conn HTTP connection that caused timeout condition.
      */
-    void timeout(NHttpServerConnection conn);
+    void timeout(
+            NHttpServerConnection conn) throws IOException;
 
     /**
      * Triggered when the connection is closed.
@@ -143,4 +133,12 @@ public interface NHttpServiceHandler {
      */
     void closed(NHttpServerConnection conn);
 
+    /**
+     * Triggered if an error occurs during the HTTP exchange.
+     *
+     * @param conn HTTP connection that caused an I/O error
+     * @param ex exception
+     */
+    void exception(NHttpServerConnection conn, Exception ex);
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServiceHandler.java Thu Dec  1 17:20:25 2011
@@ -35,7 +35,10 @@ import org.apache.http.HttpException;
  * Abstract server-side HTTP protocol handler.
  *
  * @since 4.0
+ *
+ * @deprecated use {@link NHttpServerProtocolHandler}
  */
+@Deprecated
 public interface NHttpServiceHandler {
 
     /**

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java?rev=1209158&r1=1209157&r2=1209158&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientProtocolHandler.java Thu Dec  1 17:20:25 2011
@@ -28,7 +28,6 @@
 package org.apache.http.nio.protocol;
 
 import java.io.IOException;
-import java.net.ProtocolException;
 import java.net.SocketTimeoutException;
 
 import org.apache.http.ConnectionReuseStrategy;
@@ -37,11 +36,12 @@ import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
+import org.apache.http.ProtocolException;
 import org.apache.http.annotation.Immutable;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.NHttpClientConnection;
-import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientProtocolHandler;
 import org.apache.http.nio.NHttpConnection;
 import org.apache.http.params.CoreProtocolPNames;
 import org.apache.http.protocol.HttpContext;
@@ -50,7 +50,7 @@ import org.apache.http.protocol.HttpCont
  * @since 4.2
  */
 @Immutable
-public class HttpAsyncClientProtocolHandler implements NHttpClientHandler {
+public class HttpAsyncClientProtocolHandler implements NHttpClientProtocolHandler {
 
     public static final String HTTP_HANDLER = "http.nio.exchange-handler";
 
@@ -58,7 +58,9 @@ public class HttpAsyncClientProtocolHand
         super();
     }
 
-    public void connected(final NHttpClientConnection conn, final Object attachment) {
+    public void connected(
+            final NHttpClientConnection conn,
+            final Object attachment) throws IOException, HttpException {
         State state = new State();
         HttpContext context = conn.getContext();
         context.setAttribute(HTTP_EXCHANGE_STATE, state);
@@ -73,27 +75,20 @@ public class HttpAsyncClientProtocolHand
         }
     }
 
-    public void exception(final NHttpClientConnection conn, final HttpException ex) {
-        State state = getState(conn);
-        if (state != null) {
-            handleProtocolFailure(conn, state, ex);
-        } else {
-            shutdownConnection(conn);
-            onException(ex);
-        }
-    }
-
-    public void exception(final NHttpClientConnection conn, final IOException ex) {
+    public void exception(
+            final NHttpClientConnection conn, final Exception cause) {
+        shutdownConnection(conn);
         State state = getState(conn);
         if (state != null) {
-            handleFailure(conn, state, ex);
+            closeHandler(state, cause);
+            state.reset();
         } else {
-            shutdownConnection(conn);
-            onException(ex);
+            log(cause);
         }
     }
 
-    public void requestReady(final NHttpClientConnection conn) {
+    public void requestReady(
+            final NHttpClientConnection conn) throws IOException, HttpException {
         State state = ensureNotNull(getState(conn));
         if (state.getRequestState() != MessageState.READY) {
             return;
@@ -112,130 +107,104 @@ public class HttpAsyncClientProtocolHand
         if (handler == null) {
             return;
         }
-        try {
-            HttpContext context = handler.getContext();
-            HttpRequest request = handler.generateRequest();
-            state.setRequest(request);
-
-            conn.submitRequest(request);
-
-            if (request instanceof HttpEntityEnclosingRequest) {
-                if (((HttpEntityEnclosingRequest) request).expectContinue()) {
-                    int timeout = conn.getSocketTimeout();
-                    state.setTimeout(timeout);
-                    timeout = request.getParams().getIntParameter(
-                            CoreProtocolPNames.WAIT_FOR_CONTINUE, 3000);
-                    conn.setSocketTimeout(timeout);
-                    state.setRequestState(MessageState.ACK_EXPECTED);
-                } else {
-                    state.setRequestState(MessageState.BODY_STREAM);
-                }
+        HttpContext context = handler.getContext();
+        HttpRequest request = handler.generateRequest();
+        state.setRequest(request);
+
+        conn.submitRequest(request);
+
+        if (request instanceof HttpEntityEnclosingRequest) {
+            if (((HttpEntityEnclosingRequest) request).expectContinue()) {
+                int timeout = conn.getSocketTimeout();
+                state.setTimeout(timeout);
+                timeout = request.getParams().getIntParameter(
+                        CoreProtocolPNames.WAIT_FOR_CONTINUE, 3000);
+                conn.setSocketTimeout(timeout);
+                state.setRequestState(MessageState.ACK_EXPECTED);
             } else {
-                handler.requestCompleted(context);
-                state.setRequestState(MessageState.COMPLETED);
+                state.setRequestState(MessageState.BODY_STREAM);
             }
-        } catch (HttpException ex) {
-            handleProtocolFailure(conn, state, ex);
-        } catch (IOException ex) {
-            handleFailure(conn, state, ex);
-        } catch (RuntimeException ex) {
-            terminate(conn, state);
-            throw ex;
+        } else {
+            handler.requestCompleted(context);
+            state.setRequestState(MessageState.COMPLETED);
         }
     }
 
-    public void outputReady(final NHttpClientConnection conn, final ContentEncoder encoder) {
+    public void outputReady(
+            final NHttpClientConnection conn,
+            final ContentEncoder encoder) throws IOException {
         State state = ensureNotNull(getState(conn));
         HttpAsyncClientExchangeHandler<?> handler = ensureNotNull(state.getHandler());
-        try {
-            if (state.getRequestState() == MessageState.ACK_EXPECTED) {
-                conn.suspendOutput();
-                return;
-            }
-            HttpContext context = handler.getContext();
-            handler.produceContent(encoder, conn);
-            state.setRequestState(MessageState.BODY_STREAM);
-            if (encoder.isCompleted()) {
-                handler.requestCompleted(context);
-                state.setRequestState(MessageState.COMPLETED);
-            }
-        } catch (IOException ex) {
-            handleFailure(conn, state, ex);
-        } catch (RuntimeException ex) {
-            terminate(conn, state);
-            throw ex;
+        if (state.getRequestState() == MessageState.ACK_EXPECTED) {
+            conn.suspendOutput();
+            return;
+        }
+        HttpContext context = handler.getContext();
+        handler.produceContent(encoder, conn);
+        state.setRequestState(MessageState.BODY_STREAM);
+        if (encoder.isCompleted()) {
+            handler.requestCompleted(context);
+            state.setRequestState(MessageState.COMPLETED);
         }
     }
 
-    public void responseReceived(final NHttpClientConnection conn) {
+    public void responseReceived(
+            final NHttpClientConnection conn) throws HttpException, IOException {
         State state = ensureNotNull(getState(conn));
         HttpAsyncClientExchangeHandler<?> handler = ensureNotNull(state.getHandler());
-        try {
-            HttpResponse response = conn.getHttpResponse();
-            HttpRequest request = state.getRequest();
+        HttpResponse response = conn.getHttpResponse();
+        HttpRequest request = state.getRequest();
 
-            int statusCode = response.getStatusLine().getStatusCode();
-            if (statusCode < HttpStatus.SC_OK) {
-                // 1xx intermediate response
-                if (statusCode != HttpStatus.SC_CONTINUE) {
-                    throw new ProtocolException(
-                            "Unexpected response: " + response.getStatusLine());
-                }
-                if (state.getRequestState() == MessageState.ACK_EXPECTED) {
-                    int timeout = state.getTimeout();
-                    conn.setSocketTimeout(timeout);
-                    conn.requestOutput();
-                    state.setRequestState(MessageState.ACK);
-                }
-                return;
+        int statusCode = response.getStatusLine().getStatusCode();
+        if (statusCode < HttpStatus.SC_OK) {
+            // 1xx intermediate response
+            if (statusCode != HttpStatus.SC_CONTINUE) {
+                throw new ProtocolException(
+                        "Unexpected response: " + response.getStatusLine());
             }
-            state.setResponse(response);
             if (state.getRequestState() == MessageState.ACK_EXPECTED) {
                 int timeout = state.getTimeout();
                 conn.setSocketTimeout(timeout);
-                conn.resetOutput();
-                state.setRequestState(MessageState.COMPLETED);
-            } else if (state.getRequestState() == MessageState.BODY_STREAM) {
-                // Early response
-                conn.resetOutput();
-                conn.suspendOutput();
-                state.setRequestState(MessageState.COMPLETED);
-                state.invalidate();
-            }
-            handler.responseReceived(response);
-            state.setResponseState(MessageState.BODY_STREAM);
-            if (!canResponseHaveBody(request, response)) {
-                conn.resetInput();
-                processResponse(conn, state, handler);
+                conn.requestOutput();
+                state.setRequestState(MessageState.ACK);
             }
-        } catch (HttpException ex) {
-            handleProtocolFailure(conn, state, ex);
-        } catch (IOException ex) {
-            handleFailure(conn, state, ex);
-        } catch (RuntimeException ex) {
-            terminate(conn, state);
-            throw ex;
+            return;
+        }
+        state.setResponse(response);
+        if (state.getRequestState() == MessageState.ACK_EXPECTED) {
+            int timeout = state.getTimeout();
+            conn.setSocketTimeout(timeout);
+            conn.resetOutput();
+            state.setRequestState(MessageState.COMPLETED);
+        } else if (state.getRequestState() == MessageState.BODY_STREAM) {
+            // Early response
+            conn.resetOutput();
+            conn.suspendOutput();
+            state.setRequestState(MessageState.COMPLETED);
+            state.invalidate();
+        }
+        handler.responseReceived(response);
+        state.setResponseState(MessageState.BODY_STREAM);
+        if (!canResponseHaveBody(request, response)) {
+            conn.resetInput();
+            processResponse(conn, state, handler);
         }
     }
 
-    public void inputReady(final NHttpClientConnection conn, final ContentDecoder decoder) {
+    public void inputReady(
+            final NHttpClientConnection conn,
+            final ContentDecoder decoder) throws IOException {
         State state = ensureNotNull(getState(conn));
         HttpAsyncClientExchangeHandler<?> handler = ensureNotNull(state.getHandler());
-        try {
-            handler.consumeContent(decoder, conn);
-            state.setResponseState(MessageState.BODY_STREAM);
-            if (decoder.isCompleted()) {
-                processResponse(conn, state, handler);
-            }
-        } catch (IOException ex) {
-            handleFailure(conn, state, ex);
-        } catch (RuntimeException ex) {
-            terminate(conn, state);
-            throw ex;
+        handler.consumeContent(decoder, conn);
+        state.setResponseState(MessageState.BODY_STREAM);
+        if (decoder.isCompleted()) {
+            processResponse(conn, state, handler);
         }
     }
 
-    public void timeout(final NHttpClientConnection conn) {
+    public void timeout(
+            final NHttpClientConnection conn) throws IOException {
         State state = getState(conn);
         if (state != null) {
             if (state.getRequestState() == MessageState.ACK_EXPECTED) {
@@ -248,39 +217,19 @@ public class HttpAsyncClientProtocolHand
                 closeHandler(state, new SocketTimeoutException());
             }
         }
-        try {
-            if (conn.getStatus() == NHttpConnection.ACTIVE) {
-                conn.close();
-                if (conn.getStatus() == NHttpConnection.CLOSING) {
-                    // Give the connection some grace time to
-                    // close itself nicely
-                    conn.setSocketTimeout(250);
-                }
-            } else {
-                conn.shutdown();
-            }
-        } catch (IOException ex) {
-            onException(ex);
-        }
-    }
-
-    protected void onException(final Exception ex) {
-    }
-
-    private void closeConnection(final NHttpConnection conn) {
-        try {
+        if (conn.getStatus() == NHttpConnection.ACTIVE) {
             conn.close();
-        } catch (IOException ex) {
-            onException(ex);
+            if (conn.getStatus() == NHttpConnection.CLOSING) {
+                // Give the connection some grace time to
+                // close itself nicely
+                conn.setSocketTimeout(250);
+            }
+        } else {
+            conn.shutdown();
         }
     }
 
-    private void shutdownConnection(final NHttpConnection conn) {
-        try {
-            conn.shutdown();
-        } catch (IOException ex) {
-            onException(ex);
-        }
+    protected void log(final Exception ex) {
     }
 
     private State getState(final NHttpConnection conn) {
@@ -301,6 +250,14 @@ public class HttpAsyncClientProtocolHand
         return handler;
     }
 
+    private void shutdownConnection(final NHttpConnection conn) {
+        try {
+            conn.shutdown();
+        } catch (IOException ex) {
+            log(ex);
+        }
+    }
+
     private void closeHandler(final State state, final Exception ex) {
         HttpAsyncClientExchangeHandler<?> handler = state.getHandler();
         if (handler != null) {
@@ -310,7 +267,7 @@ public class HttpAsyncClientProtocolHand
                 try {
                     handler.close();
                 } catch (IOException ioex) {
-                    onException(ioex);
+                    log(ioex);
                 }
             }
         }
@@ -322,37 +279,11 @@ public class HttpAsyncClientProtocolHand
             try {
                 handler.close();
             } catch (IOException ioex) {
-                onException(ioex);
+                log(ioex);
             }
         }
     }
 
-    private void terminate(
-            final NHttpClientConnection conn,
-            final State state) {
-        shutdownConnection(conn);
-        closeHandler(state);
-        state.reset();
-    }
-
-    private void handleFailure(
-            final NHttpClientConnection conn,
-            final State state,
-            final Exception ex) {
-        shutdownConnection(conn);
-        closeHandler(state, ex);
-        state.reset();
-    }
-
-    private void handleProtocolFailure(
-            final NHttpClientConnection conn,
-            final State state,
-            final HttpException ex) {
-        closeConnection(conn);
-        closeHandler(state, ex);
-        state.reset();
-    }
-
     private void processResponse(
             final NHttpClientConnection conn,
             final State state,