jdk/test/java/net/HttpURLConnection/NoProxyTest.java
author vtewari
Tue, 21 Jun 2016 14:00:59 +0100
changeset 39128 e991a1c8b41b
permissions -rw-r--r--
8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying Reviewed-by: chegar, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39128
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     1
/*
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     4
 *
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     8
 *
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    13
 * accompanied this code).
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    14
 *
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    18
 *
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    21
 * questions.
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    22
 */
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    23
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    24
 /*
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    25
 * @test
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    26
 * @bug 8144008
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    27
 * @summary Setting NO_PROXY on HTTP URL connections does not stop proxying
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    28
 * @run main/othervm NoProxyTest
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    29
 */
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    30
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    31
import java.io.IOException;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    32
import java.net.MalformedURLException;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    33
import java.net.Proxy;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    34
import java.net.ProxySelector;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    35
import java.net.SocketAddress;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    36
import java.net.URI;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    37
import java.net.URL;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    38
import java.net.URLConnection;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    39
import java.util.List;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    40
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    41
public class NoProxyTest {
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    42
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    43
    static class NoProxyTestSelector extends ProxySelector {
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    44
        @Override
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    45
        public List<Proxy> select(URI uri) {
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    46
            throw new RuntimeException("Should not reach here as proxy==Proxy.NO_PROXY");
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    47
        }
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    48
        @Override
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    49
        public void connectFailed(URI u, SocketAddress s, IOException e) { }
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    50
    }
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    51
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    52
    public static void main(String args[]) throws MalformedURLException {
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    53
        ProxySelector.setDefault(new NoProxyTestSelector());
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    54
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    55
        URL url = URI.create("http://127.0.0.1/").toURL();
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    56
        URLConnection connection;
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    57
        try {
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    58
            connection = url.openConnection(Proxy.NO_PROXY);
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    59
            connection.connect();
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    60
        } catch (IOException ignore) {
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    61
            //ignore
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    62
        }
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    63
    }
e991a1c8b41b 8144008: Setting NO_PROXY on HTTP URL connections does not stop proxying
vtewari
parents:
diff changeset
    64
}