Skip to content

Commit e7a1c86

Browse files
vyjaikiran
authored andcommitted
8217914: java/net/httpclient/ConnectTimeoutHandshakeSync.java failed on connection refused while doing POST
Reviewed-by: dfuchs, jpai
1 parent 644d154 commit e7a1c86

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

test/jdk/java/net/httpclient/AbstractConnectTimeoutHandshake.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,10 +44,11 @@
4444
import java.net.http.HttpRequest.BodyPublishers;
4545
import java.net.http.HttpResponse;
4646
import java.net.http.HttpResponse.BodyHandlers;
47+
48+
import jdk.test.lib.net.URIBuilder;
4749
import org.testng.annotations.AfterTest;
4850
import org.testng.annotations.BeforeTest;
4951
import org.testng.annotations.DataProvider;
50-
import static java.lang.String.format;
5152
import static java.lang.System.out;
5253
import static java.net.http.HttpClient.Builder.NO_PROXY;
5354
import static java.net.http.HttpClient.Version.HTTP_1_1;
@@ -56,7 +57,7 @@
5657
import static java.util.concurrent.TimeUnit.NANOSECONDS;
5758
import static org.testng.Assert.fail;
5859

59-
public abstract class AbstractConnectTimeoutHandshake {
60+
abstract class AbstractConnectTimeoutHandshake {
6061

6162
// The number of iterations each testXXXClient performs.
6263
static final int TIMES = 2;
@@ -197,15 +198,15 @@ static void printResponse(HttpResponse<?> response) {
197198

198199
// -- Infrastructure
199200

200-
static String serverAuthority(Server server) {
201-
return InetAddress.getLoopbackAddress().getHostName() + ":"
202-
+ server.getPort();
203-
}
204-
205201
@BeforeTest
206202
public void setup() throws Exception {
207203
server = new Server();
208-
httpsURI = URI.create("https://" + serverAuthority(server) + "/foo");
204+
httpsURI = URIBuilder.newBuilder()
205+
.scheme("https")
206+
.loopback()
207+
.port(server.getPort())
208+
.path("/foo")
209+
.build();
209210
out.println("HTTPS URI: " + httpsURI);
210211
}
211212

test/jdk/java/net/httpclient/ConnectTimeoutHandshakeAsync.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,8 @@
2929
* @test
3030
* @summary Tests connection timeouts during SSL handshake
3131
* @bug 8208391
32+
* @library /test/lib
33+
* @build AbstractConnectTimeoutHandshake
3234
* @run testng/othervm ConnectTimeoutHandshakeAsync
3335
*/
3436

test/jdk/java/net/httpclient/ConnectTimeoutHandshakeSync.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,8 @@
2929
* @test
3030
* @summary Tests connection timeouts during SSL handshake
3131
* @bug 8208391
32+
* @library /test/lib
33+
* @build AbstractConnectTimeoutHandshake
3234
* @run testng/othervm ConnectTimeoutHandshakeSync
3335
*/
3436

0 commit comments

Comments
 (0)