Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/net/httpserver/bugs/B6431193.java
41154 views
1
/*
2
* Copyright (c) 2006, 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 6431193
27
* @library /test/lib
28
* @summary The new HTTP server exits immediately
29
* @run main B6431193
30
* @run main/othervm -Djava.net.preferIPv6Addresses=true B6431193
31
*/
32
33
import java.io.IOException;
34
import java.io.InputStream;
35
import java.io.OutputStream;
36
import java.net.*;
37
import jdk.test.lib.net.URIBuilder;
38
39
import com.sun.net.httpserver.*;
40
41
public class B6431193 {
42
43
static boolean error = false;
44
45
public static void read (InputStream i) throws IOException {
46
while (i.read() != -1);
47
i.close();
48
}
49
50
/**
51
* @param args
52
*/
53
public static void main(String[] args) {
54
class MyHandler implements HttpHandler {
55
public void handle(HttpExchange t) throws IOException {
56
InputStream is = t.getRequestBody();
57
read(is);
58
// .. read the request body
59
String response = "This is the response";
60
t.sendResponseHeaders(200, response.length());
61
OutputStream os = t.getResponseBody();
62
os.write(response.getBytes());
63
os.close();
64
error = Thread.currentThread().isDaemon();
65
}
66
}
67
68
69
HttpServer server;
70
try {
71
InetAddress loopback = InetAddress.getLoopbackAddress();
72
server = HttpServer.create(new InetSocketAddress(loopback, 0), 10);
73
74
server.createContext("/apps", new MyHandler());
75
server.setExecutor(null);
76
// creates a default executor
77
server.start();
78
int port = server.getAddress().getPort();
79
String s = "http://localhost:"+port+"/apps/foo";
80
URL url = URIBuilder.newBuilder()
81
.scheme("http")
82
.loopback()
83
.port(port)
84
.path("/apps/foo")
85
.toURL();
86
InputStream is = url.openConnection(Proxy.NO_PROXY).getInputStream();
87
read (is);
88
server.stop (1);
89
if (error) {
90
throw new RuntimeException ("error in test");
91
}
92
93
}
94
catch (Exception e) {
95
throw new AssertionError("Unexpected exception: " + e, e);
96
}
97
}
98
}
99
100