Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/HttpURLConnection/NoProxyTest.java
41152 views
1
/*
2
* Copyright (c) 2016, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 8144008
27
* @library /test/lib
28
* @summary Setting NO_PROXY on HTTP URL connections does not stop proxying
29
* @run main/othervm NoProxyTest
30
*/
31
32
import java.io.IOException;
33
import java.net.InetAddress;
34
import java.net.MalformedURLException;
35
import java.net.Proxy;
36
import java.net.ProxySelector;
37
import java.net.SocketAddress;
38
import java.net.URI;
39
import java.net.URL;
40
import java.net.URLConnection;
41
import java.util.List;
42
import jdk.test.lib.net.URIBuilder;
43
44
public class NoProxyTest {
45
46
static class NoProxyTestSelector extends ProxySelector {
47
@Override
48
public List<Proxy> select(URI uri) {
49
throw new RuntimeException("Should not reach here as proxy==Proxy.NO_PROXY");
50
}
51
@Override
52
public void connectFailed(URI u, SocketAddress s, IOException e) { }
53
}
54
55
public static void main(String args[]) throws MalformedURLException {
56
ProxySelector.setDefault(new NoProxyTestSelector());
57
58
URL url = URIBuilder.newBuilder()
59
.scheme("http")
60
.loopback()
61
.path("/")
62
.toURLUnchecked();
63
System.out.println("URL: " + url);
64
URLConnection connection;
65
try {
66
connection = url.openConnection(Proxy.NO_PROXY);
67
connection.connect();
68
} catch (IOException ignore) {
69
//ignore
70
}
71
}
72
}
73
74