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 InetTestAddress = "localhost"; 65 66 public static String InetTestIP = "127.0.0.1"; 67 68 // BEGIN android-added 69 public static byte[] InetTestAddr = {127, 0, 0, 1}; 70 // END android-added 71 72 public static String InetTestAddress2 = "localhost"; 73 74 public static String InetTestIP2 = "127.0.0.1"; 75 76 public static byte[] InetTestCaddr = { 9, 26, -56, -111 }; 77 78 public static final String HomeAddress6 = "jcltest6.apache.org"; 79 80 public static String IPv6GlobalAddressJcl4 = "FE80:0000:0000:0000:020D:60FF:FE0F:A776%4"; // this 81 82 public static String ProxyServerTestHostIPv6 = "jcltest6.apache.org"; 83 84 public static String InetTestIP6 = "fe80::20d:60ff:fe24:7410"; 85 86 public static String InetTestIP6LO = "::1"; 87 88 // ip address that resolves to a host that is not present on the local 89 // network 90 // this allows us to check the timeouts for connect 91 public static String ResolvedNotExistingHost = "9.26.194.72"; 92 93 // BEGIN android-changed 94 /** 95 * An address that resolves to more than one IP address so that the 96 * getAllByName test has something to test. 97 */ 98 public static String SpecialInetTestAddress = "www.google.com"; 99 // changed from jcltestmultiple.apache.org to www.google.com since 100 // the old address vaished from the net. www.google.com has also more 101 // than one addresses returned for this host name as needed by a test 102 // END android-changed 103 104 public static String testURL = "harmony.apache.org"; 105 106 public static String hTTPURLwExpiration = "http://phpwiki.sourceforge.net/phpwiki-1.2/"; 107 108 public static String hTTPURLwLastModified = "http://www.php.net/manual/en/function.explode.php"; 109 110 public static String hTTPURLyahoo = "http://news.yahoo.com/"; 111 112 public static String hTTPURLgoogle = "http://www.google.com/ie"; 113 114 public static String testContentEncoding = "http://www.amazon.com/"; 115 116 public static int SpecialInetTestAddressNumber = 4; 117 118 /** 119 * InetAlias1 and InetAlias2 must be different host names that resolve to 120 * the same IP address. 121 */ 122 public static String InetAlias1 = "alias1.apache.org"; 123 124 public static String InetAlias2 = "alias2.apache.org"; 125 126 public static String FTPTestAddress = "jcltest:jclpass@localhost"; 127 128 public static String URLConnectionLastModifiedString = "Mon, 14 Jun 1999 21:06:22 GMT"; 129 130 public static long URLConnectionLastModified = 929394382000L; 131 132 public static long URLConnectionDate = 929106872000L; 133 134 public static boolean RunCommTests = false; 135 136 public static String Port1 = "COM1"; 137 138 public static String Port2 = "COM2"; 139 140 static Hashtable<String, String> props = null; 141 static { 142 loadProperties(); 143 HomeAddress = WebName + DomainAddress; 144 TestResources = HomeAddress + TestResourcesDir; 145 } 146 147 static void loadProperties() { 148 InputStream in = null; 149 Hashtable<String, String> props = new Hashtable<String, String>(); 150 151 String iniName = System.getProperty("test.ini.file", "JCLAuto.ini"); 152 if (System.getProperty("test.comm") != null) { 153 RunCommTests = true; 154 } 155 156 try { 157 in = new FileInputStream(iniName); 158 } catch (IOException e) { 159 } catch (Exception e) { 160 System.out.println("SupportConfiguration.loadProperties()"); 161 System.out.println(e); 162 e.printStackTrace(); 163 } 164 if (in == null) { 165 try { 166 Class<?> cl = Class 167 .forName("com.ibm.support.Support_Configuration"); 168 in = cl.getResourceAsStream(iniName); 169 } catch (ClassNotFoundException e) { 170 } 171 } 172 try { 173 if (in != null) { 174 load(in, props); 175 } 176 } catch (IOException e) { 177 } 178 if (props.size() == 0) { 179 return; 180 } 181 String value; 182 183 value = props.get("DomainAddress"); 184 if (value != null) { 185 DomainAddress = value; 186 } 187 188 value = props.get("WebName"); 189 if (value != null) { 190 WebName = value; 191 } 192 193 value = props.get("TestResourcesDir"); 194 if (value != null) { 195 TestResourcesDir = value; 196 } 197 value = props.get("HomeAddressResponse"); 198 if (value != null) { 199 HomeAddressResponse = value; 200 } 201 202 value = props.get("HomeAddressSoftware"); 203 if (value != null) { 204 HomeAddressSoftware = value; 205 } 206 207 value = props.get("ProxyServerTestHost"); 208 if (value != null) { 209 ProxyServerTestHost = value; 210 } 211 212 value = props.get("SocksServerTestHost"); 213 if (value != null) { 214 SocksServerTestHost = value; 215 } 216 217 value = props.get("SocksServerTestPort"); 218 if (value != null) { 219 SocksServerTestPort = Integer.parseInt(value); 220 } 221 222 value = props.get("UnresolvedIP"); 223 if (value != null) { 224 UnresolvedIP = value; 225 } 226 227 value = props.get("InetTestAddress"); 228 if (value != null) { 229 InetTestAddress = value; 230 } 231 232 value = props.get("InetTestIP"); 233 if (value != null) { 234 InetTestIP = value; 235 byte[] addr = new byte[4]; 236 int last = 0; 237 try { 238 for (int i = 0; i < 3; i++) { 239 int dot = InetTestIP.indexOf('.', last); 240 addr[i] = (byte) Integer.parseInt(InetTestIP.substring( 241 last, dot)); 242 last = dot + 1; 243 } 244 addr[3] = (byte) Integer.parseInt(InetTestIP.substring(last)); 245 InetTestCaddr = addr; 246 } catch (RuntimeException e) { 247 System.out.println("Error parsing InetTestIP (" + InetTestIP 248 + ")"); 249 System.out.println(e); 250 } 251 } 252 253 value = props.get("NonLocalAddressBytes"); 254 if (value != null) { 255 String nonLocalAddressBytesString = value; 256 byte[] addr = new byte[4]; 257 int last = 0; 258 try { 259 for (int i = 0; i < 3; i++) { 260 int dot = nonLocalAddressBytesString.indexOf('.', last); 261 addr[i] = (byte) Integer 262 .parseInt(nonLocalAddressBytesString.substring( 263 last, dot)); 264 last = dot + 1; 265 } 266 addr[3] = (byte) Integer.parseInt(nonLocalAddressBytesString 267 .substring(last)); 268 nonLocalAddressBytes = addr; 269 } catch (RuntimeException e) { 270 System.out.println("Error parsing NonLocalAddressBytes (" 271 + nonLocalAddressBytesString + ")"); 272 System.out.println(e); 273 } 274 } 275 276 value = props.get("InetTestAddress2"); 277 if (value != null) { 278 InetTestAddress2 = value; 279 } 280 281 value = props.get("InetTestIP2"); 282 if (value != null) { 283 InetTestIP2 = value; 284 } 285 286 value = props.get("SpecialInetTestAddress"); 287 if (value != null) { 288 SpecialInetTestAddress = value; 289 } 290 291 value = props.get("SpecialInetTestAddressNumber"); 292 if (value != null) { 293 SpecialInetTestAddressNumber = Integer.parseInt(value); 294 } 295 296 value = props.get("FTPTestAddress"); 297 if (value != null) { 298 FTPTestAddress = value; 299 } 300 301 value = props.get("URLConnectionLastModifiedString"); 302 if (value != null) { 303 URLConnectionLastModifiedString = value; 304 } 305 306 value = props.get("URLConnectionLastModified"); 307 if (value != null) { 308 URLConnectionLastModified = Long.parseLong(value); 309 } 310 311 value = props.get("URLConnectionDate"); 312 if (value != null) { 313 URLConnectionDate = Long.parseLong(value); 314 } 315 316 value = props.get("Port1"); 317 if (value != null) { 318 Port1 = value; 319 } 320 321 value = props.get("Port2"); 322 if (value != null) { 323 Port2 = value; 324 } 325 326 value = props.get("InetTestIP6"); 327 if (value != null) { 328 InetTestIP6 = value; 329 } 330 331 value = props.get("InetTestIP6LO"); 332 if (value != null) { 333 InetTestIP6LO = value; 334 } 335 336 value = props.get("ProxyServerTestHostIPv6"); 337 if (value != null) { 338 ProxyServerTestHostIPv6 = value; 339 } 340 341 value = props.get("ResolvedNotExistingHost"); 342 if (value != null) { 343 ResolvedNotExistingHost = value; 344 } 345 346 value = props.get("InetAlias1"); 347 if (value != null) { 348 InetAlias1 = value; 349 } 350 351 value = props.get("InetAlias2"); 352 if (value != null) { 353 InetAlias2 = value; 354 } 355 356 value = props.get("IPv6GlobalAddressJcl4"); 357 if (value != null) { 358 IPv6GlobalAddressJcl4 = value; 359 } 360 361 } 362 363 static void load(InputStream in, Hashtable<String, String> result) throws IOException { 364 int NONE = 0, SLASH = 1, UNICODE = 2, CONTINUE = 3, DONE = 4, IGNORE = 5; 365 int mode = NONE, unicode = 0, count = 0, nextChar; 366 StringBuffer key = new StringBuffer(), value = new StringBuffer(), buffer = key; 367 boolean firstChar = true; 368 369 while ((nextChar = in.read()) != -1) { 370 if (mode == UNICODE) { 371 int digit = Character.digit((char) nextChar, 16); 372 if (digit >= 0) { 373 unicode = (unicode << 4) + digit; 374 if (++count < 4) { 375 continue; 376 } 377 } 378 mode = NONE; 379 buffer.append((char) unicode); 380 if (nextChar != '\n') { 381 continue; 382 } 383 } 384 if (mode == SLASH) { 385 mode = NONE; 386 switch (nextChar) { 387 case '\r': 388 mode = CONTINUE; // Look for a following \n 389 continue; 390 case '\n': 391 mode = IGNORE; // Ignore whitespace on the next line 392 continue; 393 case 'b': 394 nextChar = '\b'; 395 break; 396 case 'f': 397 nextChar = '\f'; 398 break; 399 case 'n': 400 nextChar = '\n'; 401 break; 402 case 'r': 403 nextChar = '\r'; 404 break; 405 case 't': 406 nextChar = '\t'; 407 break; 408 case 'u': 409 mode = UNICODE; 410 unicode = count = 0; 411 continue; 412 } 413 } else { 414 switch (nextChar) { 415 case '#': 416 case '!': 417 if (firstChar) { 418 while ((nextChar = in.read()) != -1) { 419 if (nextChar == '\r' || nextChar == '\n') { 420 break; 421 } 422 } 423 continue; 424 } 425 break; 426 case '\n': 427 if (mode == CONTINUE) { // Part of a \r\n sequence 428 mode = IGNORE; // Ignore whitespace on the next line 429 continue; 430 } 431 // fall into the next case 432 case '\r': 433 mode = NONE; 434 firstChar = true; 435 if (key.length() > 0 || buffer == value) { 436 result.put(key.toString(), value.toString()); 437 } 438 key.setLength(0); 439 value.setLength(0); 440 buffer = key; 441 continue; 442 case '\\': 443 mode = SLASH; 444 continue; 445 case ':': 446 case '=': 447 if (buffer == key) { 448 buffer = value; 449 continue; 450 } 451 break; 452 } 453 char c = (char) nextChar; 454 if ((c >= 0x1c && c <= 0x20) || (c >= 0x9 && c <= 0xd)) { 455 if (mode == CONTINUE) { 456 mode = IGNORE; 457 } 458 if (buffer.length() == 0 || mode == IGNORE) { 459 continue; 460 } 461 if (buffer == key) { 462 mode = DONE; 463 continue; 464 } 465 } 466 if (mode == IGNORE || mode == CONTINUE) { 467 mode = NONE; 468 } 469 } 470 firstChar = false; 471 if (mode == DONE) { 472 buffer = value; 473 mode = NONE; 474 } 475 buffer.append((char) nextChar); 476 } 477 if (key.length() > 0 || buffer == value) { 478 result.put(key.toString(), value.toString()); 479 } 480 } 481 482} 483