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/08/30 17:16:47 UTC

svn commit: r1163256 [1/2] - in /httpcomponents/httpcore/trunk: ./ httpcore-contrib/ httpcore-nio/ httpcore-nio/src/main/java/org/apache/http/nio/protocol/ httpcore-nio/src/test/java/org/apache/http/nio/protocol/ httpcore-nio/src/test/java/org/apache/h...

Author: olegk
Date: Tue Aug 30 15:16:46 2011
New Revision: 1163256

URL: http://svn.apache.org/viewvc?rev=1163256&view=rev
Log:
Complete rewrite of core async HTTP protocol handlers (initial cut, server side only)

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java   (contents, props changed)
      - copied, changed from r1163238, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AbstractHttpAsyncResponseConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java   (contents, props changed)
      - copied, changed from r1163239, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/BasicHttpAsyncResponseConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestConsumer.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandler.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerRegistry.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerResolver.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java   (contents, props changed)
      - copied, changed from r1163241, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducerImpl.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseConsumer.java   (contents, props changed)
      - copied, changed from r1163235, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseProducer.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseTrigger.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncServiceHandler.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java   (contents, props changed)
      - copied, changed from r1163240, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/NHttpEntityWrapper.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NullRequestConsumer.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NullRequestHandler.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncHandlers.java   (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/LoggingIOSession.java   (contents, props changed)
      - copied, changed from r1163243, httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/LoggingNHttpClientConnection.java   (contents, props changed)
      - copied, changed from r1163246, httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/LoggingNHttpServerConnection.java   (contents, props changed)
      - copied, changed from r1163244, httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/Wire.java   (contents, props changed)
      - copied, changed from r1163243, httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/Wire.java
Modified:
    httpcomponents/httpcore/trunk/httpcore-contrib/pom.xml
    httpcomponents/httpcore/trunk/httpcore-nio/pom.xml
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpSSLServer.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/testserver/HttpServerNio.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/BasicHttpContext.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/SyncBasicHttpContext.java
    httpcomponents/httpcore/trunk/pom.xml

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/pom.xml?rev=1163256&r1=1163255&r2=1163256&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/pom.xml (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/pom.xml Tue Aug 30 15:16:46 2011
@@ -56,7 +56,6 @@
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
-      <version>1.1.1</version>
       <scope>compile</scope>
     </dependency>
   </dependencies>

Modified: httpcomponents/httpcore/trunk/httpcore-nio/pom.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/pom.xml?rev=1163256&r1=1163255&r2=1163256&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/pom.xml (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/pom.xml Tue Aug 30 15:16:46 2011
@@ -58,6 +58,11 @@
       <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <properties>

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncRequestConsumer.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,99 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @since 4.2
+ */
+@ThreadSafe
+public abstract class AbstractAsyncRequestConsumer<T> implements HttpAsyncRequestConsumer<T> {
+
+    private volatile boolean completed;
+    private volatile T result;
+    private volatile Exception ex;
+
+    public AbstractAsyncRequestConsumer() {
+        super();
+    }
+
+    protected abstract void onRequestReceived(HttpRequest request);
+
+    protected abstract void onContentReceived(
+            ContentDecoder decoder, IOControl ioctrl) throws IOException;
+
+    protected abstract T buildResult() throws Exception;
+
+    protected abstract void releaseResources();
+
+    public synchronized void requestReceived(HttpRequest request) {
+        onRequestReceived(request);
+    }
+
+    public synchronized void consumeContent(
+            final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
+        onContentReceived(decoder, ioctrl);
+    }
+
+    public synchronized void requestCompleted(final HttpContext context) {
+        if (this.completed) {
+            return;
+        }
+        this.completed = true;
+        try {
+            this.result = buildResult();
+        } catch (Exception ex) {
+            this.ex = ex;
+        } finally {
+            releaseResources();
+        }
+    }
+
+    public synchronized void close() throws IOException {
+        if (this.completed) {
+            return;
+        }
+        this.completed = true;
+        releaseResources();
+    }
+
+    public Exception getException() {
+        return this.ex;
+    }
+
+    public T getResult() {
+        return this.result;
+    }
+
+}

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

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

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

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java (from r1163238, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AbstractHttpAsyncResponseConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AbstractHttpAsyncResponseConsumer.java&r1=1163238&r2=1163256&rev=1163256&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AbstractHttpAsyncResponseConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java Tue Aug 30 15:16:46 2011
@@ -24,24 +24,28 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.nio.client.methods;
+package org.apache.http.nio.protocol;
 
 import java.io.IOException;
 
 import org.apache.http.HttpException;
 import org.apache.http.HttpResponse;
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
-import org.apache.http.nio.client.HttpAsyncResponseConsumer;
+import org.apache.http.protocol.HttpContext;
 
-public abstract class AbstractHttpAsyncResponseConsumer<T> implements HttpAsyncResponseConsumer<T> {
+/**
+ * @since 4.2
+ */
+@ThreadSafe
+public abstract class AbstractAsyncResponseConsumer<T> implements HttpAsyncResponseConsumer<T> {
 
-    private volatile HttpResponse response;
-    private volatile Exception ex;
     private volatile boolean completed;
     private volatile T result;
+    private volatile Exception ex;
 
-    public AbstractHttpAsyncResponseConsumer() {
+    public AbstractAsyncResponseConsumer() {
         super();
     }
 
@@ -50,20 +54,12 @@ public abstract class AbstractHttpAsyncR
     protected abstract void onContentReceived(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException;
 
-    protected abstract void onCleanup();
-
     protected abstract T buildResult() throws Exception;
 
-    void releaseResources() {
-        onCleanup();
-    }
+    protected abstract void releaseResources();
 
     public synchronized void responseReceived(final HttpResponse response) throws IOException, HttpException {
-        if (this.response != null) {
-            throw new IllegalStateException("HTTP response already set");
-        }
-        this.response = response;
-        onResponseReceived(this.response);
+        onResponseReceived(response);
     }
 
     public synchronized void consumeContent(
@@ -71,7 +67,7 @@ public abstract class AbstractHttpAsyncR
         onContentReceived(decoder, ioctrl);
     }
 
-    public synchronized void responseCompleted() {
+    public synchronized void responseCompleted(final HttpContext context) {
         if (this.completed) {
             return;
         }
@@ -90,7 +86,6 @@ public abstract class AbstractHttpAsyncR
             return;
         }
         this.completed = true;
-        this.response = null;
         releaseResources();
     }
 
@@ -100,7 +95,14 @@ public abstract class AbstractHttpAsyncR
         }
         this.completed = true;
         this.ex = ex;
-        this.response = null;
+        releaseResources();
+    }
+
+    public synchronized void close() {
+        if (this.completed) {
+            return;
+        }
+        this.completed = true;
         releaseResources();
     }
 

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

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

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AbstractAsyncResponseConsumer.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Aug 30 15:16:46 2011
@@ -0,0 +1 @@
+/httpcomponents/httpasyncclient/branches/conn-mgmt-redesign/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AbstractHttpAsyncResponseConsumer.java:1155312-1159070

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,93 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpRequest;
+import org.apache.http.annotation.ThreadSafe;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.nio.entity.BufferingNHttpEntity;
+import org.apache.http.nio.entity.ConsumingNHttpEntity;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
+
+/**
+ * @since 4.2
+ */
+@ThreadSafe
+public class BasicAsyncRequestConsumer extends AbstractAsyncRequestConsumer<HttpRequest> {
+
+    private final ByteBufferAllocator allocator;
+    private volatile HttpRequest request;
+    private volatile ConsumingNHttpEntity consumer;
+
+    public BasicAsyncRequestConsumer(final ByteBufferAllocator allocator) {
+        super();
+        this.allocator = allocator;
+    }
+
+    public BasicAsyncRequestConsumer() {
+        this(new HeapByteBufferAllocator());
+    }
+
+    @Override
+    protected void onRequestReceived(final HttpRequest request) {
+        this.request = request;
+        if (request instanceof HttpEntityEnclosingRequest) {
+            HttpEntity entity = ((HttpEntityEnclosingRequest) this.request).getEntity();
+            if (entity != null) {
+                this.consumer = new BufferingNHttpEntity(entity, this.allocator);
+                ((HttpEntityEnclosingRequest) this.request).setEntity(this.consumer);
+            }
+        }
+    }
+
+    @Override
+    protected void onContentReceived(
+            final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
+        if (this.consumer == null) {
+            throw new IllegalArgumentException("Content consumer is null");
+        }
+        this.consumer.consumeContent(decoder, ioctrl);
+    }
+
+    @Override
+    protected void releaseResources() {
+        this.request = null;
+        this.consumer = null;
+    }
+
+    @Override
+    protected HttpRequest buildResult() {
+        return this.request;
+    }
+
+}

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

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

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

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java (from r1163239, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/BasicHttpAsyncResponseConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/BasicHttpAsyncResponseConsumer.java&r1=1163239&r2=1163256&rev=1163256&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/BasicHttpAsyncResponseConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java Tue Aug 30 15:16:46 2011
@@ -24,46 +24,62 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.nio.client.methods;
+package org.apache.http.nio.protocol;
 
 import java.io.IOException;
 
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
+import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
 import org.apache.http.nio.entity.BufferingNHttpEntity;
 import org.apache.http.nio.entity.ConsumingNHttpEntity;
+import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 
-public class BasicHttpAsyncResponseConsumer extends AbstractHttpAsyncResponseConsumer<HttpResponse> {
+/**
+ * @since 4.2
+ */
+@ThreadSafe
+public class BasicAsyncResponseConsumer extends AbstractAsyncResponseConsumer<HttpResponse> {
 
+    private final ByteBufferAllocator allocator;
     private volatile HttpResponse response;
     private volatile ConsumingNHttpEntity consumer;
 
-    public BasicHttpAsyncResponseConsumer() {
+    public BasicAsyncResponseConsumer(final ByteBufferAllocator allocator) {
         super();
+        this.allocator = allocator;
+    }
+
+    public BasicAsyncResponseConsumer() {
+        this(new HeapByteBufferAllocator());
     }
 
     @Override
     protected void onResponseReceived(final HttpResponse response) {
         this.response = response;
-        if (response.getEntity() != null) {
-            this.consumer = new BufferingNHttpEntity(
-                    response.getEntity(), new HeapByteBufferAllocator());
-        } else {
-            this.consumer = null;
+        HttpEntity entity = this.response.getEntity();
+        if (entity != null) {
+            this.consumer = new BufferingNHttpEntity(entity, this.allocator);
+            this.response.setEntity(this.consumer);
         }
-        this.response.setEntity(this.consumer);
     }
 
     @Override
     protected void onContentReceived(
             final ContentDecoder decoder, final IOControl ioctrl) throws IOException {
+        if (this.consumer == null) {
+            throw new IllegalArgumentException("Content consumer is null");
+        }
         this.consumer.consumeContent(decoder, ioctrl);
     }
 
     @Override
-    protected void onCleanup() {
+    protected void releaseResources() {
+        this.response = null;
+        this.consumer = null;
     }
 
     @Override

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

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

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Aug 30 15:16:46 2011
@@ -0,0 +1 @@
+/httpcomponents/httpasyncclient/branches/conn-mgmt-redesign/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/BasicHttpAsyncResponseConsumer.java:1155312-1159070

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BufferingAsyncRequestHandler.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,95 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpRequestHandler;
+
+/**
+ * @since 4.2
+ */
+@Immutable
+public class BufferingAsyncRequestHandler implements HttpAsyncRequestHandler<HttpRequest> {
+
+    private final HttpRequestHandler handler;
+    private final HttpResponseFactory responseFactory;
+    private final ByteBufferAllocator allocator;
+
+    public BufferingAsyncRequestHandler(
+            final HttpRequestHandler handler,
+            final HttpResponseFactory responseFactory,
+            final ByteBufferAllocator allocator) {
+        super();
+        if (handler == null) {
+            throw new IllegalArgumentException("Request handler may not be null");
+        }
+        if (responseFactory == null) {
+            throw new IllegalArgumentException("Response factory may not be null");
+        }
+        if (allocator == null) {
+            throw new IllegalArgumentException("Byte buffer allocator may not be null");
+        }
+        this.handler = handler;
+        this.responseFactory = responseFactory;
+        this.allocator = allocator;
+    }
+
+    public BufferingAsyncRequestHandler(final HttpRequestHandler handler) {
+        this(handler, new DefaultHttpResponseFactory(), new HeapByteBufferAllocator());
+    }
+
+    public HttpAsyncRequestConsumer<HttpRequest> processRequest(final HttpRequest request,
+            final HttpContext context) {
+        return new BasicAsyncRequestConsumer(this.allocator);
+    }
+
+    public void handle(final HttpRequest request, final HttpAsyncResponseTrigger trigger,
+            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);
+        this.handler.handle(request, response, context);
+        trigger.submitResponse(new HttpAsyncRequestProducerImpl(response));
+    }
+
+}

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

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

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/ErrorResponseProducer.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,82 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.IOException;
+import java.util.Locale;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.impl.EnglishReasonPhraseCatalog;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.apache.http.protocol.HTTP;
+
+class ErrorResponseProducer implements HttpAsyncResponseProducer {
+
+    private final HttpVersion version;
+    private final int status;
+    private final ProducingNHttpEntity entity;
+    private final boolean keepAlive;
+
+    ErrorResponseProducer(
+            final HttpVersion version,
+            final int status,
+            final ProducingNHttpEntity entity,
+            final boolean keepAlive) {
+        super();
+        this.version = version;
+        this.status = status;
+        this.entity = entity;
+        this.keepAlive = keepAlive;
+    }
+
+    public HttpResponse generateResponse() {
+        BasicHttpResponse response = new BasicHttpResponse(this.version, this.status,
+                EnglishReasonPhraseCatalog.INSTANCE.getReason(this.status, Locale.US));
+        if (this.keepAlive) {
+            response.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
+        } else {
+            response.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
+        }
+        response.setEntity(this.entity);
+        return response;
+    }
+
+    public void produceContent(
+            final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
+        this.entity.produceContent(encoder, ioctrl);
+    }
+
+    public void close() throws IOException {
+        this.entity.finish();
+    }
+
+}
\ No newline at end of file

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

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

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestConsumer.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestConsumer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestConsumer.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,52 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @since 4.2
+ */
+public interface HttpAsyncRequestConsumer<T> extends Closeable {
+
+    void requestReceived(HttpRequest request);
+
+    void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws IOException;
+
+    void requestCompleted(HttpContext context);
+
+    Exception getException();
+
+    T getResult();
+
+}

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

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

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandler.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandler.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandler.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.protocol.HttpContext;
+
+/**
+ * @since 4.2
+ */
+public interface HttpAsyncRequestHandler<T> {
+
+    HttpAsyncRequestConsumer<T> processRequest(
+            HttpRequest request,
+            HttpContext context);
+
+    void handle(
+            T data,
+            HttpAsyncResponseTrigger trigger,
+            HttpContext context) throws HttpException, IOException;
+
+}

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

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

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerRegistry.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerRegistry.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerRegistry.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerRegistry.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,98 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.util.Map;
+
+import org.apache.http.protocol.UriPatternMatcher;
+
+/**
+ * Maintains a map of HTTP request handlers keyed by a request URI pattern.
+ * <br>
+ * Patterns may have three formats:
+ * <ul>
+ *   <li><code>*</code></li>
+ *   <li><code>*&lt;uri&gt;</code></li>
+ *   <li><code>&lt;uri&gt;*</code></li>
+ * </ul>
+ * <br>
+ * This class can be used to resolve an instance of {@link HttpAsyncRequestHandler} matching
+ * a particular request URI. Usually the resolved request handler will be used to process
+ * the request with the specified request URI.
+ *
+ * @since 4.2
+ */
+public class HttpAsyncRequestHandlerRegistry implements HttpAsyncRequestHandlerResolver {
+
+    private final UriPatternMatcher<HttpAsyncRequestHandler<?>> matcher;
+
+    public HttpAsyncRequestHandlerRegistry() {
+        matcher = new UriPatternMatcher<HttpAsyncRequestHandler<?>>();
+    }
+
+    /**
+     * Registers the given {@link NHttpRequestHandler} as a handler for URIs
+     * matching the given pattern.
+     *
+     * @param pattern the pattern to register the handler for.
+     * @param handler the handler.
+     */
+    public void register(final String pattern, final HttpAsyncRequestHandler<?> handler) {
+        matcher.register(pattern, handler);
+    }
+
+    /**
+     * Removes registered handler, if exists, for the given pattern.
+     *
+     * @param pattern the pattern to unregister the handler for.
+     */
+    public void unregister(final String pattern) {
+        matcher.unregister(pattern);
+    }
+
+    /**
+     * Sets handlers from the given map.
+     * @param map the map containing handlers keyed by their URI patterns.
+     */
+    public void setHandlers(final Map<String, HttpAsyncRequestHandler<?>> map) {
+        matcher.setObjects(map);
+    }
+
+    /**
+     * Get the handler map.
+     * @return The map of handlers and their associated URI patterns.
+     */
+    public Map<String, HttpAsyncRequestHandler<?>> getHandlers() {
+        return matcher.getObjects();
+    }
+
+    public HttpAsyncRequestHandler<?> lookup(String requestURI) {
+        return matcher.lookup(requestURI);
+    }
+
+}

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

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

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerResolver.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerResolver.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerResolver.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,48 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+/**
+ * HttpAsyncRequestHandlerResolver can be used to resolve an instance of
+ * {@link HttpAsyncRequestHandler} matching a particular request URI. Usually the resolved
+ * request handler will be used to process the request with the specified request URI.
+ *
+ * @since 4.2
+ */
+public interface HttpAsyncRequestHandlerResolver {
+
+    /**
+     * Looks up a handler matching the given request URI.
+     *
+     * @param requestURI the request URI
+     * @return HTTP request handler or <code>null</code> if no match
+     * is found.
+     */
+    HttpAsyncRequestHandler<?> lookup(String requestURI);
+
+}

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

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

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

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java (from r1163241, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java&r1=1163241&r2=1163256&rev=1163256&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java Tue Aug 30 15:16:46 2011
@@ -24,8 +24,9 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.nio.client;
+package org.apache.http.nio.protocol;
 
+import java.io.Closeable;
 import java.io.IOException;
 
 import org.apache.http.HttpException;
@@ -34,7 +35,10 @@ import org.apache.http.HttpRequest;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
 
-public interface HttpAsyncRequestProducer {
+/**
+ * @ since 4.2
+ */
+public interface HttpAsyncRequestProducer extends Closeable {
 
     HttpHost getTarget();
 

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

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

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducer.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Aug 30 15:16:46 2011
@@ -0,0 +1 @@
+/httpcomponents/httpasyncclient/branches/conn-mgmt-redesign/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncRequestProducer.java:1155312-1159070

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducerImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducerImpl.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducerImpl.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestProducerImpl.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,73 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.nio.entity.ProducingNHttpEntity;
+
+class HttpAsyncRequestProducerImpl implements HttpAsyncResponseProducer {
+
+    private final HttpResponse response;
+    private final ProducingNHttpEntity producer;
+
+    HttpAsyncRequestProducerImpl(final HttpResponse response) {
+        super();
+        if (response == null) {
+            throw new IllegalArgumentException("Response may not be null");
+        }
+        this.response = response;
+        HttpEntity entity = response.getEntity();
+        if (entity instanceof ProducingNHttpEntity) {
+            this.producer = (ProducingNHttpEntity) entity;
+        } else {
+            this.producer =  new NHttpEntityWrapper(entity);
+        }
+    }
+
+    public HttpResponse generateResponse() {
+        return this.response;
+    }
+
+    public void produceContent(
+            final ContentEncoder encoder, final IOControl ioctrl) throws IOException {
+        this.producer.produceContent(encoder, ioctrl);
+        if (encoder.isCompleted()) {
+            this.producer.finish();
+        }
+    }
+
+    public void close() throws IOException {
+        this.producer.finish();
+    }
+
+}

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

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

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

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseConsumer.java (from r1163235, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseConsumer.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseConsumer.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java&r1=1163235&r2=1163256&rev=1163256&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseConsumer.java Tue Aug 30 15:16:46 2011
@@ -24,22 +24,27 @@
  * <http://www.apache.org/>.
  *
  */
-package org.apache.http.nio.client;
+package org.apache.http.nio.protocol;
 
+import java.io.Closeable;
 import java.io.IOException;
 
 import org.apache.http.HttpException;
 import org.apache.http.HttpResponse;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.IOControl;
+import org.apache.http.protocol.HttpContext;
 
-public interface HttpAsyncResponseConsumer<T> {
+/**
+ * @since 4.2
+ */
+public interface HttpAsyncResponseConsumer<T> extends Closeable {
 
     void responseReceived(HttpResponse response) throws IOException, HttpException;
 
     void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws IOException;
 
-    void responseCompleted();
+    void responseCompleted(HttpContext context);
 
     void failed(Exception ex);
 

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

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

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseConsumer.java
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Aug 30 15:16:46 2011
@@ -0,0 +1 @@
+/httpcomponents/httpasyncclient/branches/conn-mgmt-redesign/httpasyncclient/src/main/java/org/apache/http/nio/client/HttpAsyncResponseConsumer.java:1155312-1159070

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseProducer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseProducer.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseProducer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseProducer.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,46 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.Closeable;
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.IOControl;
+
+/**
+ * @since 4.2
+ */
+public interface HttpAsyncResponseProducer extends Closeable {
+
+    HttpResponse generateResponse();
+
+    void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException;
+
+}

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

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

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseTrigger.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseTrigger.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseTrigger.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncResponseTrigger.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,37 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+/**
+ * @since 4.2
+ */
+public interface HttpAsyncResponseTrigger {
+
+    void submitResponse(HttpAsyncResponseProducer responseProducer);
+
+}

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

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

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

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncServiceHandler.java?rev=1163256&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncServiceHandler.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncServiceHandler.java Tue Aug 30 15:16:46 2011
@@ -0,0 +1,527 @@
+/*
+ * ====================================================================
+ * 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.nio.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
+import org.apache.http.MethodNotSupportedException;
+import org.apache.http.ProtocolException;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.UnsupportedHttpVersionException;
+import org.apache.http.annotation.Immutable;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.ContentEncoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.nio.NHttpConnection;
+import org.apache.http.nio.NHttpServerConnection;
+import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.entity.NStringEntity;
+import org.apache.http.params.DefaultedHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+
+/**
+ * @since 4.2
+ */
+@Immutable // provided injected dependencies are immutable
+public class HttpAsyncServiceHandler implements NHttpServiceHandler {
+
+    private static final String HTTP_EXCHANGE = "http.nio.http-exchange";
+
+    private final HttpAsyncRequestHandlerResolver handlerResolver;
+    private final HttpProcessor httpProcessor;
+    private final ConnectionReuseStrategy connStrategy;
+    private final HttpParams params;
+
+    public HttpAsyncServiceHandler(
+            final HttpAsyncRequestHandlerResolver handlerResolver,
+            final HttpProcessor httpProcessor,
+            final ConnectionReuseStrategy connStrategy,
+            final HttpParams params) {
+        super();
+        if (handlerResolver == null) {
+            throw new IllegalArgumentException("Handler resolver may not be null.");
+        }
+        if (httpProcessor == null) {
+            throw new IllegalArgumentException("HTTP processor may not be null.");
+        }
+        if (connStrategy == null) {
+            throw new IllegalArgumentException("Connection reuse strategy may not be null");
+        }
+        if (params == null) {
+            throw new IllegalArgumentException("HTTP parameters may not be null");
+        }
+        this.handlerResolver = handlerResolver;
+        this.httpProcessor = httpProcessor;
+        this.connStrategy = connStrategy;
+        this.params = params;
+    }
+
+    public void connected(final NHttpServerConnection conn) {
+        HttpExchange httpExchange = new HttpExchange();
+        conn.getContext().setAttribute(HTTP_EXCHANGE, httpExchange);
+    }
+
+    public void closed(final NHttpServerConnection conn) {
+        HttpExchange httpExchange = (HttpExchange) conn.getContext().getAttribute(HTTP_EXCHANGE);
+        synchronized (httpExchange) {
+            httpExchange.reset();
+        }
+    }
+
+    public void requestReceived(final NHttpServerConnection conn) {
+        HttpExchange httpExchange = (HttpExchange) conn.getContext().getAttribute(HTTP_EXCHANGE);
+        synchronized (httpExchange) {
+            try {
+                HttpRequest request = conn.getHttpRequest();
+                HttpContext context = httpExchange.getContext();
+                request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
+
+                context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
+                context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+                this.httpProcessor.process(request, context);
+
+                HttpAsyncRequestHandler<Object> requestHandler = getRequestHandler(request);
+                HttpAsyncRequestConsumer<Object> consumer = requestHandler.processRequest(request, context);
+
+                httpExchange.setRequestHandler(requestHandler);
+                httpExchange.setRequestConsumer(consumer);
+                httpExchange.setRequest(request);
+
+                consumer.requestReceived(request);
+
+                if (request instanceof HttpEntityEnclosingRequest) {
+                    HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request;
+                    if (entityRequest.expectContinue()) {
+                        ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
+                        if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
+                            // Downgrade protocol version if greater than HTTP/1.1
+                            ver = HttpVersion.HTTP_1_1;
+                        }
+                        HttpResponse response = new BasicHttpResponse(
+                                ver, HttpStatus.SC_CONTINUE, "Continue");
+                        response.setParams(
+                                new DefaultedHttpParams(response.getParams(), this.params));
+                        conn.submitResponse(response);
+                    }
+                } else {
+                    // No request content is expected.
+                    // Process request right away
+                    conn.suspendInput();
+                    processRequest(conn, httpExchange);
+                }
+            } catch (RuntimeException ex) {
+                shutdownConnection(conn);
+                throw ex;
+            } catch (Exception ex) {
+                shutdownConnection(conn);
+                onException(ex);
+            }
+        }
+    }
+
+    public void exception(final NHttpServerConnection conn, final HttpException httpex) {
+        if (conn.isResponseSubmitted()) {
+            // There is not much that we can do if a response head
+            // has already been submitted
+            closeConnection(conn);
+            onException(httpex);
+            return;
+        }
+
+        HttpExchange httpExchange = (HttpExchange) conn.getContext().getAttribute(HTTP_EXCHANGE);
+        synchronized (httpExchange) {
+            try {
+                HttpAsyncResponseProducer responseProducer = handleException(httpex);
+                httpExchange.setResponseProducer(responseProducer);
+                commitResponse(conn, httpExchange);
+            } catch (RuntimeException ex) {
+                shutdownConnection(conn);
+                throw ex;
+            } catch (Exception ex) {
+                shutdownConnection(conn);
+                onException(ex);
+            }
+        }
+    }
+
+    public void exception(final NHttpServerConnection conn, final IOException ex) {
+        shutdownConnection(conn);
+        onException(ex);
+    }
+
+    public void timeout(final NHttpServerConnection conn) {
+        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);
+        }
+    }
+
+    public void inputReady(final NHttpServerConnection conn, final ContentDecoder decoder) {
+        HttpExchange httpExchange = (HttpExchange) conn.getContext().getAttribute(HTTP_EXCHANGE);
+        synchronized (httpExchange) {
+            try {
+                HttpAsyncRequestConsumer<?> consumer = httpExchange.getRequestConsumer();
+                consumer.consumeContent(decoder, conn);
+                if (decoder.isCompleted()) {
+                    conn.suspendInput();
+                    processRequest(conn, httpExchange);
+                }
+            } catch (RuntimeException ex) {
+                shutdownConnection(conn);
+                throw ex;
+            } catch (Exception ex) {
+                shutdownConnection(conn);
+                onException(ex);
+            }
+        }
+    }
+
+    public void responseReady(final NHttpServerConnection conn) {
+        HttpExchange httpExchange = (HttpExchange) conn.getContext().getAttribute(HTTP_EXCHANGE);
+        synchronized (httpExchange) {
+            if (!httpExchange.isResponseReady()) {
+                return;
+            }
+            try {
+                commitResponse(conn, httpExchange);
+            } catch (RuntimeException ex) {
+                shutdownConnection(conn);
+                throw ex;
+            } catch (Exception ex) {
+                shutdownConnection(conn);
+                onException(ex);
+            }
+        }
+    }
+
+    public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) {
+        HttpExchange httpExchange = (HttpExchange) conn.getContext().getAttribute(HTTP_EXCHANGE);
+        synchronized (httpExchange) {
+            try {
+                HttpAsyncResponseProducer producer = httpExchange.getResponseProducer();
+                HttpContext context = httpExchange.getContext();
+                HttpResponse response = httpExchange.getResponse();
+
+                producer.produceContent(encoder, conn);
+                if (encoder.isCompleted()) {
+                    httpExchange.reset();
+                    if (!this.connStrategy.keepAlive(response, context)) {
+                        conn.close();
+                    } else {
+                        conn.requestInput();
+                    }
+                }
+            } catch (RuntimeException ex) {
+                shutdownConnection(conn);
+                throw ex;
+            } catch (Exception ex) {
+                shutdownConnection(conn);
+                onException(ex);
+            }
+        }
+    }
+
+    protected void onException(final Exception ex) {
+    }
+
+    private void closeConnection(final NHttpConnection conn) {
+        try {
+            conn.close();
+        } catch (IOException ex) {
+            try {
+                conn.shutdown();
+            } catch (IOException ex2) {
+                onException(ex2);
+            }
+        }
+    }
+
+    private void shutdownConnection(final NHttpConnection conn) {
+        try {
+            conn.shutdown();
+        } catch (IOException ex) {
+            onException(ex);
+        }
+    }
+
+    private ErrorResponseProducer handleException(final Exception ex) {
+        int code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
+        if (ex instanceof MethodNotSupportedException) {
+            code = HttpStatus.SC_NOT_IMPLEMENTED;
+        } else if (ex instanceof UnsupportedHttpVersionException) {
+            code = HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED;
+        } else if (ex instanceof ProtocolException) {
+            code = HttpStatus.SC_BAD_REQUEST;
+        }
+        String message = ex.getMessage();
+        if (message == null) {
+            message = ex.toString();
+        }
+        return new ErrorResponseProducer(
+                HttpVersion.HTTP_1_0, code, NStringEntity.create(message), false);
+    }
+
+    private boolean canResponseHaveBody(final HttpRequest request, final HttpResponse response) {
+        if (request != null && "HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) {
+            return false;
+        }
+        int status = response.getStatusLine().getStatusCode();
+        return status >= HttpStatus.SC_OK
+            && status != HttpStatus.SC_NO_CONTENT
+            && status != HttpStatus.SC_NOT_MODIFIED
+            && status != HttpStatus.SC_RESET_CONTENT;
+    }
+
+    private void processRequest(
+            final NHttpServerConnection conn,
+            final HttpExchange httpExchange) throws HttpException, IOException {
+        HttpAsyncRequestHandler<Object> handler = httpExchange.getRequestHandler();
+        HttpContext context = httpExchange.getContext();
+        HttpAsyncRequestConsumer<?> consumer = httpExchange.getRequestConsumer();
+        consumer.requestCompleted(context);
+        Exception ex = consumer.getException();
+        if (ex != null) {
+            ErrorResponseProducer responseProducer = handleException(ex);
+            httpExchange.setResponseProducer(responseProducer);
+            conn.requestOutput();
+        } else {
+            Object result = consumer.getResult();
+            HttpAsyncResponseTrigger trigger = new ResponseTriggerImpl(httpExchange, conn);
+            handler.handle(result, trigger, context);
+        }
+    }
+
+    private void commitResponse(
+            final NHttpServerConnection conn,
+            final HttpExchange httpExchange) throws IOException, HttpException {
+        HttpContext context = httpExchange.getContext();
+        HttpRequest request = httpExchange.getRequest();
+        HttpAsyncResponseProducer responseProducer = httpExchange.getResponseProducer();
+        HttpResponse response = responseProducer.generateResponse();
+        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
+
+        httpExchange.setResponse(response);
+
+        context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
+        this.httpProcessor.process(response, context);
+
+        httpExchange.setHandled(true);
+
+        HttpEntity entity = response.getEntity();
+        if (entity != null && !canResponseHaveBody(request, response)) {
+            response.setEntity(null);
+            entity = null;
+        }
+
+        conn.submitResponse(response);
+
+        if (entity == null) {
+            httpExchange.reset();
+            if (!this.connStrategy.keepAlive(response, context)) {
+                conn.close();
+            } else {
+                // Ready to process new request
+                conn.requestInput();
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private HttpAsyncRequestHandler<Object> getRequestHandler(final HttpRequest request) {
+        HttpAsyncRequestHandler<Object> handler = null;
+        if (this.handlerResolver != null) {
+            String requestURI = request.getRequestLine().getUri();
+            handler = (HttpAsyncRequestHandler<Object>) this.handlerResolver.lookup(requestURI);
+        } else {
+            handler = new NullRequestHandler();
+        }
+        return handler;
+    }
+
+    class HttpExchange {
+
+        private final BasicHttpContext context;
+        private HttpAsyncRequestHandler<Object> requestHandler;
+        private HttpAsyncRequestConsumer<Object> requestConsumer;
+        private HttpAsyncResponseProducer responseProducer;
+        private HttpRequest request;
+        private HttpResponse response;
+        private boolean handled;
+
+        HttpExchange() {
+            super();
+            this.context = new BasicHttpContext();
+        }
+
+        public HttpContext getContext() {
+            return this.context;
+        }
+
+        public HttpAsyncRequestHandler<Object> getRequestHandler() {
+            return this.requestHandler;
+        }
+
+        public void setRequestHandler(final HttpAsyncRequestHandler<Object> requestHandler) {
+            this.requestHandler = requestHandler;
+        }
+
+        public HttpAsyncRequestConsumer<Object> getRequestConsumer() {
+            return this.requestConsumer;
+        }
+
+        public void setRequestConsumer(final HttpAsyncRequestConsumer<Object> requestConsumer) {
+            this.requestConsumer = requestConsumer;
+        }
+
+        public HttpAsyncResponseProducer getResponseProducer() {
+            return this.responseProducer;
+        }
+
+        public void setResponseProducer(final HttpAsyncResponseProducer responseProducer) {
+            this.responseProducer = responseProducer;
+        }
+
+        public HttpRequest getRequest() {
+            return this.request;
+        }
+
+        public void setRequest(final HttpRequest request) {
+            this.request = request;
+        }
+
+        public HttpResponse getResponse() {
+            return this.response;
+        }
+
+        public void setResponse(final HttpResponse response) {
+            this.response = response;
+        }
+
+        public boolean isResponseReady() {
+            return !this.handled && this.responseProducer != null;
+        }
+
+        public void setHandled(boolean handled) {
+            this.handled = handled;
+        }
+
+        public void reset() {
+            this.requestHandler = null;
+            if (this.requestConsumer != null) {
+                try {
+                    this.requestConsumer.close();
+                } catch (IOException ex) {
+                    HttpAsyncServiceHandler.this.onException(ex);
+                }
+            }
+            this.requestConsumer = null;
+            if (this.responseProducer != null) {
+                try {
+                    this.responseProducer.close();
+                } catch (IOException ignore) {
+                }
+            }
+            this.responseProducer = null;
+            this.request = null;
+            this.response = null;
+            this.handled = false;
+            this.context.clear();
+        }
+
+        @Override
+        public String toString() {
+            StringBuilder buf = new StringBuilder();
+            buf.append("done: ");
+            buf.append(this.handled);
+            buf.append("; request: ");
+            if (this.request != null) {
+                buf.append(this.request.getRequestLine());
+            }
+            buf.append("; response: ");
+            if (this.response != null) {
+                buf.append(this.response.getStatusLine());
+            }
+            buf.append(";");
+            return buf.toString();
+        }
+
+    }
+
+    class ResponseTriggerImpl implements HttpAsyncResponseTrigger {
+
+        private final HttpExchange httpExchange;
+        private final IOControl iocontrol;
+
+        private volatile boolean triggered;
+
+        public ResponseTriggerImpl(final HttpExchange httpExchange, final IOControl iocontrol) {
+            super();
+            this.httpExchange = httpExchange;
+            this.iocontrol = iocontrol;
+        }
+
+        public void submitResponse(final HttpAsyncResponseProducer responseProducer) {
+            if (responseProducer == null) {
+                throw new IllegalArgumentException("Response producer may not be null");
+            }
+            if (this.triggered) {
+                throw new IllegalStateException("Response already triggered");
+            }
+            this.triggered = true;
+            synchronized (responseProducer) {
+                this.httpExchange.setResponseProducer(responseProducer);
+                this.iocontrol.requestOutput();
+            }
+        }
+
+    }
+
+}

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

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

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

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java (from r1163240, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/NHttpEntityWrapper.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/NHttpEntityWrapper.java&r1=1163240&r2=1163256&rev=1163256&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/nio/client/methods/NHttpEntityWrapper.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NHttpEntityWrapper.java Tue Aug 30 15:16:46 2011
@@ -25,7 +25,7 @@
  *
  */
 
-package org.apache.http.nio.client.methods;
+package org.apache.http.nio.protocol;
 
 import java.io.IOException;
 import java.io.InputStream;