2
|
1 |
/*
|
|
2 |
* Copyright 2004 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @test
|
|
26 |
* @bug 6181108
|
|
27 |
* @summary double encoded URL passed to ResponseCache
|
|
28 |
* @author Edward Wang
|
|
29 |
*/
|
|
30 |
|
|
31 |
import java.net.*;
|
|
32 |
import java.util.*;
|
|
33 |
import java.io.*;
|
|
34 |
|
|
35 |
|
|
36 |
public class B6181108 implements Runnable {
|
|
37 |
ServerSocket ss;
|
|
38 |
static String urlWithSpace;
|
|
39 |
|
|
40 |
/*
|
|
41 |
* "Our" http server just return 200
|
|
42 |
*/
|
|
43 |
public void run() {
|
|
44 |
try {
|
|
45 |
Socket s = ss.accept();
|
|
46 |
|
|
47 |
InputStream is = s.getInputStream ();
|
|
48 |
BufferedReader r = new BufferedReader(new InputStreamReader(is));
|
|
49 |
String x;
|
|
50 |
while ((x=r.readLine()) != null) {
|
|
51 |
if (x.length() ==0) {
|
|
52 |
break;
|
|
53 |
}
|
|
54 |
}
|
|
55 |
PrintStream out = new PrintStream(
|
|
56 |
new BufferedOutputStream(
|
|
57 |
s.getOutputStream() ));
|
|
58 |
|
|
59 |
/* response 200 */
|
|
60 |
out.print("HTTP/1.1 200 OK\r\n");
|
|
61 |
out.print("Content-Type: text/html; charset=iso-8859-1\r\n");
|
|
62 |
out.print("Content-Length: 0\r\n");
|
|
63 |
out.print("Connection: close\r\n");
|
|
64 |
out.print("\r\n");
|
|
65 |
out.print("\r\n");
|
|
66 |
|
|
67 |
out.flush();
|
|
68 |
|
|
69 |
s.close();
|
|
70 |
ss.close();
|
|
71 |
} catch (Exception e) {
|
|
72 |
e.printStackTrace();
|
|
73 |
}
|
|
74 |
}
|
|
75 |
|
|
76 |
static class ResponseCache extends java.net.ResponseCache {
|
|
77 |
public CacheResponse get (URI uri, String method, Map<String,List<String>> hdrs) {
|
|
78 |
System.out.println ("get uri = " + uri);
|
|
79 |
if (!urlWithSpace.equals(uri.toString())) {
|
|
80 |
throw new RuntimeException("test failed");
|
|
81 |
}
|
|
82 |
return null;
|
|
83 |
}
|
|
84 |
public CacheRequest put (URI uri, URLConnection urlc) {
|
|
85 |
System.out.println ("put uri = " + uri);
|
|
86 |
return null;
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
B6181108() throws Exception {
|
|
91 |
/* start the server */
|
|
92 |
ss = new ServerSocket(0);
|
|
93 |
(new Thread(this)).start();
|
|
94 |
|
|
95 |
ResponseCache.setDefault (new ResponseCache());
|
|
96 |
urlWithSpace = "http://localhost:" +
|
|
97 |
Integer.toString(ss.getLocalPort()) +
|
|
98 |
"/space%20test/page1.html";
|
|
99 |
URL url = new URL (urlWithSpace);
|
|
100 |
URLConnection urlc = url.openConnection();
|
|
101 |
int i = ((HttpURLConnection)(urlc)).getResponseCode();
|
|
102 |
System.out.println ("response code = " + i);
|
|
103 |
}
|
|
104 |
|
|
105 |
public static void main(String args[]) throws Exception {
|
|
106 |
new B6181108();
|
|
107 |
}
|
|
108 |
|
|
109 |
}
|