Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/ssl/SSLSocketImpl/NewSocketMethods.java
38853 views
1
/*
2
* Copyright (c) 2001, 2011, 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 4429176
27
* @summary need to sync up SSL sockets with merlin java.net changes
28
* @run main/othervm NewSocketMethods
29
*
30
* SunJSSE does not support dynamic system properties, no way to re-use
31
* system properties in samevm/agentvm mode.
32
*/
33
34
import java.io.*;
35
import java.net.*;
36
import javax.net.*;
37
import javax.net.ssl.*;
38
39
/**
40
* There are new methods for java.net.Socket class added to merlin
41
* This test case checks the behaviour of these new methods when overriden
42
* by methods of SSLSocket. The following methods are covered in this
43
* test case.
44
*
45
* public void sendUrgentData (int data) throws IOException
46
* public void setOOBInline(boolean on) throws SocketException
47
* public boolean getOOBInline() throws SocketException
48
* public SocketChannel getChannel() -- call on plain socket
49
* public void setTrafficClass(int tc) -- call on plain socket
50
* throws SocketException
51
* public int getTrafficClass() -- call on plain socket
52
* throws SocketException
53
* public void setReuseAddress(boolean on) -- call on plain socket
54
* throws SocketException
55
* public boolean getReuseAddress() -- call on plain socket
56
* throws SocketException
57
* public boolean isInputShutdown()
58
* public boolean isOutputShutdown()
59
*
60
* The methods below are covered by the test case located at:
61
* ../SocketCreation/SocketCreation.java
62
* public boolean isConnected()
63
* public boolean isBound()
64
*
65
*/
66
67
public class NewSocketMethods {
68
69
/*
70
* =============================================================
71
* Set the various variables needed for the tests, then
72
* specify what tests to run on each side.
73
*/
74
75
/*
76
* Should we run the client or server in a separate thread?
77
* Both sides can throw exceptions, but do you have a preference
78
* as to which side should be the main thread.
79
*/
80
static boolean separateServerThread = true;
81
82
/*
83
* If some one quickly wants to check the plain socket behaviour
84
* as a reference
85
*/
86
static boolean useSSL = true;
87
88
/*
89
* Where do we find the keystores?
90
*/
91
static String pathToStores = "../../../../javax/net/ssl/etc";
92
static String keyStoreFile = "keystore";
93
static String trustStoreFile = "truststore";
94
static String passwd = "passphrase";
95
96
/*
97
* Is the server ready to serve?
98
*/
99
volatile static boolean serverReady = false;
100
101
/*
102
* Turn on SSL debugging?
103
*/
104
static boolean debug = false;
105
106
/*
107
* If the client or server is doing some kind of object creation
108
* that the other side depends on, and that thread prematurely
109
* exits, you may experience a hang. The test harness will
110
* terminate all hung threads after its timeout has expired,
111
* currently 3 minutes by default, but you might try to be
112
* smart about it....
113
*/
114
115
/*
116
* Define the server side of the test.
117
*
118
* If the server prematurely exits, serverReady will be set to true
119
* to avoid infinite hangs.
120
*/
121
void doServerSide() throws Exception {
122
Socket socket;
123
ServerSocket serverSocket;
124
if (useSSL) {
125
SSLServerSocketFactory sslssf =
126
(SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
127
serverSocket =
128
(SSLServerSocket) sslssf.createServerSocket(serverPort);
129
} else {
130
serverSocket = (ServerSocket) ServerSocketFactory.
131
getDefault().createServerSocket(serverPort);
132
}
133
serverPort = serverSocket.getLocalPort();
134
135
/*
136
* Signal Client, we're ready for his connect.
137
*/
138
serverReady = true;
139
try {
140
socket = serverSocket.accept();
141
InputStream is = socket.getInputStream();
142
OutputStream os = socket.getOutputStream();
143
144
/**
145
* Test some new methods of java.net.Socket added to merlin
146
*/
147
System.out.println("Server getChannel(): "
148
+ socket.getChannel());
149
try {
150
socket.setOOBInline(true);
151
} catch (IOException success) {
152
// Currently we throw an IOException if this method is called
153
}
154
try {
155
System.out.println("Server getOOBInline(): "
156
+ socket.getOOBInline());
157
} catch (IOException success) {
158
// Currently we throw an IOException if this method is called
159
}
160
System.out.println("Server read: " + is.read());
161
os.write(85);
162
os.flush();
163
socket.close();
164
} catch (Exception unexpected) {
165
throw new Exception(" test failed, caught exception: "
166
+ unexpected);
167
}
168
}
169
170
/*
171
* Define the client side of the test.
172
*
173
* If the server prematurely exits, serverReady will be set to true
174
* to avoid infinite hangs.
175
*/
176
void doClientSide() throws Exception {
177
/*
178
* Wait for server to get started.
179
*/
180
while (!serverReady) {
181
Thread.sleep(50);
182
}
183
Socket socket;
184
if (useSSL) {
185
SSLSocketFactory sslsf =
186
(SSLSocketFactory) SSLSocketFactory.getDefault();
187
Socket plainSocket = new Socket("localhost", serverPort);
188
socket = (SSLSocket)
189
sslsf.createSocket(plainSocket, "localhost", serverPort, true);
190
}
191
else
192
socket = new Socket("localhost", serverPort);
193
try {
194
InputStream is = socket.getInputStream();
195
OutputStream os = socket.getOutputStream();
196
197
/**
198
* test some new methods of java.net.Socket added to merlin.
199
*/
200
socket.setTrafficClass(8);
201
socket.setReuseAddress(true);
202
System.out.println("Client getTrafficClass(): "
203
+ socket.getTrafficClass());
204
System.out.println("Client isInputShutdown() "
205
+ socket.isInputShutdown());
206
System.out.println("Client getReuseAddress(): "
207
+ socket.getReuseAddress());
208
os.write(237);
209
os.flush();
210
System.out.println("Client read: " + is.read());
211
socket.close();
212
System.out.println("Client isOutputShutdown() "
213
+ socket.isOutputShutdown());
214
} catch (Exception unexpected) {
215
throw new Exception(" test failed, caught exception: "
216
+ unexpected);
217
}
218
}
219
220
/*
221
* =============================================================
222
* The remainder is just support stuff
223
*/
224
225
// use any free port by default
226
volatile int serverPort = 0;
227
228
volatile Exception serverException = null;
229
volatile Exception clientException = null;
230
231
public static void main(String[] args) throws Exception {
232
String keyFilename =
233
System.getProperty("test.src", "./") + "/" + pathToStores +
234
"/" + keyStoreFile;
235
String trustFilename =
236
System.getProperty("test.src", "./") + "/" + pathToStores +
237
"/" + trustStoreFile;
238
239
System.setProperty("javax.net.ssl.keyStore", keyFilename);
240
System.setProperty("javax.net.ssl.keyStorePassword", passwd);
241
System.setProperty("javax.net.ssl.trustStore", trustFilename);
242
System.setProperty("javax.net.ssl.trustStorePassword", passwd);
243
244
if (debug)
245
System.setProperty("javax.net.debug", "all");
246
247
/*
248
* Start the tests.
249
*/
250
new NewSocketMethods();
251
}
252
253
Thread clientThread = null;
254
Thread serverThread = null;
255
256
/*
257
* Primary constructor, used to drive remainder of the test.
258
*
259
* Fork off the other side, then do your work.
260
*/
261
NewSocketMethods() throws Exception {
262
if (separateServerThread) {
263
startServer(true);
264
startClient(false);
265
} else {
266
startClient(true);
267
startServer(false);
268
}
269
270
/*
271
* Wait for other side to close down.
272
*/
273
if (separateServerThread) {
274
serverThread.join();
275
} else {
276
clientThread.join();
277
}
278
279
/*
280
* When we get here, the test is pretty much over.
281
*
282
* If the main thread excepted, that propagates back
283
* immediately. If the other thread threw an exception, we
284
* should report back.
285
*/
286
if (serverException != null)
287
throw serverException;
288
if (clientException != null)
289
throw clientException;
290
}
291
292
void startServer(boolean newThread) throws Exception {
293
if (newThread) {
294
serverThread = new Thread() {
295
public void run() {
296
try {
297
doServerSide();
298
} catch (Exception e) {
299
/*
300
* Our server thread just died.
301
*
302
* Release the client, if not active already...
303
*/
304
System.err.println("Server died... ");
305
e.printStackTrace();
306
serverReady = true;
307
serverException = e;
308
}
309
}
310
};
311
serverThread.start();
312
} else {
313
doServerSide();
314
}
315
}
316
317
void startClient(boolean newThread) throws Exception {
318
if (newThread) {
319
clientThread = new Thread() {
320
public void run() {
321
try {
322
doClientSide();
323
} catch (Exception e) {
324
/*
325
* Our client thread just died.
326
*/
327
System.err.println("Client died...");
328
clientException = e;
329
}
330
}
331
};
332
clientThread.start();
333
} else {
334
doClientSide();
335
}
336
}
337
}
338
339