author | chegar |
Fri, 27 Sep 2019 09:55:35 +0100 | |
changeset 58365 | 73950479184b |
parent 54822 | f542a3a135bd |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2004, 2019, 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 6181108 |
|
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
27 |
* @library /test/lib |
2 | 28 |
* @summary double encoded URL passed to ResponseCache |
29 |
* @author Edward Wang |
|
30 |
*/ |
|
31 |
||
32 |
import java.net.*; |
|
33 |
import java.util.*; |
|
34 |
import java.io.*; |
|
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
35 |
import jdk.test.lib.net.URIBuilder; |
58365
73950479184b
8231504: Update networking tests to avoid implicit dependency on the system proxies
chegar
parents:
54822
diff
changeset
|
36 |
import static java.net.Proxy.NO_PROXY; |
2 | 37 |
|
38 |
public class B6181108 implements Runnable { |
|
39 |
ServerSocket ss; |
|
40 |
static String urlWithSpace; |
|
41 |
||
42 |
/* |
|
43 |
* "Our" http server just return 200 |
|
44 |
*/ |
|
45 |
public void run() { |
|
46 |
try { |
|
47 |
Socket s = ss.accept(); |
|
48 |
||
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
49 |
InputStream is = s.getInputStream(); |
2 | 50 |
BufferedReader r = new BufferedReader(new InputStreamReader(is)); |
51 |
String x; |
|
52 |
while ((x=r.readLine()) != null) { |
|
53 |
if (x.length() ==0) { |
|
54 |
break; |
|
55 |
} |
|
56 |
} |
|
57 |
PrintStream out = new PrintStream( |
|
58 |
new BufferedOutputStream( |
|
59 |
s.getOutputStream() )); |
|
60 |
||
61 |
/* response 200 */ |
|
62 |
out.print("HTTP/1.1 200 OK\r\n"); |
|
63 |
out.print("Content-Type: text/html; charset=iso-8859-1\r\n"); |
|
64 |
out.print("Content-Length: 0\r\n"); |
|
65 |
out.print("Connection: close\r\n"); |
|
66 |
out.print("\r\n"); |
|
67 |
out.print("\r\n"); |
|
68 |
||
69 |
out.flush(); |
|
70 |
||
71 |
s.close(); |
|
72 |
} catch (Exception e) { |
|
73 |
e.printStackTrace(); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
74 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
75 |
try { ss.close(); } catch (IOException unused) {} |
2 | 76 |
} |
77 |
} |
|
78 |
||
79 |
static class ResponseCache extends java.net.ResponseCache { |
|
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
80 |
public CacheResponse get(URI uri, String method, Map<String,List<String>> hdrs) { |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
81 |
System.out.println("get uri = " + uri); |
2 | 82 |
if (!urlWithSpace.equals(uri.toString())) { |
83 |
throw new RuntimeException("test failed"); |
|
84 |
} |
|
85 |
return null; |
|
86 |
} |
|
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
87 |
public CacheRequest put(URI uri, URLConnection urlc) { |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
88 |
System.out.println("put uri = " + uri); |
2 | 89 |
return null; |
90 |
} |
|
91 |
} |
|
92 |
||
93 |
B6181108() throws Exception { |
|
94 |
/* start the server */ |
|
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
95 |
InetAddress loopback = InetAddress.getLoopbackAddress(); |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
96 |
ss = new ServerSocket(); |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
97 |
ss.bind(new InetSocketAddress(loopback, 0)); |
2 | 98 |
(new Thread(this)).start(); |
99 |
||
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
100 |
ResponseCache.setDefault(new ResponseCache()); |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
101 |
String base = URIBuilder.newBuilder() |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
102 |
.scheme("http") |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
103 |
.loopback() |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
104 |
.port(ss.getLocalPort()) |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
105 |
.build() |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
106 |
.toString(); |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
107 |
urlWithSpace = base + "/space%20test/page1.html"; |
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
108 |
URL url = new URL(urlWithSpace); |
58365
73950479184b
8231504: Update networking tests to avoid implicit dependency on the system proxies
chegar
parents:
54822
diff
changeset
|
109 |
URLConnection urlc = url.openConnection(NO_PROXY); |
2 | 110 |
int i = ((HttpURLConnection)(urlc)).getResponseCode(); |
54822
f542a3a135bd
8223632: Replace wildcard address with loopback or local host in tests - part 5
dfuchs
parents:
47216
diff
changeset
|
111 |
System.out.println("response code = " + i); |
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
112 |
ResponseCache.setDefault(null); |
2 | 113 |
} |
114 |
||
115 |
public static void main(String args[]) throws Exception { |
|
116 |
new B6181108(); |
|
117 |
} |
|
118 |
||
119 |
} |