001: /*
002: * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0-beta1/module-nio/src/test/java/org/apache/http/HttpCoreNIOSSLTestBase.java $
003: * $Revision: 612997 $
004: * $Date: 2008-01-17 23:42:36 +0100 (Thu, 17 Jan 2008) $
005: * ====================================================================
006: * Licensed to the Apache Software Foundation (ASF) under one
007: * or more contributor license agreements. See the NOTICE file
008: * distributed with this work for additional information
009: * regarding copyright ownership. The ASF licenses this file
010: * to you under the Apache License, Version 2.0 (the
011: * "License"); you may not use this file except in compliance
012: * with the License. You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing,
017: * software distributed under the License is distributed on an
018: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
019: * KIND, either express or implied. See the License for the
020: * specific language governing permissions and limitations
021: * under the License.
022: * ====================================================================
023: *
024: * This software consists of voluntary contributions made by many
025: * individuals on behalf of the Apache Software Foundation. For more
026: * information on the Apache Software Foundation, please see
027: * <http://www.apache.org/>.
028: *
029: */
030:
031: package org.apache.http;
032:
033: import junit.framework.TestCase;
034:
035: import org.apache.http.impl.DefaultConnectionReuseStrategy;
036: import org.apache.http.impl.DefaultHttpResponseFactory;
037: import org.apache.http.mockup.SimpleHttpRequestHandlerResolver;
038: import org.apache.http.mockup.TestHttpSSLClient;
039: import org.apache.http.mockup.TestHttpSSLServer;
040: import org.apache.http.nio.NHttpClientHandler;
041: import org.apache.http.nio.NHttpServiceHandler;
042: import org.apache.http.nio.protocol.BufferingHttpClientHandler;
043: import org.apache.http.nio.protocol.BufferingHttpServiceHandler;
044: import org.apache.http.nio.protocol.EventListener;
045: import org.apache.http.nio.protocol.HttpRequestExecutionHandler;
046: import org.apache.http.params.BasicHttpParams;
047: import org.apache.http.params.CoreConnectionPNames;
048: import org.apache.http.params.HttpParams;
049: import org.apache.http.params.CoreProtocolPNames;
050: import org.apache.http.protocol.BasicHttpProcessor;
051: import org.apache.http.protocol.HttpExpectationVerifier;
052: import org.apache.http.protocol.HttpRequestHandler;
053: import org.apache.http.protocol.RequestConnControl;
054: import org.apache.http.protocol.RequestContent;
055: import org.apache.http.protocol.RequestExpectContinue;
056: import org.apache.http.protocol.RequestTargetHost;
057: import org.apache.http.protocol.RequestUserAgent;
058: import org.apache.http.protocol.ResponseConnControl;
059: import org.apache.http.protocol.ResponseContent;
060: import org.apache.http.protocol.ResponseDate;
061: import org.apache.http.protocol.ResponseServer;
062:
063: /**
064: * Base class for all HttpCore NIO tests
065: *
066: * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
067: */
068: public class HttpCoreNIOSSLTestBase extends TestCase {
069:
070: public HttpCoreNIOSSLTestBase(String testName) {
071: super (testName);
072: }
073:
074: protected TestHttpSSLServer server;
075: protected TestHttpSSLClient client;
076:
077: @Override
078: protected void setUp() throws Exception {
079: HttpParams serverParams = new BasicHttpParams();
080: serverParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
081: 5000).setIntParameter(
082: CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
083: .setBooleanParameter(
084: CoreConnectionPNames.STALE_CONNECTION_CHECK,
085: false).setBooleanParameter(
086: CoreConnectionPNames.TCP_NODELAY, true)
087: .setParameter(CoreProtocolPNames.ORIGIN_SERVER,
088: "TEST-SERVER/1.1");
089:
090: this .server = new TestHttpSSLServer(serverParams);
091:
092: HttpParams clientParams = new BasicHttpParams();
093: clientParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
094: 5000).setIntParameter(
095: CoreConnectionPNames.CONNECTION_TIMEOUT, 2000)
096: .setIntParameter(
097: CoreConnectionPNames.SOCKET_BUFFER_SIZE,
098: 8 * 1024).setBooleanParameter(
099: CoreConnectionPNames.STALE_CONNECTION_CHECK,
100: false).setBooleanParameter(
101: CoreConnectionPNames.TCP_NODELAY, true)
102: .setParameter(CoreProtocolPNames.USER_AGENT,
103: "TEST-CLIENT/1.1");
104:
105: this .client = new TestHttpSSLClient(clientParams);
106: }
107:
108: @Override
109: protected void tearDown() throws Exception {
110: this .server.shutdown();
111: this .client.shutdown();
112: }
113:
114: protected NHttpServiceHandler createHttpServiceHandler(
115: final HttpRequestHandler requestHandler,
116: final HttpExpectationVerifier expectationVerifier,
117: final EventListener eventListener) {
118:
119: BasicHttpProcessor httpproc = new BasicHttpProcessor();
120: httpproc.addInterceptor(new ResponseDate());
121: httpproc.addInterceptor(new ResponseServer());
122: httpproc.addInterceptor(new ResponseContent());
123: httpproc.addInterceptor(new ResponseConnControl());
124:
125: BufferingHttpServiceHandler serviceHandler = new BufferingHttpServiceHandler(
126: httpproc, new DefaultHttpResponseFactory(),
127: new DefaultConnectionReuseStrategy(), this .server
128: .getParams());
129:
130: serviceHandler
131: .setHandlerResolver(new SimpleHttpRequestHandlerResolver(
132: requestHandler));
133: serviceHandler.setExpectationVerifier(expectationVerifier);
134: serviceHandler.setEventListener(eventListener);
135:
136: return serviceHandler;
137: }
138:
139: protected NHttpClientHandler createHttpClientHandler(
140: final HttpRequestExecutionHandler requestExecutionHandler,
141: final EventListener eventListener) {
142:
143: BasicHttpProcessor httpproc = new BasicHttpProcessor();
144: httpproc.addInterceptor(new RequestContent());
145: httpproc.addInterceptor(new RequestTargetHost());
146: httpproc.addInterceptor(new RequestConnControl());
147: httpproc.addInterceptor(new RequestUserAgent());
148: httpproc.addInterceptor(new RequestExpectContinue());
149:
150: BufferingHttpClientHandler clientHandler = new BufferingHttpClientHandler(
151: httpproc, requestExecutionHandler,
152: new DefaultConnectionReuseStrategy(), this.client
153: .getParams());
154:
155: clientHandler.setEventListener(eventListener);
156:
157: return clientHandler;
158: }
159:
160: }
|