author | chegar |
Wed, 06 Dec 2017 11:11:59 -0800 | |
changeset 48083 | b1c1b4ef4be2 |
parent 47216 | 71c04702a3d5 |
child 49765 | ee6f7a61f3a5 |
child 55973 | 4d9b002587db |
permissions | -rw-r--r-- |
37906
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
1 |
/* |
48083 | 2 |
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. |
37906
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; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
32 |
import java.util.concurrent.CompletionException; |
37906
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
33 |
import javax.net.ssl.SSLServerSocket; |
44854
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
34 |
import javax.net.ssl.SSLParameters; |
37906
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; |
48083 | 37 |
import static jdk.incubator.http.HttpRequest.BodyPublisher.fromString; |
42460
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"); |
44854
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
78 |
SSLParameters params = ssocket.getSSLParameters(); |
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
79 |
params.setApplicationProtocols(new String[]{"h2"}); |
5a486e0acd29
8175814: Update default HttpClient protocol version and optional request version
michaelm
parents:
42460
diff
changeset
|
80 |
ssocket.setSSLParameters(params); |
37906
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
81 |
ready = true; |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
82 |
try (SSLSocket socket = (SSLSocket) ssocket.accept()) { |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
83 |
|
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
84 |
// just read forever |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
85 |
System.out.println("server: accepted"); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
86 |
while (true) { |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
87 |
socket.getInputStream().read(); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
88 |
} |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
89 |
} catch (IOException e) { |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
90 |
// ignore exceptions on server side |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
91 |
System.out.println("server: exception: " + e); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
92 |
} |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
93 |
} |
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 |
server.setDaemon(true); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
96 |
server.start(); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
97 |
|
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
98 |
// wait for server is ready |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
99 |
do { |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
100 |
Thread.sleep(1000); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
101 |
} while (!ready); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
102 |
|
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
103 |
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
|
104 |
if (async) { |
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 asynchronously"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
106 |
connectAsync(uri); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
107 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
108 |
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
|
109 |
connect(uri); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
110 |
} |
37906
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
111 |
} |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
112 |
} |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
113 |
|
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
114 |
private static void connect(String server) throws Exception { |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
115 |
try { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
116 |
HttpClient client = HttpClient.newBuilder() |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
117 |
.version(HttpClient.Version.HTTP_2) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
118 |
.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
119 |
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
|
120 |
.timeout(Duration.ofMillis(TIMEOUT)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
121 |
.POST(fromString("body")) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
122 |
.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
123 |
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
|
124 |
System.out.println("Received unexpected reply: " + response.statusCode()); |
37906
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
125 |
throw new RuntimeException("unexpected successful connection"); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
126 |
} catch (HttpTimeoutException e) { |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
127 |
System.out.println("expected exception: " + e); |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
128 |
} |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
129 |
} |
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
130 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
131 |
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
|
132 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
133 |
HttpClient client = HttpClient.newBuilder() |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
134 |
.version(HttpClient.Version.HTTP_2) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
135 |
.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
136 |
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
|
137 |
.timeout(Duration.ofMillis(TIMEOUT)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
138 |
.POST(fromString("body")) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
139 |
.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
} catch (CompletionException e) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
144 |
if (e.getCause() instanceof HttpTimeoutException) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
145 |
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
|
146 |
} else { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
147 |
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
|
148 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
149 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
150 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
37906
diff
changeset
|
151 |
|
37906
c2ea5f68c2ff
8156710: HttpTimeoutException should be thrown if server doesn't respond
asmotrak
parents:
diff
changeset
|
152 |
} |