hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1331596 - 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 Fri, 27 Apr 2012 21:04:40 GMT
Author: olegk
Date: Fri Apr 27 21:04:40 2012
New Revision: 1331596

URL: http://svn.apache.org/viewvc?rev=1331596&view=rev
Log:
Fixed HttpAsyncRequestExecutor incorrect execution of message exchanges that span across multiple
hosts (for instance, in case of a request redirect)

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=1331596&r1=1331595&r2=1331596&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Fri Apr 27 21:04:40 2012
@@ -15,6 +15,10 @@ primitives. 
 Changelog
 -------------------
 
+* Fixed HttpAsyncRequestExecutor incorrect execution of message exchanges that span across
multiple 
+  hosts (for instance, in case of a request redirect).  
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * AbstractHttpClientConnection#isResponseAvailable method now catches SocketTimeoutException
   and returns false.
   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=1331596&r1=1331595&r2=1331596&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
Fri Apr 27 21:04:40 2012
@@ -31,7 +31,6 @@ 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;
@@ -103,33 +102,20 @@ public class HttpAsyncRequestExecutor im
 
     public void closed(final NHttpClientConnection conn) {
         State state = getState(conn);
+        HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
         if (state != null) {
-            if (!state.isValid()) {
-                closeHandler(state);
-            }
             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);
-            }
+        } else {
+            closeHandler(handler, null);
         }
     }
 
     public void exception(
             final NHttpClientConnection conn, final Exception cause) {
         shutdownConnection(conn);
-        State state = getState(conn);
-        if (state != null) {
-            closeHandler(state, cause);
-            state.reset();
+        HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
+        if (handler != null) {
+            closeHandler(handler, cause);
         } else {
             log(cause);
         }
@@ -141,18 +127,13 @@ public class HttpAsyncRequestExecutor im
         if (state.getRequestState() != MessageState.READY) {
             return;
         }
-        HttpAsyncRequestExecutionHandler<?> handler = state.getHandler();
+        HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
         if (handler != null && handler.isDone()) {
-            closeHandler(state);
+            closeHandler(handler, null);
             state.reset();
             handler = null;
         }
         if (handler == null) {
-            handler = (HttpAsyncRequestExecutionHandler<?>) conn.getContext().removeAttribute(
-                    HTTP_HANDLER);
-            state.setHandler(handler);
-        }
-        if (handler == null) {
             return;
         }
 
@@ -192,7 +173,7 @@ public class HttpAsyncRequestExecutor im
             final NHttpClientConnection conn,
             final ContentEncoder encoder) throws IOException {
         State state = ensureNotNull(getState(conn));
-        HttpAsyncRequestExecutionHandler<?> handler = ensureNotNull(state.getHandler());
+        HttpAsyncRequestExecutionHandler<?> handler = ensureNotNull(getHandler(conn));
         if (state.getRequestState() == MessageState.ACK_EXPECTED) {
             conn.suspendOutput();
             return;
@@ -209,7 +190,7 @@ public class HttpAsyncRequestExecutor im
     public void responseReceived(
             final NHttpClientConnection conn) throws HttpException, IOException {
         State state = ensureNotNull(getState(conn));
-        HttpAsyncRequestExecutionHandler<?> handler = ensureNotNull(state.getHandler());
+        HttpAsyncRequestExecutionHandler<?> handler = ensureNotNull(getHandler(conn));
         HttpResponse response = conn.getHttpResponse();
         HttpRequest request = state.getRequest();
 
@@ -261,7 +242,7 @@ public class HttpAsyncRequestExecutor im
             final NHttpClientConnection conn,
             final ContentDecoder decoder) throws IOException {
         State state = ensureNotNull(getState(conn));
-        HttpAsyncRequestExecutionHandler<?> handler = ensureNotNull(state.getHandler());
+        HttpAsyncRequestExecutionHandler<?> handler = ensureNotNull(getHandler(conn));
         handler.consumeContent(decoder, conn);
         state.setResponseState(MessageState.BODY_STREAM);
         if (decoder.isCompleted()) {
@@ -285,7 +266,7 @@ public class HttpAsyncRequestExecutor im
                 return;
             } else {
                 state.invalidate();
-                closeHandler(state, new SocketTimeoutException());
+                closeHandler(getHandler(conn), new SocketTimeoutException());
             }
         }
         if (conn.getStatus() == NHttpConnection.ACTIVE) {
@@ -320,6 +301,10 @@ public class HttpAsyncRequestExecutor im
         return state;
     }
 
+    private HttpAsyncRequestExecutionHandler<?> getHandler(final NHttpConnection conn)
{
+        return (HttpAsyncRequestExecutionHandler<?>) conn.getContext().getAttribute(HTTP_HANDLER);
+    }
+
     private HttpAsyncRequestExecutionHandler<?> ensureNotNull(final HttpAsyncRequestExecutionHandler<?>
handler) {
         if (handler == null) {
             throw new IllegalStateException("HTTP exchange handler is null");
@@ -335,11 +320,12 @@ public class HttpAsyncRequestExecutor im
         }
     }
 
-    private void closeHandler(final State state, final Exception ex) {
-        HttpAsyncRequestExecutionHandler<?> handler = state.getHandler();
+    private void closeHandler(final HttpAsyncRequestExecutionHandler<?> handler, final
Exception ex) {
         if (handler != null) {
             try {
-                handler.failed(ex);
+                if (ex != null) {
+                    handler.failed(ex);
+                }
             } finally {
                 try {
                     handler.close();
@@ -350,18 +336,6 @@ public class HttpAsyncRequestExecutor im
         }
     }
 
-    private void closeHandler(final State state) {
-        HttpAsyncRequestExecutionHandler<?> handler = state.getHandler();
-        if (handler != null) {
-            state.setHandler(null);
-            try {
-                handler.close();
-            } catch (IOException ioex) {
-                log(ioex);
-            }
-        }
-    }
-
     private void processResponse(
             final NHttpClientConnection conn,
             final State state,
@@ -406,7 +380,6 @@ public class HttpAsyncRequestExecutor im
 
     static class State {
 
-        private volatile HttpAsyncRequestExecutionHandler<?> handler;
         private volatile MessageState requestState;
         private volatile MessageState responseState;
         private volatile HttpRequest request;
@@ -421,14 +394,6 @@ public class HttpAsyncRequestExecutor im
             this.responseState = MessageState.READY;
         }
 
-        public HttpAsyncRequestExecutionHandler<?> getHandler() {
-            return this.handler;
-        }
-
-        public void setHandler(final HttpAsyncRequestExecutionHandler<?> handler) {
-            this.handler = handler;
-        }
-
         public MessageState getRequestState() {
             return this.requestState;
         }

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=1331596&r1=1331595&r2=1331596&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
Fri Apr 27 21:04:40 2012
@@ -32,7 +32,6 @@ 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;
@@ -102,7 +101,6 @@ public class TestHttpAsyncRequestExecuto
         State state = (State) this.connContext.getAttribute(
                 HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE);
         Assert.assertNotNull(state);
-        Assert.assertSame(this.exchangeHandler, state.getHandler());
         Mockito.verify(this.exchangeHandler).generateRequest();
         Assert.assertSame(request, state.getRequest());
         Mockito.verify(this.conn).submitRequest(request);
@@ -117,8 +115,8 @@ public class TestHttpAsyncRequestExecuto
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.COMPLETED);
         state.setResponseState(MessageState.COMPLETED);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
 
         this.protocolHandler.closed(this.conn);
 
@@ -128,28 +126,11 @@ public class TestHttpAsyncRequestExecuto
     }
 
     @Test
-    public void testClosedInvalidState() throws Exception {
-        State state = new HttpAsyncRequestExecutor.State();
-        state.setRequestState(MessageState.COMPLETED);
-        state.setResponseState(MessageState.COMPLETED);
-        state.invalidate();
-        state.setHandler(this.exchangeHandler);
-        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
-
-        this.protocolHandler.closed(this.conn);
-
-        Assert.assertEquals(MessageState.READY, state.getRequestState());
-        Assert.assertEquals(MessageState.READY, state.getResponseState());
-        Mockito.verify(this.exchangeHandler).close();
-    }
-
-    @Test
-    public void testClosedUnexpectedly() throws Exception {
+    public void testClosedNullState() 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();
     }
 
@@ -158,8 +139,8 @@ public class TestHttpAsyncRequestExecuto
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.COMPLETED);
         state.setResponseState(MessageState.COMPLETED);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
 
         HttpException httpex = new HttpException();
         this.protocolHandler.exception(this.conn, httpex);
@@ -174,8 +155,8 @@ public class TestHttpAsyncRequestExecuto
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.COMPLETED);
         state.setResponseState(MessageState.COMPLETED);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
 
         IOException ioex = new IOException();
         this.protocolHandler.exception(this.conn, ioex);
@@ -188,8 +169,8 @@ public class TestHttpAsyncRequestExecuto
     @Test
     public void testBasicRequest() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         HttpRequest request = new BasicHttpRequest("GET", "/");
         Mockito.when(this.exchangeHandler.generateRequest()).thenReturn(request);
 
@@ -211,8 +192,8 @@ public class TestHttpAsyncRequestExecuto
     @Test
     public void testEntityEnclosingRequestWithoutExpectContinue() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
"/");
         request.setEntity(new NStringEntity("stuff"));
         Mockito.when(this.exchangeHandler.generateRequest()).thenReturn(request);
@@ -229,8 +210,8 @@ public class TestHttpAsyncRequestExecuto
     @Test
     public void testEntityEnclosingRequestWithExpectContinue() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
"/");
         request.setHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
         Mockito.when(this.exchangeHandler.generateRequest()).thenReturn(request);
@@ -250,8 +231,8 @@ public class TestHttpAsyncRequestExecuto
     @Test
     public void testRequestContentOutput() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.encoder.isCompleted()).thenReturn(false);
 
         this.protocolHandler.outputReady(this.conn, this.encoder);
