hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1569024 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
Date Mon, 17 Feb 2014 15:35:49 GMT
Author: olegk
Date: Mon Feb 17 15:35:49 2014
New Revision: 1569024

URL: http://svn.apache.org/r1569024
Log:
HTTPASYNC-69: async request handler is closed by HttpAsyncRequestExecutor#closed if the underlying
connection is found to be in an inconsistent state

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    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/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1569024&r1=1569023&r2=1569024&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Mon Feb 17 15:35:49 2014
@@ -1,6 +1,10 @@
 Changes for release 4.4-alpha1
 -------------------
 
+* [HTTPASYNC-69]: async request handler is closed by HttpAsyncRequestExecutor#closed 
+  if the underlying connection is found to be in an inconsistent state.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCORE-373] Out of sequence HTTP response causes NPE in HttpAsyncRequestExecutor.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

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=1569024&r1=1569023&r2=1569024&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
Mon Feb 17 15:35:49 2014
@@ -109,12 +109,16 @@ public class HttpAsyncRequestExecutor im
     public void closed(final NHttpClientConnection conn) {
         final State state = getState(conn);
         final HttpAsyncClientExchangeHandler handler = getHandler(conn);
+        if (state != null) {
+            if (state.getRequestState() != MessageState.READY || state.getResponseState()
!= MessageState.READY) {
+                if (handler != null) {
+                    handler.failed(new ConnectionClosedException("Connection closed unexpectedly"));
+                }
+            }
+        }
         if (state == null || (handler != null && handler.isDone())) {
             closeHandler(handler);
         }
-        if (state != null) {
-            state.reset();
-        }
     }
 
     @Override

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=1569024&r1=1569023&r2=1569024&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
Mon Feb 17 15:35:49 2014
@@ -101,15 +101,13 @@ public class TestHttpAsyncRequestExecuto
     @Test
     public void testClosed() throws Exception {
         final State state = new HttpAsyncRequestExecutor.State();
-        state.setRequestState(MessageState.COMPLETED);
-        state.setResponseState(MessageState.COMPLETED);
+        state.setRequestState(MessageState.READY);
+        state.setResponseState(MessageState.READY);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
 
         this.protocolHandler.closed(this.conn);
 
-        Assert.assertEquals(MessageState.READY, state.getRequestState());
-        Assert.assertEquals(MessageState.READY, state.getResponseState());
         Mockito.verify(this.exchangeHandler, Mockito.never()).close();
     }
 
@@ -123,6 +121,19 @@ public class TestHttpAsyncRequestExecuto
     }
 
     @Test
+    public void testClosedInconsistentState() throws Exception {
+        final State state = new HttpAsyncRequestExecutor.State();
+        state.setRequestState(MessageState.COMPLETED);
+        state.setResponseState(MessageState.INIT);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
+
+        this.protocolHandler.closed(this.conn);
+
+        Mockito.verify(this.exchangeHandler).failed(Mockito.any(ConnectionClosedException.class));
+    }
+
+    @Test
     public void testHttpExceptionHandling() throws Exception {
         final State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.COMPLETED);



Mime
View raw message