Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/net/httpserver/TestLogging.java
38855 views
1
/*
2
* Copyright (c) 2006, 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 6422914
27
* @summary change httpserver exception printouts
28
*/
29
30
import com.sun.net.httpserver.*;
31
32
import java.util.*;
33
import java.util.concurrent.*;
34
import java.util.logging.*;
35
import java.io.*;
36
import java.net.*;
37
import java.security.*;
38
import java.security.cert.*;
39
import javax.net.ssl.*;
40
41
public class TestLogging extends Test {
42
43
public static void main (String[] args) throws Exception {
44
HttpServer s1 = null;
45
ExecutorService executor=null;
46
47
try {
48
System.out.print ("Test9: ");
49
String root = System.getProperty ("test.src")+ "/docs";
50
InetSocketAddress addr = new InetSocketAddress (0);
51
Logger logger = Logger.getLogger ("com.sun.net.httpserver");
52
logger.setLevel (Level.ALL);
53
Handler h1 = new ConsoleHandler ();
54
h1.setLevel (Level.ALL);
55
logger.addHandler (h1);
56
s1 = HttpServer.create (addr, 0);
57
logger.info (root);
58
HttpHandler h = new FileServerHandler (root);
59
HttpContext c1 = s1.createContext ("/test1", h);
60
executor = Executors.newCachedThreadPool();
61
s1.setExecutor (executor);
62
s1.start();
63
64
int p1 = s1.getAddress().getPort();
65
66
URL url = new URL ("http://127.0.0.1:"+p1+"/test1/smallfile.txt");
67
HttpURLConnection urlc = (HttpURLConnection)url.openConnection();
68
InputStream is = urlc.getInputStream();
69
while (is.read() != -1) ;
70
is.close();
71
72
url = new URL ("http://127.0.0.1:"+p1+"/test1/doesntexist.txt");
73
urlc = (HttpURLConnection)url.openConnection();
74
try {
75
is = urlc.getInputStream();
76
while (is.read() != -1) ;
77
is.close();
78
} catch (IOException e) {
79
System.out.println ("caught expected exception");
80
}
81
82
Socket s = new Socket ("127.0.0.1", p1);
83
OutputStream os = s.getOutputStream();
84
//os.write ("GET xxx HTTP/1.1\r\n".getBytes());
85
os.write ("HELLO WORLD\r\n".getBytes());
86
is = s.getInputStream();
87
while (is.read() != -1) ;
88
os.close(); is.close(); s.close();
89
System.out.println ("OK");
90
} finally {
91
delay();
92
if (s1 != null)
93
s1.stop(2);
94
if (executor != null)
95
executor.shutdown();
96
}
97
}
98
}
99
100