@@ -263,8 +244,8 @@ public class TestHttpAsyncRequestExecuto
     @Test
     public void testRequestContentOutputCompleted() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.encoder.isCompleted()).thenReturn(true);
 
         this.protocolHandler.outputReady(this.conn, this.encoder);
@@ -278,8 +259,8 @@ public class TestHttpAsyncRequestExecuto
     public void testRequestContentContinueExpected() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.ACK_EXPECTED);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
 
         this.protocolHandler.outputReady(this.conn, this.encoder);
 
@@ -293,8 +274,8 @@ public class TestHttpAsyncRequestExecuto
         State state = new HttpAsyncRequestExecutor.State();
         HttpRequest request = new BasicHttpRequest("GET", "/");
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
 
@@ -314,8 +295,8 @@ public class TestHttpAsyncRequestExecuto
         BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
"/");
         request.setEntity(new NStringEntity("stuff"));
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
 
@@ -335,8 +316,8 @@ public class TestHttpAsyncRequestExecuto
         BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
"/");
         request.setEntity(new NStringEntity("stuff"));
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
 
@@ -355,8 +336,8 @@ public class TestHttpAsyncRequestExecuto
         BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
"/");
         request.setEntity(new NStringEntity("stuff"));
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 111, "WTF?");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
 
@@ -371,8 +352,8 @@ public class TestHttpAsyncRequestExecuto
         BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
