author | alanb |
Fri, 02 Nov 2012 15:50:11 +0000 | |
changeset 14342 | 8435a30053c1 |
parent 13788 | 3f38e525f30a |
child 30820 | 0d4717a011d3 |
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) 2005, 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 6296310 |
|
27 |
* @library ../../httptest/ |
|
13788 | 28 |
* @build HttpCallback TestHttpServer HttpTransaction |
2 | 29 |
* @run main/othervm B6296310 |
30 |
* @summary REGRESSION: AppletClassLoader.getResourceAsStream() behaviour is wrong in some cases |
|
31 |
*/ |
|
32 |
||
33 |
import java.net.*; |
|
34 |
import java.io.*; |
|
35 |
import java.util.*; |
|
36 |
||
37 |
/* |
|
38 |
* http server returns 200 and content-length=0 |
|
39 |
* Test will throw NPE if bug still exists |
|
40 |
*/ |
|
41 |
||
42 |
public class B6296310 |
|
43 |
{ |
|
44 |
static SimpleHttpTransaction httpTrans; |
|
13788 | 45 |
static TestHttpServer server; |
2 | 46 |
|
47 |
public static void main(String[] args) |
|
48 |
{ |
|
49 |
ResponseCache.setDefault(new MyCacheHandler()); |
|
50 |
startHttpServer(); |
|
51 |
||
52 |
makeHttpCall(); |
|
53 |
} |
|
54 |
||
55 |
public static void startHttpServer() { |
|
56 |
try { |
|
57 |
httpTrans = new SimpleHttpTransaction(); |
|
13788 | 58 |
server = new TestHttpServer(httpTrans, 1, 10, 0); |
2 | 59 |
} catch (IOException e) { |
60 |
e.printStackTrace(); |
|
61 |
} |
|
62 |
} |
|
63 |
||
64 |
public static void makeHttpCall() { |
|
65 |
try { |
|
66 |
System.out.println("http server listen on: " + server.getLocalPort()); |
|
67 |
URL url = new URL("http" , InetAddress.getLocalHost().getHostAddress(), |
|
68 |
server.getLocalPort(), "/"); |
|
69 |
HttpURLConnection uc = (HttpURLConnection)url.openConnection(); |
|
70 |
System.out.println(uc.getResponseCode()); |
|
71 |
} catch (IOException e) { |
|
72 |
e.printStackTrace(); |
|
73 |
} finally { |
|
74 |
server.terminate(); |
|
75 |
} |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
class SimpleHttpTransaction implements HttpCallback |
|
80 |
{ |
|
81 |
/* |
|
82 |
* Our http server which simply retruns a file with no content |
|
83 |
*/ |
|
84 |
public void request(HttpTransaction trans) { |
|
85 |
try { |
|
86 |
trans.setResponseEntityBody(""); |
|
87 |
trans.sendResponse(200, "OK"); |
|
88 |
} catch (Exception e) { |
|
89 |
e.printStackTrace(); |
|
90 |
} |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
class MyCacheHandler extends ResponseCache |
|
95 |
{ |
|
96 |
public CacheResponse get(URI uri, String rqstMethod, Map rqstHeaders) |
|
97 |
{ |
|
98 |
return null; |
|
99 |
} |
|
100 |
||
101 |
public CacheRequest put(URI uri, URLConnection conn) |
|
102 |
{ |
|
103 |
return new MyCacheRequest(); |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
class MyCacheRequest extends CacheRequest |
|
108 |
{ |
|
109 |
public void abort() {} |
|
110 |
||
111 |
public OutputStream getBody() throws IOException { |
|
112 |
return null; |
|
113 |
} |
|
114 |
} |