Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/net/ssl/HttpsURLConnection/Equals.java
41152 views
1
/*
2
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
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
26
* @bug 8055299
27
* @library /test/lib
28
* @modules jdk.httpserver
29
* @build jdk.test.lib.net.SimpleSSLContext
30
* @run main/othervm -Djavax.net.debug=ssl,handshake,record Equals
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.test.lib.net.SimpleSSLContext;
38
39
public class Equals {
40
41
static SSLContext ctx;
42
43
public static void main(String[] args) throws Exception {
44
HttpsServer s2 = null;
45
ExecutorService executor = null;
46
try {
47
InetSocketAddress addr = new InetSocketAddress(0);
48
s2 = HttpsServer.create(addr, 0);
49
HttpHandler h = new Handler();
50
HttpContext c2 = s2.createContext("/test1", h);
51
executor = Executors.newCachedThreadPool();
52
s2.setExecutor(executor);
53
ctx = new SimpleSSLContext().get();
54
s2.setHttpsConfigurator(new HttpsConfigurator(ctx));
55
s2.start();
56
int httpsport = s2.getAddress().getPort();
57
System.out.printf("%nServer address: %s%n", s2.getAddress());
58
test(httpsport);
59
System.out.println("OK");
60
} finally {
61
if (s2 != null) {
62
s2.stop(2);
63
}
64
if (executor != null) {
65
executor.shutdown();
66
}
67
}
68
}
69
70
static class Handler implements HttpHandler {
71
72
int invocation = 1;
73
74
public void handle(HttpExchange t)
75
throws IOException {
76
InputStream is = t.getRequestBody();
77
while (is.read() != -1) {
78
}
79
is.close();
80
t.sendResponseHeaders(200, 0);
81
t.close();
82
}
83
}
84
85
static void test(int port) throws Exception {
86
System.out.printf("%nClient using port number: %s%n", port);
87
String spec = String.format("https://localhost:%s/test1/", port);
88
URL url = new URL(spec);
89
HttpsURLConnection urlcs = (HttpsURLConnection) url.openConnection();
90
urlcs.setHostnameVerifier(new HostnameVerifier() {
91
public boolean verify(String s, SSLSession s1) {
92
return true;
93
}
94
});
95
urlcs.setSSLSocketFactory(ctx.getSocketFactory());
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
}
106
107