jdk/test/java/net/httpclient/http2/Timeout.java
author michaelm
Fri, 09 Dec 2016 11:35:02 +0000
changeset 42460 7133f144981a
parent 37906 c2ea5f68c2ff
child 44854 5a486e0acd29
permissions -rw-r--r--
8170648: Move java.net.http package out of Java SE to incubator namespace Reviewed-by: chegar, dfuchs, michaelm, prappo, skuksenko Contributed-by: Chris Hegarty <chris.hegarty@oracle.com>, Daniel Fuchs <daniel.fuchs@oracle.com>, Michael McMahon <michael.x.mcmahon@oracle.com>, Pavel Rappo <pavel.rappo@oracle.com>, Sergey Kuksenko <sergey.kuksenko@oracle.com>, anthony.vanelverdinghe@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37906
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     1
/*
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     4
 *
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     7
 * published by the Free Software Foundation.
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     8
 *
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    13
 * accompanied this code).
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    14
 *
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    18
 *
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    21
 * questions.
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    22
 */
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    23
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    24
import java.io.File;
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    25
import java.io.IOException;
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    26
import java.net.URI;
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    27
import jdk.incubator.http.HttpClient;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    28
import jdk.incubator.http.HttpRequest;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    29
import jdk.incubator.http.HttpResponse;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    30
import jdk.incubator.http.HttpTimeoutException;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    31
import java.time.Duration;
37906
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    32
import java.util.concurrent.TimeUnit;
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    33
import java.util.concurrent.CompletionException;
37906
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    34
import javax.net.ssl.SSLServerSocket;
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    35
import javax.net.ssl.SSLServerSocketFactory;
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    36
import javax.net.ssl.SSLSocket;
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    37
import static jdk.incubator.http.HttpRequest.BodyProcessor.fromString;
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    38
import static jdk.incubator.http.HttpResponse.BodyHandler.asString;
37906
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    39
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    40
/*
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    41
 * @test
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    42
 * @bug 8156710
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    43
 * @summary Check if HttpTimeoutException is thrown if a server doesn't reply
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    44
 * @run main/othervm Timeout
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    45
 */
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    46
public class Timeout {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    47
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    48
    private static final int RANDOM_PORT = 0;
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    49
    private static final int TIMEOUT = 3 * 1000; // in millis
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    50
    private static final String KEYSTORE = System.getProperty("test.src")
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    51
            + File.separator + "keystore.p12";
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    52
    private static final String PASSWORD = "password";
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    53
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    54
    // indicates if server is ready to accept connections
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    55
    private static volatile boolean ready = false;
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    56
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    57
    public static void main(String[] args) throws Exception {
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    58
        test(false);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    59
        test(true);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    60
    }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    61
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
    62
    public static void test(boolean async) throws Exception {
37906
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    63
        System.setProperty("javax.net.ssl.keyStore", KEYSTORE);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    64
        System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    65
        System.setProperty("javax.net.ssl.trustStore", KEYSTORE);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    66
        System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    67
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    68
        SSLServerSocketFactory factory =
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    69
                (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    70
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    71
        try (SSLServerSocket ssocket =
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    72
                (SSLServerSocket) factory.createServerSocket(RANDOM_PORT)) {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    73
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    74
            // start server
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    75
            Thread server = new Thread(() -> {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    76
                while (true) {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    77
                    System.out.println("server: ready");
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    78
                    ready = true;
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    79
                    try (SSLSocket socket = (SSLSocket) ssocket.accept()) {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    80
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    81
                        // just read forever
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    82
                        System.out.println("server: accepted");
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    83
                        while (true) {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    84
                            socket.getInputStream().read();
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    85
                        }
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    86
                    } catch (IOException e) {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    87
                        // ignore exceptions on server side
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    88
                        System.out.println("server: exception: " + e);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    89
                    }
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    90
                }
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    91
            });
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    92
            server.setDaemon(true);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    93
            server.start();
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    94
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    95
            // wait for server is ready
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    96
            do {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    97
                Thread.sleep(1000);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    98
            } while (!ready);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
    99
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   100
            String uri = "https://localhost:" + ssocket.getLocalPort();
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   101
            if (async) {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   102
                System.out.println(uri + ": Trying to connect asynchronously");
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   103
                connectAsync(uri);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   104
            } else {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   105
                System.out.println(uri + ": Trying to connect synchronously");
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   106
                connect(uri);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   107
            }
37906
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   108
        }
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   109
    }
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   110
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   111
    private static void connect(String server) throws Exception {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   112
        try {
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   113
            HttpClient client = HttpClient.newBuilder()
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   114
                                          .version(HttpClient.Version.HTTP_2)
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   115
                                          .build();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   116
            HttpRequest request = HttpRequest.newBuilder(new URI(server))
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   117
                                             .timeout(Duration.ofMillis(TIMEOUT))
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   118
                                             .POST(fromString("body"))
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   119
                                             .build();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   120
            HttpResponse<String> response = client.send(request, asString());
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   121
            System.out.println("Received unexpected reply: " + response.statusCode());
37906
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   122
            throw new RuntimeException("unexpected successful connection");
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   123
        } catch (HttpTimeoutException e) {
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   124
            System.out.println("expected exception: " + e);
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   125
        }
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   126
    }
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   127
42460
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   128
    private static void connectAsync(String server) throws Exception {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   129
        try {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   130
            HttpClient client = HttpClient.newBuilder()
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   131
                    .version(HttpClient.Version.HTTP_2)
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   132
                    .build();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   133
            HttpRequest request = HttpRequest.newBuilder(new URI(server))
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   134
                    .timeout(Duration.ofMillis(TIMEOUT))
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   135
                    .POST(fromString("body"))
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   136
                    .build();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   137
            HttpResponse<String> response = client.sendAsync(request, asString()).join();
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   138
            System.out.println("Received unexpected reply: " + response.statusCode());
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   139
            throw new RuntimeException("unexpected successful connection");
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   140
        } catch (CompletionException e) {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   141
            if (e.getCause() instanceof HttpTimeoutException) {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   142
                System.out.println("expected exception: " + e.getCause());
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   143
            } else {
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   144
                throw new RuntimeException("Unexpected exception received: " + e.getCause(), e);
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   145
            }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   146
        }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   147
    }
7133f144981a 8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents: 37906
diff changeset
   148
37906
c2ea5f68c2ff 8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff changeset
   149
}