Support_Configuration.java revision 470c1f75f26d58eb33bbaa0d7e08ed2723f25647
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package tests.support; 19 20import java.io.FileInputStream; 21import java.io.IOException; 22import java.io.InputStream; 23import java.util.Hashtable; 24 25/** 26 * This class is responsible for providing the dynamic names and addresses for 27 * the java.net classes. There are two directories which need to be placed on an 28 * ftp server and an http server which should accompany this source. The 29 * ftp-files have to be placed on an ftp server and have to be the root of a 30 * user jcltest with password jclpass. The testres files must be available on an 31 * HTTP server and the name and location can be configured below. 32 */ 33public class Support_Configuration { 34 35 public static String DomainAddress = "apache.org"; 36 37 public static String WebName = "jcltest."; 38 39 public static final String HomeAddress; 40 41 public static String TestResourcesDir = "/testres231"; 42 43 public static final String TestResources; 44 45 public static String HomeAddressResponse = "HTTP/1.1 200 OK"; 46 47 public static String HomeAddressSoftware = "Jetty(6.0.x)"; 48 49 public static String ProxyServerTestHost = "jcltest.apache.org"; 50 51 public static String SocksServerTestHost = "jcltest.apache.org"; 52 53 public static int SocksServerTestPort = 1080; 54 55 // Need an IP address that does not resolve to a host name 56 public static String UnresolvedIP = "192.168.99.99"; 57 58 // the bytes for an address which represents an address which is not 59 // one of the addresses for any of our machines on which tests will run 60 // it is used to verify we get the expected error when we try to bind 61 // to an address that is not one of the machines local addresses 62 public static byte nonLocalAddressBytes[] = { 1, 0, 0, 0 }; 63 64 public static String InetTestIP = "127.0.0.1"; 65 66 public static String InetTestIP2 = "127.0.0.1"; 67 68 public static final String HomeAddress6 = "jcltest6.apache.org"; 69 70 public static String IPv6GlobalAddressJcl4 = "FE80:0000:0000:0000:020D:60FF:FE0F:A776%4"; // this 71 72 public static String ProxyServerTestHostIPv6 = "jcltest6.apache.org"; 73 74 // ip address that resolves to a host that is not present on the local 75 // network 76 // this allows us to check the timeouts for connect 77 public static String ResolvedNotExistingHost = "9.26.194.72"; 78 79 /** 80 * You can compute the hash code with the following code: try { String name = 81 * "whatever.xxx.com"; 82 * System.out.println(InetAddress.getByName(name).hashCode()); } catch 83 * (UnknownHostException e) {} 84 */ 85 86 public static String FTPTestAddress = "jcltest:jclpass@localhost"; 87 88 public static String URLConnectionLastModifiedString = "Mon, 14 Jun 1999 21:06:22 GMT"; 89 90 public static long URLConnectionLastModified = 929394382000L; 91 92 public static boolean RunCommTests = false; 93 94 public static String Port1 = "COM1"; 95 96 public static String Port2 = "COM2"; 97 98 static Hashtable<String, String> props = null; 99 static { 100 loadProperties(); 101 HomeAddress = WebName + DomainAddress; 102 TestResources = HomeAddress + TestResourcesDir; 103 } 104 105 static void loadProperties() { 106 InputStream in = null; 107 Hashtable<String, String> props = new Hashtable<String, String>(); 108 109 String iniName = System.getProperty("test.ini.file", "JCLAuto.ini"); 110 if (System.getProperty("test.comm") != null) { 111 RunCommTests = true; 112 } 113 114 try { 115 in = new FileInputStream(iniName); 116 } catch (IOException e) { 117 } catch (Exception e) { 118 System.out.println("SupportConfiguration.loadProperties()"); 119 System.out.println(e); 120 e.printStackTrace(); 121 } 122 if (in == null) { 123 try { 124 Class<?> cl = Class 125 .forName("com.ibm.support.Support_Configuration"); 126 in = cl.getResourceAsStream(iniName); 127 } catch (ClassNotFoundException e) { 128 } 129 } 130 try { 131 if (in != null) { 132 load(in, props); 133 } 134 } catch (IOException e) { 135 } 136 if (props.size() == 0) { 137 return; 138 } 139 String value; 140 141 value = props.get("DomainAddress"); 142 if (value != null) { 143 DomainAddress = value; 144 } 145 146 value = props.get("WebName"); 147 if (value != null) { 148 WebName = value; 149 } 150 151 value = props.get("TestResourcesDir"); 152 if (value != null) { 153 TestResourcesDir = value; 154 } 155 value = props.get("HomeAddressResponse"); 156 if (value != null) { 157 HomeAddressResponse = value; 158 } 159 160 value = props.get("HomeAddressSoftware"); 161 if (value != null) { 162 HomeAddressSoftware = value; 163 } 164 165 value = props.get("ProxyServerTestHost"); 166 if (value != null) { 167 ProxyServerTestHost = value; 168 } 169 170 value = props.get("SocksServerTestHost"); 171 if (value != null) { 172 SocksServerTestHost = value; 173 } 174 175 value = props.get("SocksServerTestPort"); 176 if (value != null) { 177 SocksServerTestPort = Integer.parseInt(value); 178 } 179 180 value = props.get("UnresolvedIP"); 181 if (value != null) { 182 UnresolvedIP = value; 183 } 184 185 value = props.get("FTPTestAddress"); 186 if (value != null) { 187 FTPTestAddress = value; 188 } 189 190 value = props.get("URLConnectionLastModifiedString"); 191 if (value != null) { 192 URLConnectionLastModifiedString = value; 193 } 194 195 value = props.get("URLConnectionLastModified"); 196 if (value != null) { 197 URLConnectionLastModified = Long.parseLong(value); 198 } 199 200 value = props.get("Port1"); 201 if (value != null) { 202 Port1 = value; 203 } 204 205 value = props.get("Port2"); 206 if (value != null) { 207 Port2 = value; 208 } 209 210 value = props.get("ProxyServerTestHostIPv6"); 211 if (value != null) { 212 ProxyServerTestHostIPv6 = value; 213 } 214 215 value = props.get("ResolvedNotExistingHost"); 216 if (value != null) { 217 ResolvedNotExistingHost = value; 218 } 219 220 value = props.get("IPv6GlobalAddressJcl4"); 221 if (value != null) { 222 IPv6GlobalAddressJcl4 = value; 223 } 224 225 } 226 227 static void load(InputStream in, Hashtable<String, String> result) throws IOException { 228 int NONE = 0, SLASH = 1, UNICODE = 2, CONTINUE = 3, DONE = 4, IGNORE = 5; 229 int mode = NONE, unicode = 0, count = 0, nextChar; 230 StringBuffer key = new StringBuffer(), value = new StringBuffer(), buffer = key; 231 boolean firstChar = true; 232 233 while ((nextChar = in.read()) != -1) { 234 if (mode == UNICODE) { 235 int digit = Character.digit((char) nextChar, 16); 236 if (digit >= 0) { 237 unicode = (unicode << 4) + digit; 238 if (++count < 4) { 239 continue; 240 } 241 } 242 mode = NONE; 243 buffer.append((char) unicode); 244 if (nextChar != '\n') { 245 continue; 246 } 247 } 248 if (mode == SLASH) { 249 mode = NONE; 250 switch (nextChar) { 251 case '\r': 252 mode = CONTINUE; // Look for a following \n 253 continue; 254 case '\n': 255 mode = IGNORE; // Ignore whitespace on the next line 256 continue; 257 case 'b': 258 nextChar = '\b'; 259 break; 260 case 'f': 261 nextChar = '\f'; 262 break; 263 case 'n': 264 nextChar = '\n'; 265 break; 266 case 'r': 267 nextChar = '\r'; 268 break; 269 case 't': 270 nextChar = '\t'; 271 break; 272 case 'u': 273 mode = UNICODE; 274 unicode = count = 0; 275 continue; 276 } 277 } else { 278 switch (nextChar) { 279 case '#': 280 case '!': 281 if (firstChar) { 282 while ((nextChar = in.read()) != -1) { 283 if (nextChar == '\r' || nextChar == '\n') { 284 break; 285 } 286 } 287 continue; 288 } 289 break; 290 case '\n': 291 if (mode == CONTINUE) { // Part of a \r\n sequence 292 mode = IGNORE; // Ignore whitespace on the next line 293 continue; 294 } 295 // fall into the next case 296 case '\r': 297 mode = NONE; 298 firstChar = true; 299 if (key.length() > 0 || buffer == value) { 300 result.put(key.toString(), value.toString()); 301 } 302 key.setLength(0); 303 value.setLength(0); 304 buffer = key; 305 continue; 306 case '\\': 307 mode = SLASH; 308 continue; 309 case ':': 310 case '=': 311 if (buffer == key) { 312 buffer = value; 313 continue; 314 } 315 break; 316 } 317 char c = (char) nextChar; 318 if ((c >= 0x1c && c <= 0x20) || (c >= 0x9 && c <= 0xd)) { 319 if (mode == CONTINUE) { 320 mode = IGNORE; 321 } 322 if (buffer.length() == 0 || mode == IGNORE) { 323 continue; 324 } 325 if (buffer == key) { 326 mode = DONE; 327 continue; 328 } 329 } 330 if (mode == IGNORE || mode == CONTINUE) { 331 mode = NONE; 332 } 333 } 334 firstChar = false; 335 if (mode == DONE) { 336 buffer = value; 337 mode = NONE; 338 } 339 buffer.append((char) nextChar); 340 } 341 if (key.length() > 0 || buffer == value) { 342 result.put(key.toString(), value.toString()); 343 } 344 } 345 346} 347