hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r542942 - in /jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio: mockup/ reactor/
Date Wed, 30 May 2007 21:38:50 GMT
Author: olegk
Date: Wed May 30 14:38:49 2007
New Revision: 542942

URL: http://svn.apache.org/viewvc?view=rev&rev=542942
Log:
Refactored HttpCore NIOSSL tests

Added:
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
  (with props)
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleHttpRequestHandlerResolver.java
  (with props)
Removed:
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLServiceBase.java
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLClient.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLServer.java
    jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java

Added: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java?view=auto&rev=542942
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
Wed May 30 14:38:49 2007
@@ -0,0 +1,85 @@
+/*
+ * $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.mockup;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.nio.NHttpConnection;
+import org.apache.http.nio.protocol.EventListener;
+
+public class CountingEventListener implements EventListener {
+
+    private volatile int connCount = 0;
+    
+    public CountingEventListener() {
+        super();
+    }
+    
+    public int getConnCount() {
+        return this.connCount;
+    }
+    
+    private void incrementConnCount() {
+        synchronized (this) {
+            this.connCount++;
+            this.notifyAll();
+        }
+    }
+    
+    public void await(int connCount, long timeout) throws InterruptedException {
+        synchronized (this) {
+            while (this.connCount < connCount) {
+                this.wait(timeout);
+            }
+        }
+    }
+    
+    public void connectionOpen(final NHttpConnection conn) {
+    }
+
+    public void connectionTimeout(final NHttpConnection conn) {
+    }
+
+    public void connectionClosed(final NHttpConnection conn) {
+        incrementConnCount();
+    }
+
+    public void fatalIOException(final IOException ex, final NHttpConnection conn) {
+        ex.printStackTrace();
+    }
+
+    public void fatalProtocolException(final HttpException ex, NHttpConnection conn) {
+        ex.printStackTrace();
+    }
+        
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/CountingEventListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleHttpRequestHandlerResolver.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleHttpRequestHandlerResolver.java?view=auto&rev=542942
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleHttpRequestHandlerResolver.java
(added)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleHttpRequestHandlerResolver.java
Wed May 30 14:38:49 2007
@@ -0,0 +1,49 @@
+/*
+ * $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.mockup;
+
+import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.protocol.HttpRequestHandlerResolver;
+
+public class SimpleHttpRequestHandlerResolver implements HttpRequestHandlerResolver {
+
+    private final HttpRequestHandler handler;
+    
+    public SimpleHttpRequestHandlerResolver(final HttpRequestHandler handler) {
+        super();
+        this.handler = handler;
+    }
+    
+    public HttpRequestHandler lookup(final String requestURI) {
+        return this.handler;
+    }
+
+}

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleHttpRequestHandlerResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleHttpRequestHandlerResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/SimpleHttpRequestHandlerResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLClient.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLClient.java?view=diff&rev=542942&r1=542941&r2=542942
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLClient.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLClient.java
Wed May 30 14:38:49 2007
@@ -40,29 +40,26 @@
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.TrustManagerFactory;
 
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
 import org.apache.http.impl.nio.reactor.SSLClientIOEventDispatch;
-import org.apache.http.nio.protocol.BufferingHttpClientHandler;
-import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
+import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
 import org.apache.http.nio.reactor.IOEventDispatch;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.BasicHttpProcessor;
-import org.apache.http.protocol.RequestConnControl;
-import org.apache.http.protocol.RequestContent;
-import org.apache.http.protocol.RequestExpectContinue;
-import org.apache.http.protocol.RequestTargetHost;
-import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.params.HttpParams;
 
-public class TestHttpSSLClient extends TestHttpSSLServiceBase {
+public class TestHttpSSLClient {
 
     private final SSLContext sslcontext;
-    private HttpRequestExecutionHandler execHandler;
+    private final ConnectingIOReactor ioReactor;
+    private final HttpParams params;
     
-    public TestHttpSSLClient() throws Exception {
+    private volatile IOReactorThread thread;
+
+    
+    public TestHttpSSLClient(final HttpParams params) throws Exception {
         super();
+        this.params = params;
+        this.ioReactor = new DefaultConnectingIOReactor(2, this.params);
         
         ClassLoader cl = getClass().getClassLoader();
         URL url = cl.getResource("test.keystore");
@@ -74,38 +71,13 @@
         TrustManager[] trustmanagers = tmfactory.getTrustManagers(); 
         this.sslcontext = SSLContext.getInstance("TLS");
         this.sslcontext.init(null, trustmanagers, null);
-        
-        this.params
-            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 15000)
-            .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 15000)
-            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
-            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
-            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
-            .setParameter(HttpProtocolParams.USER_AGENT, "TEST-SSL-CLIENT/1.1");
-
-        this.ioReactor = new DefaultConnectingIOReactor(2, this.params);
     }
     
-    public void setHttpRequestExecutionHandler(final HttpRequestExecutionHandler handler)
{
-        this.execHandler = handler;
+    public HttpParams getParams() {
+        return this.params;
     }
     
-    protected void execute() throws IOException {
-        BasicHttpProcessor httpproc = new BasicHttpProcessor();
-        httpproc.addInterceptor(new RequestContent());
-        httpproc.addInterceptor(new RequestTargetHost());
-        httpproc.addInterceptor(new RequestConnControl());
-        httpproc.addInterceptor(new RequestUserAgent());
-        httpproc.addInterceptor(new RequestExpectContinue());
-        
-        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
-                httpproc,
-                this.execHandler,
-                new DefaultConnectionReuseStrategy(),
-                this.params);
-        
-        clientHandler.setEventListener(new EventLogger());
-
+    private void execute(final NHttpClientHandler clientHandler) throws IOException {
         IOEventDispatch ioEventDispatch = new SSLClientIOEventDispatch(
                 clientHandler, 
                 this.sslcontext,
@@ -115,8 +87,39 @@
     }
     
     public void openConnection(final InetSocketAddress address, final Object attachment)
{
-        ((ConnectingIOReactor) this.ioReactor).connect(
-                address, null, attachment, null);
+        this.ioReactor.connect(address, null, attachment, null);
+    }
+ 
+    public void start(final NHttpClientHandler clientHandler) {
+        this.thread = new IOReactorThread(clientHandler);
+        this.thread.start();
     }
+    
+    public void shutdown() throws IOException {
+        this.ioReactor.shutdown();
+        try {
+            this.thread.join(500);
+        } catch (InterruptedException ignore) {
+        }
+    }
+    
+    private class IOReactorThread extends Thread {
+
+        private final NHttpClientHandler clientHandler;
+        
+        public IOReactorThread(final NHttpClientHandler clientHandler) {
+            super();
+            this.clientHandler = clientHandler;
+        }
+        
+        public void run() {
+            try {
+                execute(this.clientHandler);
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+
+    }    
     
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLServer.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLServer.java?view=diff&rev=542942&r1=542941&r2=542942
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLServer.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/mockup/TestHttpSSLServer.java
Wed May 30 14:38:49 2007
@@ -33,7 +33,6 @@
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 import java.net.URL;
 import java.security.KeyStore;
 
@@ -41,38 +40,34 @@
 import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
 
-import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.impl.DefaultHttpResponseFactory;
 import org.apache.http.impl.nio.reactor.DefaultListeningIOReactor;
 import org.apache.http.impl.nio.reactor.SSLServerIOEventDispatch;
-import org.apache.http.nio.protocol.BufferingHttpServiceHandler;
+import org.apache.http.nio.NHttpServiceHandler;
 import org.apache.http.nio.reactor.IOEventDispatch;
 import org.apache.http.nio.reactor.ListeningIOReactor;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.BasicHttpProcessor;
-import org.apache.http.protocol.HttpRequestHandler;
-import org.apache.http.protocol.HttpRequestHandlerRegistry;
-import org.apache.http.protocol.ResponseConnControl;
-import org.apache.http.protocol.ResponseContent;
-import org.apache.http.protocol.ResponseDate;
-import org.apache.http.protocol.ResponseServer;
+import org.apache.http.params.HttpParams;
 
 /**
  * Trivial test server based on HttpCore NIO SSL
  * 
  * @author Oleg Kalnichevski
  */
