Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/net/httpserver/Test7a.java
41152 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 6270015
27
* @library /test/lib
28
* @build jdk.test.lib.net.SimpleSSLContext jdk.test.lib.net.URIBuilder
29
* @run main/othervm Test7a
30
* @run main/othervm -Djava.net.preferIPv6Addresses=true Test7a
31
* @summary Light weight HTTP server
32
*/
33
34
import com.sun.net.httpserver.*;
35
36
import java.util.concurrent.*;
37
import java.io.*;
38
import java.net.*;
39
import javax.net.ssl.*;
40
import jdk.test.lib.net.SimpleSSLContext;
41
import jdk.test.lib.net.URIBuilder;
42
43
/**
44
* Test POST large file via chunked encoding (large chunks)
45
*/
46
47
public class Test7a extends Test {
48
49
public static void main (String[] args) throws Exception {
50
//Logger log = Logger.getLogger ("com.sun.net.httpserver");
51
//log.setLevel (Level.FINE);
52
//ConsoleHandler h = new ConsoleHandler();
53
//h.setLevel (Level.ALL);
54
//log.addHandler (h);
55
Handler handler = new Handler();
56
InetAddress loopback = InetAddress.getLoopbackAddress();
57
InetSocketAddress addr = new InetSocketAddress(loopback, 0);
58
HttpsServer server = HttpsServer.create (addr, 0);
59
HttpContext ctx = server.createContext ("/test", handler);
60
ExecutorService executor = Executors.newCachedThreadPool();
61
SSLContext ssl = new SimpleSSLContext().get();
62
server.setHttpsConfigurator(new HttpsConfigurator (ssl));
63
server.setExecutor (executor);
64
server.start ();
65
66
URL url = URIBuilder.newBuilder()
67
.scheme("https")
68
.loopback()
69
.port(server.getAddress().getPort())
70
.path("/test/foo.html")
71
.toURL();
72
73
System.out.print ("Test7a: " );
74
HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection(Proxy.NO_PROXY);
75
urlc.setDoOutput (true);
76
urlc.setRequestMethod ("POST");
77
urlc.setChunkedStreamingMode (16 * 1024); // big chunks
78
urlc.setHostnameVerifier (new DummyVerifier());
79
urlc.setSSLSocketFactory (ssl.getSocketFactory());
80
OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
81
for (int i=0; i<SIZE; i++) {
82
os.write (i % 100);
83
}
84
os.close();
85
int resp = urlc.getResponseCode();
86
if (resp != 200) {
87
throw new RuntimeException ("test failed response code");
88
}
89
if (error) {
90
throw new RuntimeException ("test failed error");
91
}
92
delay();
93
server.stop(2);
94
executor.shutdown();
95
System.out.println ("OK");
96
97
}
98
99
public static boolean error = false;
100
final static int SIZE = 999999;
101
102
static class Handler implements HttpHandler {
103
int invocation = 1;
104
public void handle (HttpExchange t)
105
throws IOException
106
{
107
InputStream is = t.getRequestBody();
108
Headers map = t.getRequestHeaders();
109
Headers rmap = t.getResponseHeaders();
110
int c, count=0;
111
while ((c=is.read ()) != -1) {
112
if (c != (count % 100)) {
113
error = true;
114
break;
115
}
116
count ++;
117
}
118
if (count != SIZE) {
119
error = true;
120
}
121
is.close();
122
t.sendResponseHeaders (200, -1);
123
t.close();
124
}
125
}
126
}
127
128