author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 55330 | 1fef7d9309a9 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54086
ccb4a50bee06
8220083: Use InetAddress.getLoopbackAddress() in place of 127.0.0.1 for some tests
aeubanks
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2006, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 6422914 |
|
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
27 |
* @library /test/lib |
2 | 28 |
* @summary change httpserver exception printouts |
55330
1fef7d9309a9
8225512: Replace wildcard address with loopback or local host in tests - part 15
dfuchs
parents:
54314
diff
changeset
|
29 |
* @run main TestLogging |
1fef7d9309a9
8225512: Replace wildcard address with loopback or local host in tests - part 15
dfuchs
parents:
54314
diff
changeset
|
30 |
* @run main/othervm -Djava.net.preferIPv6Addresses=true TestLogging |
2 | 31 |
*/ |
32 |
||
33 |
import com.sun.net.httpserver.*; |
|
34 |
||
35 |
import java.util.*; |
|
36 |
import java.util.concurrent.*; |
|
37 |
import java.util.logging.*; |
|
38 |
import java.io.*; |
|
39 |
import java.net.*; |
|
40 |
import java.security.*; |
|
41 |
import java.security.cert.*; |
|
42 |
import javax.net.ssl.*; |
|
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
43 |
import jdk.test.lib.net.URIBuilder; |
2 | 44 |
|
45 |
public class TestLogging extends Test { |
|
46 |
||
47 |
public static void main (String[] args) throws Exception { |
|
48 |
HttpServer s1 = null; |
|
49 |
ExecutorService executor=null; |
|
50 |
||
51 |
try { |
|
52 |
System.out.print ("Test9: "); |
|
53 |
String root = System.getProperty ("test.src")+ "/docs"; |
|
55330
1fef7d9309a9
8225512: Replace wildcard address with loopback or local host in tests - part 15
dfuchs
parents:
54314
diff
changeset
|
54 |
InetAddress loopback = InetAddress.getLoopbackAddress(); |
1fef7d9309a9
8225512: Replace wildcard address with loopback or local host in tests - part 15
dfuchs
parents:
54314
diff
changeset
|
55 |
InetSocketAddress addr = new InetSocketAddress(loopback, 0); |
2 | 56 |
Logger logger = Logger.getLogger ("com.sun.net.httpserver"); |
57 |
logger.setLevel (Level.ALL); |
|
58 |
Handler h1 = new ConsoleHandler (); |
|
59 |
h1.setLevel (Level.ALL); |
|
60 |
logger.addHandler (h1); |
|
61 |
s1 = HttpServer.create (addr, 0); |
|
62 |
logger.info (root); |
|
63 |
HttpHandler h = new FileServerHandler (root); |
|
64 |
HttpContext c1 = s1.createContext ("/test1", h); |
|
65 |
executor = Executors.newCachedThreadPool(); |
|
66 |
s1.setExecutor (executor); |
|
67 |
s1.start(); |
|
68 |
||
69 |
int p1 = s1.getAddress().getPort(); |
|
70 |
||
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
71 |
URL url = URIBuilder.newBuilder() |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
72 |
.scheme("http") |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
73 |
.loopback() |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
74 |
.port(p1) |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
75 |
.path("/test1/smallfile.txt") |
55330
1fef7d9309a9
8225512: Replace wildcard address with loopback or local host in tests - part 15
dfuchs
parents:
54314
diff
changeset
|
76 |
.toURL(); |
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
77 |
System.out.println("URL: " + url); |
55330
1fef7d9309a9
8225512: Replace wildcard address with loopback or local host in tests - part 15
dfuchs
parents:
54314
diff
changeset
|
78 |
HttpURLConnection urlc = (HttpURLConnection)url.openConnection(Proxy.NO_PROXY); |
2 | 79 |
InputStream is = urlc.getInputStream(); |
80 |
while (is.read() != -1) ; |
|
81 |
is.close(); |
|
82 |
||
54314
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
83 |
url = URIBuilder.newBuilder() |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
84 |
.scheme("http") |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
85 |
.loopback() |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
86 |
.port(p1) |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
87 |
.path("/test1/doesntexist.txt") |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
88 |
.toURLUnchecked(); |
46cf212cdcca
8220575: Replace hardcoded 127.0.0.1 in URLs with new URI builder
aeubanks
parents:
54086
diff
changeset
|
89 |
System.out.println("URL: " + url); |
2 | 90 |
urlc = (HttpURLConnection)url.openConnection(); |
91 |
try { |
|
92 |
is = urlc.getInputStream(); |
|
93 |
while (is.read() != -1) ; |
|
94 |
is.close(); |
|
95 |
} catch (IOException e) { |
|
96 |
System.out.println ("caught expected exception"); |
|
97 |
} |
|
98 |
||
54086
ccb4a50bee06
8220083: Use InetAddress.getLoopbackAddress() in place of 127.0.0.1 for some tests
aeubanks
parents:
47216
diff
changeset
|
99 |
Socket s = new Socket (InetAddress.getLoopbackAddress(), p1); |
2 | 100 |
OutputStream os = s.getOutputStream(); |
101 |
//os.write ("GET xxx HTTP/1.1\r\n".getBytes()); |
|
102 |
os.write ("HELLO WORLD\r\n".getBytes()); |
|
103 |
is = s.getInputStream(); |
|
104 |
while (is.read() != -1) ; |
|
105 |
os.close(); is.close(); s.close(); |
|
106 |
System.out.println ("OK"); |
|
107 |
} finally { |
|
108 |
delay(); |
|
3070
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
109 |
if (s1 != null) |
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
110 |
s1.stop(2); |
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
111 |
if (executor != null) |
0175bbf9a833
6513803: httpserver regression test Test13 failing and causing NullPointerException
michaelm
parents:
2
diff
changeset
|
112 |
executor.shutdown(); |
2 | 113 |
} |
114 |
} |
|
115 |
} |