public static final class NetHttpTransport.BuilderConstructors
Builder()
public Builder()Methods
build()
public NetHttpTransport build()Returns a new instance of NetHttpTransport based on the options.
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport |
|
doNotValidateCertificate()
public NetHttpTransport.Builder doNotValidateCertificate()Beta
Disables validating server SSL certificates by setting the SSL socket factory using SslUtils#trustAllSSLContext() for the SSL context and SslUtils#trustAllHostnameVerifier() for the host name verifier.
Be careful! Disabling certificate validation is dangerous and should only be done in testing environments.
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
| Exceptions | |
|---|---|
| Type | Description |
GeneralSecurityException |
|
getHostnameVerifier()
public HostnameVerifier getHostnameVerifier()Returns the host name verifier or null for the default.
| Returns | |
|---|---|
| Type | Description |
HostnameVerifier |
|
getSslSocketFactory()
public SSLSocketFactory getSslSocketFactory()Returns the SSL socket factory.
| Returns | |
|---|---|
| Type | Description |
SSLSocketFactory |
|
setConnectionFactory(ConnectionFactory connectionFactory)
public NetHttpTransport.Builder setConnectionFactory(ConnectionFactory connectionFactory)Sets the ConnectionFactory or null to use a DefaultConnectionFactory.
This value is ignored if the #setProxy has been called with a non-null value.
If you wish to use a Proxy, it should be included in your ConnectionFactory implementation.
| Parameter | |
|---|---|
| Name | Description |
connectionFactory |
ConnectionFactory |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
setHostnameVerifier(HostnameVerifier hostnameVerifier)
public NetHttpTransport.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)Sets the host name verifier or null for the default.
| Parameter | |
|---|---|
| Name | Description |
hostnameVerifier |
HostnameVerifier |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
setProxy(Proxy proxy)
public NetHttpTransport.Builder setProxy(Proxy proxy)Sets the HTTP proxy or null to use the proxy settings from system
properties.
For example:
setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)))
| Parameter | |
|---|---|
| Name | Description |
proxy |
Proxy |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
setSecurityProvider(Provider securityProvider)
public NetHttpTransport.Builder setSecurityProvider(Provider securityProvider)Sets the custom security provider or null to use the default JRE provider.
When enabling Post-Quantum Cryptography (PQC) transport:
- On JDK 8-19: A custom JCA provider (such as Conscrypt or BouncyCastle) must be configured via this method, in addition to configuring a custom SslSocketConfigurator callback to select the hybrid/PQC curves using provider-specific APIs.
- On JDK 20-26: A custom provider (like Conscrypt) is recommended, but a custom SslSocketConfigurator invoking
SSLParameters.setNamedGroups(String[])directly can be used natively without a custom JCA provider if standard JSSE supports the curves. - On JDK 27+: Neither a custom provider nor a configurator is required as PQC algorithms are negotiated natively by default.
| Parameter | |
|---|---|
| Name | Description |
securityProvider |
Providerprovider to use |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
setSslSocketConfigurator(SslSocketConfigurator configurator)
public NetHttpTransport.Builder setSslSocketConfigurator(SslSocketConfigurator configurator)Sets the custom SslSocketConfigurator callback to configure active SSLSockets.
If both a custom SSLSocketFactory (via #setSslSocketFactory(SSLSocketFactory)) and a custom configurator are set, the configurator callback will be applied to all sockets created by the custom socket factory. If no custom factory is provided, the configurator will wrap and apply to sockets created by the default resolved socket factory.
When enabling Post-Quantum Cryptography (PQC) transport:
- On JDK 20-26: Callers can configure a custom SslSocketConfigurator that sets
the named groups (such as
X25519MLKEM768) directly onSSLParameters. - On JDK 8-19: Callers must provide a custom SslSocketConfigurator implementation to inspect the socket types and invoke provider-specific API extensions (e.g. Conscrypt JNI interfaces) to configure the curves.
| Parameter | |
|---|---|
| Name | Description |
configurator |
SslSocketConfiguratorthe callback configurator |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
setSslSocketFactory(SSLSocketFactory sslSocketFactory)
public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)Sets the SSL socket factory or null for the default.
Note: If a custom SslSocketConfigurator is also provided, it will wrap and apply its configuration callback to all sockets created by this factory.
| Parameter | |
|---|---|
| Name | Description |
sslSocketFactory |
SSLSocketFactory |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
trustCertificates(KeyStore trustStore)
public NetHttpTransport.Builder trustCertificates(KeyStore trustStore)Sets the SSL socket factory based on a root certificate trust store.
| Parameter | |
|---|---|
| Name | Description |
trustStore |
KeyStorecertificate trust store (use for example SecurityUtils#loadKeyStore or SecurityUtils#loadKeyStoreFromCertificates) |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
| Exceptions | |
|---|---|
| Type | Description |
GeneralSecurityException |
|
trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword)
public NetHttpTransport.Builder trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword)Beta
Sets the SSL socket factory based on a root certificate trust store and a client certificate
key store. The client certificate key store will be used to establish mutual TLS.
| Parameters | |
|---|---|
| Name | Description |
trustStore |
KeyStorecertificate trust store (use for example SecurityUtils#loadKeyStore or SecurityUtils#loadKeyStoreFromCertificates) |
mtlsKeyStore |
KeyStorekey store for client certificate and key to establish mutual TLS. (use for example SecurityUtils#createMtlsKeyStore(InputStream)) |
mtlsKeyStorePassword |
Stringpassword for mtlsKeyStore parameter |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
| Exceptions | |
|---|---|
| Type | Description |
GeneralSecurityException |
|
trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass)
public NetHttpTransport.Builder trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass)Sets the SSL socket factory based on root certificates in a Java KeyStore.
Example usage:
trustCertificatesFromJavaKeyStore(new FileInputStream("certs.jks"), "password");
| Parameters | |
|---|---|
| Name | Description |
keyStoreStream |
InputStreaminput stream to the key store (closed at the end of this method in a finally block) |
storePass |
Stringpassword protecting the key store file |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
| Exceptions | |
|---|---|
| Type | Description |
GeneralSecurityException |
|
IOException |
|
trustCertificatesFromStream(InputStream certificateStream)
public NetHttpTransport.Builder trustCertificatesFromStream(InputStream certificateStream)Sets the SSL socket factory based root certificates generated from the specified stream using CertificateFactory#generateCertificates(InputStream).
Example usage:
trustCertificatesFromStream(new FileInputStream("certs.pem"));
| Parameter | |
|---|---|
| Name | Description |
certificateStream |
InputStreamcertificate stream |
| Returns | |
|---|---|
| Type | Description |
NetHttpTransport.Builder |
|
| Exceptions | |
|---|---|
| Type | Description |
GeneralSecurityException |
|
IOException |
|