Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/ProxySelector/SystemProxies.java
38812 views
/*1* Copyright (c) 2010, 2013, 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* This is a manual test to determine the proxies set on the system for various25* protocols. See bug 6912868.26*/27import java.net.Proxy;28import java.net.ProxySelector;29import java.net.URI;30import java.net.URISyntaxException;31import java.util.List;3233public class SystemProxies {3435static final String[] uriAuthority = { "myMachine/", "local", "localhost",36"127.0.0.1", "127.0.0.123",37"127.0.2.2", "127.3.3.3",38"128.0.0.1" };39static final ProxySelector proxySel = ProxySelector.getDefault();4041public static void main(String[] args) {42if (! "true".equals(System.getProperty("java.net.useSystemProxies"))) {43System.out.println("Usage: java -Djava.net.useSystemProxies=true SystemProxies");44return;45}4647printProxies("http://");48printProxies("https://");49printProxies("ftp://");50printProxies("none://");51printProxies("gopher://");52printProxies("rtsp://");53printProxies("socket://");54}5556static void printProxies(String proto) {57System.out.println("Protocol:" + proto);58for (String uri : uriAuthority) {59String uriStr = proto + uri;60try {61List<Proxy> proxies = proxySel.select(new URI(uriStr));62System.out.println("\tProxies returned for " + uriStr);63for (Proxy proxy : proxies)64System.out.println("\t\t" + proxy);65} catch (URISyntaxException e) {66System.err.println(e);67}68}69}70}717273