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 2008/02/20 11:37:14 UTC

svn commit: r629409 - in /httpcomponents/httpcore/branches/limewire_contrib/module-nio/src: examples/org/apache/http/examples/nio/ main/java/org/apache/http/nio/entity/ main/java/org/apache/http/nio/protocol/ test/java/org/apache/http/nio/protocol/

Author: olegk
Date: Wed Feb 20 02:37:10 2008
New Revision: 629409

URL: http://svn.apache.org/viewvc?rev=629409&view=rev
Log:
HTTPCORE-148: 

* Changed NHttpRequestHandler interface to use ConsumingNHttpEntity instead of ContentListener; 
* Added ConsumingNHttpEntityTemplate that can be used to consume incoming content using ContentListener

Added:
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java   (with props)
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java   (with props)
Removed:
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/BasicConsumingNHttpEntity.java
Modified:
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ContentListener.java
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandler.java
    httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java?rev=629409&r1=629408&r2=629409&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java Wed Feb 20 02:37:10 2008
@@ -52,6 +52,8 @@
 import org.apache.http.nio.FileContentDecoder;
 import org.apache.http.nio.IOControl;
 import org.apache.http.nio.NHttpConnection;
+import org.apache.http.nio.entity.ConsumingNHttpEntity;
+import org.apache.http.nio.entity.ConsumingNHttpEntityTemplate;
 import org.apache.http.nio.entity.ContentListener;
 import org.apache.http.nio.entity.NFileEntity;
 import org.apache.http.nio.entity.NStringEntity;
@@ -146,10 +148,12 @@
             this.useFileChannels = useFileChannels;
         }
 