"/");
         request.setEntity(new NStringEntity("stuff"));
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 403, "Unauthorized");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
 
@@ -393,8 +374,8 @@ public class TestHttpAsyncRequestExecuto
         BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST",
"/");
         request.setEntity(new NStringEntity("stuff"));
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 403, "Unauthorized");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
 
@@ -413,8 +394,8 @@ public class TestHttpAsyncRequestExecuto
         State state = new HttpAsyncRequestExecutor.State();
         HttpRequest request = new BasicHttpRequest("HEAD", "/");
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
         Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(true);
@@ -435,8 +416,8 @@ public class TestHttpAsyncRequestExecuto
         State state = new HttpAsyncRequestExecutor.State();
         HttpRequest request = new BasicHttpRequest("Connect", "/");
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
         Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(true);
@@ -457,8 +438,8 @@ public class TestHttpAsyncRequestExecuto
         State state = new HttpAsyncRequestExecutor.State();
         HttpRequest request = new BasicHttpRequest("Connect", "/");
         state.setRequest(request);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
                 HttpStatus.SC_NOT_MODIFIED, "Not modified");
         Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
@@ -478,8 +459,8 @@ public class TestHttpAsyncRequestExecuto
     @Test
     public void testResponseContentInput() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.decoder.isCompleted()).thenReturn(false);
 
         this.protocolHandler.inputReady(this.conn, this.decoder);
