Return-Path: Delivered-To: apmail-jakarta-httpcomponents-commits-archive@www.apache.org Received: (qmail 73219 invoked from network); 18 Jul 2007 20:44:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Jul 2007 20:44:03 -0000 Received: (qmail 3697 invoked by uid 500); 18 Jul 2007 20:43:49 -0000 Delivered-To: apmail-jakarta-httpcomponents-commits-archive@jakarta.apache.org Received: (qmail 3682 invoked by uid 500); 18 Jul 2007 20:43:49 -0000 Mailing-List: contact httpcomponents-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpcomponents-dev@jakarta.apache.org Delivered-To: mailing list httpcomponents-commits@jakarta.apache.org Received: (qmail 3673 invoked by uid 99); 18 Jul 2007 20:43:49 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jul 2007 13:43:49 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Jul 2007 13:43:46 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id E70941A981A; Wed, 18 Jul 2007 13:43:25 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r557393 - in /jakarta/httpcomponents/httpcore/trunk: ./ module-nio/src/main/java/org/apache/http/impl/nio/ module-niossl/src/test/java/org/apache/http/impl/nio/reactor/ Date: Wed, 18 Jul 2007 20:43:25 -0000 To: httpcomponents-commits@jakarta.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070718204325.E70941A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Wed Jul 18 13:43:24 2007 New Revision: 557393 URL: http://svn.apache.org/viewvc?view=rev&rev=557393 Log: HTTPCORE-103: NIO connections now attempt to consume all available session data while parsing HTTP messages. This can potentially improve performance of non-blocking SSL connections. Contributed by Steffen Pingel Reviewed by Oleg Kalnichevski Added: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java (with props) Modified: jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java Modified: jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?view=diff&rev=557393&r1=557392&r2=557393 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original) +++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Wed Jul 18 13:43:24 2007 @@ -1,5 +1,10 @@ Changes since release 4.0 Alpha 5 +* [HTTPCORE-103] NIO connections now attempt to consume all available session + data while parsing HTTP messages. This can potentially improve performance + of non-blocking SSL connections. + Contributed by Steffen Pingel + * [HTTPCORE-102] Exceeding of maximum line length limit detected late Contributed by Steffen Pingel Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?view=diff&rev=557393&r1=557392&r2=557393 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java Wed Jul 18 13:43:24 2007 @@ -90,11 +90,14 @@ } try { if (this.response == null) { - int bytesRead = this.responseParser.fillBuffer(this.session.channel()); - if (bytesRead > 0) { - this.inTransportMetrics.incrementBytesTransferred(bytesRead); - } - this.response = (HttpResponse) this.responseParser.parse(); + int bytesRead; + do { + bytesRead = this.responseParser.fillBuffer(this.session.channel()); + if (bytesRead > 0) { + this.inTransportMetrics.incrementBytesTransferred(bytesRead); + } + this.response = (HttpResponse) this.responseParser.parse(); + } while (bytesRead > 0 && this.response == null); if (this.response != null) { if (this.response.getStatusLine().getStatusCode() >= 200) { HttpEntity entity = prepareDecoder(this.response); Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?view=diff&rev=557393&r1=557392&r2=557393 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java Wed Jul 18 13:43:24 2007 @@ -87,11 +87,14 @@ } try { if (this.request == null) { - int bytesRead = this.requestParser.fillBuffer(this.session.channel()); - if (bytesRead > 0) { - this.inTransportMetrics.incrementBytesTransferred(bytesRead); - } - this.request = (HttpRequest) this.requestParser.parse(); + int bytesRead; + do { + bytesRead = this.requestParser.fillBuffer(this.session.channel()); + if (bytesRead > 0) { + this.inTransportMetrics.incrementBytesTransferred(bytesRead); + } + this.request = (HttpRequest) this.requestParser.parse(); + } while (bytesRead > 0 && this.request == null); if (this.request != null) { if (this.request instanceof HttpEntityEnclosingRequest) { // Receive incoming entity Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java?view=diff&rev=557393&r1=557392&r2=557393 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestAll.java Wed Jul 18 13:43:24 2007 @@ -41,6 +41,7 @@ public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(TestNIOSSLHttp.suite()); + suite.addTest(TestBaseIOReactorSSL.suite()); return suite; } Added: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java?view=auto&rev=557393 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java (added) +++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java Wed Jul 18 13:43:24 2007 @@ -0,0 +1,164 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * ==================================================================== + * 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 + * . + * + */ +package org.apache.http.impl.nio.reactor; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.net.Socket; +import java.net.URL; +import java.security.KeyStore; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.http.HttpException; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.impl.DefaultConnectionReuseStrategy; +import org.apache.http.impl.DefaultHttpResponseFactory; +import org.apache.http.impl.nio.mockup.SimpleHttpRequestHandlerResolver; +import org.apache.http.impl.nio.mockup.TestHttpSSLServer; +import org.apache.http.nio.NHttpServiceHandler; +import org.apache.http.nio.protocol.BufferingHttpServiceHandler; +import org.apache.http.nio.protocol.EventListener; +import org.apache.http.params.BasicHttpParams; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; +import org.apache.http.params.HttpProtocolParams; +import org.apache.http.protocol.BasicHttpProcessor; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpExpectationVerifier; +import org.apache.http.protocol.HttpRequestHandler; +import org.apache.http.protocol.ResponseConnControl; +import org.apache.http.protocol.ResponseContent; +import org.apache.http.protocol.ResponseDate; +import org.apache.http.protocol.ResponseServer; + +public class TestBaseIOReactorSSL extends TestCase { + + private TestHttpSSLServer server; + + protected void setUp() throws Exception { + HttpParams serverParams = new BasicHttpParams(); + serverParams + .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 5000) + .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 10) + .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false) + .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true) + .setParameter(HttpProtocolParams.ORIGIN_SERVER, "TEST-SERVER/1.1"); + + this.server = new TestHttpSSLServer(serverParams); + } + + protected void tearDown() throws Exception { + this.server.shutdown(); + } + + public static Test suite() { + return new TestSuite(TestBaseIOReactorSSL.class); + } + + private NHttpServiceHandler createHttpServiceHandler( + final HttpRequestHandler requestHandler, + final HttpExpectationVerifier expectationVerifier, + final EventListener eventListener) { + BasicHttpProcessor httpproc = new BasicHttpProcessor(); + httpproc.addInterceptor(new ResponseDate()); + httpproc.addInterceptor(new ResponseServer()); + httpproc.addInterceptor(new ResponseContent()); + httpproc.addInterceptor(new ResponseConnControl()); + + BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler( + httpproc, + new DefaultHttpResponseFactory(), + new DefaultConnectionReuseStrategy(), + this.server.getParams()); + + serviceHandler.setHandlerResolver( + new SimpleHttpRequestHandlerResolver(requestHandler)); + serviceHandler.setExpectationVerifier(expectationVerifier); + serviceHandler.setEventListener(eventListener); + + return serviceHandler; + } + + public void testBufferedInput() throws Exception { + final int[] result = new int[1]; + HttpRequestHandler requestHandler = new HttpRequestHandler() { + public void handle(HttpRequest request, HttpResponse response, + HttpContext context) throws HttpException, IOException { + result[0]++; + synchronized (result) { + result.notify(); + } + } + }; + + NHttpServiceHandler serviceHandler = createHttpServiceHandler( + requestHandler, + null, + null); + + this.server.start(serviceHandler); + + ClassLoader cl = getClass().getClassLoader(); + URL url = cl.getResource("test.keystore"); + KeyStore keystore = KeyStore.getInstance("jks"); + keystore.load(url.openStream(), "nopassword".toCharArray()); + TrustManagerFactory tmfactory = TrustManagerFactory.getInstance( + TrustManagerFactory.getDefaultAlgorithm()); + tmfactory.init(keystore); + TrustManager[] trustmanagers = tmfactory.getTrustManagers(); + SSLContext sslcontext = SSLContext.getInstance("TLS"); + sslcontext.init(null, trustmanagers, null); + + Socket socket = sslcontext.getSocketFactory().createSocket("localhost", server.getSocketAddress().getPort()); + BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); + // 123456789012345678901234567890 + writer.write("GET / HTTP/1.1\r\n"); + writer.write("Header: \r\n"); + writer.write("Header: \r\n"); + writer.write("Header: \r\n"); + writer.write("\r\n"); + writer.flush(); + + synchronized (result) { + result.wait(500); + } + assertEquals(1, result[0]); + } + +} Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestBaseIOReactorSSL.java ------------------------------------------------------------------------------ svn:mime-type = text/plain