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