• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 ProxyServerTestHostIPv6 = "jcltest6.apache.org";
71 
72 	// ip address that resolves to a host that is not present on the local
73 	// network
74 	// this allows us to check the timeouts for connect
75 	public static String ResolvedNotExistingHost = "9.26.194.72";
76 
77 	/**
78 	 * You can compute the hash code with the following code: try { String name =
79 	 * "whatever.xxx.com";
80 	 * System.out.println(InetAddress.getByName(name).hashCode()); } catch
81 	 * (UnknownHostException e) {}
82 	 */
83 
84 	public static String FTPTestAddress = "jcltest:jclpass@localhost";
85 
86 	public static String URLConnectionLastModifiedString = "Mon, 14 Jun 1999 21:06:22 GMT";
87 
88 	public static long URLConnectionLastModified = 929394382000L;
89 
90 	public static boolean RunCommTests = false;
91 
92 	public static String Port1 = "COM1";
93 
94 	public static String Port2 = "COM2";
95 
96 	static Hashtable<String, String> props = null;
97 	static {
loadProperties()98 		loadProperties();
99 		HomeAddress = WebName + DomainAddress;
100 		TestResources = HomeAddress + TestResourcesDir;
101 	}
102 
loadProperties()103 	static void loadProperties() {
104 		InputStream in = null;
105 		Hashtable<String, String> props = new Hashtable<String, String>();
106 
107 		String iniName = System.getProperty("test.ini.file", "JCLAuto.ini");
108 		if (System.getProperty("test.comm") != null) {
109 			RunCommTests = true;
110 		}
111 
112 		try {
113 			in = new FileInputStream(iniName);
114 		} catch (IOException e) {
115 		} catch (Exception e) {
116 			System.out.println("SupportConfiguration.loadProperties()");
117 			System.out.println(e);
118 			e.printStackTrace();
119 		}
120 		if (in == null) {
121 			try {
122 				Class<?> cl = Class
123 						.forName("com.ibm.support.Support_Configuration");
124 				in = cl.getResourceAsStream(iniName);
125 			} catch (ClassNotFoundException e) {
126 			}
127 		}
128 		try {
129 			if (in != null) {
130 				load(in, props);
131 			}
132 		} catch (IOException e) {
133 		}
134 		if (props.size() == 0) {
135             return;
136         }
137 		String value;
138 
139 		value = props.get("DomainAddress");
140 		if (value != null) {
141             DomainAddress = value;
142         }
143 
144 		value = props.get("WebName");
145 		if (value != null) {
146             WebName = value;
147         }
148 
149 		value = props.get("TestResourcesDir");
150 		if (value != null) {
151             TestResourcesDir = value;
152         }
153 		value = props.get("HomeAddressResponse");
154 		if (value != null) {
155             HomeAddressResponse = value;
156         }
157 
158 		value = props.get("HomeAddressSoftware");
159 		if (value != null) {
160             HomeAddressSoftware = value;
161         }
162 
163 		value = props.get("ProxyServerTestHost");
164 		if (value != null) {
165             ProxyServerTestHost = value;
166         }
167 
168 		value = props.get("SocksServerTestHost");
169 		if (value != null) {
170             SocksServerTestHost = value;
171         }
172 
173 		value = props.get("SocksServerTestPort");
174 		if (value != null) {
175             SocksServerTestPort = Integer.parseInt(value);
176         }
177 
178 		value = props.get("UnresolvedIP");
179 		if (value != null) {
180             UnresolvedIP = value;
181         }
182 
183 		value = props.get("FTPTestAddress");
184 		if (value != null) {
185             FTPTestAddress = value;
186         }
187 
188 		value = props.get("URLConnectionLastModifiedString");
189 		if (value != null) {
190             URLConnectionLastModifiedString = value;
191         }
192 
193 		value = props.get("URLConnectionLastModified");
194 		if (value != null) {
195             URLConnectionLastModified = Long.parseLong(value);
196         }
197 
198 		value = props.get("Port1");
199 		if (value != null) {
200             Port1 = value;
201         }
202 
203 		value = props.get("Port2");
204 		if (value != null) {
205             Port2 = value;
206         }
207 
208 		value = props.get("ProxyServerTestHostIPv6");
209 		if (value != null) {
210             ProxyServerTestHostIPv6 = value;
211         }
212 
213 		value = props.get("ResolvedNotExistingHost");
214 		if (value != null) {
215             ResolvedNotExistingHost = value;
216         }
217 
218 	}
219 
load(InputStream in, Hashtable<String, String> result)220 	static void load(InputStream in, Hashtable<String, String> result) throws IOException {
221 		int NONE = 0, SLASH = 1, UNICODE = 2, CONTINUE = 3, DONE = 4, IGNORE = 5;
222 		int mode = NONE, unicode = 0, count = 0, nextChar;
223 		StringBuffer key = new StringBuffer(), value = new StringBuffer(), buffer = key;
224 		boolean firstChar = true;
225 
226 		while ((nextChar = in.read()) != -1) {
227 			if (mode == UNICODE) {
228 				int digit = Character.digit((char) nextChar, 16);
229 				if (digit >= 0) {
230 					unicode = (unicode << 4) + digit;
231 					if (++count < 4) {
232                         continue;
233                     }
234 				}
235 				mode = NONE;
236 				buffer.append((char) unicode);
237 				if (nextChar != '\n') {
238                     continue;
239                 }
240 			}
241 			if (mode == SLASH) {
242 				mode = NONE;
243 				switch (nextChar) {
244 				case '\r':
245 					mode = CONTINUE; // Look for a following \n
246 					continue;
247 				case '\n':
248 					mode = IGNORE; // Ignore whitespace on the next line
249 					continue;
250 				case 'b':
251 					nextChar = '\b';
252 					break;
253 				case 'f':
254 					nextChar = '\f';
255 					break;
256 				case 'n':
257 					nextChar = '\n';
258 					break;
259 				case 'r':
260 					nextChar = '\r';
261 					break;
262 				case 't':
263 					nextChar = '\t';
264 					break;
265 				case 'u':
266 					mode = UNICODE;
267 					unicode = count = 0;
268 					continue;
269 				}
270 			} else {
271 				switch (nextChar) {
272 				case '#':
273 				case '!':
274 					if (firstChar) {
275 						while ((nextChar = in.read()) != -1) {
276                             if (nextChar == '\r' || nextChar == '\n') {
277                                 break;
278                             }
279                         }
280 						continue;
281 					}
282 					break;
283 				case '\n':
284 					if (mode == CONTINUE) { // Part of a \r\n sequence
285 						mode = IGNORE; // Ignore whitespace on the next line
286 						continue;
287 					}
288 					// fall into the next case
289 				case '\r':
290 					mode = NONE;
291 					firstChar = true;
292 					if (key.length() > 0 || buffer == value) {
293                         result.put(key.toString(), value.toString());
294                     }
295 					key.setLength(0);
296 					value.setLength(0);
297 					buffer = key;
298 					continue;
299 				case '\\':
300 					mode = SLASH;
301 					continue;
302 				case ':':
303 				case '=':
304 					if (buffer == key) {
305 						buffer = value;
306 						continue;
307 					}
308 					break;
309 				}
310 				char c = (char) nextChar;
311 				if ((c >= 0x1c && c <= 0x20) || (c >= 0x9 && c <= 0xd)) {
312 					if (mode == CONTINUE) {
313                         mode = IGNORE;
314                     }
315 					if (buffer.length() == 0 || mode == IGNORE) {
316                         continue;
317                     }
318 					if (buffer == key) {
319 						mode = DONE;
320 						continue;
321 					}
322 				}
323 				if (mode == IGNORE || mode == CONTINUE) {
324                     mode = NONE;
325                 }
326 			}
327 			firstChar = false;
328 			if (mode == DONE) {
329 				buffer = value;
330 				mode = NONE;
331 			}
332 			buffer.append((char) nextChar);
333 		}
334 		if (key.length() > 0 || buffer == value) {
335             result.put(key.toString(), value.toString());
336         }
337 	}
338 
339 }
340