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/03/10 20:22:13 UTC

svn commit: r635662 - in /httpcomponents/httpcore/trunk/module-nio/src: main/java/org/apache/http/nio/protocol/ test/java/org/apache/http/nio/protocol/

Author: olegk
Date: Mon Mar 10 12:22:07 2008
New Revision: 635662

URL: http://svn.apache.org/viewvc?rev=635662&view=rev
Log:
* Eliminated superfluous abstract / base protocol handlers

Removed:
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AbstractNHttpClientHandler.java
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AbstractNHttpServiceHandler.java
Modified:
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java
    httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
    httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandler.java

Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java?rev=635662&r1=635661&r2=635662&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java Mon Mar 10 12:22:07 2008
@@ -43,6 +43,7 @@
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.entity.ConsumingNHttpEntity;
 import org.apache.http.nio.entity.ConsumingNHttpEntityTemplate;
 import org.apache.http.nio.entity.NHttpEntityWrapper;
@@ -68,7 +69,8 @@
  * @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
  *
  */
-public class AsyncNHttpClientHandler extends AbstractNHttpClientHandler {
+public class AsyncNHttpClientHandler extends NHttpHandlerBase
+                                     implements NHttpClientHandler {
 
     protected NHttpRequestExecutionHandler execHandler;
 
@@ -109,7 +111,6 @@
         requestReady(conn);
     }
 
-    @Override
     public void closed(final NHttpClientConnection conn) {
         HttpContext context = conn.getContext();
 
@@ -123,6 +124,20 @@
         }
     }
 
+    public void exception(final NHttpClientConnection conn, final HttpException ex) {
+        closeConnection(conn, ex);
+        if (this.eventListener != null) {
+            this.eventListener.fatalProtocolException(ex, conn);
+        }
+    }
+
+    public void exception(final NHttpClientConnection conn, final IOException ex) {
+        shutdownConnection(conn, ex);
+        if (this.eventListener != null) {
+            this.eventListener.fatalIOException(ex, conn);
+        }
+    }
+    
     public void requestReady(final NHttpClientConnection conn) {
         HttpContext context = conn.getContext();
 

Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java?rev=635662&r1=635661&r2=635662&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpServiceHandler.java Mon Mar 10 12:22:07 2008
@@ -63,6 +63,7 @@
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.ExecutionContext;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpExpectationVerifier;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.util.EncodingUtils;
 
@@ -92,10 +93,13 @@
  * @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a>
  * @author Steffen Pingel
  */
-public class AsyncNHttpServiceHandler extends AbstractNHttpServiceHandler
-                                         implements NHttpServiceHandler {
+public class AsyncNHttpServiceHandler extends NHttpHandlerBase
+                                      implements NHttpServiceHandler {
+
+    protected final HttpResponseFactory responseFactory;
 
     protected NHttpRequestHandlerResolver handlerResolver;
+    protected HttpExpectationVerifier expectationVerifier;
 
     public AsyncNHttpServiceHandler(
             final HttpProcessor httpProcessor,
@@ -103,7 +107,11 @@
             final ConnectionReuseStrategy connStrategy,
             final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(httpProcessor, responseFactory, connStrategy, allocator, params);
+        super(httpProcessor, connStrategy, allocator, params);
+        if (responseFactory == null) {
+            throw new IllegalArgumentException("Response factory may not be null");
+        }
+        this.responseFactory = responseFactory;
     }
 
     public AsyncNHttpServiceHandler(
@@ -115,6 +123,10 @@
                 new HeapByteBufferAllocator(), params);
     }
 
+    public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier) {
+        this.expectationVerifier = expectationVerifier;
+    }
+
     public void setHandlerResolver(final NHttpRequestHandlerResolver handlerResolver) {
         this.handlerResolver = handlerResolver;
     }
@@ -264,6 +276,18 @@
                 this.eventListener.fatalProtocolException(ex, conn);
             }
         }
