hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r629214 [2/3] - in /httpcomponents/httpcore/branches/limewire_contrib/module-nio/src: examples/org/apache/http/examples/nio/ main/java/org/apache/http/nio/ main/java/org/apache/http/nio/entity/ main/java/org/apache/http/nio/protocol/ test/j...
Date Tue, 19 Feb 2008 20:13:55 GMT
Added: 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=629214&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
(added)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
Tue Feb 19 12:13:52 2008
@@ -0,0 +1,507 @@
+/*
+ * $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.protocol;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+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.HttpResponseFactory;
+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.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.ContentListener;
+import org.apache.http.nio.entity.NByteArrayEntity;
+import org.apache.http.nio.entity.ProducingNHttpEntity;
+import org.apache.http.nio.util.ByteBufferAllocator;
+import org.apache.http.nio.util.HeapByteBufferAllocator;
+import org.apache.http.params.DefaultedHttpParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.util.EncodingUtils;
+
+/**
+ * HTTP service handler implementation that works with
+ * {@link ConsumingNHttpEntity} and {@link ProducingNHttpEntity}. The contents
+ * of HTTP headers are stored in memory, HTTP entities are streamed directly
+ * from the NHttpEntity to the underlying channel (and vice versa).
+ * <p>
+ * When using this {@link NHttpServiceHandler}, it is important to ensure that
+ * entities supplied for writing implement ProducingNHttpEntity. Doing
+ * so will allow the entity to be written out asynchronously. If entities
+ * supplied for writing do not implement ProducingNHttpEntity, a delegate is
+ * added that buffers the entire contents in memory. Additionally, the buffering
+ * might take place in the I/O thread, which could cause I/O to block
+ * temporarily. For best results, ensure that all entities set on
+ * {@link HttpResponse HttpResponses} from
+ * {@link HttpRequestHandler HttpRequestHandlers} implement
+ * ProducingNHttpEntity.
+ * <p>
+ * If incoming requests have entities, HttpRequestHandlers <b>must not</b> call
+ * {@link HttpEntity#getContent()}. Doing so will throw an
+ * {@link UnsupportedOperationException}. Instead, handlers must expect that
+ * incoming entities implement ConsumingNHttpEntity and install a
+ * {@link ContentListener} on those entities. The ContentListener will be
+ * notified when new data is available for reading. After all data has been
+ * read, the response will automatically be sent.
+ * <p>
+ * To support legacy HttpRequestHandlers that do use getContent(), you can wrap
+ * the handler within a {@link NBlockingHttpRequestHandler}. Doing so will
+ * allow the handler to be processed on a new thread, in a blocking manner.
+ * <p>
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
+ * @author Steffen Pingel
+ */
+public class AsyncNHttpServiceHandler extends AbstractNHttpServiceHandler
+                                         implements NHttpServiceHandler {
+
+    protected NHttpRequestHandlerResolver handlerResolver;
+
+    public AsyncNHttpServiceHandler(final HttpProcessor httpProcessor,
+            final HttpResponseFactory responseFactory,
+            final ConnectionReuseStrategy connStrategy,
+            final ByteBufferAllocator allocator, final HttpParams params) {
+        super(httpProcessor, responseFactory, connStrategy, allocator, params);
+    }
+
+    public AsyncNHttpServiceHandler(final HttpProcessor httpProcessor,
+            final HttpResponseFactory responseFactory,
+            final ConnectionReuseStrategy connStrategy, final HttpParams params) {
+        this(httpProcessor, responseFactory, connStrategy,
+                new HeapByteBufferAllocator(), params);
+    }
+
+    public void setHandlerResolver(final NHttpRequestHandlerResolver handlerResolver) {
+        this.handlerResolver = handlerResolver;
+    }
+
+
+    public void connected(final NHttpServerConnection conn) {
+        HttpContext context = conn.getContext();
+
+        ServerConnState connState = new ServerConnState();
+        context.setAttribute(CONN_STATE, connState);
+        context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
+
+        if (this.eventListener != null) {
+            this.eventListener.connectionOpen(conn);
+        }
+    }
+
+    public void requestReceived(final NHttpServerConnection conn) {
+        HttpContext context = conn.getContext();
+
+        HttpRequest request = conn.getHttpRequest();
+        request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
+
+        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;
+
+        try {
+
+            if (request instanceof HttpEntityEnclosingRequest) {
+                if (((HttpEntityEnclosingRequest) request).expectContinue()) {
+                    response = this.responseFactory.newHttpResponse(
+                            ver, HttpStatus.SC_CONTINUE, context);
+                    response.setParams(
+                            new DefaultedHttpParams(response.getParams(), this.params));
+
+                    if (this.expectationVerifier != null) {
+                        try {
+                            this.expectationVerifier.verify(request, response, context);
+                        } catch (HttpException ex) {
+                            ex.printStackTrace();
+                            response = this.responseFactory.newHttpResponse(
+                                    HttpVersion.HTTP_1_0,
+                                    HttpStatus.SC_INTERNAL_SERVER_ERROR,
+                                    context);
+                            response.setParams(
+                                    new DefaultedHttpParams(response.getParams(), this.params));
+                            handleException(ex, response);
+                        }
+                    }
+
+                    if (response.getStatusLine().getStatusCode() < 200) {
+                        // Send 1xx response indicating the server expections
+                        // have been met
+                        conn.submitResponse(response);
+                    } else {
+                        conn.resetInput();
+                        sendResponse(conn, request, response);
+                    }
+                }
+                // Request content is expected.
+                // Wait until the request content is fully received
+            } else {
+                // No request content is expected.
+                // Process request right away
+                conn.suspendInput();
+                processRequest(conn, request);
+            }
+
+        } catch (IOException ex) {
+            shutdownConnection(conn, ex);
+            if (this.eventListener != null) {
+                this.eventListener.fatalIOException(ex, conn);
+            }
+        } catch (HttpException ex) {
+            closeConnection(conn, ex);
+            if (this.eventListener != null) {
+                this.eventListener.fatalProtocolException(ex, conn);
+            }
+        }
+
+    }
+
+    public void closed(final NHttpServerConnection conn) {
+        HttpContext context = conn.getContext();
+
+        ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE);
+        connState.finish();
+
+        if (this.eventListener != null) {
+            this.eventListener.connectionClosed(conn);
+        }
+    }
+
+    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, httpex);
+            if (eventListener != null) {
+                eventListener.fatalProtocolException(httpex, conn);
+            }
+            return;
+        }
+
+        HttpContext context = conn.getContext();
+        try {
+            HttpResponse response = this.responseFactory.newHttpResponse(
+                    HttpVersion.HTTP_1_0, HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
+            response.setParams(
+                    new DefaultedHttpParams(response.getParams(), this.params));
+            handleException(httpex, response);
+            response.setEntity(null);
+            sendResponse(conn, null, response);
+
+        } catch (IOException ex) {
+            shutdownConnection(conn, ex);
+            if (this.eventListener != null) {
+                this.eventListener.fatalIOException(ex, conn);
+            }
+        } catch (HttpException ex) {
+            closeConnection(conn, ex);
+            if (this.eventListener != null) {
+                this.eventListener.fatalProtocolException(ex, conn);
+            }
+        }
+    }
+
+    public void inputReady(final NHttpServerConnection conn, final ContentDecoder decoder)
{
+        HttpContext context = conn.getContext();
+        HttpEntityEnclosingRequest request = (HttpEntityEnclosingRequest) conn.getHttpRequest();
+        HttpEntity entity = request.getEntity();
+        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);
+            }
+
+            BasicConsumingNHttpEntity consumingEntity = (BasicConsumingNHttpEntity) entity;
+            consumingEntity.getContentListener().consumeContent(decoder, conn);
+
+            if (decoder.isCompleted()) {
+                conn.suspendInput();
+
+                if (!consumingEntity.isHandled()) {
+                    consumingEntity.setHandled(true);
+                    processRequest(conn, request);
+                }
+            }
+
+        } catch (IOException ex) {
+            shutdownConnection(conn, ex);
+            if (this.eventListener != null) {
+                this.eventListener.fatalIOException(ex, conn);
+            }
+        } catch (HttpException ex) {
+            closeConnection(conn, ex);
+            if (this.eventListener != null) {
+                this.eventListener.fatalProtocolException(ex, conn);
+            }
+        }
+    }
+
+    public void responseReady(final NHttpServerConnection conn) {
+        if (conn.isOpen()) {
+            // Make sure there is no input stuck in the session buffer
+            conn.requestInput();
+        }
+    }
+
+    public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder)
{
+        HttpContext context = conn.getContext();
+        HttpResponse response = conn.getHttpResponse();
+        ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE);
+
+        try {
+            ProducingNHttpEntity entity = (ProducingNHttpEntity) response.getEntity();
+            entity.produceContent(encoder, conn);
+
+            if (encoder.isCompleted()) {
+                connState.finishOutput();
+                if (!this.connStrategy.keepAlive(response, context)) {
+                    conn.close();
+                }
+            }
+
+        } catch (IOException ex) {
+            shutdownConnection(conn, ex);
+            if (this.eventListener != null) {
+                this.eventListener.fatalIOException(ex, conn);
+            }
+        }
+    }
+
+    @Override
+    protected void closeConnection(final NHttpConnection conn, final Throwable cause) {
+        HttpContext context = conn.getContext();
+        ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE);
+        connState.finish();
+
+        super.closeConnection(conn, cause);
+    }
+
+    @Override
+    protected void shutdownConnection(NHttpConnection conn, Throwable cause) {
+        HttpContext context = conn.getContext();
+        ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE);
+        connState.finish();
+
+        super.shutdownConnection(conn, cause);
+    }
+
+    private void handleException(final HttpException ex, final HttpResponse response) {
+        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;
+        }
+        response.setStatusCode(code);
+
+        byte[] msg = EncodingUtils.getAsciiBytes(ex.getMessage());
+        NByteArrayEntity entity = new NByteArrayEntity(msg);
+        entity.setContentType("text/plain; charset=US-ASCII");
+        response.setEntity(entity);
+    }
+
+    private void processRequest(
+            final NHttpServerConnection conn,
+            final HttpRequest request) throws IOException, HttpException {
+
+        HttpContext context = conn.getContext();
+        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 = this.responseFactory.newHttpResponse(
+                ver,
+                HttpStatus.SC_OK,
+                conn.getContext());
+        response.setParams(
+                new DefaultedHttpParams(response.getParams(), this.params));
+
+        try {
+
+            this.httpProcessor.process(request, context);
+
+            NHttpRequestHandler handler = getRequestHandler(request);
+            if (handler != null) {
+                handler.handle(request, response, context);
+            } else {
+                response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
+            }
+            sendResponse(conn, request, response);
+
+        } catch (HttpException ex) {
+            response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0,
+                    HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
+            response.setParams(
+                    new DefaultedHttpParams(response.getParams(), this.params));
+            handleException(ex, response);
+        }
+    }
+
+    private void sendResponse(final NHttpServerConnection conn,
+            HttpRequest request, HttpResponse response) throws IOException,
+            HttpException {
+        HttpContext context = conn.getContext();
+        ServerConnState connState = (ServerConnState) context.getAttribute(CONN_STATE);
+
+        // Now that a response is ready, we can cleanup the listener for the request.
+        connState.finishInput();
+
+        // Some processers need the request that generated this response.
+        context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
+        this.httpProcessor.process(response, context);
+        context.setAttribute(ExecutionContext.HTTP_REQUEST, null);
+
+        if (response.getEntity() != null && !canResponseHaveBody(request, response))
{
+            response.setEntity(null);
+        }
+
+        HttpEntity entity = response.getEntity();
+        if (entity != null) {
+            ProducingNHttpEntity producingEntity = (ProducingNHttpEntity) entity;
+            connState.setProducingEntity(producingEntity);
+        } else {
+            if (!this.connStrategy.keepAlive(response, context)) {
+                conn.close();
+            }
+        }
+
+        conn.submitResponse(response);
+    }
+
+    private NHttpRequestHandler getRequestHandler(HttpRequest request) {
+        NHttpRequestHandler handler = null;
+         if (this.handlerResolver != null) {
+             String requestURI = request.getRequestLine().getUri();
+             handler = this.handlerResolver.lookup(requestURI);
+         }
+
+         return handler;
+    }
+
+    static class ServerConnState {
+
+        private ContentListener consumingEntity;
+        private ProducingNHttpEntity producingEntity;
+
+        void finishInput() {
+            if (this.consumingEntity != null) {
+                this.consumingEntity.finish();
+                this.consumingEntity = null;
+            }
+        }
+
+        void finishOutput() {
+            if (this.producingEntity != null) {
+                this.producingEntity.finish();
+                this.producingEntity = null;
+            }
+        }
+
+        void finish() {
+            finishInput();
+            finishOutput();
+        }
+
+        public void setProducingEntity(final ProducingNHttpEntity producingEntity) {
+            this.producingEntity = producingEntity;
+        }
+
+        public void setConsumingEntity(final ContentListener consumingEntity) {
+            this.consumingEntity = consumingEntity;
+        }
+
+    }
+
+    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 void finish() {
+        }
+
+    }
+
+}

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

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

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

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java?rev=629214&r1=629213&r2=629214&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java
(original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java
Tue Feb 19 12:13:52 2008
@@ -34,7 +34,6 @@
 import java.io.IOException;
 
 import org.apache.http.ConnectionReuseStrategy;
-import org.apache.http.HttpConnection;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
@@ -46,16 +45,16 @@
 public abstract class NHttpHandlerBase {
 
     protected static final String CONN_STATE = "http.nio.conn-state";
-    
+
     protected final HttpProcessor httpProcessor;
     protected final ConnectionReuseStrategy connStrategy;
     protected final ByteBufferAllocator allocator;
     protected final HttpParams params;
-    
+
     protected EventListener eventListener;
-    
+
     public NHttpHandlerBase(
-            final HttpProcessor httpProcessor, 
+            final HttpProcessor httpProcessor,
             final ConnectionReuseStrategy connStrategy,
             final ByteBufferAllocator allocator,
             final HttpParams params) {
@@ -81,12 +80,12 @@
     public HttpParams getParams() {
         return this.params;
     }
-    
+
     public void setEventListener(final EventListener eventListener) {
         this.eventListener = eventListener;
     }
 
-    protected void closeConnection(final HttpConnection conn, final Throwable cause) {
+    protected void closeConnection(final NHttpConnection conn, final Throwable cause) {
         try {
             // Try to close it nicely
             conn.close();
@@ -98,14 +97,14 @@
             }
         }
     }
-    
-    protected void shutdownConnection(final HttpConnection conn, final Throwable cause) {
+
+    protected void shutdownConnection(final NHttpConnection conn, final Throwable cause)
{
         try {
             conn.shutdown();
         } catch (IOException ignore) {
         }
     }
-    
+
     protected void handleTimeout(final NHttpConnection conn) {
         try {
             if (conn.getStatus() == NHttpConnection.ACTIVE) {
@@ -124,19 +123,19 @@
         } catch (IOException ignore) {
         }
     }
-    
+
     protected 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 
+
+        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; 
+            && status != HttpStatus.SC_RESET_CONTENT;
     }
-    
+
 }

Added: 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=629214&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandler.java
(added)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandler.java
Tue Feb 19 12:13:52 2008
@@ -0,0 +1,51 @@
+/*
+ * $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.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpEntityEnclosingRequest;
+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.protocol.HttpContext;
+
+public interface NHttpRequestHandler {
+
+    ContentListener entityRequest(HttpEntityEnclosingRequest request, HttpContext context)
+        throws HttpException, IOException;
+
+    void handle(HttpRequest request, HttpResponse response, HttpContext context)
+            throws HttpException, IOException;
+
+}

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

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

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

Added: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerResolver.java?rev=629214&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerResolver.java
(added)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpRequestHandlerResolver.java
Tue Feb 19 12:13:52 2008
@@ -0,0 +1,46 @@
+/*
+ * $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.protocol;
+
+/**
+ * Interface to be implemented by objects that can resolve
+ * {@link NHttpRequestHandler} instances by request URI.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision:$
+ */
+public interface NHttpRequestHandlerResolver {
+
+    NHttpRequestHandler lookup(String requestURI);
+
+}

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

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

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

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java?rev=629214&r1=629213&r2=629214&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java
(original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java
Tue Feb 19 12:13:52 2008
@@ -31,67 +31,36 @@
 
 package org.apache.http.nio.protocol;
 
-import java.io.IOException;
-
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpResponseFactory;
-import org.apache.http.nio.NHttpServerConnection;
-import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.util.ByteBufferAllocator;
-import org.apache.http.nio.util.HeapByteBufferAllocator;
 import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HttpExpectationVerifier;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestHandlerResolver;
 
-public abstract class NHttpServiceHandlerBase extends NHttpHandlerBase
-                                              implements NHttpServiceHandler {
-
-    protected final HttpResponseFactory responseFactory;
+public abstract class NHttpServiceHandlerBase extends AbstractNHttpServiceHandler {
 
     protected HttpRequestHandlerResolver handlerResolver;
-    protected HttpExpectationVerifier expectationVerifier;
-    
+
     public NHttpServiceHandlerBase(
-            final HttpProcessor httpProcessor, 
+            final HttpProcessor httpProcessor,
             final HttpResponseFactory responseFactory,
             final ConnectionReuseStrategy connStrategy,
             final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(httpProcessor, connStrategy, allocator, params);
-        if (responseFactory == null) {
-            throw new IllegalArgumentException("Response factory may not be null");
-        }
-        this.responseFactory = responseFactory;
+        super(httpProcessor, responseFactory, connStrategy, allocator, params);
     }
 
     public NHttpServiceHandlerBase(
-            final HttpProcessor httpProcessor, 
+            final HttpProcessor httpProcessor,
             final HttpResponseFactory responseFactory,
             final ConnectionReuseStrategy connStrategy,
             final HttpParams params) {
-        this(httpProcessor, responseFactory, connStrategy, 
-                new HeapByteBufferAllocator(), params);
+        super(httpProcessor, responseFactory, connStrategy, params);
     }
-    
+
     public void setHandlerResolver(final HttpRequestHandlerResolver handlerResolver) {
         this.handlerResolver = handlerResolver;
     }
 
-    public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier)
{
-        this.expectationVerifier = expectationVerifier;
-    }
-
-    public void exception(final NHttpServerConnection conn, final IOException ex) {
-        shutdownConnection(conn, ex);
-        
-        if (this.eventListener != null) {
-            this.eventListener.fatalIOException(ex, conn);
-        }
-    }
-
-    public void timeout(final NHttpServerConnection conn) {
-        handleTimeout(conn);
-    }
-    
 }

Added: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/mockup/SimpleNHttpRequestHandlerResolver.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/mockup/SimpleNHttpRequestHandlerResolver.java?rev=629214&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/mockup/SimpleNHttpRequestHandlerResolver.java
(added)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/mockup/SimpleNHttpRequestHandlerResolver.java
Tue Feb 19 12:13:52 2008
@@ -0,0 +1,48 @@
+/*
+ * $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.mockup;
+
+import org.apache.http.nio.protocol.NHttpRequestHandler;
+import org.apache.http.nio.protocol.NHttpRequestHandlerResolver;
+
+public class SimpleNHttpRequestHandlerResolver implements NHttpRequestHandlerResolver {
+
+    private final NHttpRequestHandler handler;
+
+    public SimpleNHttpRequestHandlerResolver(final NHttpRequestHandler handler) {
+        this.handler = handler;
+    }
+
+    public NHttpRequestHandler lookup(final String requestURI) {
+        return this.handler;
+    }
+
+}

Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/mockup/SimpleNHttpRequestHandlerResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/mockup/SimpleNHttpRequestHandlerResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAllProtocol.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAllProtocol.java?rev=629214&r1=629213&r2=629214&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAllProtocol.java
(original)
+++ httpcomponents/httpcore/branches/limewire_contrib/module-nio/src/test/java/org/apache/http/nio/protocol/TestAllProtocol.java
Tue Feb 19 12:13:52 2008
@@ -43,6 +43,7 @@
         suite.addTest(TestBufferingNHttpHandlers.suite());
         suite.addTest(TestThrottlingNHttpHandler.suite());
         suite.addTest(TestNIOSSLHttp.suite());
+        suite.addTest(TestAsyncNHttpHandlers.suite());
         return suite;
     }
 



Mime
View raw message