-public class TestHttpSSLServer extends TestHttpSSLServiceBase {
+public class TestHttpSSLServer {
 
     private final SSLContext sslcontext;
-    private final HttpRequestHandlerRegistry reqistry;
-    private volatile SocketAddress address;
-    private final Object mutex;
+    private final ListeningIOReactor ioReactor;
+    private final HttpParams params;
+    private final Object socketMutex;
     
-    public TestHttpSSLServer() throws Exception {
+    private volatile IOReactorThread thread;
+    private volatile InetSocketAddress address;
+    
+    public TestHttpSSLServer(final HttpParams params) throws Exception {
         super();
-
+        this.params = params;
+        this.ioReactor = new DefaultListeningIOReactor(2, this.params);
+        this.socketMutex = new Object();
+        
         ClassLoader cl = getClass().getClassLoader();
         URL url = cl.getResource("test.keystore");
         KeyStore keystore  = KeyStore.getInstance("jks");
@@ -83,60 +78,66 @@
         KeyManager[] keymanagers = kmfactory.getKeyManagers(); 
         this.sslcontext = SSLContext.getInstance("TLS");
         this.sslcontext.init(keymanagers, null, null);
-        
-        this.params
-            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 15000)
-            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
-            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
-            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
-            .setParameter(HttpProtocolParams.ORIGIN_SERVER, "TEST-SSL-SERVER/1.1");
-        
-        this.reqistry = new HttpRequestHandlerRegistry();
-        this.ioReactor = new DefaultListeningIOReactor(2, this.params);
-        this.mutex = new Object();
     }
     
-    public void registerHandler(
-            final String pattern, 
-            final HttpRequestHandler handler) {
-        this.reqistry.register(pattern, handler);
+    public HttpParams getParams() {
+        return this.params;
     }
     
-    protected void execute() throws IOException {
-        synchronized (this.mutex) {
-            this.address = ((ListeningIOReactor) this.ioReactor).listen(new InetSocketAddress(0));
-            this.mutex.notifyAll();
+    private void execute(final NHttpServiceHandler serviceHandler) throws IOException {
+        synchronized (this.socketMutex) {
+            this.address = (InetSocketAddress) this.ioReactor.listen(
+                    new InetSocketAddress(0));
+            this.socketMutex.notifyAll();
         }
-        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.params);
-        
-        serviceHandler.setEventListener(new EventLogger());
-        
-        serviceHandler.setHandlerResolver(this.reqistry);
         
         IOEventDispatch ioEventDispatch = new SSLServerIOEventDispatch(
                 serviceHandler, 
                 this.sslcontext,
                 this.params);
+        
         this.ioReactor.execute(ioEventDispatch);
     }
     
-    public SocketAddress getSocketAddress() throws InterruptedException {
-        synchronized (this.mutex) {
+    public InetSocketAddress getSocketAddress() throws InterruptedException {
+        synchronized (this.socketMutex) {
             while (this.address == null) {
-                this.mutex.wait();
+                this.socketMutex.wait();
             }
         }
         return this.address;
     }
+
+    public void start(final NHttpServiceHandler serviceHandler) {
+        this.thread = new IOReactorThread(serviceHandler);
+        this.thread.start();
+    }
+    
+    public void shutdown() throws IOException {
+        this.ioReactor.shutdown();
+        try {
+            this.thread.join(500);
+        } catch (InterruptedException ignore) {
+        }
+    }
+    
+    private class IOReactorThread extends Thread {
+
+        private final NHttpServiceHandler serviceHandler;
+        
+        public IOReactorThread(final NHttpServiceHandler serviceHandler) {
+            super();
+            this.serviceHandler = serviceHandler;
+        }
+        
+        public void run() {
+            try {
+                execute(this.serviceHandler);
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+
+    }    
     
 }

Modified: jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java?view=diff&rev=542942&r1=542941&r2=542942
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-niossl/src/test/java/org/apache/http/impl/nio/reactor/TestNIOSSLHttp.java
Wed May 30 14:38:49 2007
@@ -46,16 +46,39 @@
 import org.apache.http.HttpVersion;
 import org.apache.http.entity.ByteArrayEntity;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.DefaultHttpResponseFactory;
+import org.apache.http.impl.nio.mockup.CountingEventListener;
+import org.apache.http.impl.nio.mockup.SimpleHttpRequestHandlerResolver;
 import org.apache.http.impl.nio.mockup.TestHttpSSLClient;
 import org.apache.http.impl.nio.mockup.TestHttpSSLServer;
 import org.apache.http.message.BasicHttpRequest;
 import org.apache.http.message.BasicHttpEntityEnclosingRequest;
+import org.apache.http.nio.NHttpClientHandler;
 import org.apache.http.nio.NHttpConnection;
+import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.protocol.BufferingHttpClientHandler;
+import org.apache.http.nio.protocol.BufferingHttpServiceHandler;
+import org.apache.http.nio.protocol.EventListener;
 import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
+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.HttpExecutionContext;
+import org.apache.http.protocol.HttpExpectationVerifier;
 import org.apache.http.protocol.HttpRequestHandler;
+import org.apache.http.protocol.RequestConnControl;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestExpectContinue;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.protocol.ResponseConnControl;
+import org.apache.http.protocol.ResponseContent;
+import org.apache.http.protocol.ResponseDate;
+import org.apache.http.protocol.ResponseServer;
 import org.apache.http.util.EntityUtils;
 
 import junit.framework.Test;
@@ -92,8 +115,26 @@
     private TestHttpSSLClient client;
     
     protected void setUp() throws Exception {
-        this.server = new TestHttpSSLServer();
-        this.client = new TestHttpSSLClient();
+        HttpParams serverParams = new BasicHttpParams();
+        serverParams
+            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 2000)
+            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
+            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
+            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
+            .setParameter(HttpProtocolParams.ORIGIN_SERVER, "TEST-SERVER/1.1");
+        
+        this.server = new TestHttpSSLServer(serverParams);
+        
+        HttpParams clientParams = new BasicHttpParams();
+        clientParams
+            .setIntParameter(HttpConnectionParams.SO_TIMEOUT, 2000)
+            .setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 2000)
+            .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
+            .setBooleanParameter(HttpConnectionParams.STALE_CONNECTION_CHECK, false)
+            .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, true)
+            .setParameter(HttpProtocolParams.USER_AGENT, "TEST-CLIENT/1.1");
+        
+        this.client = new TestHttpSSLClient(clientParams);
     }
 
     protected void tearDown() throws Exception {
@@ -101,6 +142,51 @@
         this.client.shutdown();
     }
 
+    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;
+    }
+    
+    private NHttpClientHandler createHttpClientHandler(
+            final HttpRequestExecutionHandler requestExecutionHandler,
+            final EventListener eventListener) {
+        BasicHttpProcessor httpproc = new BasicHttpProcessor();
+        httpproc.addInterceptor(new RequestContent());
+        httpproc.addInterceptor(new RequestTargetHost());
+        httpproc.addInterceptor(new RequestConnControl());
+        httpproc.addInterceptor(new RequestUserAgent());
+        httpproc.addInterceptor(new RequestExpectContinue());
+        
+        BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
+                httpproc,
+                requestExecutionHandler,
+                new DefaultConnectionReuseStrategy(),
+                this.client.getParams());
+
+        clientHandler.setEventListener(eventListener);
+
+        return clientHandler;
+    }
+    
     /**
      * This test case executes a series of simple (non-pipelined) GET requests 
      * over multiple connections. 
@@ -127,8 +213,7 @@
             responseData[i] = new ArrayList();
         }
         
-        // Initialize the server-side request handler
-        this.server.registerHandler("*", new HttpRequestHandler() {
+        HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
             public void handle(
                     final HttpRequest request, 
@@ -148,10 +233,9 @@
                 response.setEntity(entity);
             }
             
-        });
+        };
         
-        // Initialize the client side request executor
-        this.client.setHttpRequestExecutionHandler(new HttpRequestExecutionHandler() {
+        HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
 
             public void initalizeContext(final HttpContext context, final Object attachment)
{
                 context.setAttribute("LIST", (List) attachment);
@@ -197,10 +281,22 @@
                 }
             }
             
-        });
+        };
         
-        this.server.start();
-        this.client.start();
+        CountingEventListener serverEventListener = new CountingEventListener();
+        CountingEventListener clientEventListener = new CountingEventListener();
+        
+        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
+                requestHandler, 
+                null,
+                serverEventListener);
+
+        NHttpClientHandler clientHandler = createHttpClientHandler(
+                requestExecutionHandler, 
+                clientEventListener);
+
+        this.server.start(serviceHandler);
+        this.client.start(clientHandler);
         
         InetSocketAddress serverAddress = (InetSocketAddress) this.server.getSocketAddress();
         
@@ -210,8 +306,8 @@
                     responseData[i]);
         }
      
-        this.client.await(connNo, 1000);
-        assertEquals(connNo, this.client.getConnCount());
+        clientEventListener.await(connNo, 1000);
+        assertEquals(connNo, clientEventListener.getConnCount());
         
         this.client.shutdown();
         this.server.shutdown();
@@ -259,8 +355,7 @@
             responseData[i] = new ArrayList();
         }
         
-        // Initialize the server-side request handler
-        this.server.registerHandler("*", new HttpRequestHandler() {
+        HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
             public void handle(
                     final HttpRequest request, 
@@ -280,10 +375,9 @@
                 }
             }
             
-        });
+        };
         
-        // Initialize the client side request executor
-        this.client.setHttpRequestExecutionHandler(new HttpRequestExecutionHandler() {
+        HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
 
             public void initalizeContext(final HttpContext context, final Object attachment)
{
                 context.setAttribute("LIST", (List) attachment);
@@ -333,10 +427,22 @@
                 }
             }
             
-        });
+        };
+        
+        CountingEventListener serverEventListener = new CountingEventListener();
+        CountingEventListener clientEventListener = new CountingEventListener();
         
-        this.server.start();
-        this.client.start();
+        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
+                requestHandler, 
+                null,
+                serverEventListener);
+
+        NHttpClientHandler clientHandler = createHttpClientHandler(
+                requestExecutionHandler, 
+                clientEventListener);
+
+        this.server.start(serviceHandler);
+        this.client.start(clientHandler);
         
         InetSocketAddress serverAddress = (InetSocketAddress) this.server.getSocketAddress();
         
@@ -346,8 +452,8 @@
                     responseData[i]);
         }
      
-        this.client.await(connNo, 1000);
-        assertEquals(connNo, this.client.getConnCount());
+        clientEventListener.await(connNo, 1000);
+        assertEquals(connNo, clientEventListener.getConnCount());
         
         this.client.shutdown();
         this.server.shutdown();
@@ -395,8 +501,7 @@
             responseData[i] = new ArrayList();
         }
         
-        // Initialize the server-side request handler
-        this.server.registerHandler("*", new HttpRequestHandler() {
+        HttpRequestHandler requestHandler = new HttpRequestHandler() {
 
             public void handle(
                     final HttpRequest request, 
@@ -415,10 +520,9 @@
                 }
             }
             
-        });
+        };
         
-        // Initialize the client side request executor
-        this.client.setHttpRequestExecutionHandler(new HttpRequestExecutionHandler() {
+        HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
 
             public void initalizeContext(final HttpContext context, final Object attachment)
{
                 context.setAttribute("LIST", (List) attachment);
@@ -469,10 +573,22 @@
                 }
             }
             
-        });
+        };
+        
+        CountingEventListener serverEventListener = new CountingEventListener();
+        CountingEventListener clientEventListener = new CountingEventListener();
         
-        this.server.start();
-        this.client.start();
+        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
+                requestHandler, 
+                null,
+                serverEventListener);
+
+        NHttpClientHandler clientHandler = createHttpClientHandler(
+                requestExecutionHandler, 
+                clientEventListener);
+
+        this.server.start(serviceHandler);
+        this.client.start(clientHandler);
         
         InetSocketAddress serverAddress = (InetSocketAddress) this.server.getSocketAddress();
         
@@ -482,8 +598,8 @@
                     responseData[i]);
         }
      
-        this.client.await(connNo, 1000);
-        assertEquals(connNo, this.client.getConnCount());
+        clientEventListener.await(connNo, 1000);
+        assertEquals(connNo, clientEventListener.getConnCount());
         
         this.client.shutdown();
         this.server.shutdown();
@@ -531,8 +647,7 @@
             responseData[i] = new ArrayList();
         }
         
-        // Initialize the server-side request handler
-        this.server.registerHandler("*", new HttpRequestHandler() {
+        HttpRequestHandler requestHandler = new HttpRequestHandler() {
             
 
             public void handle(
@@ -553,13 +668,13 @@
                 }
             }
             
-        });
+        };
         
-        // Initialize the client side request executor
         // Set protocol level to HTTP/1.0
         this.client.getParams().setParameter(
                 HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
-        this.client.setHttpRequestExecutionHandler(new HttpRequestExecutionHandler() {
+        
+        HttpRequestExecutionHandler requestExecutionHandler = new HttpRequestExecutionHandler()
{
 
             public void initalizeContext(final HttpContext context, final Object attachment)
{
                 context.setAttribute("LIST", (List) attachment);
@@ -609,10 +724,22 @@
                 }
             }
             
-        });
+        };
         
-        this.server.start();
-        this.client.start();
+        CountingEventListener serverEventListener = new CountingEventListener();
+        CountingEventListener clientEventListener = new CountingEventListener();
+        
+        NHttpServiceHandler serviceHandler = createHttpServiceHandler(
+                requestHandler, 
+                null,
+                serverEventListener);
+
+        NHttpClientHandler clientHandler = createHttpClientHandler(
+                requestExecutionHandler, 
+                clientEventListener);
+
+        this.server.start(serviceHandler);
+        this.client.start(clientHandler);
         
         InetSocketAddress serverAddress = (InetSocketAddress) this.server.getSocketAddress();
         
@@ -622,8 +749,8 @@
                     responseData[i]);
         }
      
-        this.client.await(connNo, 1000);
-        assertEquals(connNo, this.client.getConnCount());
+        clientEventListener.await(connNo, 1000);
+        assertEquals(connNo, clientEventListener.getConnCount());
         
         this.client.shutdown();
         this.server.shutdown();



Mime
View raw message