+    }
+
+    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);
     }
 
     public void inputReady(final NHttpServerConnection conn, final ContentDecoder decoder) {

Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java?rev=635662&r1=635661&r2=635662&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java Mon Mar 10 12:22:07 2008
@@ -31,12 +31,19 @@
 
 package org.apache.http.nio.protocol;
 
+import java.io.IOException;
+
 import org.apache.http.ConnectionReuseStrategy;
+import org.apache.http.HttpException;
+import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.util.ByteBufferAllocator;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.HttpProcessor;
 
-public abstract class NHttpClientHandlerBase extends AbstractNHttpClientHandler {
+@Deprecated
+public abstract class NHttpClientHandlerBase extends NHttpHandlerBase
+                                             implements NHttpClientHandler {
 
     protected HttpRequestExecutionHandler execHandler;
 
@@ -51,6 +58,26 @@
             throw new IllegalArgumentException("HTTP request execution handler may not be null.");
         }
         this.execHandler = execHandler;
+    }
+
+    public void closed(final NHttpClientConnection conn) {
+        if (this.eventListener != null) {
+            this.eventListener.connectionClosed(conn);
+        }
+    }
+
+    public void exception(final NHttpClientConnection conn, final HttpException ex) {
+        closeConnection(conn, ex);
+        if (this.eventListener != null) {
+            this.eventListener.fatalProtocolException(ex, conn);
+        }
+    }
+
+    public void exception(final NHttpClientConnection conn, final IOException ex) {
+        shutdownConnection(conn, ex);
+        if (this.eventListener != null) {
+            this.eventListener.fatalIOException(ex, conn);
+        }
     }
 
 }

Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java?rev=635662&r1=635661&r2=635662&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java Mon Mar 10 12:22:07 2008
@@ -31,15 +31,26 @@
 
 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 AbstractNHttpServiceHandler {
+@Deprecated
+public abstract class NHttpServiceHandlerBase extends NHttpHandlerBase
+                                              implements NHttpServiceHandler {
+
+    protected final HttpResponseFactory responseFactory;
 
+    protected HttpExpectationVerifier expectationVerifier;
     protected HttpRequestHandlerResolver handlerResolver;
 
     public NHttpServiceHandlerBase(
@@ -48,7 +59,11 @@
             final ConnectionReuseStrategy connStrategy,
             final ByteBufferAllocator allocator,
             final HttpParams params) {
-        super(httpProcessor, responseFactory, connStrategy, allocator, params);
+        super(httpProcessor, connStrategy, allocator, params);
+        if (responseFactory == null) {
+            throw new IllegalArgumentException("Response factory may not be null");
+        }
+        this.responseFactory = responseFactory;
     }
 
     public NHttpServiceHandlerBase(
@@ -56,11 +71,28 @@
             final HttpResponseFactory responseFactory,
             final ConnectionReuseStrategy connStrategy,
             final HttpParams params) {
-        super(httpProcessor, responseFactory, connStrategy, params);
+        this(httpProcessor, responseFactory, connStrategy, 
+                new HeapByteBufferAllocator(), 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);
     }
 
 }

Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java?rev=635662&r1=635661&r2=635662&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java Mon Mar 10 12:22:07 2008
@@ -46,6 +46,7 @@
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
 import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.NHttpConnection;
 import org.apache.http.nio.entity.ContentBufferEntity;
 import org.apache.http.nio.entity.ContentOutputStream;
@@ -81,8 +82,10 @@
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  */
-public class ThrottlingHttpClientHandler extends NHttpClientHandlerBase {
+public class ThrottlingHttpClientHandler extends NHttpHandlerBase
+                                         implements NHttpClientHandler {
 
+    protected HttpRequestExecutionHandler execHandler;
     protected final Executor executor;
     
     public ThrottlingHttpClientHandler(
@@ -92,10 +95,14 @@
             final ByteBufferAllocator allocator,
             final Executor executor,
             final HttpParams params) {
-        super(httpProcessor, execHandler, connStrategy, allocator, params);
+        super(httpProcessor, connStrategy, allocator, params);
+        if (execHandler == null) {
+            throw new IllegalArgumentException("HTTP request execution handler may not be null.");
+        }
         if (executor == null) {
             throw new IllegalArgumentException("Executor may not be null");
         }
+        this.execHandler = execHandler;
         this.executor = executor;
     }
     
@@ -126,18 +133,31 @@
         requestReady(conn);        
     }
 
-    @Override
     public void closed(final NHttpClientConnection conn) {
         HttpContext context = conn.getContext();
 
         this.execHandler.finalizeContext(context);
         
-        // TODO - replace with super.closed(conn); ?
         if (this.eventListener != null) {
             this.eventListener.connectionClosed(conn);
         }
     }
 
+    public void exception(final NHttpClientConnection conn, final HttpException ex) {
+        closeConnection(conn, ex);
+        if (this.eventListener != null) {
+            this.eventListener.fatalProtocolException(ex, conn);
+        }
+    }
+
+    public void exception(final NHttpClientConnection conn, final IOException ex) {
+        shutdownConnection(conn, ex);
+        if (this.eventListener != null) {
+            this.eventListener.fatalIOException(ex, conn);
+        }
+    }
+
+    
     public void requestReady(final NHttpClientConnection conn) {
         HttpContext context = conn.getContext();
 

Modified: httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java?rev=635662&r1=635661&r2=635662&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java Mon Mar 10 12:22:07 2008
@@ -54,6 +54,7 @@
 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.ContentBufferEntity;
 import org.apache.http.nio.entity.ContentOutputStream;
 import org.apache.http.nio.params.NIOReactorPNames;
@@ -67,8 +68,10 @@
 import org.apache.http.params.DefaultedHttpParams;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpExpectationVerifier;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.protocol.HttpRequestHandlerResolver;
 import org.apache.http.util.EncodingUtils;
 
 /**
@@ -88,9 +91,14 @@
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  */
-public class ThrottlingHttpServiceHandler extends NHttpServiceHandlerBase {
+public class ThrottlingHttpServiceHandler extends NHttpHandlerBase
+                                          implements NHttpServiceHandler {
 
+    protected final HttpResponseFactory responseFactory;
     protected final Executor executor;
+
+    protected HttpRequestHandlerResolver handlerResolver;
+    protected HttpExpectationVerifier expectationVerifier;
     
     public ThrottlingHttpServiceHandler(
             final HttpProcessor httpProcessor, 
@@ -99,7 +107,14 @@
             final ByteBufferAllocator allocator,
             final Executor executor,
             final HttpParams params) {
-        super(httpProcessor, responseFactory, connStrategy, allocator, params);
+        super(httpProcessor, connStrategy, allocator, params);
+        if (responseFactory == null) {
+            throw new IllegalArgumentException("Response factory may not be null");
+        }
+        if (executor == null) {
+            throw new IllegalArgumentException("Executor may not be null");
+        }
+        this.responseFactory = responseFactory;
         this.executor = executor;
     }
 
@@ -113,6 +128,14 @@
                 new DirectByteBufferAllocator(), executor, params);
     }
 
+    public void setHandlerResolver(final HttpRequestHandlerResolver handlerResolver) {
+        this.handlerResolver = handlerResolver;
+    }
+    
+    public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier) {
+        this.expectationVerifier = expectationVerifier;
+    }
+
     public void connected(final NHttpServerConnection conn) {
         HttpContext context = conn.getContext();
 
@@ -181,6 +204,18 @@
                 eventListener.fatalProtocolException(ex, conn);
             }
         }
+    }
+
+    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);
     }
 
     public void requestReceived(final NHttpServerConnection conn) {

Modified: httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandler.java?rev=635662&r1=635661&r2=635662&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandler.java (original)
+++ httpcomponents/httpcore/trunk/module-nio/src/test/java/org/apache/http/nio/protocol/TestThrottlingNHttpHandler.java Mon Mar 10 12:22:07 2008
@@ -1,7 +1,7 @@
 /*
- * $HeadURL:$
- * $Revision:$
- * $Date:$
+ * $HeadURL$
+ * $Revision$
+ * $Date$
  * ====================================================================
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -82,7 +82,7 @@
  *
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  * 
- * @version $Id:$
+ * @version $Id$
  */
 public class TestThrottlingNHttpHandler extends TestCase {
 
@@ -149,7 +149,7 @@
         httpproc.addInterceptor(new ResponseContent());
         httpproc.addInterceptor(new ResponseConnControl());
 
-        NHttpServiceHandlerBase serviceHandler = new ThrottlingHttpServiceHandler(
+        ThrottlingHttpServiceHandler serviceHandler = new ThrottlingHttpServiceHandler(
                 httpproc,
                 new DefaultHttpResponseFactory(),
                 new DefaultConnectionReuseStrategy(),