hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1296856 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
Date Sun, 04 Mar 2012 19:02:37 GMT
Author: olegk
Date: Sun Mar  4 19:02:37 2012
New Revision: 1296856

URL: http://svn.apache.org/viewvc?rev=1296856&view=rev
Log:
Make sure the request execution handler gets closed in case #requestReady never fired to due
an unexpected connection shutdown

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1296856&r1=1296855&r2=1296856&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Sun Mar  4 19:02:37 2012
@@ -31,6 +31,7 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.net.SocketTimeoutException;
 
+import org.apache.http.ConnectionClosedException;
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpConnection;
 import org.apache.http.HttpEntityEnclosingRequest;
@@ -108,6 +109,18 @@ public class HttpAsyncRequestExecutor im
             }
             state.reset();
         }
+        // Make sure the request handler gets closed in case #requestReady never fired
+        // to due unexpected connection shutdown.
+        HttpAsyncRequestExecutionHandler<?> handler = (HttpAsyncRequestExecutionHandler<?>)
conn.
+                getContext().removeAttribute(HTTP_HANDLER);
+        if (handler != null) {
+            handler.failed(new ConnectionClosedException("Connection closed"));
+            try {
+                handler.close();
+            } catch (IOException ioex) {
+                log(ioex);
+            }
+        }
     }
 
     public void exception(

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java?rev=1296856&r1=1296855&r2=1296856&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
Sun Mar  4 19:02:37 2012
@@ -32,6 +32,7 @@ import java.net.SocketTimeoutException;
 
 import junit.framework.Assert;
 
+import org.apache.http.ConnectionClosedException;
 import org.apache.http.ConnectionReuseStrategy;
 import org.apache.http.HttpException;
 import org.apache.http.HttpRequest;
@@ -143,6 +144,16 @@ public class TestHttpAsyncRequestExecuto
     }
 
     @Test
+    public void testClosedUnexpectedly() throws Exception {
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
+
+        this.protocolHandler.closed(this.conn);
+
+        Mockito.verify(this.exchangeHandler).failed(Mockito.any(ConnectionClosedException.class));
+        Mockito.verify(this.exchangeHandler).close();
+    }
+
+    @Test
     public void testHttpExceptionHandling() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.COMPLETED);



Mime
View raw message