-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
9
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
public class SimpleTimeoutTest {
public static void main(String[] args) throws Exception {
String uri = "..."; // a long time access
HttpClient client = HttpClient.create().build();
CompletableFuture<HttpResponse<String>> responseFC = client
.request(new URI(uri)).timeout(Duration.ofSeconds(1)).GET()
.responseAsync(HttpResponse.BodyHandler.asString());
System.out.println(responseFC.join().body());
}
}
The above test doesn't throw HttpTimeoutException and cannot finish.
import java.net.http.HttpClient;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
public class SimpleTimeoutTest {
public static void main(String[] args) throws Exception {
String uri = "..."; // a long time access
HttpClient client = HttpClient.create().build();
CompletableFuture<HttpResponse<String>> responseFC = client
.request(new URI(uri)).timeout(Duration.ofSeconds(1)).GET()
.responseAsync(HttpResponse.BodyHandler.asString());
System.out.println(responseFC.join().body());
}
}
The above test doesn't throw HttpTimeoutException and cannot finish.