Return-Path: Delivered-To: apmail-hc-commits-archive@www.apache.org Received: (qmail 27757 invoked from network); 22 Nov 2010 22:15:26 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 22 Nov 2010 22:15:26 -0000 Received: (qmail 66996 invoked by uid 500); 22 Nov 2010 22:15:58 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 66955 invoked by uid 500); 22 Nov 2010 22:15:57 -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 66948 invoked by uid 99); 22 Nov 2010 22:15:57 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Nov 2010 22:15:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED,T_FRT_STOCK2 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; Mon, 22 Nov 2010 22:15:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7A01D238899C; Mon, 22 Nov 2010 22:14:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1037915 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java Date: Mon, 22 Nov 2010 22:14:22 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101122221422.7A01D238899C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Mon Nov 22 22:14:22 2010 New Revision: 1037915 URL: http://svn.apache.org/viewvc?rev=1037915&view=rev Log: HTTPCORE-242: Fixed NPE in AsyncNHttpClientHandler caused by an early response to an entity enclosing request Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1037915&r1=1037914&r2=1037915&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original) +++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Mon Nov 22 22:14:22 2010 @@ -1,10 +1,17 @@ +Changes since 4.1 + +* [HTTPCORE-242]: Fixed NPE in AsyncNHttpClientHandler caused by an early response to an + entity enclosing request. + Contributed by Oleg Kalnichevski + + Release 4.1 ------------------- -This is the first stable (GA) release of HttpCore 4.1. This release provides a compatibility mode +This is the first stable (GA) release of HttpCore 4.1. This release provides a compatibility mode with JREs that have a naive (broken) implementation of SelectionKey API and also improves -compatibility with the Google Android platform. There has also been a number of performance -related improvements and bug fixes in both blocking and non-blocking components. +compatibility with the Google Android platform. There has also been a number of performance +related improvements and bug fixes in both blocking and non-blocking components. All upstream projects are encouraged to upgrade. @@ -19,7 +26,7 @@ simultaneous HTTP connections in a resou * [HTTPCORE-240]: DefaultConnectingIOReactor leaks a socket descriptor if the session request fails. Contributed by Oleg Kalnichevski -* [HTTPCORE-239]: The ChunkEncoder could request for a negative buffer limit causing an +* [HTTPCORE-239]: The ChunkEncoder could request for a negative buffer limit causing an IllegalArgumentException. Contributed by Asankha Perera Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java?rev=1037915&r1=1037914&r2=1037915&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java (original) +++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/AsyncNHttpClientHandler.java Mon Nov 22 22:14:22 2010 @@ -212,6 +212,8 @@ public class AsyncNHttpClientHandler ext CoreProtocolPNames.WAIT_FOR_CONTINUE, 3000); conn.setSocketTimeout(timeout); connState.setOutputState(ClientConnState.EXPECT_CONTINUE); + } else if (connState.getProducingEntity() != null) { + connState.setOutputState(ClientConnState.REQUEST_BODY_STREAM); } } catch (IOException ex) { @@ -266,6 +268,9 @@ public class AsyncNHttpClientHandler ext ProducingNHttpEntity entity = connState.getProducingEntity(); entity.produceContent(encoder, conn); + if (encoder.isCompleted()) { + connState.setOutputState(ClientConnState.REQUEST_BODY_DONE); + } } catch (IOException ex) { shutdownConnection(conn, ex); if (this.eventListener != null) { @@ -295,9 +300,13 @@ public class AsyncNHttpClientHandler ext return; } else { connState.setResponse(response); - if (connState.getOutputState() == ClientConnState.EXPECT_CONTINUE) { cancelRequest(conn, connState); + } else if (connState.getOutputState() == ClientConnState.REQUEST_BODY_STREAM) { + // Early response + cancelRequest(conn, connState); + connState.invalidate(); + conn.suspendOutput(); } } @@ -378,7 +387,7 @@ public class AsyncNHttpClientHandler ext conn.setSocketTimeout(timeout); conn.requestOutput(); - connState.setOutputState(ClientConnState.REQUEST_SENT); + connState.setOutputState(ClientConnState.REQUEST_BODY_STREAM); } private void cancelRequest( @@ -404,7 +413,7 @@ public class AsyncNHttpClientHandler ext this.execHandler.handleResponse(response, context); - if (!this.connStrategy.keepAlive(response, context)) { + if (!connState.isValid() || !this.connStrategy.keepAlive(response, context)) { conn.close(); } else { // Ready for another request @@ -431,9 +440,14 @@ public class AsyncNHttpClientHandler ext private HttpResponse response; private ConsumingNHttpEntity consumingEntity; private ProducingNHttpEntity producingEntity; - + private boolean valid; private int timeout; + public ClientConnState() { + super(); + this.valid = true; + } + public void setConsumingEntity(final ConsumingNHttpEntity consumingEntity) { this.consumingEntity = consumingEntity; } @@ -503,6 +517,15 @@ public class AsyncNHttpClientHandler ext resetInput(); resetOutput(); } + + public boolean isValid() { + return this.valid; + } + + public void invalidate() { + this.valid = false; + } + } }