You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/02/11 14:20:38 UTC
svn commit: r1567105 - in /httpcomponents/httpcore/trunk: ./
httpcore-nio/src/main/java/org/apache/http/nio/protocol/
httpcore-nio/src/test/java/org/apache/http/nio/integration/
Author: olegk
Date: Tue Feb 11 13:20:38 2014
New Revision: 1567105
URL: http://svn.apache.org/r1567105
Log:
HTTPCORE-373: out of sequence HTTP response causes NPE in HttpAsyncRequestExecutor
Added:
httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java (with props)
Modified:
httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1567105&r1=1567104&r2=1567105&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Tue Feb 11 13:20:38 2014
@@ -1,6 +1,9 @@
Changes for release 4.4-alpha1
-------------------
+* [HTTPCORE-373] Out of sequence HTTP response causes NPE in HttpAsyncRequestExecutor.
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
* [HTTPCORE-372] Blocking and non-blocking chunk decoders to throw an I/O exception if data stream
is terminated without a closing chunk.
Contributed by Dmitry Potapov <potapov.d at gmail.com>
@@ -13,7 +16,7 @@ Changes for release 4.4-alpha1
* [HTTPCORE-370] Race condition if connection request succeeds and times out at the same time.
Contributed by Oleg Kalnichevski <olegk at apache.org>
-
+
* [HTTPCORE-357] Avoid DNS lookups in SSLIOSession.
Contributed by Oleg Kalnichevski <olegk at apache.org>
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=1567105&r1=1567104&r2=1567105&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 Feb 11 13:20:38 2014
@@ -191,9 +191,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/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java?rev=1567105&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java (added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java Tue Feb 11 13:20:38 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/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestClientOutOfSequenceResponse.java
------------------------------------------------------------------------------
svn:mime-type = text/plain