author | ssahoo |
Thu, 07 Jul 2016 09:50:35 -0700 | |
changeset 39493 | 837860f3f432 |
parent 38327 | 77143af4d719 |
permissions | -rw-r--r-- |
26221 | 1 |
/* |
38327
77143af4d719
8155088: Fix module dependencies in java/sql/* and javax/* tests
xiaofeya
parents:
26221
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
26221 | 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 |
|
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
26 |
* @bug 8055299 |
26221 | 27 |
* @library /lib/testlibrary |
38327
77143af4d719
8155088: Fix module dependencies in java/sql/* and javax/* tests
xiaofeya
parents:
26221
diff
changeset
|
28 |
* @modules jdk.httpserver |
26221 | 29 |
* @build jdk.testlibrary.SimpleSSLContext |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
30 |
* @run main/othervm -Djavax.net.debug=ssl,handshake,record Equals |
26221 | 31 |
*/ |
32 |
import com.sun.net.httpserver.*; |
|
33 |
import java.net.*; |
|
34 |
import java.io.*; |
|
35 |
import javax.net.ssl.*; |
|
36 |
import java.util.concurrent.*; |
|
37 |
import jdk.testlibrary.SimpleSSLContext; |
|
38 |
||
39 |
public class Equals { |
|
40 |
||
41 |
static SSLContext ctx; |
|
42 |
||
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
43 |
public static void main(String[] args) throws Exception { |
26221 | 44 |
HttpsServer s2 = null; |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
45 |
ExecutorService executor = null; |
26221 | 46 |
try { |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
47 |
InetSocketAddress addr = new InetSocketAddress(0); |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
48 |
s2 = HttpsServer.create(addr, 0); |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
49 |
HttpHandler h = new Handler(); |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
50 |
HttpContext c2 = s2.createContext("/test1", h); |
26221 | 51 |
executor = Executors.newCachedThreadPool(); |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
52 |
s2.setExecutor(executor); |
26221 | 53 |
ctx = new SimpleSSLContext().get(); |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
54 |
s2.setHttpsConfigurator(new HttpsConfigurator(ctx)); |
26221 | 55 |
s2.start(); |
56 |
int httpsport = s2.getAddress().getPort(); |
|
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
57 |
System.out.printf("%nServer address: %s%n", s2.getAddress()); |
26221 | 58 |
test(httpsport); |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
59 |
System.out.println("OK"); |
26221 | 60 |
} finally { |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
61 |
if (s2 != null) { |
26221 | 62 |
s2.stop(2); |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
63 |
} |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
64 |
if (executor != null) { |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
65 |
executor.shutdown(); |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
66 |
} |
26221 | 67 |
} |
68 |
} |
|
69 |
||
70 |
static class Handler implements HttpHandler { |
|
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
71 |
|
26221 | 72 |
int invocation = 1; |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
73 |
|
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
74 |
public void handle(HttpExchange t) |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
75 |
throws IOException { |
26221 | 76 |
InputStream is = t.getRequestBody(); |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
77 |
while (is.read() != -1) { |
26221 | 78 |
} |
79 |
is.close(); |
|
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
80 |
t.sendResponseHeaders(200, 0); |
26221 | 81 |
t.close(); |
82 |
} |
|
83 |
} |
|
84 |
||
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
85 |
static void test(int port) throws Exception { |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
86 |
System.out.printf("%nClient using port number: %s%n", port); |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
87 |
String spec = String.format("https://localhost:%s/test1/", port); |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
88 |
URL url = new URL(spec); |
26221 | 89 |
HttpsURLConnection urlcs = (HttpsURLConnection) url.openConnection(); |
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
90 |
urlcs.setHostnameVerifier(new HostnameVerifier() { |
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
91 |
public boolean verify(String s, SSLSession s1) { |
26221 | 92 |
return true; |
93 |
} |
|
94 |
}); |
|
39493
837860f3f432
8160940: Enable debug log in javax/net/ssl/HttpsURLConnection/Equals.java to track JDK-8160210
ssahoo
parents:
38327
diff
changeset
|
95 |
urlcs.setSSLSocketFactory(ctx.getSocketFactory()); |
26221 | 96 |
|
97 |
InputStream is = urlcs.getInputStream(); |
|
98 |
while (is.read() != -1) { |
|
99 |
} |
|
100 |
is.close(); |
|
101 |
if (!urlcs.equals(urlcs)) { |
|
102 |
throw new RuntimeException("Test failed"); |
|
103 |
} |
|
104 |
} |
|
105 |
} |