1 30 package org.apache.commons.httpclient; 31 32 import junit.framework.TestCase; 33 34 40 public abstract class TestLocalHostBase extends TestCase { 41 42 private final String protocol = System.getProperty( 43 "httpclient.test.localHost.protocol", 44 "http" 45 ); 46 private final String host = System.getProperty("httpclient.test.localHost","localhost"); 47 private final int port; 48 private final String proxyHost = System.getProperty("httpclient.test.proxy.host"); 49 private final int proxyPort; 50 51 55 public TestLocalHostBase(String testName) { 56 super(testName); 57 String portString = System.getProperty("httpclient.test.localPort","8080"); 58 int tempPort = 8080; 59 try { 60 tempPort = Integer.parseInt(portString); 61 } catch(Exception e) { 62 tempPort = 8080; 63 } 64 port = tempPort; 65 String proxyPortString = System.getProperty("httpclient.test.proxy.port","3128"); 66 int tempProxyPort = 3128; 67 try { 68 tempProxyPort = Integer.parseInt(proxyPortString); 69 } catch(Exception e) { 70 tempProxyPort = 3128; 71 } 72 proxyPort = tempProxyPort; 73 } 74 75 81 public HttpClient createHttpClient() { 82 return createHttpClient(null); 83 } 84 85 93 public HttpClient createHttpClient(HttpConnectionManager connectionManager) { 94 95 HttpClient client = null; 96 97 if (connectionManager == null) { 98 client = new HttpClient(); 99 } else { 100 client = new HttpClient(connectionManager); 101 } 102 103 client.getHostConfiguration().setHost(host, port, protocol); 104 if (proxyHost != null) { 105 client.getHostConfiguration().setProxy(proxyHost, proxyPort); 106 } 107 108 return client; 109 } 110 111 114 public String getHost() { 115 return host; 116 } 117 118 121 public int getPort() { 122 return port; 123 } 124 125 128 public String getProtocol() { 129 return protocol; 130 } 131 132 } 133 | Popular Tags |