Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B521FE266 for ; Tue, 29 Jan 2013 14:35:34 +0000 (UTC) Received: (qmail 42493 invoked by uid 500); 29 Jan 2013 14:35:34 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 42451 invoked by uid 500); 29 Jan 2013 14:35:34 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 42443 invoked by uid 99); 29 Jan 2013 14:35:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Jan 2013 14:35:34 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Jan 2013 14:35:31 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 53A4323889E1 for ; Tue, 29 Jan 2013 14:35:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1439909 - in /httpcomponents/httpcore/trunk/httpcore-nio/src: main/java/org/apache/http/nio/protocol/ test/java/org/apache/http/nio/protocol/ Date: Tue, 29 Jan 2013 14:35:11 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130129143511.53A4323889E1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Tue Jan 29 14:35:10 2013 New Revision: 1439909 URL: http://svn.apache.org/viewvc?rev=1439909&view=rev Log: HTTPASYNC-34: a proper fix for incorrect handling of prematurely termination of a persistent connection by the opposite end Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncClientExchangeHandler.java httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientExchangeHandler.java 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/TestBasicAsyncClientExchangeHandler.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/BasicAsyncClientExchangeHandler.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncClientExchangeHandler.java?rev=1439909&r1=1439908&r2=1439909&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncClientExchangeHandler.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncClientExchangeHandler.java Tue Jan 29 14:35:10 2013 @@ -30,6 +30,7 @@ package org.apache.http.nio.protocol; import java.io.IOException; import java.util.concurrent.Future; +import org.apache.http.ConnectionClosedException; import org.apache.http.ConnectionReuseStrategy; import org.apache.http.HttpException; import org.apache.http.HttpRequest; @@ -185,6 +186,10 @@ public class BasicAsyncClientExchangeHan return this.connReuseStrategy.keepAlive(response, this.localContext); } + public void inputTerminated() { + failed(new ConnectionClosedException("Connection closed")); + } + public void failed(final Exception ex) { try { if (!this.requestSent) { Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientExchangeHandler.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientExchangeHandler.java?rev=1439909&r1=1439908&r2=1439909&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientExchangeHandler.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncClientExchangeHandler.java Tue Jan 29 14:35:10 2013 @@ -139,6 +139,12 @@ public interface HttpAsyncClientExchange boolean keepAlive(HttpResponse response); /** + * Invoked to signal that the connection has been terminated prematurely + * by the opposite end. + */ + void inputTerminated(); + + /** * Invoked to signal that the response processing terminated abnormally. * * @param ex exception 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=1439909&r1=1439908&r2=1439909&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 Tue Jan 29 14:35:10 2013 @@ -244,8 +244,14 @@ public class HttpAsyncRequestExecutor im if (state != null) { if (state.getRequestState().compareTo(MessageState.READY) != 0) { state.invalidate(); - HttpAsyncClientExchangeHandler handler = getHandler(conn); - handler.failed(new ConnectionClosedException("Connection closed")); + } + HttpAsyncClientExchangeHandler handler = getHandler(conn); + if (handler != null) { + if (state.isValid()) { + handler.inputTerminated(); + } else { + handler.failed(new ConnectionClosedException("Connection closed")); + } } } // Closing connection in an orderly manner and Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncClientExchangeHandler.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncClientExchangeHandler.java?rev=1439909&r1=1439908&r2=1439909&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncClientExchangeHandler.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestBasicAsyncClientExchangeHandler.java Tue Jan 29 14:35:10 2013 @@ -29,6 +29,9 @@ package org.apache.http.nio.protocol; import java.util.concurrent.ExecutionException; +import junit.framework.Assert; + +import org.apache.http.ConnectionClosedException; import org.apache.http.ConnectionReuseStrategy; import org.apache.http.HttpRequest; import org.apache.http.HttpVersion; @@ -42,7 +45,6 @@ import org.apache.http.protocol.Executio import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpProcessor; import org.junit.After; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -349,6 +351,17 @@ public class TestBasicAsyncClientExchang } @Test + public void testInputTerminated() throws Exception { + this.exchangeHandler.inputTerminated(); + Mockito.verify(this.responseConsumer).failed(Mockito.any()); + try { + this.exchangeHandler.getFuture().get(); + Assert.fail("ExecutionException expected"); + } catch (final ExecutionException exex) { + } + } + + @Test public void testIsDone() throws Exception { this.exchangeHandler.isDone(); Mockito.verify(this.responseConsumer).isDone(); 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=1439909&r1=1439908&r2=1439909&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 Tue Jan 29 14:35:10 2013 @@ -538,6 +538,20 @@ public class TestHttpAsyncRequestExecuto } @Test + public void testPrematureEndOfInputRequestReady() throws Exception { + final State state = new HttpAsyncRequestExecutor.State(); + state.setRequestState(MessageState.READY); + this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state); + this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler); + + this.protocolHandler.endOfInput(this.conn); + + Assert.assertTrue(state.isValid()); + + Mockito.verify(this.exchangeHandler).inputTerminated(); + } + + @Test public void testTimeoutNoHandler() throws Exception { final State state = new HttpAsyncRequestExecutor.State(); this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);