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