author | mikael |
Fri, 04 Dec 2015 15:08:49 -0800 | |
changeset 35090 | 1f5b6aa795d0 |
parent 7668 | d4a77089c587 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2003, 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 |
/* @test |
|
25 |
* @summary getResponseCode() doesn't return correct value when using cached response |
|
26 |
* @bug 4921268 |
|
27 |
* @author Yingxian Wang |
|
28 |
*/ |
|
29 |
||
30 |
import java.net.*; |
|
31 |
import java.util.*; |
|
32 |
import java.io.*; |
|
5165 | 33 |
|
2 | 34 |
|
35 |
/** |
|
36 |
* Request should get serviced by the cache handler. Response get |
|
37 |
* saved through the cache handler. |
|
38 |
*/ |
|
39 |
public class getResponseCode { |
|
40 |
static URL url; |
|
41 |
static String FNPrefix; |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
42 |
static List<Closeable> resources = new ArrayList<>(); |
2 | 43 |
|
44 |
getResponseCode() throws Exception { |
|
45 |
url = new URL("http://localhost/file1.cache"); |
|
46 |
HttpURLConnection http = (HttpURLConnection)url.openConnection(); |
|
47 |
int respCode = http.getResponseCode(); |
|
48 |
http.disconnect(); |
|
49 |
||
50 |
if (respCode != 200) { |
|
51 |
throw new RuntimeException("Response code should return 200, but it is returning "+respCode); |
|
52 |
} |
|
53 |
} |
|
54 |
public static void main(String args[]) throws Exception { |
|
5165 | 55 |
try { |
56 |
ResponseCache.setDefault(new MyResponseCache()); |
|
57 |
FNPrefix = System.getProperty("test.src", ".")+"/"; |
|
58 |
new getResponseCode(); |
|
59 |
} finally{ |
|
60 |
ResponseCache.setDefault(null); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
61 |
for (Closeable c : resources) { |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
62 |
try { c.close(); } catch (IOException unused) {} |
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
63 |
} |
5165 | 64 |
} |
2 | 65 |
} |
66 |
||
67 |
static class MyResponseCache extends ResponseCache { |
|
68 |
public CacheResponse |
|
69 |
get(URI uri, String rqstMethod, Map<String,List<String>> requestHeaders) |
|
70 |
throws IOException { |
|
71 |
return new MyResponse(FNPrefix+"file1.cache"); |
|
72 |
} |
|
73 |
public CacheRequest put(URI uri, URLConnection uconn) throws IOException {; |
|
74 |
return null; |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
static class MyResponse extends CacheResponse { |
|
79 |
FileInputStream fis; |
|
80 |
Map<String,List<String>> headers; |
|
81 |
public MyResponse(String filename) { |
|
82 |
try { |
|
83 |
fis = new FileInputStream(new File(filename)); |
|
6115
7c523cf2bc8a
6969395: TEST_BUG: Tests in java/net sun/net problems
chegar
parents:
5506
diff
changeset
|
84 |
resources.add(fis); |
2 | 85 |
headers = (Map<String,List<String>>)new ObjectInputStream(fis).readObject(); |
86 |
} catch (Exception ex) { |
|
87 |
throw new RuntimeException(ex.getMessage()); |
|
88 |
} |
|
89 |
} |
|
90 |
public InputStream getBody() throws IOException { |
|
91 |
return fis; |
|
92 |
} |
|
93 |
||
94 |
public Map<String,List<String>> getHeaders() throws IOException { |
|
95 |
return headers; |
|
96 |
} |
|
97 |
} |
|
98 |
} |