hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
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 GMT
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 <spingel at limewire.com>
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 <spingel at limewire.com>
+
 * [HTTPCORE-102] Exceeding of maximum line length limit detected late
   Contributed by Steffen Pingel <spingel at limewire.com>
 

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
+ * <http://www.apache.org/>.
+ *
+ */
+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



Mime
View raw message