jdk/test/javax/net/ssl/templates/SSLSocketTemplate.java
author vinnie
Wed, 02 Dec 2015 03:37:29 +0000
changeset 34380 2b2609379881
parent 23052 241885315119
child 36642 f0c07da61416
permissions -rw-r--r--
8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension Reviewed-by: wetmore, xuelei, mullan, coffeys
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 23052
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
    24
// SunJSSE does not support dynamic system properties, no way to re-use
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
    25
// system properties in samevm/agentvm mode.
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
    26
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @bug 1234567
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @summary Use this template to help speed your client/server tests.
10328
06c93c42bca0 7055363: jdk_security3 test target cleanup
weijun
parents: 5506
diff changeset
    31
 * @run main/othervm SSLSocketTemplate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @author Brad Wetmore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class SSLSocketTemplate {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * Set the various variables needed for the tests, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * specify what tests to run on each side.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Should we run the client or server in a separate thread?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Both sides can throw exceptions, but do you have a preference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * as to which side should be the main thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static boolean separateServerThread = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Where do we find the keystores?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static String pathToStores = "../etc";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static String keyStoreFile = "keystore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static String trustStoreFile = "truststore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static String passwd = "passphrase";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Is the server ready to serve?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    volatile static boolean serverReady = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Turn on SSL debugging?
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * If the client or server is doing some kind of object creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * that the other side depends on, and that thread prematurely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * exits, you may experience a hang.  The test harness will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * terminate all hung threads after its timeout has expired,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * currently 3 minutes by default, but you might try to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * smart about it....
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Define the server side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * If the server prematurely exits, serverReady will be set to true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * to avoid infinite hangs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    void doServerSide() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        SSLServerSocketFactory sslssf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        SSLServerSocket sslServerSocket =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            (SSLServerSocket) sslssf.createServerSocket(serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        serverPort = sslServerSocket.getLocalPort();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         * Signal Client, we're ready for his connect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        serverReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        SSLSocket sslSocket = (SSLSocket) sslServerSocket.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        InputStream sslIS = sslSocket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        OutputStream sslOS = sslSocket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        sslOS.write(85);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        sslSocket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Define the client side of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * If the server prematurely exits, serverReady will be set to true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * to avoid infinite hangs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    void doClientSide() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * Wait for server to get started.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        while (!serverReady) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            Thread.sleep(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        SSLSocketFactory sslsf =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            (SSLSocketFactory) SSLSocketFactory.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        SSLSocket sslSocket = (SSLSocket)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            sslsf.createSocket("localhost", serverPort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        InputStream sslIS = sslSocket.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        OutputStream sslOS = sslSocket.getOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        sslOS.write(280);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        sslOS.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        sslIS.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        sslSocket.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * =============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * The remainder is just support stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    // use any free port by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    volatile int serverPort = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    volatile Exception serverException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    volatile Exception clientException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        String keyFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            System.getProperty("test.src", ".") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                "/" + keyStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        String trustFilename =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            System.getProperty("test.src", ".") + "/" + pathToStores +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                "/" + trustStoreFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        System.setProperty("javax.net.ssl.keyStore", keyFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        System.setProperty("javax.net.ssl.keyStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        System.setProperty("javax.net.ssl.trustStore", trustFilename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        System.setProperty("javax.net.ssl.trustStorePassword", passwd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 23052
diff changeset
   164
        if (debug) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            System.setProperty("javax.net.debug", "all");
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 23052
diff changeset
   166
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         * Start the tests.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        new SSLSocketTemplate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    Thread clientThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    Thread serverThread = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Primary constructor, used to drive remainder of the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Fork off the other side, then do your work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    SSLSocketTemplate() throws Exception {
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   183
        Exception startException = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            if (separateServerThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                startServer(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                startClient(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                startClient(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                startServer(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        } catch (Exception e) {
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   193
            startException = e;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * Wait for other side to close down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (separateServerThread) {
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   200
            if (serverThread != null) {
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   201
                serverThread.join();
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   202
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } else {
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   204
            if (clientThread != null) {
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   205
                clientThread.join();
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   206
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         * When we get here, the test is pretty much over.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * Which side threw the error?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        Exception local;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        Exception remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (separateServerThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            remote = serverException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            local = clientException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            remote = clientException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            local = serverException;
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   222
        }
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   223
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   224
        Exception exception = null;
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   225
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   226
        /*
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   227
         * Check various exception conditions.
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   228
         */
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   229
        if ((local != null) && (remote != null)) {
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   230
            // If both failed, return the curthread's exception.
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   231
            local.initCause(remote);
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   232
            exception = local;
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   233
        } else if (local != null) {
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   234
            exception = local;
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   235
        } else if (remote != null) {
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   236
            exception = remote;
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   237
        } else if (startException != null) {
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   238
            exception = startException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        /*
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   242
         * If there was an exception *AND* a startException,
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   243
         * output it.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
         */
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   245
        if (exception != null) {
19575
ff87fda24d33 8022228: Intermittent test failures in sun/security/ssl/javax/net/ssl/NewAPIs
xuelei
parents: 18784
diff changeset
   246
            if (exception != startException && startException != null) {
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   247
                exception.addSuppressed(startException);
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   248
            }
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   249
            throw exception;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
18784
7f517475eeb4 8019341: Update CookieHttpsClientTest to use the newer framework.
wetmore
parents: 14342
diff changeset
   252
        // Fall-through: no exception to throw!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    void startServer(boolean newThread) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            serverThread = new Thread() {
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 23052
diff changeset
   258
                @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                        doServerSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                         * Our server thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                         * Release the client, if not active already...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        System.err.println("Server died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        serverReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        serverException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            serverThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                doServerSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                serverException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                serverReady = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    void startClient(boolean newThread) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (newThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            clientThread = new Thread() {
34380
2b2609379881 8144093: JEP 244/8051498 - TLS Application-Layer Protocol Negotiation Extension
vinnie
parents: 23052
diff changeset
   289
                @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        doClientSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                         * Our client thread just died.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                        System.err.println("Client died...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                        clientException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            clientThread.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                doClientSide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                clientException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}