Path: blob/master/test/jdk/java/net/ProxySelector/SystemProxies.java
41152 views
/*1* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6912868 817086826* @summary Basic test to provide some coverage of system proxy code. Will27* always pass. Should be run manually for specific systems to inspect output.28* @run main/othervm -Djava.net.useSystemProxies=true SystemProxies29*/3031import java.net.Proxy;32import java.net.ProxySelector;33import java.net.URI;34import java.net.URISyntaxException;35import java.util.List;3637public class SystemProxies {3839static final String[] uriAuthority = { "myMachine/", "local", "localhost",40"127.0.0.1", "127.0.0.123",41"127.0.2.2", "127.3.3.3",42"128.0.0.1" };43static final ProxySelector proxySel = ProxySelector.getDefault();4445public static void main(String[] args) {46if (! "true".equals(System.getProperty("java.net.useSystemProxies"))) {47System.out.println("Usage: java -Djava.net.useSystemProxies=true SystemProxies");48return;49}5051printProxies("http://");52printProxies("https://");53printProxies("ftp://");54printProxies("none://");55printProxies("rtsp://");56printProxies("socket://");57}5859static void printProxies(String proto) {60System.out.println("Protocol:" + proto);61for (String uri : uriAuthority) {62String uriStr = proto + uri;63try {64List<Proxy> proxies = proxySel.select(new URI(uriStr));65System.out.println("\tProxies returned for " + uriStr);66for (Proxy proxy : proxies)67System.out.println("\t\t" + proxy);68} catch (URISyntaxException e) {69System.err.println(e);70}71}72}73}747576