hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1362541 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src: main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
Date Tue, 17 Jul 2012 15:28:28 GMT
Author: olegk
Date: Tue Jul 17 15:28:28 2012
New Revision: 1362541

URL: http://svn.apache.org/viewvc?rev=1362541&view=rev
Log:
Temporary workaround for HTTPASYNC-21

Modified:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java?rev=1362541&r1=1362540&r2=1362541&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
Tue Jul 17 15:28:28 2012
@@ -28,13 +28,16 @@
 package org.apache.http.impl.nio.client;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.http.ConnectionClosedException;
 import org.apache.http.HttpException;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
 import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
 
 class LoggingAsyncRequestExecutor extends HttpAsyncRequestExecutor {
@@ -128,4 +131,23 @@ class LoggingAsyncRequestExecutor extend
         super.timeout(conn);
     }
 
+    @Override
+    public void endOfInput(NHttpClientConnection conn) throws IOException {
+        ///
+        /// TODO: remove when fix for HTTPASYNC-21 is available in HttpCore stable release
+        ///
+        HttpAsyncRequestExecutionHandler<?> handler = (HttpAsyncRequestExecutionHandler<?>)
conn.getContext().getAttribute(HTTP_HANDLER);
+        Object state = conn.getContext().getAttribute("http.nio.http-exchange-state");
+        try {
+            Method m1 = state.getClass().getDeclaredMethod("getRequestState");
+            m1.setAccessible(true);
+            Object obj = m1.invoke(state);
+            if (!obj.toString().equals("READY")) {
+                handler.failed(new ConnectionClosedException("Connection closed"));
+            }
+        } catch (Exception ex) {
+        }
+        super.endOfInput(conn);
+    }
+
 }

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java?rev=1362541&r1=1362540&r2=1362541&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
Tue Jul 17 15:28:28 2012
@@ -65,7 +65,6 @@ import org.apache.http.protocol.HttpCont
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class TestHttpAsyncPrematureTermination extends HttpAsyncTestBase {
@@ -115,7 +114,7 @@ public class TestHttpAsyncPrematureTermi
         return target;
     }
 
-    @Test @Ignore
+    @Test
     public void testConnectionTerminatedProcessingRequest() throws Exception {
         HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
         registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
@@ -125,7 +124,6 @@ public class TestHttpAsyncPrematureTermi
                     final HttpContext context) throws HttpException, IOException {
                 HttpConnection conn = (HttpConnection) context.getAttribute(
                         ExecutionContext.HTTP_CONNECTION);
-                System.out.println("Boom!!!!");
                 conn.shutdown();
                 return new BasicAsyncRequestConsumer();
             }
@@ -165,7 +163,7 @@ public class TestHttpAsyncPrematureTermi
         Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
     }
 
-    @Test @Ignore
+    @Test
     public void testConnectionTerminatedHandlingRequest() throws Exception {
         HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
         registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
@@ -182,7 +180,6 @@ public class TestHttpAsyncPrematureTermi
                     final HttpContext context) throws HttpException, IOException {
                 HttpConnection conn = (HttpConnection) context.getAttribute(
                         ExecutionContext.HTTP_CONNECTION);
-                System.out.println("Boom!!!!");
                 conn.shutdown();
                 HttpResponse response = httpExchange.getResponse();
                 response.setEntity(new NStringEntity("all is well", ContentType.TEXT_PLAIN));



Mime
View raw message