@@ -495,8 +476,8 @@ public class TestHttpAsyncRequestExecuto
         state.setRequest(request);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
         state.setResponse(response);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(true);
         Mockito.when(this.decoder.isCompleted()).thenReturn(true);
 
@@ -517,8 +498,8 @@ public class TestHttpAsyncRequestExecuto
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
         state.setResponse(response);
         state.invalidate();
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.decoder.isCompleted()).thenReturn(true);
 
         this.protocolHandler.inputReady(this.conn, this.decoder);
@@ -537,8 +518,8 @@ public class TestHttpAsyncRequestExecuto
         state.setRequest(request);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
         state.setResponse(response);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(false);
         Mockito.when(this.decoder.isCompleted()).thenReturn(true);
 
@@ -570,8 +551,8 @@ public class TestHttpAsyncRequestExecuto
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.ACK_EXPECTED);
         state.setTimeout(1000);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
 
         this.protocolHandler.timeout(this.conn);
 
@@ -585,8 +566,8 @@ public class TestHttpAsyncRequestExecuto
     public void testTimeoutActiveConnection() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.BODY_STREAM);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.conn.getStatus()).thenReturn(NHttpConnection.ACTIVE, NHttpConnection.CLOSED);
 
         this.protocolHandler.timeout(this.conn);
@@ -603,8 +584,8 @@ public class TestHttpAsyncRequestExecuto
     public void testTimeoutActiveConnectionBufferedData() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.BODY_STREAM);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.conn.getStatus()).thenReturn(NHttpConnection.ACTIVE, NHttpConnection.CLOSING);
 
         this.protocolHandler.timeout(this.conn);
@@ -621,8 +602,8 @@ public class TestHttpAsyncRequestExecuto
     public void testTimeoutClosingConnection() throws Exception {
         State state = new HttpAsyncRequestExecutor.State();
         state.setRequestState(MessageState.BODY_STREAM);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.conn.getStatus()).thenReturn(NHttpConnection.CLOSING, NHttpConnection.CLOSED);
 
         this.protocolHandler.timeout(this.conn);
@@ -641,8 +622,8 @@ public class TestHttpAsyncRequestExecuto
         state.setRequest(request);
         BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
         state.setResponse(response);
-        state.setHandler(this.exchangeHandler);
         this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
+        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
         Mockito.when(this.exchangeHandler.isDone()).thenReturn(true);
 
         Assert.assertEquals("request state: READY; request: GET / HTTP/1.1; " +
@@ -653,7 +634,6 @@ public class TestHttpAsyncRequestExecuto
 
         Assert.assertEquals(MessageState.READY, state.getRequestState());
         Assert.assertEquals(MessageState.READY, state.getResponseState());
-        Assert.assertNull(state.getHandler());
     }
 
 }



Mime
View raw message