|
1 | 1 | /* |
2 | | - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
24 | 24 | /** |
25 | 25 | * @test |
26 | 26 | * @bug 7128648 |
| 27 | + * @library /test/lib |
27 | 28 | * @modules jdk.httpserver |
28 | 29 | * @summary HttpURLConnection.getHeaderFields should return an unmodifiable Map |
29 | 30 | */ |
30 | 31 |
|
31 | 32 | import java.io.IOException; |
| 33 | +import java.net.InetAddress; |
32 | 34 | import java.net.InetSocketAddress; |
33 | 35 | import java.net.URI; |
34 | 36 | import java.net.HttpURLConnection; |
|
41 | 43 | import com.sun.net.httpserver.HttpServer; |
42 | 44 | import com.sun.net.httpserver.Headers; |
43 | 45 | import static java.net.Proxy.NO_PROXY; |
| 46 | +import jdk.test.lib.net.URIBuilder; |
44 | 47 |
|
45 | 48 | public class UnmodifiableMaps { |
46 | 49 |
|
47 | 50 | void test(String[] args) throws Exception { |
48 | 51 | HttpServer server = startHttpServer(); |
49 | 52 | try { |
50 | 53 | InetSocketAddress address = server.getAddress(); |
51 | | - URI uri = new URI("http://localhost:" + address.getPort() + "/foo"); |
| 54 | + URI uri = URIBuilder.newBuilder() |
| 55 | + .scheme("http") |
| 56 | + .host(address.getAddress()) |
| 57 | + .port(address.getPort()) |
| 58 | + .path("/foo") |
| 59 | + .build(); |
52 | 60 | doClient(uri); |
53 | 61 | } finally { |
54 | 62 | server.stop(0); |
@@ -78,7 +86,8 @@ void doClient(URI uri) throws Exception { |
78 | 86 |
|
79 | 87 | // HTTP Server |
80 | 88 | HttpServer startHttpServer() throws IOException { |
81 | | - HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0); |
| 89 | + InetAddress loopback = InetAddress.getLoopbackAddress(); |
| 90 | + HttpServer httpServer = HttpServer.create(new InetSocketAddress(loopback, 0), 0); |
82 | 91 | httpServer.createContext("/foo", new SimpleHandler()); |
83 | 92 | httpServer.start(); |
84 | 93 | return httpServer; |
@@ -146,4 +155,3 @@ public void instanceMain(String[] args) throws Throwable { |
146 | 155 | System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed); |
147 | 156 | if (failed > 0) throw new AssertionError("Some tests failed");} |
148 | 157 | } |
149 | | - |
|
0 commit comments