1 /* 2 * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestLocalHostBase.java,v 1.4 2003/03/12 22:13:15 olegk Exp $ 3 * $Revision: 1.4 $ 4 * $Date: 2003/03/12 22:13:15 $ 5 * ==================================================================== 6 * 7 * The Apache Software License, Version 1.1 8 * 9 * Copyright (c) 2002-2003 The Apache Software Foundation. All rights 10 * reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 19 * 2. Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in 21 * the documentation and/or other materials provided with the 22 * distribution. 23 * 24 * 3. The end-user documentation included with the redistribution, if 25 * any, must include the following acknowlegement: 26 * "This product includes software developed by the 27 * Apache Software Foundation (http://www.apache.org/)." 28 * Alternately, this acknowlegement may appear in the software itself, 29 * if and wherever such third-party acknowlegements normally appear. 30 * 31 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software 32 * Foundation" must not be used to endorse or promote products derived 33 * from this software without prior written permission. For written 34 * permission, please contact apache@apache.org. 35 * 36 * 5. Products derived from this software may not be called "Apache" 37 * nor may "Apache" appear in their names without prior written 38 * permission of the Apache Group. 39 * 40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 43 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51 * SUCH DAMAGE. 52 * ==================================================================== 53 * 54 * This software consists of voluntary contributions made by many 55 * individuals on behalf of the Apache Software Foundation. For more 56 * information on the Apache Software Foundation, please see 57 * <http://www.apache.org/>. 58 * 59 * [Additional notices, if required by prior licensing conditions] 60 * 61 */ 62 package org.apache.commons.httpclient; 63 64 import junit.framework.TestCase; 65 66 /*** 67 * The base class for all tests that need to connection to the localhost 68 * web server. 69 * 70 * @author Michael Becke 71 */ 72 public abstract class TestLocalHostBase extends TestCase { 73 74 private final String protocol = System.getProperty( 75 "httpclient.test.localHost.protocol", 76 "http" 77 ); 78 private final String host = System.getProperty("httpclient.test.localHost","localhost"); 79 private final int port; 80 private final String proxyHost = System.getProperty("httpclient.test.proxy.host"); 81 private final int proxyPort; 82 83 /*** 84 * Constructor for TestLocalHostBase. 85 * @param testName 86 */ 87 public TestLocalHostBase(String testName) { 88 super(testName); 89 String portString = System.getProperty("httpclient.test.localPort","8080"); 90 int tempPort = 8080; 91 try { 92 tempPort = Integer.parseInt(portString); 93 } catch(Exception e) { 94 tempPort = 8080; 95 } 96 port = tempPort; 97 String proxyPortString = System.getProperty("httpclient.test.proxy.port","3128"); 98 int tempProxyPort = 3128; 99 try { 100 tempProxyPort = Integer.parseInt(proxyPortString); 101 } catch(Exception e) { 102 tempProxyPort = 3128; 103 } 104 proxyPort = tempProxyPort; 105 } 106 107 /*** 108 * Gets a new HttpClient instance. This instance has been configured 109 * with all appropriate host/proxy values. 110 * 111 * @return a new HttpClient instance 112 */ 113 public HttpClient createHttpClient() { 114 return createHttpClient(null); 115 } 116 117 /*** 118 * Gets a new HttpClient instance that uses the given connection manager. 119 * This instance has been configured with all appropriate host/proxy values. 120 * 121 * @param connectionManager the connection manager to use or <code>null</code> 122 * 123 * @return a new HttpClient instance 124 */ 125 public HttpClient createHttpClient(HttpConnectionManager connectionManager) { 126 127 HttpClient client = null; 128 129 if (connectionManager == null) { 130 client = new HttpClient(); 131 } else { 132 client = new HttpClient(connectionManager); 133 } 134 135 client.getHostConfiguration().setHost(host, port, protocol); 136 if (proxyHost != null) { 137 client.getHostConfiguration().setProxy(proxyHost, proxyPort); 138 } 139 140 return client; 141 } 142 143 /*** 144 * @return String 145 */ 146 public String getHost() { 147 return host; 148 } 149 150 /*** 151 * @return int 152 */ 153 public int getPort() { 154 return port; 155 } 156 157 /*** 158 * @return String 159 */ 160 public String getProtocol() { 161 return protocol; 162 } 163 164 }

This page was automatically generated by Maven