hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1567106 - in /httpcomponents/httpcore/branches/4.3.x: ./ httpcore-nio/src/main/java/org/apache/http/nio/protocol/ httpcore-nio/src/test/java/org/apache/http/nio/integration/
Date Tue, 11 Feb 2014 13:21:09 GMT
Author: olegk
Date: Tue Feb 11 13:21:09 2014
New Revision: 1567106

URL: http://svn.apache.org/r1567106
Log:
HTTPCORE-373: out of sequence HTTP response causes NPE in HttpAsyncRequestExecutor

Added:
    httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
  (with props)
Modified:
    httpcomponents/httpcore/branches/4.3.x/RELEASE_NOTES.txt
    httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java

Modified: httpcomponents/httpcore/branches/4.3.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.3.x/RELEASE_NOTES.txt?rev=1567106&r1=1567105&r2=1567106&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.3.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/branches/4.3.x/RELEASE_NOTES.txt Tue Feb 11 13:21:09 2014
@@ -1,6 +1,9 @@
 Changes since release 4.3.1
 -------------------
 
+* [HTTPCORE-373] Out of sequence HTTP response causes NPE in HttpAsyncRequestExecutor.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCORE-370] Race condition if connection request succeeds and times out at the same
time.  
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

Modified: httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1567106&r1=1567105&r2=1567106&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Tue Feb 11 13:21:09 2014
@@ -185,9 +185,12 @@ public class HttpAsyncRequestExecutor im
     public void responseReceived(
             final NHttpClientConnection conn) throws HttpException, IOException {
         final State state = ensureNotNull(getState(conn));
+        final HttpRequest request = state.getRequest();
+        if (request == null) {
+            throw new HttpException("Out of sequence response");
+        }
         final HttpAsyncClientExchangeHandler handler = ensureNotNull(getHandler(conn));
         final HttpResponse response = conn.getHttpResponse();
-        final HttpRequest request = state.getRequest();
 
         final int statusCode = response.getStatusLine().getStatusCode();
         if (statusCode < HttpStatus.SC_OK) {

Added: httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java?rev=1567106&view=auto
==============================================================================
--- httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
(added)
+++ httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
Tue Feb 11 13:21:09 2014
@@ -0,0 +1,107 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.nio.integration;
+
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+import org.apache.http.Consts;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.config.ConnectionConfig;
+import org.apache.http.impl.nio.pool.BasicNIOConnFactory;
+import org.apache.http.message.BasicHttpRequest;
+import org.apache.http.nio.testserver.HttpClientNio;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests for handling out of sequence responses.
+ */
+public class TestClientOutOfSequenceResponse {
+
+    private ServerSocket server;
+    private HttpClientNio client;
+
+    @Before
+    public void setup() throws Exception {
+        server = new ServerSocket(0, 1);
+        client = new HttpClientNio(new BasicNIOConnFactory(ConnectionConfig.DEFAULT));
+    }
+
+    @After
+    public void cleanup() throws Exception {
+        if (client != null) {
+            client.shutdown();
+        }
+        if (server != null) {
+            server.close();
+        }
+    }
+
+    @Test
+    public void testOutOfSequenceResponse() throws Exception {
+        client.setMaxPerRoute(1);
+        client.setMaxTotal(1);
+
+        client.start();
+        final HttpHost target = new HttpHost("localhost", server.getLocalPort());
+        final HttpRequest get1 = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+        final Future<HttpResponse> future1 = client.execute(target, get1);
+        final HttpRequest get2 = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+        final Future<HttpResponse> future2 = client.execute(target, get2);
+
+        final Socket socket = server.accept();
+        Thread.sleep(100);
+        for (int i = 0; i < 3; ++i) {
+            socket.getOutputStream().write((
+                    "HTTP/1.1 200 OK\r\n" +
+                    "Content-Length: 0\r\n" +
+                    "Connection: keep-alive\r\n\r\n").getBytes(Consts.UTF_8));
+            socket.getOutputStream().flush();
+        }
+
+        final HttpResponse response1 = future1.get();
+        Assert.assertEquals(200, response1.getStatusLine().getStatusCode());
+
+        try {
+            final HttpResponse response2 = future2.get();
+            Assert.assertEquals(200, response2.getStatusLine().getStatusCode());
+        } catch (ExecutionException ex) {
+            Assert.assertTrue(ex.getCause() instanceof HttpException);
+        }
+    }
+
+}

Propchange: httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/branches/4.3.x/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message