-        public ContentListener entityRequest(
+        public ConsumingNHttpEntity entityRequest(
                 HttpEntityEnclosingRequest request, HttpContext context)
                 throws HttpException, IOException {
-            return new FileWriteListener(useFileChannels);
+            return new ConsumingNHttpEntityTemplate(
+                    request.getEntity(),
+                    new FileWriteListener(useFileChannels));
         }
 
         public void handle(
@@ -192,7 +196,7 @@
             this.useFileChannels = useFileChannels;
         }
 
-        public void consumeContent(ContentDecoder decoder, IOControl ioctrl)
+        public void contentAvailable(ContentDecoder decoder, IOControl ioctrl)
                 throws IOException {
             long transferred;
             if(useFileChannels && decoder instanceof FileContentDecoder) {
@@ -207,7 +211,7 @@
                 idx += transferred;
         }
 
-        public void finish() {
+        public void finished() {
             try {
                 inputFile.close();
             } catch(IOException ignored) {}

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java?rev=629409&r1=629408&r2=629409&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java Wed Feb 20 02:37:10 2008
@@ -1,7 +1,7 @@
 /*
- * $HeadURL:$
- * $Revision:$
- * $Date:$
+ * $HeadURL$
+ * $Revision$
+ * $Date$
  *
  * ====================================================================
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -31,22 +31,27 @@
 
 package org.apache.http.nio.entity;
 
+import java.io.IOException;
+
 import org.apache.http.HttpEntity;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.IOControl;
 
 /**
  * A non-blocking entity that allows content to be consumed from a decoder.
  *
- * If external code wants to be notified when more content is available, it
- * should install a ContentListener on the entity via
- * {@link #setContentListener(org.apache.http.nio.entity.ConsumingNHttpEntity.ContentListener)}.
- * When content becomes available, implementations must notify the listener.
- * <p>
- * All blocking methods throw an {@link UnsupportedOperationException}.
- *
  * @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
  */
 public interface ConsumingNHttpEntity extends HttpEntity {
 
-    ContentListener getContentListener();
+    /**
+     * Notification that content is available to be read from the decoder.
+     */
+    void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws IOException;
+
+    /**
+     * Notification that any resources allocated for reading can be released.
+     */
+    void finish();
 
 }

Added: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java?rev=629409&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java (added)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java Wed Feb 20 02:37:10 2008
@@ -0,0 +1,83 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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.entity;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.HttpEntityWrapper;
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.IOControl;
+
+public class ConsumingNHttpEntityTemplate
+    extends HttpEntityWrapper implements ConsumingNHttpEntity {
+
+    private final ContentListener contentListener;
+
+    public ConsumingNHttpEntityTemplate(final HttpEntity httpEntity, final ContentListener contentListener) {
+        super(httpEntity);
+        this.contentListener = contentListener;
+    }
+
+    public ContentListener getContentListener() {
+        return contentListener;
+    }
+
+    public InputStream getContent() throws IOException, IllegalStateException {
+        throw new UnsupportedOperationException("Does not support blocking methods");
+    }
+
+    public boolean isStreaming() {
+        return true;
+    }
+
+    public void writeTo(OutputStream out) throws IOException {
+        throw new UnsupportedOperationException("Does not support blocking methods");
+    }
+
+    public void consumeContent() throws IOException, UnsupportedOperationException {
+        throw new UnsupportedOperationException("Does not support blocking methods");
+    }
+
+    public void consumeContent(
+            final ContentDecoder decoder,
+            final IOControl ioctrl) throws IOException {
+        this.contentListener.contentAvailable(decoder, ioctrl);
+    }
+
+    public void finish() {
+        this.contentListener.finished();
+    }
+
+}

Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntityTemplate.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ContentListener.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ContentListener.java?rev=629409&r1=629408&r2=629409&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ContentListener.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/ContentListener.java Wed Feb 20 02:37:10 2008
@@ -13,11 +13,11 @@
     /**
      * Notification that content is available to be read from the decoder.
      */
-    void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws IOException;
+    void contentAvailable(ContentDecoder decoder, IOControl ioctrl) throws IOException;
 
     /**
      * Notification that any resources allocated for reading can be released.
      */
-    void finish();
+    void finished();
 
 }

Added: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java?rev=629409&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java (added)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java Wed Feb 20 02:37:10 2008
@@ -0,0 +1,69 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * 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.entity;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.http.nio.ContentDecoder;
+import org.apache.http.nio.IOControl;
+import org.apache.http.nio.util.ByteBufferAllocator;
+
+public class SkipContentListener implements ContentListener {
+
+    private final ByteBuffer buffer;
+
+    public SkipContentListener(final ByteBufferAllocator allocator) {
+        super();
+        if (allocator == null) {
+            throw new IllegalArgumentException("ByteBuffer allocator may not be null");
+        }
+        this.buffer = allocator.allocate(2048);
+    }
+
+    public void contentAvailable(
+            final ContentDecoder decoder,
+            final IOControl ioctrl) throws IOException {
+        int totalRead = 0;
+        int lastRead;
+        do {
+            buffer.clear();
+            lastRead = decoder.read(buffer);
+            if (lastRead > 0)
+                totalRead += lastRead;
+        } while (lastRead > 0);
+    }
+
+    public void finished() {
+    }
+
+}
\ No newline at end of file

Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/entity/SkipContentListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java?rev=629409&r1=629408&r2=629409&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java Wed Feb 20 02:37:10 2008
@@ -1,7 +1,7 @@
 /*
- * $HeadURL:$
- * $Revision:$
- * $Date:$
+ * $HeadURL$
+ * $Revision$
+ * $Date$
  *
  * ====================================================================
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -32,7 +32,6 @@
 package org.apache.http.nio.protocol;
 
 import java.io.IOException;
-import java.nio.ByteBuffer;
 
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpEntity;
@@ -49,15 +48,15 @@
 import org.apache.http.UnsupportedHttpVersionException;
 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.BasicConsumingNHttpEntity;
 import org.apache.http.nio.entity.ConsumingNHttpEntity;
+import org.apache.http.nio.entity.ConsumingNHttpEntityTemplate;
 import org.apache.http.nio.entity.ContentListener;
 import org.apache.http.nio.entity.NByteArrayEntity;
 import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.apache.http.nio.entity.SkipContentListener;
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.DefaultedHttpParams;
@@ -141,9 +140,14 @@
     public void requestReceived(final NHttpServerConnection conn) {
         HttpContext context = conn.getContext();
 
+        ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE);
+
         HttpRequest request = conn.getHttpRequest();
         request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
 
+        NHttpRequestHandler requestHandler = getRequestHandler(request);
+        connState.setRequestHandler(requestHandler);
+
         ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
         if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
             // Downgrade protocol version if greater than HTTP/1.1
@@ -186,7 +190,21 @@
                     }
                 }
                 // Request content is expected.
-                // Wait until the request content is fully received
+                HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
+
+                // Lookup request handler for this request
+                if (requestHandler != null) {
+                    ConsumingNHttpEntity consumingEntity = requestHandler.entityRequest(
+                            (HttpEntityEnclosingRequest) request, context);
+                    if (consumingEntity == null) {
+                        consumingEntity = new ConsumingNHttpEntityTemplate(
+                                entity,
+                                new SkipContentListener(this.allocator));
+                    }
+                    ((HttpEntityEnclosingRequest) request).setEntity(consumingEntity);
+                    connState.setConsumingEntity(consumingEntity);
+                }
+
             } else {
                 // No request content is expected.
                 // Process request right away
@@ -255,36 +273,18 @@
 
     public void inputReady(final NHttpServerConnection conn, final ContentDecoder decoder) {
         HttpContext context = conn.getContext();
-        HttpEntityEnclosingRequest request = (HttpEntityEnclosingRequest) conn.getHttpRequest();
-        HttpEntity entity = request.getEntity();
+        HttpRequest request = conn.getHttpRequest();
+
         ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE);
 
-        try {
-            // If we haven't set the entity for asynchronous input yet...
-            if (!(entity instanceof ConsumingNHttpEntity)) {
-                NHttpRequestHandler handler = getRequestHandler(request);
-                ContentListener listener = null;
-                if (handler != null) {
-                    listener = handler.entityRequest(request, context);
-                }
-                if (listener == null) {
-                    listener = new SkipContentListener(allocator);
-                }
-                connState.setConsumingEntity(listener);
-                entity = new BasicConsumingNHttpEntity(listener, entity);
-                request.setEntity(entity);
-            }
+        ConsumingNHttpEntity consumingEntity = connState.getConsumingEntity();
 
-            BasicConsumingNHttpEntity consumingEntity = (BasicConsumingNHttpEntity) entity;
-            consumingEntity.getContentListener().consumeContent(decoder, conn);
+        try {
 
+            consumingEntity.consumeContent(decoder, conn);
             if (decoder.isCompleted()) {
                 conn.suspendInput();
-
-                if (!consumingEntity.isHandled()) {
-                    consumingEntity.setHandled(true);
-                    processRequest(conn, request);
-                }
+                processRequest(conn, request);
             }
 
         } catch (IOException ex) {
@@ -449,7 +449,8 @@
 
     static class ServerConnState {
 
-        private ContentListener consumingEntity;
+        private NHttpRequestHandler requestHandler;
+        private ConsumingNHttpEntity consumingEntity;
         private ProducingNHttpEntity producingEntity;
 
         void finishInput() {
@@ -471,35 +472,28 @@
             finishOutput();
         }
 
-        public void setProducingEntity(final ProducingNHttpEntity producingEntity) {
-            this.producingEntity = producingEntity;
+        public NHttpRequestHandler getRequestHandler() {
+            return this.requestHandler;
         }
 
-        public void setConsumingEntity(final ContentListener consumingEntity) {
-            this.consumingEntity = consumingEntity;
+        public void setRequestHandler(final NHttpRequestHandler requestHandler) {
+            this.requestHandler = requestHandler;
         }
 
-    }
+        public ProducingNHttpEntity getProducingEntity() {
+            return this.producingEntity;
+        }
+
+        public void setProducingEntity(final ProducingNHttpEntity producingEntity) {
+            this.producingEntity = producingEntity;
+        }
 
-    static class SkipContentListener implements ContentListener {
-        private final ByteBuffer buffer;
-        public SkipContentListener(ByteBufferAllocator allocator) {
-            this.buffer = allocator.allocate(2048);
-        }
-
-        public void consumeContent(ContentDecoder decoder, IOControl ioctrl)
-                throws IOException {
-            int totalRead = 0;
-            int lastRead;
-            do {
-                buffer.clear();
-                lastRead = decoder.read(buffer);
-                if (lastRead > 0)
-                    totalRead += lastRead;
-            } while (lastRead > 0);
+        public ConsumingNHttpEntity getConsumingEntity() {
+            return this.consumingEntity;
         }
 
-        public void finish() {
+        public void setConsumingEntity(final ConsumingNHttpEntity consumingEntity) {
+            this.consumingEntity = consumingEntity;
         }
 
     }

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandler.java?rev=629409&r1=629408&r2=629409&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandler.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandler.java Wed Feb 20 02:37:10 2008
@@ -1,7 +1,7 @@
 /*
- * $HeadURL:$
- * $Revision:$
- * $Date:$
+ * $HeadURL$
+ * $Revision$
+ * $Date$
  *
  * ====================================================================
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -37,12 +37,12 @@
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
-import org.apache.http.nio.entity.ContentListener;
+import org.apache.http.nio.entity.ConsumingNHttpEntity;
 import org.apache.http.protocol.HttpContext;
 
 public interface NHttpRequestHandler {
 
-    ContentListener entityRequest(HttpEntityEnclosingRequest request, HttpContext context)
+    ConsumingNHttpEntity entityRequest(HttpEntityEnclosingRequest request, HttpContext context)
         throws HttpException, IOException;
 
     void handle(HttpRequest request, HttpResponse response, HttpContext context)

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java?rev=629409&r1=629408&r2=629409&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java (original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAsyncNHttpHandlers.java Wed Feb 20 02:37:10 2008
@@ -1,7 +1,7 @@
 /*
- * $HeadURL:$
- * $Revision:$
- * $Date:$
+ * $HeadURL$
+ * $Revision$
+ * $Date$
  *
  * ====================================================================
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -68,6 +68,7 @@
 import org.apache.http.nio.NHttpConnection;
 import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.entity.ConsumingNHttpEntity;
+import org.apache.http.nio.entity.ConsumingNHttpEntityTemplate;
 import org.apache.http.nio.entity.ContentListener;
 import org.apache.http.nio.entity.NByteArrayEntity;
 import org.apache.http.nio.entity.NStringEntity;
@@ -101,7 +102,7 @@
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
  *
- * @version $Id:$
+ * @version $Id$
  */
 public class TestAsyncNHttpHandlers extends TestCase {
 
@@ -241,9 +242,9 @@
 
         NHttpRequestHandler requestHandler = new NHttpRequestHandler() {
 
-            public ContentListener entityRequest(
+            public ConsumingNHttpEntity entityRequest(
                     HttpEntityEnclosingRequest request, HttpContext context) {
-                throw new UnsupportedOperationException();
+                return null;
             }
 
             public void handle(
@@ -374,17 +375,19 @@
 
         NHttpRequestHandler requestHandler = new NHttpRequestHandler() {
 
-            public ContentListener entityRequest(
+            public ConsumingNHttpEntity entityRequest(
                     HttpEntityEnclosingRequest request, HttpContext context)
                     throws HttpException, IOException {
-                return new ByteContentListener();
+                return new ConsumingNHttpEntityTemplate(
+                        request.getEntity(),
+                        new ByteContentListener());
             }
 
             public void handle(
                     HttpRequest request, HttpResponse response, HttpContext context)
                     throws HttpException, IOException {
                 if (request instanceof HttpEntityEnclosingRequest) {
-                    ConsumingNHttpEntity incoming = (ConsumingNHttpEntity)((HttpEntityEnclosingRequest) request).getEntity();
+                    ConsumingNHttpEntityTemplate incoming = (ConsumingNHttpEntityTemplate)((HttpEntityEnclosingRequest) request).getEntity();
                     byte[] b = ((ByteContentListener)incoming.getContentListener()).getContent();
                     response.setEntity(new NByteArrayEntity(b));
                 } else {
@@ -509,17 +512,19 @@
 
         NHttpRequestHandler requestHandler = new NHttpRequestHandler() {
 
-            public ContentListener entityRequest(
+            public ConsumingNHttpEntity entityRequest(
                     HttpEntityEnclosingRequest request, HttpContext context)
                     throws HttpException, IOException {
-                return new ByteContentListener();
+                return new ConsumingNHttpEntityTemplate(
+                        request.getEntity(),
+                        new ByteContentListener());
             }
 
             public void handle(
                     HttpRequest request, HttpResponse response, HttpContext context)
                     throws HttpException, IOException {
                 if (request instanceof HttpEntityEnclosingRequest) {
-                    ConsumingNHttpEntity incoming = (ConsumingNHttpEntity)((HttpEntityEnclosingRequest) request).getEntity();
+                    ConsumingNHttpEntityTemplate incoming = (ConsumingNHttpEntityTemplate)((HttpEntityEnclosingRequest) request).getEntity();
                     byte[] b = ((ByteContentListener)incoming.getContentListener()).getContent();
                     NByteArrayEntity outgoing = new NByteArrayEntity(b);
                     outgoing.setChunked(true);
@@ -649,17 +654,19 @@
 
         NHttpRequestHandler requestHandler = new NHttpRequestHandler() {
 
-            public ContentListener entityRequest(
+            public ConsumingNHttpEntity entityRequest(
                     HttpEntityEnclosingRequest request, HttpContext context)
                     throws HttpException, IOException {
-                return new ByteContentListener();
+                return new ConsumingNHttpEntityTemplate(
+                        request.getEntity(),
+                        new ByteContentListener());
             }
 
             public void handle(
                     HttpRequest request, HttpResponse response, HttpContext context)
                     throws HttpException, IOException {
                 if (request instanceof HttpEntityEnclosingRequest) {
-                    ConsumingNHttpEntity incoming = (ConsumingNHttpEntity)((HttpEntityEnclosingRequest) request).getEntity();
+                    ConsumingNHttpEntityTemplate incoming = (ConsumingNHttpEntityTemplate)((HttpEntityEnclosingRequest) request).getEntity();
                     byte[] b = ((ByteContentListener)incoming.getContentListener()).getContent();
                     NByteArrayEntity outgoing = new NByteArrayEntity(b);
                     outgoing.setChunked(false);
@@ -789,17 +796,19 @@
 
         NHttpRequestHandler requestHandler = new NHttpRequestHandler() {
 
-            public ContentListener entityRequest(
+            public ConsumingNHttpEntity entityRequest(
                     HttpEntityEnclosingRequest request, HttpContext context)
                     throws HttpException, IOException {
-                return new ByteContentListener();
+                return new ConsumingNHttpEntityTemplate(
+                        request.getEntity(),
+                        new ByteContentListener());
             }
 
             public void handle(
                     HttpRequest request, HttpResponse response, HttpContext context)
                     throws HttpException, IOException {
                 if (request instanceof HttpEntityEnclosingRequest) {
-                    ConsumingNHttpEntity incoming = (ConsumingNHttpEntity)((HttpEntityEnclosingRequest) request).getEntity();
+                    ConsumingNHttpEntityTemplate incoming = (ConsumingNHttpEntityTemplate)((HttpEntityEnclosingRequest) request).getEntity();
                     byte[] b = ((ByteContentListener)incoming.getContentListener()).getContent();
                     NByteArrayEntity outgoing = new NByteArrayEntity(b);
                     outgoing.setChunked(true);
@@ -922,10 +931,12 @@
 
         NHttpRequestHandler requestHandler = new NHttpRequestHandler() {
 
-            public ContentListener entityRequest(
+            public ConsumingNHttpEntity entityRequest(
                     HttpEntityEnclosingRequest request, HttpContext context)
                     throws HttpException, IOException {
-                return new ByteContentListener();
+                return new ConsumingNHttpEntityTemplate(
+                        request.getEntity(),
+                        new ByteContentListener());
             }
 
             public void handle(
@@ -1078,9 +1089,12 @@
 
         NHttpRequestHandler requestHandler = new NHttpRequestHandler() {
 
-            public ContentListener entityRequest(
-                    HttpEntityEnclosingRequest request, HttpContext context) {
-                throw new UnsupportedOperationException();
+            public ConsumingNHttpEntity entityRequest(
+                    HttpEntityEnclosingRequest request, HttpContext context)
+                    throws HttpException, IOException {
+                return new ConsumingNHttpEntityTemplate(
+                        request.getEntity(),
+                        new ByteContentListener());
             }
 
             public void handle(
@@ -1208,12 +1222,12 @@
     static class ByteContentListener implements ContentListener {
         final SimpleInputBuffer input = new SimpleInputBuffer(2048, new HeapByteBufferAllocator());
 
-        public void consumeContent(ContentDecoder decoder, IOControl ioctrl)
+        public void contentAvailable(ContentDecoder decoder, IOControl ioctrl)
                 throws IOException {
             input.consumeContent(decoder);
         }
 
-        public void finish() {
+        public void finished() {
             input.reset();
         }