Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/http/B6296310.java
41159 views
1
/*
2
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. 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 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.
22
*/
23
24
/*
25
* @test
26
* @bug 6296310
27
* @modules java.base/sun.net.www
28
* @library ../../httptest/
29
* @build HttpCallback TestHttpServer HttpTransaction
30
* @run main/othervm B6296310
31
* @run main/othervm -Djava.net.preferIPv6Addresses=true B6296310
32
* @summary REGRESSION: AppletClassLoader.getResourceAsStream() behaviour is wrong in some cases
33
*/
34
35
import java.net.*;
36
import java.io.*;
37
import java.util.*;
38
39
/*
40
* http server returns 200 and content-length=0
41
* Test will throw NPE if bug still exists
42
*/
43
44
public class B6296310
45
{
46
static SimpleHttpTransaction httpTrans;
47
static TestHttpServer server;
48
49
public static void main(String[] args) throws Exception
50
{
51
ResponseCache.setDefault(new MyCacheHandler());
52
startHttpServer();
53
makeHttpCall();
54
}
55
56
public static void startHttpServer() throws IOException {
57
httpTrans = new SimpleHttpTransaction();
58
InetAddress loopback = InetAddress.getLoopbackAddress();
59
server = new TestHttpServer(httpTrans, 1, 10, loopback, 0);
60
}
61
62
public static void makeHttpCall() throws IOException {
63
try {
64
System.out.println("http server listen on: " + server.getLocalPort());
65
URL url = new URL("http" , InetAddress.getLoopbackAddress().getHostAddress(),
66
server.getLocalPort(), "/");
67
HttpURLConnection uc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY);
68
System.out.println(uc.getResponseCode());
69
} finally {
70
server.terminate();
71
}
72
}
73
}
74
75
class SimpleHttpTransaction implements HttpCallback
76
{
77
/*
78
* Our http server which simply retruns a file with no content
79
*/
80
public void request(HttpTransaction trans) {
81
try {
82
trans.setResponseEntityBody("");
83
trans.sendResponse(200, "OK");
84
} catch (Exception e) {
85
e.printStackTrace();
86
}
87
}
88
}
89
90
class MyCacheHandler extends ResponseCache
91
{
92
public CacheResponse get(URI uri, String rqstMethod, Map rqstHeaders)
93
{
94
return null;
95
}
96
97
public CacheRequest put(URI uri, URLConnection conn)
98
{
99
return new MyCacheRequest();
100
}
101
}
102
103
class MyCacheRequest extends CacheRequest
104
{
105
public void abort() {}
106
107
public OutputStream getBody() throws IOException {
108
return null;
109
}
110
}
111
112