Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Temporary workaround for HTTPASYNC-21

  • Loading branch information...
commit 56b3b2dd1d506b898d9d033362993d87f625dc69 1 parent 1b829f2
@ok2c ok2c authored
View
22 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
@@ -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 @@ public void timeout(final NHttpClientConnection conn) throws IOException {
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);
+ }
+
}
View
7 httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
@@ -65,7 +65,6 @@
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 @@ private HttpHost start(
return target;
}
- @Test @Ignore
+ @Test
public void testConnectionTerminatedProcessingRequest() throws Exception {
HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
registry.register("*", new HttpAsyncRequestHandler<HttpRequest>() {
@@ -125,7 +124,6 @@ public void testConnectionTerminatedProcessingRequest() throws Exception {
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 void completed(final HttpResponse response) {
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 void handle(
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));
Please sign in to comment.
Something went wrong with that request. Please try again.