jdk/test/java/net/ProxySelector/SystemProxies.java
changeset 4922 16f23522269d
child 5506 202f599c92aa
equal deleted inserted replaced
4921:8ff9a8e09752 4922:16f23522269d
       
     1 /*
       
     2  * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * This is a manual test to determine the proxies set on the system for various
       
    26  * protocols. See bug 6912868.
       
    27  */
       
    28 import java.net.Proxy;
       
    29 import java.net.ProxySelector;
       
    30 import java.net.URI;
       
    31 import java.net.URISyntaxException;
       
    32 import java.util.List;
       
    33 
       
    34 public class SystemProxies {
       
    35 
       
    36     static final String uriAuthority = "myMachine/";
       
    37     static final ProxySelector proxySel = ProxySelector.getDefault();
       
    38 
       
    39     public static void main(String[] args) {
       
    40         if (! "true".equals(System.getProperty("java.net.useSystemProxies"))) {
       
    41             System.out.println("Usage: java -Djava.net.useSystemProxies SystemProxies");
       
    42             return;
       
    43         }
       
    44 
       
    45         printProxies("http://");
       
    46         printProxies("https://");
       
    47         printProxies("ftp://");
       
    48     }
       
    49 
       
    50     static void printProxies(String proto) {
       
    51         String uriStr =  proto + uriAuthority;
       
    52         try {
       
    53             List<Proxy> proxies = proxySel.select(new URI(uriStr));
       
    54             System.out.println("Proxies returned for " + uriStr);
       
    55             for (Proxy proxy : proxies)
       
    56                 System.out.println("\t" + proxy);
       
    57         } catch (URISyntaxException e) {
       
    58             System.err.println(e);
       
    59         }
       
    60     }
       
    61 }