1 /* |
1 /* |
2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 /** |
23 /** |
24 * @test |
24 * @test |
25 * @bug 6890349 |
25 * @bug 6890349 |
|
26 * @library /test/lib |
26 * @run main/othervm B6890349 |
27 * @run main/othervm B6890349 |
|
28 * @run main/othervm -Djava.net.preferIPv6Addresses=true B6890349 |
27 * @summary Light weight HTTP server |
29 * @summary Light weight HTTP server |
28 */ |
30 */ |
29 |
31 |
30 import java.net.*; |
32 import java.net.*; |
31 import java.io.*; |
33 import java.io.*; |
32 |
34 |
33 public class B6890349 extends Thread { |
35 public class B6890349 extends Thread { |
34 public static final void main(String[] args) throws Exception { |
36 public static final void main(String[] args) throws Exception { |
35 |
37 |
36 try { |
38 try { |
37 ServerSocket server = new ServerSocket (0); |
39 ServerSocket server = new ServerSocket(); |
|
40 InetAddress loopback = InetAddress.getLoopbackAddress(); |
|
41 InetSocketAddress address = new InetSocketAddress(loopback, 0); |
|
42 server.bind(address); |
|
43 |
38 int port = server.getLocalPort(); |
44 int port = server.getLocalPort(); |
39 System.out.println ("listening on " + port); |
45 System.out.println ("listening on " + port); |
40 B6890349 t = new B6890349 (server); |
46 B6890349 t = new B6890349 (server); |
41 t.start(); |
47 t.start(); |
42 URL u = new URL("http", |
48 URL u = new URL("http", |
43 InetAddress.getLoopbackAddress().getHostAddress(), |
49 InetAddress.getLoopbackAddress().getHostAddress(), |
44 port, |
50 port, |
45 "/foo\nbar"); |
51 "/foo\nbar"); |
46 System.out.println("URL: " + u); |
52 System.out.println("URL: " + u); |
47 HttpURLConnection urlc = (HttpURLConnection)u.openConnection (); |
53 HttpURLConnection urlc = (HttpURLConnection)u.openConnection(Proxy.NO_PROXY); |
48 InputStream is = urlc.getInputStream(); |
54 InputStream is = urlc.getInputStream(); |
49 throw new RuntimeException ("Test failed"); |
55 throw new RuntimeException ("Test failed"); |
50 } catch (IOException e) { |
56 } catch (IOException e) { |
51 System.out.println ("OK"); |
57 System.out.println ("Caught expected exception: " + e); |
52 } |
58 } |
53 } |
59 } |
54 |
60 |
55 ServerSocket server; |
61 ServerSocket server; |
56 |
62 |