1 /* |
1 /* |
2 * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1999, 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. |
26 * @bug 4277155 |
26 * @bug 4277155 |
27 * @summary Make sure HttpClient.getHttpKeepAliveSet() has |
27 * @summary Make sure HttpClient.getHttpKeepAliveSet() has |
28 * doPrivileged() call at appropriate places. |
28 * doPrivileged() call at appropriate places. |
29 * @modules java.base/sun.net |
29 * @modules java.base/sun.net |
30 * java.base/sun.net.www.http |
30 * java.base/sun.net.www.http |
|
31 * @library /test/lib |
31 * @run main/othervm/policy=IsKeepingAlive.policy IsKeepingAlive |
32 * @run main/othervm/policy=IsKeepingAlive.policy IsKeepingAlive |
32 */ |
33 */ |
33 |
34 |
|
35 import java.net.InetAddress; |
|
36 import java.net.InetSocketAddress; |
34 import java.net.URL; |
37 import java.net.URL; |
35 import java.net.ServerSocket; |
38 import java.net.ServerSocket; |
36 import sun.net.www.http.HttpClient; |
39 import sun.net.www.http.HttpClient; |
37 import java.security.*; |
40 import java.security.*; |
|
41 import jdk.test.lib.net.URIBuilder; |
38 |
42 |
39 public class IsKeepingAlive { |
43 public class IsKeepingAlive { |
40 |
44 |
41 public static void main(String[] args) throws Exception { |
45 public static void main(String[] args) throws Exception { |
42 |
46 |
43 ServerSocket ss = new ServerSocket(0); |
47 ServerSocket ss = new ServerSocket(); |
|
48 InetAddress loopback = InetAddress.getLoopbackAddress(); |
|
49 ss.bind(new InetSocketAddress(loopback, 0)); |
44 |
50 |
45 SecurityManager security = System.getSecurityManager(); |
51 try (ServerSocket toClose = ss) { |
46 if (security == null) { |
52 SecurityManager security = System.getSecurityManager(); |
47 security = new SecurityManager(); |
53 if (security == null) { |
48 System.setSecurityManager(security); |
54 security = new SecurityManager(); |
|
55 System.setSecurityManager(security); |
|
56 } |
|
57 |
|
58 URL url1 = URIBuilder.newBuilder() |
|
59 .scheme("http") |
|
60 .loopback() |
|
61 .port(ss.getLocalPort()) |
|
62 .toURL(); |
|
63 |
|
64 HttpClient c1 = HttpClient.New(url1); |
|
65 |
|
66 boolean keepAlive = c1.isKeepingAlive(); |
49 } |
67 } |
50 |
|
51 URL url1 = new URL("http://localhost:" + ss.getLocalPort()); |
|
52 |
|
53 HttpClient c1 = HttpClient.New(url1); |
|
54 |
|
55 boolean keepAlive = c1.isKeepingAlive(); |
|
56 |
|
57 ss.close(); |
|
58 } |
68 } |
59 } |
69 } |