I know with Apache's HttpClientBuilder
you can call useSystemProperties()
and it will create a client with an SSLContext
configured from the javax.net.ssl.keyStore
(and truststore) if passed as JAVA_OPTS
:
try (CloseableHttpClient client = HttpClientBuilder.create().useSystemProperties.build()) {
// If javax.net.ssl props are set, make requests that require client auth
// Otherwise make regular requests
}
I want to do something similar with the Java 11 HttpClient
. The reason for this is in my use-case, I am treating key stores and trust stores as optional and it would be nice to not have to check their existence in my code. Basically, I want to set an SSLContext
based on JAVA_OPTS
if they exist; otherwise just use the "Default"
context.