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