1666N/A/*
3261N/A * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
1666N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1666N/A *
1666N/A * This code is free software; you can redistribute it and/or modify it
1666N/A * under the terms of the GNU General Public License version 2 only, as
1666N/A * published by the Free Software Foundation.
1666N/A *
1666N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1666N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1666N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1666N/A * version 2 for more details (a copy is included in the LICENSE file that
1666N/A * accompanied this code).
1666N/A *
1666N/A * You should have received a copy of the GNU General Public License version
1666N/A * 2 along with this work; if not, write to the Free Software Foundation,
1666N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1666N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1666N/A */
1666N/A/*
1666N/A * @test
1666N/A * @bug 6737819
2244N/A * @run main/othervm B6737819
1666N/A * @summary sun.misc.net.DefaultProxySelector doesn't use proxy setting to localhost
1666N/A */
1666N/A
2244N/A/* Run in othervm mode since the test sets HTTP proxy system properties that
2244N/A * are read once and cached by the protocol handler. A previous test using the
2244N/A * HTTP handler may run and these system properties may be ignored for this test.
2244N/A */
2244N/A
1666N/Aimport java.net.ProxySelector;
1666N/Aimport java.net.Proxy;
1666N/Aimport java.net.URI;
1666N/A
1666N/Apublic class B6737819 {
1666N/A private static String[] uris = {
1666N/A "http://localhost/index.html",
1666N/A "http://127.0.0.1/index.html",
1666N/A "http://127.2/index.html",
1666N/A "http://[::1]/index.html"
1666N/A };
1666N/A public static void main(String[] args) throws Exception {
1666N/A System.setProperty("http.proxyHost", "myproxy");
1666N/A System.setProperty("http.proxyPort", "8080");
1666N/A ProxySelector sel = ProxySelector.getDefault();
1666N/A java.util.List<Proxy> l;
1666N/A // Default value for http.nonProxyHots should exclude all this uris
1666N/A // from going through the HTTP proxy
1666N/A for (String s : uris) {
1666N/A l = sel.select(new URI(s));
1666N/A if (l.size() == 1 && l.get(0).type() != Proxy.Type.DIRECT) {
1666N/A throw new RuntimeException("ProxySelector returned the wrong proxy for " + s);
1666N/A }
1666N/A }
1666N/A // Let's override the default nonProxyHosts and make sure we now get a
1666N/A // HTTP proxy
1666N/A System.setProperty("http.nonProxyHosts", "");
1666N/A for (String s : uris) {
1666N/A l = sel.select(new URI(s));
1666N/A if (l.size() == 1 && l.get(0).type() != Proxy.Type.HTTP) {
1666N/A throw new RuntimeException("ProxySelector returned the wrong proxy for " + s);
1666N/A }
1666N/A }
1666N/A }
1666N/A}