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