author | mfang |
Wed, 17 Aug 2011 14:18:26 -0700 | |
changeset 10294 | 8fcdae2a7ec7 |
parent 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2004, 2010, 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 |
|
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 |
} catch (Exception e) { |
|
71 |
e.printStackTrace(); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
72 |
} finally { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
73 |
try { ss.close(); } catch (IOException unused) {} |
2 | 74 |
} |
75 |
} |
|
76 |
||
77 |
static class ResponseCache extends java.net.ResponseCache { |
|
78 |
public CacheResponse get (URI uri, String method, Map<String,List<String>> hdrs) { |
|
79 |
System.out.println ("get uri = " + uri); |
|
80 |
if (!urlWithSpace.equals(uri.toString())) { |
|
81 |
throw new RuntimeException("test failed"); |
|
82 |
} |
|
83 |
return null; |
|
84 |
} |
|
85 |
public CacheRequest put (URI uri, URLConnection urlc) { |
|
86 |
System.out.println ("put uri = " + uri); |
|
87 |
return null; |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
B6181108() throws Exception { |
|
92 |
/* start the server */ |
|
93 |
ss = new ServerSocket(0); |
|
94 |
(new Thread(this)).start(); |
|
95 |
||
96 |
ResponseCache.setDefault (new ResponseCache()); |
|
97 |
urlWithSpace = "http://localhost:" + |
|
98 |
Integer.toString(ss.getLocalPort()) + |
|
99 |
"/space%20test/page1.html"; |
|
100 |
URL url = new URL (urlWithSpace); |
|
101 |
URLConnection urlc = url.openConnection(); |
|
102 |
int i = ((HttpURLConnection)(urlc)).getResponseCode(); |
|
103 |
System.out.println ("response code = " + i); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
104 |
ResponseCache.setDefault(null); |
2 | 105 |
} |
106 |
||
107 |
public static void main(String args[]) throws Exception { |
|
108 |
new B6181108(); |
|
109 |
} |
|
110 |
||
111 |
} |