Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/http/B8012625.java
41159 views
1
/*
2
* Copyright (c) 2013, 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 8012625
27
* @library /test/lib
28
* @modules jdk.httpserver
29
* @run main B8012625
30
*/
31
32
import java.net.*;
33
import java.io.*;
34
35
import java.net.*;
36
import java.io.*;
37
import java.util.concurrent.*;
38
39
import jdk.test.lib.net.URIBuilder;
40
41
import com.sun.net.httpserver.*;
42
43
public class B8012625 implements HttpHandler {
44
45
public static void main (String[] args) throws Exception {
46
B8012625 test = new B8012625();
47
test.run();
48
}
49
50
public void run() throws Exception {
51
URL url = URIBuilder.newBuilder()
52
.scheme("http")
53
.loopback()
54
.port(port)
55
.path("/foo")
56
.toURL();
57
System.out.println("URL: " + url);
58
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
59
uc.setDoOutput(true);
60
uc.setRequestMethod("POST");
61
uc.addRequestProperty("Expect", "100-Continue");
62
//uc.setFixedLengthStreamingMode(256);
63
System.out.println ("Client: getting outputstream");
64
long before = System.currentTimeMillis();
65
OutputStream os = uc.getOutputStream();
66
long after = System.currentTimeMillis();
67
System.out.println ("Client: writing to outputstream");
68
byte[] buf = new byte[256];
69
os.write(buf);
70
System.out.println ("Client: done writing ");
71
int r = uc.getResponseCode();
72
System.out.println ("Client: received response code " + r);
73
server.stop(1);
74
ex.shutdownNow();
75
if (after - before >= 5000) {
76
throw new RuntimeException("Error: 5 second delay seen");
77
}
78
}
79
80
int port;
81
HttpServer server;
82
ExecutorService ex;
83
84
public B8012625 () throws Exception {
85
InetAddress loopback = InetAddress.getLoopbackAddress();
86
server = HttpServer.create(new InetSocketAddress(loopback, 0), 10);
87
HttpContext ctx = server.createContext("/", this);
88
ex = Executors.newFixedThreadPool(5);
89
server.setExecutor(ex);
90
server.start();
91
port = server.getAddress().getPort();
92
}
93
94
public void handle(HttpExchange ex) throws IOException {
95
String s = ex.getRequestMethod();
96
if (!s.equals("POST")) {
97
ex.getResponseHeaders().set("Allow", "POST");
98
ex.sendResponseHeaders(500, -1);
99
ex.close();
100
return;
101
}
102
System.out.println ("Server: reading request body");
103
InputStream is = ex.getRequestBody();
104
// read request
105
byte[] buf = new byte [1024];
106
while (is.read(buf) != -1) ;
107
is.close();
108
ex.sendResponseHeaders(200, -1);
109
ex.close();
110
}
111
}
112
113