Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/net/httpserver/Test10.java
41152 views
1
/*
2
* Copyright (c) 2010, 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 7005016
27
* @summary pit jdk7 b121 sqe test jhttp/HttpServer150013 failing
28
* @run main/othervm -Dsun.net.httpserver.clockTick=1000 -Dsun.net.httpserver.idleInterval=3 Test10
29
* @run main/othervm -Dsun.net.httpserver.clockTick=1000 -Dsun.net.httpserver.idleInterval=3
30
* -Djava.net.preferIPv6Addresses Test10
31
*/
32
33
import com.sun.net.httpserver.*;
34
35
import java.io.*;
36
import java.net.*;
37
import java.util.concurrent.*;
38
39
/*
40
* Test handling of empty Http headers
41
*/
42
43
public class Test10 extends Test {
44
public static void main (String[] args) throws Exception {
45
System.out.print ("Test10: ");
46
Handler handler = new Handler();
47
InetAddress loopback = InetAddress.getLoopbackAddress();
48
InetSocketAddress addr = new InetSocketAddress(loopback, 0);
49
HttpServer server = HttpServer.create (addr, 0);
50
int port = server.getAddress().getPort();
51
HttpContext c2 = server.createContext ("/test", handler);
52
53
ExecutorService exec = Executors.newCachedThreadPool();
54
server.setExecutor (exec);
55
try {
56
server.start ();
57
doClient(port);
58
System.out.println ("OK");
59
} finally {
60
delay();
61
if (server != null)
62
server.stop(2);
63
if (exec != null)
64
exec.shutdown();
65
}
66
}
67
68
static class Handler implements HttpHandler {
69
volatile int invocation = 0;
70
public void handle (HttpExchange t)
71
throws IOException
72
{
73
InputStream is = t.getRequestBody();
74
while (is.read() != -1);
75
Headers map = t.getRequestHeaders();
76
t.sendResponseHeaders (200, -1);
77
t.close();
78
}
79
}
80
81
public static void doClient (int port) throws Exception {
82
String s = "GET /test/1.html HTTP/1.1\r\n\r\n";
83
84
Socket socket = new Socket (InetAddress.getLoopbackAddress(), port);
85
OutputStream os = socket.getOutputStream();
86
os.write (s.getBytes());
87
socket.setSoTimeout (10 * 1000);
88
InputStream is = socket.getInputStream();
89
int c;
90
byte[] b = new byte [1024];
91
while ((c=is.read(b)) != -1) ;
92
is.close();
93
socket.close();
94
}
95
}
96
97