8373515: Migrate "test/jdk/java/net/httpclient/" to null-safe "SimpleSSLContext" methods

Reviewed-by: jpai
This commit is contained in:
Volkan Yazici 2026-01-06 10:21:14 +00:00
parent 2cb228e142
commit 3a80c639d8
179 changed files with 312 additions and 921 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -44,14 +44,9 @@ import java.net.http.HttpClient;
public class ALPNProxyFailureTest extends ALPNFailureTest {
static final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
static {
try {
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(context);
}
public static void main(String[] args) throws Exception{

View File

@ -53,7 +53,7 @@ import static org.testng.Assert.assertEquals;
public abstract class AbstractNoBody implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -186,9 +186,6 @@ public abstract class AbstractNoBody implements HttpServerAdapters {
public void setup() throws Exception {
printStamp(START, "setup");
HttpServerAdapters.enableServerLogging();
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_fixedLengthNoBodyHandler = new FixedLengthNoBodyHandler();

View File

@ -82,7 +82,7 @@ import org.junit.jupiter.api.extension.TestWatcher;
public abstract class AbstractThrowingPublishers implements HttpServerAdapters {
static SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
static HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
static HttpTestServer httpsTestServer; // HTTPS/1.1
static HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -757,10 +757,6 @@ public abstract class AbstractThrowingPublishers implements HttpServerAdapters {
System.out.println(now() + "setup");
System.err.println(now() + "setup");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_fixedLengthHandler = new HTTP_FixedLengthHandler();
HttpTestHandler h1_chunkHandler = new HTTP_ChunkedHandler();

View File

@ -98,7 +98,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
@ -108,7 +107,7 @@ import org.junit.jupiter.api.extension.TestWatcher;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public abstract class AbstractThrowingPushPromises implements HttpServerAdapters {
static SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
static HttpTestServer http2TestServer; // HTTP/2 ( h2c )
static HttpTestServer https2TestServer; // HTTP/2 ( h2 )
static HttpTestServer http3TestServer; // HTTP/3 ( h3 )
@ -758,10 +757,6 @@ public abstract class AbstractThrowingPushPromises implements HttpServerAdapters
@BeforeAll
public static void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/2
HttpTestHandler fixedLengthHandler = new HTTP_FixedLengthHandler();
HttpTestHandler chunkedHandler = new HTTP_ChunkedHandler();

View File

@ -81,7 +81,7 @@ import org.junit.jupiter.api.extension.TestWatcher;
public abstract class AbstractThrowingSubscribers implements HttpServerAdapters {
static SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
static HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
static HttpTestServer httpsTestServer; // HTTPS/1.1
static HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -821,10 +821,6 @@ public abstract class AbstractThrowingSubscribers implements HttpServerAdapters
System.out.println(now() + "setup");
System.err.println(now() + "setup");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
System.out.println(now() + "HTTP/1.1 server created");
// HTTP/1.1

View File

@ -93,7 +93,7 @@ import static org.testng.Assert.expectThrows;
public class AggregateRequestBodyTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer http1TestServer; // HTTP/1.1 ( http )
HttpTestServer https1TestServer; // HTTPS/1.1 ( https )
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -855,10 +855,6 @@ public class AggregateRequestBodyTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
HttpTestHandler handler = new HttpTestEchoHandler();
http1TestServer = HttpTestServer.create(HTTP_1_1);
http1TestServer.addHandler(handler, "/http1/echo/");

View File

@ -59,7 +59,7 @@ import static java.net.http.HttpOption.Http3DiscoveryMode.HTTP_3_URI_ONLY;
*/
public class AltServiceUsageTest implements HttpServerAdapters {
private SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
private HttpTestServer originServer;
private HttpTestServer altServer;
@ -67,11 +67,6 @@ public class AltServiceUsageTest implements HttpServerAdapters {
@BeforeClass
public void beforeClass() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null) {
throw new AssertionError("Unexpected null sslContext");
}
// attempt to create an HTTP/3 server, an HTTP/2 server, and a
// DatagramChannel bound to the same port as the HTTP/2 server
int count = 0;

View File

@ -90,7 +90,7 @@ import static org.testng.Assert.fail;
*/
public class AsFileDownloadTest {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpsServer httpsTestServer; // HTTPS/1.1
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
@ -351,10 +351,6 @@ public class AsFileDownloadTest {
//ch.setLevel(Level.ALL);
//logger.addHandler(ch);
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
httpTestServer = HttpServer.create(sa, 0);
httpTestServer.createContext("/http1/afdt", new Http1FileDispoHandler());

View File

@ -93,7 +93,7 @@ public class AsyncExecutorShutdown implements HttpServerAdapters {
static final Random RANDOM = RandomFactory.getRandom();
ExecutorService readerService;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 6 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -412,9 +412,6 @@ public class AsyncExecutorShutdown implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
out.println("\n**** Setup ****\n");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
readerService = Executors.newCachedThreadPool();
httpTestServer = HttpTestServer.create(HTTP_1_1);

View File

@ -97,7 +97,7 @@ public class AsyncShutdownNow implements HttpServerAdapters {
static final Random RANDOM = RandomFactory.getRandom();
ExecutorService readerService;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -406,9 +406,6 @@ public class AsyncShutdownNow implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
out.println("\n**** Setup ****\n");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
readerService = Executors.newCachedThreadPool();
httpTestServer = HttpTestServer.create(HTTP_1_1);

View File

@ -75,15 +75,10 @@ public class AuthFilterCacheTest implements HttpServerAdapters {
static final int REQUEST_COUNT = 5;
static final int URI_COUNT = 8;
static final CyclicBarrier barrier = new CyclicBarrier(REQUEST_COUNT * URI_COUNT);
static final SSLContext context;
private static final SSLContext context = jdk.test.lib.net.SimpleSSLContext.findSSLContext();
static {
try {
context = new jdk.test.lib.net.SimpleSSLContext().get();
SSLContext.setDefault(context);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(context);
}
HttpTestServer http1Server;

View File

@ -71,7 +71,7 @@ public class BasicAuthTest implements HttpServerAdapters {
ExecutorService e = Executors.newCachedThreadPool();
Handler h = new Handler();
SSLContext sslContext = secure || version == Version.HTTP_3
? new SimpleSSLContext().get() : null;
? SimpleSSLContext.findSSLContext() : null;
HttpTestServer server = HttpTestServer.create(version, sslContext, e);
HttpTestContext serverContext = server.addHandler(h,"/test/");
ServerAuth sa = new ServerAuth("foo realm");

View File

@ -71,7 +71,7 @@ import static org.testng.Assert.assertTrue;
public class BasicHTTP2Test implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer https2TestServer; // HTTP/2 ( h2 )
String https2URI;
DatagramSocket udp;
@ -239,10 +239,6 @@ public class BasicHTTP2Test implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/2
HttpTestHandler handler = new Handler();
HttpTestHandler h3Handler = new Handler();

View File

@ -78,7 +78,7 @@ import static java.net.http.HttpOption.Http3DiscoveryMode.ALT_SVC;
*/
public class BasicHTTP3Test implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer https2TestServer; // HTTP/2 ( h2 )
String https2URI;
HttpTestServer h3TestServer; // HTTP/2 ( h2 + h3)
@ -343,10 +343,6 @@ public class BasicHTTP3Test implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null) {
throw new AssertionError("Unexpected null sslContext");
}
https2TestServer = HttpTestServer.create(HTTP_2, sslContext);
https2TestServer.addHandler(new Handler(), "/https2/test/");
https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/test/x";

View File

@ -68,7 +68,7 @@ import static org.testng.Assert.assertTrue;
public class BasicRedirectTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -270,10 +270,6 @@ public class BasicRedirectTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new BasicHttpRedirectHandler(), "/http1/same/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/same/redirect";

View File

@ -79,7 +79,7 @@ class BufferSize1Test implements HttpServerAdapters {
void test(Version version, boolean secure) throws Exception {
// Create the server
var sslContext = secure || HTTP_3.equals(version) ? new SimpleSSLContext().get() : null;
var sslContext = secure || HTTP_3.equals(version) ? SimpleSSLContext.findSSLContext() : null;
try (var server = switch (version) {
case HTTP_1_1, HTTP_2 -> HttpTestServer.create(version, sslContext);
case HTTP_3 -> HttpTestServer.create(HTTP_3_URI_ONLY, sslContext);

View File

@ -93,7 +93,7 @@ public class CancelRequestTest implements HttpServerAdapters {
private static final Random random = RandomFactory.getRandom();
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -642,10 +642,6 @@ public class CancelRequestTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_chunkHandler = new HTTPSlowHandler();
httpTestServer = HttpTestServer.create(HTTP_1_1);

View File

@ -78,7 +78,7 @@ import static org.testng.Assert.assertTrue;
public class CancelStreamedBodyTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -352,10 +352,6 @@ public class CancelStreamedBodyTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_chunkHandler = new HTTPSlowHandler();
httpTestServer = HttpTestServer.create(HTTP_1_1);

View File

@ -85,7 +85,7 @@ public class CancelledPartialResponseTest {
URI warmup, h2PartialResponseResetNoError, h2PartialResponseResetError, h2FullResponseResetNoError, h2FullResponseResetError;
URI h3PartialResponseStopSending, h3FullResponseStopSending;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
static PrintStream err = new PrintStream(System.err);
static PrintStream out = System.out;
@ -163,10 +163,6 @@ public class CancelledPartialResponseTest {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
http2TestServer = new Http2TestServer(false, 0);
http3TestServer = HttpTestServer.create(Http3DiscoveryMode.HTTP_3_URI_ONLY, sslContext);

View File

@ -93,11 +93,10 @@ public class CancelledResponse {
static final ReferenceTracker TRACKER = ReferenceTracker.INSTANCE;
final ServerSocketFactory factory;
final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
final boolean useSSL;
CancelledResponse(boolean useSSL) throws IOException {
this.useSSL = useSSL;
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
factory = useSSL ? SSLServerSocketFactory.getDefault()
: ServerSocketFactory.getDefault();

View File

@ -81,7 +81,7 @@ public class CancelledResponse2 implements HttpServerAdapters {
URI h3TestServerURI;
HttpTestServer h2h3TestServer;
HttpTestServer h3TestServer;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
@DataProvider(name = "versions")
public Object[][] positive() {
@ -152,8 +152,6 @@ public class CancelledResponse2 implements HttpServerAdapters {
@BeforeTest
public void setup() throws IOException {
sslContext = new SimpleSSLContext().get();
h2TestServer = HttpTestServer.create(HTTP_2, sslContext);
h2TestServer.addHandler(new CancelledResponseHandler(), "/h2");
h2TestServerURI = URI.create("https://" + h2TestServer.serverAuthority() + "/h2");

View File

@ -89,7 +89,7 @@ import static org.testng.Assert.fail;
public class ConcurrentResponses {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpsServer httpsTestServer; // HTTPS/1.1
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
@ -303,10 +303,6 @@ public class ConcurrentResponses {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
httpTestServer = HttpServer.create(sa, 0);
httpTestServer.createContext("/http1/fixed", new Http1FixedHandler());

View File

@ -77,7 +77,7 @@ public class ContentLengthHeaderTest implements HttpServerAdapters {
static HttpTestServer testContentLengthServerH2;
static HttpTestServer testContentLengthServerH3;
static PrintStream testLog = System.err;
static SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpClient hc;
URI testContentLengthURIH1;
@ -86,7 +86,6 @@ public class ContentLengthHeaderTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws IOException, URISyntaxException, InterruptedException {
sslContext = new SimpleSSLContext().get();
testContentLengthServerH1 = HttpTestServer.create(HTTP_1_1);
testContentLengthServerH2 = HttpTestServer.create(HTTP_2, sslContext);
testContentLengthServerH3 = HttpTestServer.create(HTTP_3, sslContext);

View File

@ -83,7 +83,7 @@ import static org.testng.Assert.assertTrue;
public class CookieHeaderTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 6 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -194,10 +194,6 @@ public class CookieHeaderTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new CookieValidationHandler(), "/http1/cookie/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/cookie/retry";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -69,7 +69,7 @@ import static org.testng.Assert.fail;
public class CustomRequestPublisher implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -339,10 +339,6 @@ public class CustomRequestPublisher implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new HttpTestEchoHandler(), "/http1/echo");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -70,7 +70,7 @@ import static org.testng.Assert.assertTrue;
public class CustomResponseSubscriber {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpsServer httpsTestServer; // HTTPS/1.1
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
@ -187,10 +187,6 @@ public class CustomResponseSubscriber {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();

View File

@ -94,7 +94,7 @@ import static org.testng.Assert.assertTrue;
public class DependentActionsTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -643,10 +643,6 @@ public class DependentActionsTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_fixedLengthHandler = new HTTP_FixedLengthHandler();
HttpTestHandler h1_chunkHandler = new HTTP_ChunkedHandler();

View File

@ -98,7 +98,7 @@ import static org.testng.Assert.assertTrue;
public class DependentPromiseActionsTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
HttpTestServer https2TestServer; // HTTP/2 ( h2 )
HttpTestServer http3TestServer; // HTTP/3 ( h3 )
@ -701,10 +701,6 @@ public class DependentPromiseActionsTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/2
HttpTestHandler fixedLengthHandler = new HTTP_FixedLengthHandler();
HttpTestHandler chunkedHandler = new HTTP_ChunkedHandler();

View File

@ -165,14 +165,9 @@ public class DigestEchoClient {
static final AtomicInteger NC = new AtomicInteger();
static final Random random = new Random();
static final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
static {
try {
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(context);
}
static final List<Boolean> BOOLEANS = List.of(true, false);

View File

@ -102,15 +102,7 @@ public class DurationOverflowTest {
private static final Logger LOGGER = Utils.getDebugLogger(CLASS_NAME::toString, Utils.DEBUG);
private static final SSLContext SSL_CONTEXT = createSslContext();
private static SSLContext createSslContext() {
try {
return new SimpleSSLContext().get();
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
private static final SSLContext SSL_CONTEXT = SimpleSSLContext.findSSLContext();
private static final List<Infra> INFRAS = loadInfras();

View File

@ -56,18 +56,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
class EmptyAuthenticate {
private static final SSLContext SSL_CONTEXT = createSslContext();
private static final SSLContext SSL_CONTEXT = SimpleSSLContext.findSSLContext();
private static final String WWW_AUTH_HEADER_NAME = "WWW-Authenticate";
private static SSLContext createSslContext() {
try {
return new SimpleSSLContext().get();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
@ParameterizedTest
@MethodSource("args")
void test(Version version, boolean secure) throws Exception {

View File

@ -88,7 +88,7 @@ import static org.testng.Assert.assertTrue;
public class EncodedCharsInURI implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -311,10 +311,6 @@ public class EncodedCharsInURI implements HttpServerAdapters {
public void setup() throws Exception {
out.println(now() + "begin setup");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_fixedLengthHandler = new HTTP_FixedLengthHandler();
HttpTestHandler h1_chunkHandler = new HTTP_ChunkedHandler();

View File

@ -69,7 +69,7 @@ import static org.testng.Assert.assertEquals;
public class EscapedOctetsInURI implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -267,10 +267,6 @@ public class EscapedOctetsInURI implements HttpServerAdapters {
public void setup() throws Exception {
out.println(now() + "begin setup");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new HttpASCIIUriStringHandler(), "/http1/get");

View File

@ -88,7 +88,7 @@ public class ExecutorShutdown implements HttpServerAdapters {
}
static final Random RANDOM = RandomFactory.getRandom();
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 6 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -311,10 +311,6 @@ public class ExecutorShutdown implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
out.println("\n**** Setup ****\n");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new ServerRequestHandler(), "/http1/exec/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/exec/retry";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -60,7 +60,7 @@ import static org.testng.Assert.assertEquals;
public class ExpectContinue {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpServer httpTestServer; // HTTP/1.1 [ 2 servers ]
HttpsServer httpsTestServer; // HTTPS/1.1
String httpURI;
@ -139,10 +139,6 @@ public class ExpectContinue {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
httpTestServer = HttpServer.create(sa, 0);
httpTestServer.createContext("/http1/ec", new Http1ExpectContinueHandler());

View File

@ -90,7 +90,7 @@ class FileChannelPublisherTest {
private static final int DEFAULT_BUFFER_SIZE = Utils.getBuffer().capacity();
private static final SSLContext SSL_CONTEXT = createSslContext();
private static final SSLContext SSL_CONTEXT = SimpleSSLContext.findSSLContext();
private static final HttpClient CLIENT = HttpClient.newBuilder().sslContext(SSL_CONTEXT).proxy(NO_PROXY).build();
@ -102,14 +102,6 @@ class FileChannelPublisherTest {
HTTP2 = ServerRequestPair.of(Version.HTTP_2, false),
HTTPS2 = ServerRequestPair.of(Version.HTTP_2, true);
private static SSLContext createSslContext() {
try {
return new SimpleSSLContext().get();
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
private record ServerRequestPair(
String serverName,
HttpTestServer server,

View File

@ -61,7 +61,7 @@ import static java.net.http.HttpClient.Version.HTTP_2;
import static org.testng.Assert.assertEquals;
public class FilePublisherTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpServerAdapters.HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpServerAdapters.HttpTestServer httpsTestServer; // HTTPS/1.1
HttpServerAdapters.HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -183,10 +183,6 @@ public class FilePublisherTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
defaultFsPath = defaultFsFile();
zipFs = newZipFs();
zipFsPath = zipFsFile(zipFs);

View File

@ -67,7 +67,7 @@ import static org.testng.Assert.fail;
public class FlowAdapterPublisherTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -358,10 +358,6 @@ public class FlowAdapterPublisherTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(Version.HTTP_1_1);
httpTestServer.addHandler(new HttpEchoHandler(), "/http1/echo");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/echo";

View File

@ -77,7 +77,7 @@ import static org.testng.Assert.assertTrue;
public class FlowAdapterSubscriberTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -633,10 +633,6 @@ public class FlowAdapterSubscriberTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(Version.HTTP_1_1);
httpTestServer.addHandler(new HttpEchoHandler(), "/http1/echo");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/echo";

View File

@ -82,11 +82,10 @@ import static java.net.http.HttpOption.Http3DiscoveryMode.HTTP_3_URI_ONLY;
import static java.net.http.HttpOption.H3_DISCOVERY;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
public class ForbiddenHeadTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -336,10 +335,6 @@ public class ForbiddenHeadTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new UnauthorizedHandler(), "/http1/");
httpTestServer.addHandler(new UnauthorizedHandler(), "/http2/proxy/");

View File

@ -72,7 +72,7 @@ import static org.testng.Assert.assertEquals;
public class GZIPInputStreamTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -489,10 +489,6 @@ public class GZIPInputStreamTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
HttpTestHandler plainHandler = new LoremIpsumPlainHandler();
HttpTestHandler gzipHandler = new LoremIpsumGZIPHandler();

View File

@ -59,7 +59,7 @@ import static org.testng.Assert.assertEquals;
public class HeadTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -147,10 +147,6 @@ public class HeadTest implements HttpServerAdapters {
// TODO: See if test performs better with Vthreads, see H3SimplePost and H3SimpleGet
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new HeadHandler(), "/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/";

View File

@ -72,14 +72,10 @@ public class HeadersLowerCaseTest implements HttpServerAdapters {
private HttpTestServer h3server;
private String h2ReqURIBase;
private String h3ReqURIBase;
private SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
@BeforeAll
public void beforeAll() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null) {
throw new AssertionError("Unexpected null sslContext");
}
h2server = HttpTestServer.create(HTTP_2, sslContext);
h2server.start();
h2ReqURIBase = "https://" + h2server.serverAuthority();

View File

@ -56,15 +56,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
class HttpClientAuthRetryLimitTest implements HttpServerAdapters {
private static final SSLContext SSL_CONTEXT = createSslContext();
private static SSLContext createSslContext() {
try {
return new SimpleSSLContext().get();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
private static final SSLContext SSL_CONTEXT = SimpleSSLContext.findSSLContext();
// This is the system default value for jdk.httpclient.auth.retrylimit
private static final int DEFAULT_RETRY_LIMIT = 3;

View File

@ -318,18 +318,18 @@ public class HttpClientBuilderTest {
@Test
public void testSSLContext() throws Exception {
HttpClient.Builder builder = HttpClient.newBuilder();
SSLContext a = (new SimpleSSLContext()).get();
SSLContext a = SimpleSSLContext.findSSLContext();
builder.sslContext(a);
try (var closer = closeable(builder)) {
assertTrue(closer.build().sslContext() == a);
}
SSLContext b = (new SimpleSSLContext()).get();
SSLContext b = SimpleSSLContext.findSSLContext();
builder.sslContext(b);
try (var closer = closeable(builder)) {
assertTrue(closer.build().sslContext() == b);
}
assertThrows(NPE, () -> builder.sslContext(null));
SSLContext c = (new SimpleSSLContext()).get();
SSLContext c = SimpleSSLContext.findSSLContext();
builder.sslContext(c);
try (var closer = closeable(builder)) {
assertTrue(closer.build().sslContext() == c);

View File

@ -97,7 +97,7 @@ public class HttpClientClose implements HttpServerAdapters {
static final Random RANDOM = RandomFactory.getRandom();
ExecutorService readerService;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -343,9 +343,6 @@ public class HttpClientClose implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
out.println("\n**** Setup ****\n");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
readerService = Executors.newCachedThreadPool();
httpTestServer = HttpTestServer.create(HTTP_1_1);

View File

@ -69,7 +69,7 @@ import static java.net.http.HttpClient.Version.HTTP_2;
*/
public class HttpClientLocalAddrTest implements HttpServerAdapters {
private static SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
private static HttpServerAdapters.HttpTestServer http1_1_Server;
private static URI httpURI;
private static HttpServerAdapters.HttpTestServer https_1_1_Server;
@ -83,9 +83,6 @@ public class HttpClientLocalAddrTest implements HttpServerAdapters {
// start various HTTP/HTTPS servers that will be invoked against in the tests
@BeforeClass
public static void beforeClass() throws Exception {
sslContext = new SimpleSSLContext().get();
Assert.assertNotNull(sslContext, "Unexpected null sslContext");
HttpServerAdapters.HttpTestHandler handler = (exchange) -> {
// the handler receives a request and sends back a 200 response with the
// response body containing the raw IP address (in byte[] form) of the client from whom

View File

@ -95,8 +95,7 @@ public class HttpClientSNITest {
@ParameterizedTest
@ValueSource(booleans = {false, true})
void testRequestToIPLiteralHost(final boolean sniConfiguredOnClient) throws Exception {
final SSLContext sslContext = new SimpleSSLContext().get();
assertNotNull(sslContext, "could not create a SSLContext");
final SSLContext sslContext = SimpleSSLContext.findSSLContext();
final String expectedSNI = "non-dns-resolvable.foo.bar.localhost";
final ServerNameMatcher matcher = new ServerNameMatcher(expectedSNI);
final HttpTestServer server = createServer(matcher, sslContext);
@ -149,8 +148,7 @@ public class HttpClientSNITest {
@ParameterizedTest
@ValueSource(booleans = {false, true})
void testRequestResolvedHostName(final boolean sniConfiguredOnClient) throws Exception {
final SSLContext sslContext = new SimpleSSLContext().get();
assertNotNull(sslContext, "could not create a SSLContext");
final SSLContext sslContext = SimpleSSLContext.findSSLContext();
final String resolvedHostName = InetAddress.getLoopbackAddress().getHostName();
final String expectedSNI = resolvedHostName;
final ServerNameMatcher matcher = new ServerNameMatcher(expectedSNI);

View File

@ -101,7 +101,7 @@ public class HttpClientShutdown implements HttpServerAdapters {
static final Random RANDOM = RandomFactory.getRandom();
ExecutorService readerService;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -464,9 +464,6 @@ public class HttpClientShutdown implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
out.println("\n**** Setup ****\n");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
readerService = Executors.newCachedThreadPool();
httpTestServer = HttpTestServer.create(HTTP_1_1);

View File

@ -98,11 +98,7 @@ public class HttpGetInCancelledFuture {
? HttpServerAdapters.createClientBuilderForH3()
: HttpClient.newBuilder();
if (uri.getScheme().equalsIgnoreCase("https")) {
try {
builder.sslContext(new SimpleSSLContext().get());
} catch (IOException io) {
throw new UncheckedIOException(io);
}
builder.sslContext(SimpleSSLContext.findSSLContext());
}
return builder.connectTimeout(Duration.ofSeconds(1))
.executor(executor)

View File

@ -80,14 +80,9 @@ import jdk.httpclient.test.lib.common.HttpServerAdapters;
public class HttpRedirectTest implements HttpServerAdapters {
static final String GET_RESPONSE_BODY = "Lorem ipsum dolor sit amet";
static final String REQUEST_BODY = "Here it goes";
static final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
static {
try {
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(context);
}
final AtomicLong requestCounter = new AtomicLong();

View File

@ -87,7 +87,7 @@ class HttpResponseConnectionLabelTest {
private static final String SERVER_ID_HEADER_NAME = "X-Server-Id";
private static final SSLContext SSL_CONTEXT = createSslContext();
private static final SSLContext SSL_CONTEXT = SimpleSSLContext.findSSLContext();
// For each test instance, start with a fresh client having no connections in the pool
private final HttpClient client = HttpServerAdapters
@ -120,14 +120,6 @@ class HttpResponseConnectionLabelTest {
private static final ServerRequestPair SEC_HTTP3 = ServerRequestPair.of(Version.HTTP_3, true);
private static SSLContext createSslContext() {
try {
return new SimpleSSLContext().get();
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
private record ServerRequestPair(
HttpTestServer server,
ExecutorService executor,

View File

@ -107,15 +107,7 @@ class HttpResponseLimitingTest {
private record ServerClientPair(HttpTestServer server, HttpClient client, HttpRequest request, boolean secure) {
private static final SSLContext SSL_CONTEXT = createSslContext();
private static SSLContext createSslContext() {
try {
return new SimpleSSLContext().get();
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
private static final SSLContext SSL_CONTEXT = SimpleSSLContext.findSSLContext();
private ServerClientPair {
try {

View File

@ -85,14 +85,9 @@ public class HttpSlowServerTest implements HttpServerAdapters {
"Excepteur sint occaecat cupidatat non proident."
);
static final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
static {
try {
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(context);
}
final AtomicLong requestCounter = new AtomicLong();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -61,7 +61,7 @@ import static org.testng.Assert.assertTrue;
public class HttpVersionsTest {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
Http2TestServer http2TestServer;
Http2TestServer https2TestServer;
String http2URI;
@ -205,10 +205,6 @@ public class HttpVersionsTest {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
http2TestServer = new Http2TestServer("localhost", false, 0, executor, 50, null, null, true);
http2TestServer.addHandler(new Http2VerEchoHandler(), "/http2/vts");
http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/vts";

View File

@ -74,14 +74,9 @@ public class HttpsTunnelAuthTest implements HttpServerAdapters, AutoCloseable {
"Excepteur sint occaecat cupidatat non proident."
};
static final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
static {
try {
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(context);
}
final String realm = "earth";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -82,14 +82,9 @@ public class HttpsTunnelTest implements HttpServerAdapters {
"Excepteur sint occaecat cupidatat non proident."
};
static final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
static {
try {
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(context);
}
HttpsTunnelTest() {

View File

@ -88,7 +88,7 @@ import static org.testng.Assert.assertTrue;
public class ISO_8859_1_Test implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
DummyServer http1DummyServer;
HttpTestServer http1TestServer; // HTTP/1.1 ( http )
HttpTestServer https1TestServer; // HTTPS/1.1 ( https )
@ -412,10 +412,6 @@ public class ISO_8859_1_Test implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
HttpServerAdapters.HttpTestHandler handler = new ISO88591Handler();
InetSocketAddress loopback = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);

View File

@ -94,7 +94,7 @@ import static org.testng.Assert.assertEquals;
public class IdleConnectionTimeoutTest {
URI timeoutUriH2, noTimeoutUriH2, timeoutUriH3, noTimeoutUriH3, getH3;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
static volatile QuicServerConnection latestServerConn;
final String KEEP_ALIVE_PROPERTY = "jdk.httpclient.keepalive.timeout";
final String IDLE_CONN_PROPERTY_H2 = "jdk.httpclient.keepalive.timeout.h2";
@ -112,7 +112,6 @@ public class IdleConnectionTimeoutTest {
http2TestServer.addHandler(new ServerNoTimeoutHandlerH2(), NO_TIMEOUT_PATH);
http2TestServer.setExchangeSupplier(TestExchange::new);
sslContext = new SimpleSSLContext().get();
http3TestServer = new Http3TestServer(sslContext) {
@Override
public boolean acceptIncoming(SocketAddress source, QuicServerConnection quicConn) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -68,7 +68,7 @@ import static org.testng.Assert.*;
public class ImmutableFlowItems {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpsServer httpsTestServer; // HTTPS/1.1
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
@ -175,10 +175,6 @@ public class ImmutableFlowItems {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();

View File

@ -90,15 +90,11 @@ public class ImmutableSSLSessionTest implements HttpServerAdapters {
private String h1ReqURIBase;
private String h2ReqURIBase;
private String h3ReqURIBase;
private static SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
private final AtomicInteger counter = new AtomicInteger();
@BeforeAll
public void beforeAll() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null) {
throw new AssertionError("Unexpected null sslContext");
}
h1server = HttpTestServer.create(HTTP_1_1, sslContext);
h1server.start();
h1ReqURIBase = "https://" + h1server.serverAuthority() + "/h1ImmutableSSLSessionTest/";

View File

@ -100,7 +100,7 @@ import static org.testng.Assert.assertEquals;
public class InvalidInputStreamSubscriptionRequest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -565,10 +565,6 @@ public class InvalidInputStreamSubscriptionRequest implements HttpServerAdapters
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_fixedLengthHandler = new HTTP_FixedLengthHandler();
HttpTestHandler h1_chunkHandler = new HTTP_VariableLengthHandler();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -62,7 +62,7 @@ import static java.net.http.HttpClient.Version.HTTP_2;
public class InvalidSSLContextTest {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
volatile SSLServerSocket sslServerSocket;
volatile String uri;
@ -147,10 +147,6 @@ public class InvalidSSLContextTest {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// server-side uses a different context to that of the client-side
sslServerSocket = (SSLServerSocket)sslContext
.getServerSocketFactory()

View File

@ -78,7 +78,7 @@ import static org.testng.Assert.assertEquals;
public class InvalidSubscriptionRequest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -461,10 +461,6 @@ public class InvalidSubscriptionRequest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_fixedLengthHandler = new HTTP_FixedLengthHandler();
HttpTestHandler h1_chunkHandler = new HTTP_VariableLengthHandler();

View File

@ -82,14 +82,9 @@ public class LargeResponseTest implements HttpServerAdapters {
}
}
static final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
static {
try {
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
} catch (Exception x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(context);
}
final AtomicLong requestCounter = new AtomicLong();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -55,7 +55,7 @@ import jdk.test.lib.net.SimpleSSLContext;
public class LightWeightHttpServer {
static SSLContext ctx;
static final SSLContext ctx = SimpleSSLContext.findSSLContext();
static HttpServer httpServer;
static HttpsServer httpsServer;
static ExecutorService executor;
@ -111,7 +111,6 @@ public class LightWeightHttpServer {
executor = Executors.newCachedThreadPool();
httpServer.setExecutor(executor);
httpsServer.setExecutor(executor);
ctx = new SimpleSSLContext().get();
httpsServer.setHttpsConfigurator(new TestServerConfigurator(addr.getAddress(), ctx));
httpServer.start();
httpsServer.start();

View File

@ -86,7 +86,7 @@ import static org.testng.Assert.assertTrue;
public class LineBodyHandlerTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -677,10 +677,6 @@ public class LineBodyHandlerTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1, null,
executorFor("HTTP/1.1 Server Thread"));
httpTestServer.addHandler(new HttpTestEchoHandler(), "/http1/echo");

View File

@ -104,7 +104,7 @@ public class ManyRequests {
+ " requests; delay=" + INSERT_DELAY
+ ", chunks=" + CHUNK_SIZE
+ ", XFixed=" + XFIXED);
SSLContext ctx = new SimpleSSLContext().get();
SSLContext ctx = SimpleSSLContext.findSSLContext();
InetSocketAddress addr = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
HttpsServer server = HttpsServer.create(addr, 0);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -105,7 +105,7 @@ public class ManyRequestsLegacy {
+ " requests; delay=" + INSERT_DELAY
+ ", chunks=" + CHUNK_SIZE
+ ", XFixed=" + XFIXED);
SSLContext ctx = new SimpleSSLContext().get();
SSLContext ctx = SimpleSSLContext.findSSLContext();
SSLContext.setDefault(ctx);
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -75,7 +75,7 @@ import static org.testng.Assert.assertTrue;
public class MappingResponseSubscriber {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpsServer httpsTestServer; // HTTPS/1.1
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
@ -215,10 +215,6 @@ public class MappingResponseSubscriber {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpHandler h1_fixedLengthHandler = new HTTP1_FixedLengthHandler();
HttpHandler h1_chunkHandler = new HTTP1_ChunkedHandler();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -67,7 +67,7 @@ public class MaxStreams {
Http2TestServer http2TestServer; // HTTP/2 ( h2c )
Http2TestServer https2TestServer; // HTTP/2 ( h2 )
final Http2FixedHandler handler = new Http2FixedHandler();
SSLContext ctx;
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
String http2FixedURI;
String https2FixedURI;
ExecutorService exec;
@ -163,7 +163,6 @@ public class MaxStreams {
@BeforeTest
public void setup() throws Exception {
ctx = (new SimpleSSLContext()).get();
exec = Executors.newCachedThreadPool();
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);

View File

@ -67,7 +67,7 @@ import static org.testng.Assert.assertEquals;
public class NonAsciiCharsInURI implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -280,10 +280,6 @@ public class NonAsciiCharsInURI implements HttpServerAdapters {
public void setup() throws Exception {
out.println(now() + "begin setup");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
HttpTestHandler handler = new HttpUriStringHandler();
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(handler, "/http1/get");

View File

@ -80,7 +80,7 @@ public class BodyHandlerOfFileDownloadTest implements HttpServerAdapters {
static final String MSG = "msg";
static final String contentDispositionValue = "attachment; filename=example.html";
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -208,10 +208,6 @@ public class BodyHandlerOfFileDownloadTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
defaultFsPath = defaultFsDir();
zipFs = newZipFs();
zipFsPath = zipFsDir(zipFs);

View File

@ -71,7 +71,7 @@ import static org.testng.Assert.assertEquals;
public class BodyHandlerOfFileTest implements HttpServerAdapters {
static final String MSG = "msg";
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -216,10 +216,6 @@ public class BodyHandlerOfFileTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
defaultFsPath = defaultFsFile();
zipFs = newZipFs();
zipFsPath = zipFsFile(zipFs);

View File

@ -75,7 +75,7 @@ import static org.testng.Assert.assertEquals;
public class BodySubscriberOfFileTest implements HttpServerAdapters {
static final String MSG = "msg";
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -246,10 +246,6 @@ public class BodySubscriberOfFileTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
defaultFsPath = defaultFsFile();
zipFs = newZipFs();
zipFsPath = zipFsFile(zipFs);

View File

@ -101,7 +101,7 @@ import static java.net.http.HttpClient.Version.HTTP_1_1;
// -Djava.security.debug=all
class PlainConnectionLockTest implements HttpServerAdapters {
private SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
private HttpTestServer http1Server;
private HttpTestServer https1Server;
private String http1URI;
@ -133,10 +133,6 @@ class PlainConnectionLockTest implements HttpServerAdapters {
requestSemaphore = new Semaphore(0);
responseSemaphore = new Semaphore(0);
successfulCompletion = false;
sslContext = new SimpleSSLContext().get();
if (sslContext == null) {
throw new AssertionError("Unexpected null sslContext");
}
serverExecutor = Executors.newThreadPerTaskExecutor(
Thread.ofVirtual().name("Http1Server", 0).factory());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -86,7 +86,7 @@ import static org.testng.Assert.assertEquals;
public class ProxySelectorTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1
HttpTestServer proxyHttpTestServer; // HTTP/1.1
HttpTestServer authProxyHttpTestServer; // HTTP/1.1
@ -320,10 +320,6 @@ public class ProxySelectorTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new PlainServerHandler("plain-server"), "/http1/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -80,16 +80,12 @@ import static java.net.Proxy.NO_PROXY;
public class ProxyTest {
static {
try {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext.setDefault(new SimpleSSLContext().get());
} catch (IOException ex) {
throw new ExceptionInInitializerError(ex);
}
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
SSLContext.setDefault(SimpleSSLContext.findSSLContext());
}
static final String RESPONSE = "<html><body><p>Hello World!</body></html>";

View File

@ -55,7 +55,7 @@ import static org.testng.Assert.assertEquals;
public class RedirectMethodChange implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpClient client;
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
@ -203,10 +203,6 @@ public class RedirectMethodChange implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
client = newClientBuilderForH3()
.followRedirects(HttpClient.Redirect.NORMAL)
.sslContext(sslContext)

View File

@ -66,7 +66,7 @@ import static jdk.test.lib.Utils.adjustTimeout;
public class RedirectTimeoutTest implements HttpServerAdapters {
static SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
static HttpTestServer h1TestServer, h2TestServer, h3TestServer;
static URI h1Uri, h1RedirectUri, h2Uri, h2RedirectUri,
h3Uri, h3RedirectUri, h2WarmupUri, h3WarmupUri, testRedirectURI;
@ -77,10 +77,6 @@ public class RedirectTimeoutTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws IOException {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
h1TestServer = HttpTestServer.create(HTTP_1_1);
h2TestServer = HttpTestServer.create(HTTP_2);
h3TestServer = HttpTestServer.create(HTTP_3_URI_ONLY, sslContext);

View File

@ -61,7 +61,7 @@ import static org.testng.Assert.assertTrue;
public class RedirectWithCookie implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -160,10 +160,6 @@ public class RedirectWithCookie implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new CookieRedirectHandler(), "/http1/cookie/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/cookie/redirect";

View File

@ -76,7 +76,7 @@ public class Response1xxTest implements HttpServerAdapters {
private String http2RequestURIBase;
private SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
private HttpTestServer https2Server; // h2
private String https2RequestURIBase;
@ -107,10 +107,6 @@ public class Response1xxTest implements HttpServerAdapters {
http2Server.start();
System.out.println("Started HTTP2 server at " + http2Server.getAddress());
sslContext = new SimpleSSLContext().get();
if (sslContext == null) {
throw new AssertionError("Unexpected null sslContext");
}
https2Server = HttpTestServer.create(HTTP_2, sslContext);
https2Server.addHandler(new Http2Handler(), "/http2/101");
https2RequestURIBase = URIBuilder.newBuilder().scheme("https").loopback()

View File

@ -76,7 +76,7 @@ import static java.net.http.HttpOption.H3_DISCOVERY;
public class Response204V2Test implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
HttpTestServer https2TestServer; // HTTP/2 ( h2 )
HttpTestServer http3TestServer; // HTTP/3 ( h3 )
@ -284,10 +284,6 @@ public class Response204V2Test implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/2
HttpTestHandler handler204 = new Handler204();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -82,7 +82,7 @@ public class ResponseBodyBeforeError {
String httpURIFixLen;
String httpsURIFixLen;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
static final String EXPECTED_RESPONSE_BODY =
"<html><body><h1>Heading</h1><p>Some Text</p></body></html>";
@ -538,9 +538,6 @@ public class ResponseBodyBeforeError {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
SSLContext.setDefault(sslContext);
variableLengthServer = new PlainVariableLengthServer();

View File

@ -79,7 +79,7 @@ import static org.testng.Assert.assertTrue;
public class ResponsePublisher implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -456,10 +456,6 @@ public class ResponsePublisher implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
// HTTP/1.1
HttpTestHandler h1_fixedLengthHandler = new HTTP_FixedLengthHandler();
HttpTestHandler h1_chunkHandler = new HTTP_VariableLengthHandler();

View File

@ -72,7 +72,7 @@ import static org.testng.Assert.assertTrue;
public class RetryWithCookie implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 5 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -158,10 +158,6 @@ public class RetryWithCookie implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new CookieRetryHandler(), "/http1/cookie/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/cookie/retry";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -77,7 +77,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
public class ServerCloseTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
DummyServer httpDummyServer; // HTTP/1.1 [ 2 servers ]
DummyServer httpsDummyServer; // HTTPS/1.1
String httpDummy;
@ -226,10 +226,6 @@ public class ServerCloseTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
// DummyServer

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -82,7 +82,7 @@ public abstract class ShortResponseBody {
String httpsURIVarLen;
String httpURIFixLen;
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
SSLParameters sslParameters;
HttpClient client;
int numberOfRequests;
@ -657,9 +657,6 @@ public abstract class ShortResponseBody {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
SSLContext.setDefault(sslContext);
sslParameters = new SSLParameters();

View File

@ -91,7 +91,7 @@ public class ShutdownNow implements HttpServerAdapters {
}
static final Random RANDOM = RandomFactory.getRandom();
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -321,10 +321,6 @@ public class ShutdownNow implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
out.println("\n**** Setup ****\n");
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new ServerRequestHandler(), "/http1/exec/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/exec/retry";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -121,7 +121,7 @@ import java.util.logging.Logger;
* in docs directory.
*/
public class SmokeTest {
static SSLContext ctx;
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
static SSLParameters sslparams;
static HttpServer s1 ;
static HttpsServer s2;
@ -808,7 +808,6 @@ public class SmokeTest {
executor = Executors.newCachedThreadPool();
s1.setExecutor(executor);
s2.setExecutor(executor);
ctx = new SimpleSSLContext().get();
sslparams = ctx.getDefaultSSLParameters();
//sslparams.setProtocols(new String[]{"TLSv1.2"});
s2.setHttpsConfigurator(new Configurator(addr.getAddress(), ctx));

View File

@ -100,7 +100,7 @@ import static org.testng.Assert.assertTrue;
public class SpecialHeadersTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -555,9 +555,6 @@ public class SpecialHeadersTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
out.println("--- Starting setup " + now());
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
HttpTestHandler handler = new HttpUriStringHandler();
httpTestServer = HttpTestServer.create(HTTP_1_1);

View File

@ -94,11 +94,10 @@ public class SplitResponse {
};
final ServerSocketFactory factory;
final SSLContext context;
private static final SSLContext context = SimpleSSLContext.findSSLContext();
final boolean useSSL;
SplitResponse(boolean useSSL) throws IOException {
SplitResponse(boolean useSSL) {
this.useSSL = useSSL;
context = new SimpleSSLContext().get();
SSLContext.setDefault(context);
factory = useSSL ? SSLServerSocketFactory.getDefault()
: ServerSocketFactory.getDefault();

View File

@ -59,7 +59,7 @@ import static org.testng.Assert.assertEquals;
public class StreamingBody implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -126,10 +126,6 @@ public class StreamingBody implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new MessageHandler(), "/http1/streamingbody/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/streamingbody/w";

View File

@ -83,11 +83,7 @@ public class TimeoutBasic {
static final List<String> SCHEMES = List.of("https", "http");
static {
try {
SSLContext.setDefault(new SimpleSSLContext().get());
} catch (IOException x) {
throw new ExceptionInInitializerError(x);
}
SSLContext.setDefault(SimpleSSLContext.findSSLContext());
}
public static void main(String[] args) throws Exception {

View File

@ -72,7 +72,7 @@ public class TimeoutResponseTestSupport {
private static final Logger LOGGER = Utils.getDebugLogger(CLASS_NAME::toString, Utils.DEBUG);
private static final SSLContext SSL_CONTEXT = createSslContext();
private static final SSLContext SSL_CONTEXT = SimpleSSLContext.findSSLContext();
protected static final Duration REQUEST_TIMEOUT =
Duration.ofMillis(Long.parseLong(System.getProperty("test.requestTimeoutMillis")));
@ -126,14 +126,6 @@ public class TimeoutResponseTestSupport {
HTTPS2 = ServerRequestPair.of(Version.HTTP_2, true),
HTTP3 = ServerRequestPair.of(Version.HTTP_3, true);
private static SSLContext createSslContext() {
try {
return new SimpleSSLContext().get();
} catch (IOException exception) {
throw new UncheckedIOException(exception);
}
}
protected record ServerRequestPair(HttpTestServer server, HttpRequest request, boolean secure) {
private static final ExecutorService EXECUTOR = Executors.newVirtualThreadPerTaskExecutor();

View File

@ -75,7 +75,7 @@ public class TlsContextTest implements HttpServerAdapters {
// Re-enable TLSv1 and TLSv1.1 since test depends on them
SecurityUtils.removeFromDisabledTlsAlgs("TLSv1", "TLSv1.1");
server = SimpleSSLContext.getContext("TLS");
server = SimpleSSLContext.findSSLContext("TLS");
final ExecutorService executor = Executors.newCachedThreadPool();
https2Server = HttpTestServer.of(
new Http2TestServer("localhost", true, 0, executor, 50, null, server, true)
@ -89,13 +89,13 @@ public class TlsContextTest implements HttpServerAdapters {
@DataProvider(name = "scenarios")
public Object[][] scenarios() throws Exception {
return new Object[][]{
{ SimpleSSLContext.getContext("TLS"), HTTP_2, "TLSv1.3" },
{ SimpleSSLContext.getContext("TLSv1.2"), HTTP_2, "TLSv1.2" },
{ SimpleSSLContext.getContext("TLSv1.1"), HTTP_1_1, "TLSv1.1" },
{ SimpleSSLContext.getContext("TLSv1.1"), HTTP_2, "TLSv1.1" },
{ SimpleSSLContext.getContext("TLSv1.3"), HTTP_3, "TLSv1.3" },
{ SimpleSSLContext.getContext("TLSv1.2"), HTTP_3, "TLSv1.2" },
{ SimpleSSLContext.getContext("TLSv1.1"), HTTP_3, "TLSv1.1" },
{ SimpleSSLContext.findSSLContext("TLS"), HTTP_2, "TLSv1.3" },
{ SimpleSSLContext.findSSLContext("TLSv1.2"), HTTP_2, "TLSv1.2" },
{ SimpleSSLContext.findSSLContext("TLSv1.1"), HTTP_1_1, "TLSv1.1" },
{ SimpleSSLContext.findSSLContext("TLSv1.1"), HTTP_2, "TLSv1.1" },
{ SimpleSSLContext.findSSLContext("TLSv1.3"), HTTP_3, "TLSv1.3" },
{ SimpleSSLContext.findSSLContext("TLSv1.2"), HTTP_3, "TLSv1.2" },
{ SimpleSSLContext.findSSLContext("TLSv1.1"), HTTP_3, "TLSv1.1" },
};
}

View File

@ -70,7 +70,7 @@ import static org.testng.Assert.assertTrue;
public class UnauthorizedTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -207,10 +207,6 @@ public class UnauthorizedTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new UnauthorizedHandler(), "/http1/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1";

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -59,7 +59,7 @@ import jdk.test.lib.net.SimpleSSLContext;
public class UnknownBodyLengthTest {
static final byte[] BUF = new byte[32 * 10234 + 2];
volatile SSLContext ctx;
private static final SSLContext ctx = SimpleSSLContext.findSSLContext();
volatile ServerSocketFactory factory;
volatile String clientURL;
volatile int port;
@ -67,7 +67,6 @@ public class UnknownBodyLengthTest {
final List<Socket> acceptedList = new CopyOnWriteArrayList<>();
UnknownBodyLengthTest(boolean useSSL) throws Exception {
ctx = new SimpleSSLContext().get();
SSLContext.setDefault(ctx);
factory = useSSL ? SSLServerSocketFactory.getDefault()
: ServerSocketFactory.getDefault();

View File

@ -88,7 +88,7 @@ class UserAuthWithAuthenticator {
}
private static void h2Test(final boolean useHeader, boolean rightPassword) throws Exception {
SSLContext sslContext = new SimpleSSLContext().get();
SSLContext sslContext = SimpleSSLContext.findSSLContext();
try (ExecutorService executor = Executors.newCachedThreadPool();
HttpTestServer server = HttpTestServer.of(new Http2TestServer(
InetAddress.getLoopbackAddress(),
@ -117,7 +117,7 @@ class UserAuthWithAuthenticator {
}
private static void h3Test(final boolean useHeader, boolean rightPassword) throws Exception {
SSLContext sslContext = new SimpleSSLContext().get();
SSLContext sslContext = SimpleSSLContext.findSSLContext();
try (ExecutorService executor = Executors.newCachedThreadPool();
HttpTestServer server = HttpTestServer.create(Http3DiscoveryMode.HTTP_3_URI_ONLY, sslContext, executor);
HttpClient client = HttpServerAdapters.createClientBuilderForH3()

View File

@ -84,7 +84,7 @@ import static org.testng.Assert.assertEquals;
public class UserCookieTest implements HttpServerAdapters {
SSLContext sslContext;
private static final SSLContext sslContext = SimpleSSLContext.findSSLContext();
HttpTestServer httpTestServer; // HTTP/1.1 [ 7 servers ]
HttpTestServer httpsTestServer; // HTTPS/1.1
HttpTestServer http2TestServer; // HTTP/2 ( h2c )
@ -202,10 +202,6 @@ public class UserCookieTest implements HttpServerAdapters {
@BeforeTest
public void setup() throws Exception {
sslContext = new SimpleSSLContext().get();
if (sslContext == null)
throw new AssertionError("Unexpected null sslContext");
httpTestServer = HttpTestServer.create(HTTP_1_1);
httpTestServer.addHandler(new CookieValidationHandler(), "/http1/cookie/");
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/cookie/retry";

Some files were not shown because too many files have changed in this diff Show More