author | aeubanks |
Tue, 16 Apr 2019 13:06:23 -0700 | |
changeset 54770 | 62b6e7587b1f |
parent 47216 | 71c04702a3d5 |
child 54822 | f542a3a135bd |
permissions | -rw-r--r-- |
2 | 1 |
/* |
14342
8435a30053c1
7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents:
13788
diff
changeset
|
2 |
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4696512 |
|
27 |
* @summary HTTP client: Improve proxy server configuration and selection |
|
30820 | 28 |
* @modules java.base/sun.net.www |
2 | 29 |
* @library ../../../sun/net/www/httptest/ |
13788 | 30 |
* @build ClosedChannelList TestHttpServer HttpTransaction HttpCallback |
4347
ab0a9f495844
6907177: Update jdk tests to remove unncessary -source and -target options
darcy
parents:
2
diff
changeset
|
31 |
* @compile ProxyTest.java |
2 | 32 |
* @run main/othervm -Dhttp.proxyHost=inexistant -Dhttp.proxyPort=8080 ProxyTest |
33 |
*/ |
|
34 |
||
35 |
import java.net.*; |
|
36 |
import java.io.*; |
|
37 |
import java.util.ArrayList; |
|
38 |
||
39 |
public class ProxyTest implements HttpCallback { |
|
13788 | 40 |
static TestHttpServer server; |
2 | 41 |
|
42 |
public ProxyTest() { |
|
43 |
} |
|
44 |
||
45 |
public void request (HttpTransaction req) { |
|
46 |
req.setResponseEntityBody ("Hello ."); |
|
47 |
try { |
|
48 |
req.sendResponse (200, "Ok"); |
|
49 |
req.orderlyClose(); |
|
50 |
} catch (IOException e) { |
|
51 |
} |
|
52 |
} |
|
53 |
||
54 |
static public class MyProxySelector extends ProxySelector { |
|
55 |
private ProxySelector def = null; |
|
56 |
private ArrayList<Proxy> noProxy; |
|
57 |
||
58 |
public MyProxySelector() { |
|
59 |
noProxy = new ArrayList<Proxy>(1); |
|
60 |
noProxy.add(Proxy.NO_PROXY); |
|
61 |
} |
|
62 |
||
63 |
public java.util.List<Proxy> select(URI uri) { |
|
64 |
return noProxy; |
|
65 |
} |
|
66 |
||
67 |
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
||
72 |
public static void main(String[] args) { |
|
73 |
ProxySelector defSelector = ProxySelector.getDefault(); |
|
74 |
if (defSelector == null) |
|
75 |
throw new RuntimeException("Default ProxySelector is null"); |
|
76 |
ProxySelector.setDefault(new MyProxySelector()); |
|
77 |
try { |
|
13788 | 78 |
server = new TestHttpServer (new ProxyTest(), 1, 10, 0); |
2 | 79 |
URL url = new URL("http://localhost:"+server.getLocalPort()); |
80 |
System.out.println ("client opening connection to: " + url); |
|
81 |
HttpURLConnection urlc = (HttpURLConnection)url.openConnection (); |
|
82 |
InputStream is = urlc.getInputStream (); |
|
83 |
is.close(); |
|
84 |
} catch (Exception e) { |
|
85 |
throw new RuntimeException(e); |
|
86 |
} finally { |
|
87 |
if (server != null) { |
|
88 |
server.terminate(); |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
92 |
} |