public static final class NetHttpTransport.Builder extends Object
NetHttpTransport.
Implementation is not thread-safe.
| Constructor and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
NetHttpTransport |
build()
Returns a new instance of
NetHttpTransport based on the options. |
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. |
HostnameVerifier |
getHostnameVerifier()
Returns the host name verifier or
null for the default. |
SSLSocketFactory |
getSslSocketFactory()
Returns the SSL socket factory.
|
NetHttpTransport.Builder |
setConnectionFactory(ConnectionFactory connectionFactory)
|
NetHttpTransport.Builder |
setHostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the host name verifier or
null for the default. |
NetHttpTransport.Builder |
setProxy(Proxy proxy)
Sets the HTTP proxy or
null to use the proxy settings from system
properties. |
NetHttpTransport.Builder |
setSecurityProvider(Provider securityProvider)
Sets the custom security provider or
null to use the default JRE provider. |
NetHttpTransport.Builder |
setSslSocketConfigurator(SslSocketConfigurator configurator)
Sets the custom
SslSocketConfigurator callback to configure active SSLSockets. |
NetHttpTransport.Builder |
setSslSocketFactory(SSLSocketFactory sslSocketFactory)
Sets the SSL socket factory or
null for the default. |
NetHttpTransport.Builder |
trustCertificates(KeyStore trustStore)
Sets the SSL socket factory based on a root certificate trust store.
|
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. |
NetHttpTransport.Builder |
trustCertificatesFromJavaKeyStore(InputStream keyStoreStream,
String storePass)
Sets the SSL socket factory based on root certificates in a Java KeyStore.
|
NetHttpTransport.Builder |
trustCertificatesFromStream(InputStream certificateStream)
Sets the SSL socket factory based root certificates generated from the specified stream using
CertificateFactory.generateCertificates(InputStream). |
public NetHttpTransport.Builder setProxy(Proxy proxy)
null to use the proxy settings from system
properties.
For example:
setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)))
public NetHttpTransport.Builder setConnectionFactory(ConnectionFactory connectionFactory)
ConnectionFactory or null to use a DefaultConnectionFactory.
This value is ignored if the setProxy(java.net.Proxy) has been called with a non-null value.
If you wish to use a Proxy, it should be included in your ConnectionFactory implementation.
public NetHttpTransport.Builder trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass) throws GeneralSecurityException, IOException
Example usage:
trustCertificatesFromJavaKeyStore(new FileInputStream("certs.jks"), "password");
keyStoreStream - input stream to the key store (closed at the end of this method in a
finally block)storePass - password protecting the key store fileGeneralSecurityExceptionIOExceptionpublic NetHttpTransport.Builder trustCertificatesFromStream(InputStream certificateStream) throws GeneralSecurityException, IOException
CertificateFactory.generateCertificates(InputStream).
Example usage:
trustCertificatesFromStream(new FileInputStream("certs.pem"));
certificateStream - certificate streamGeneralSecurityExceptionIOExceptionpublic NetHttpTransport.Builder trustCertificates(KeyStore trustStore) throws GeneralSecurityException
trustStore - certificate trust store (use for example SecurityUtils.loadKeyStore(java.security.KeyStore, java.io.InputStream, java.lang.String)
or SecurityUtils.loadKeyStoreFromCertificates(java.security.KeyStore, java.security.cert.CertificateFactory, java.io.InputStream))GeneralSecurityException@Beta public NetHttpTransport.Builder trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword) throws GeneralSecurityException
Beta trustStore - certificate trust store (use for example SecurityUtils.loadKeyStore(java.security.KeyStore, java.io.InputStream, java.lang.String)
or SecurityUtils.loadKeyStoreFromCertificates(java.security.KeyStore, java.security.cert.CertificateFactory, java.io.InputStream))mtlsKeyStore - key store for client certificate and key to establish mutual TLS. (use
for example SecurityUtils.createMtlsKeyStore(InputStream))mtlsKeyStorePassword - password for mtlsKeyStore parameterGeneralSecurityException@Beta public NetHttpTransport.Builder doNotValidateCertificate() throws GeneralSecurityException
Beta 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.
GeneralSecurityExceptionpublic SSLSocketFactory getSslSocketFactory()
public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)
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.
public NetHttpTransport.Builder setSecurityProvider(Provider securityProvider)
null to use the default JRE provider.
When enabling Post-Quantum Cryptography (PQC) transport:
SslSocketConfigurator callback to select the hybrid/PQC curves using provider-specific
APIs.
SslSocketConfigurator invoking SSLParameters.setNamedGroups(String[]) directly
can be used natively without a custom JCA provider if standard JSSE supports the
curves.
securityProvider - provider to usepublic NetHttpTransport.Builder setSslSocketConfigurator(SslSocketConfigurator configurator)
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:
SslSocketConfigurator that sets
the named groups (such as X25519MLKEM768) directly on SSLParameters.
SslSocketConfigurator implementation
to inspect the socket types and invoke provider-specific API extensions (e.g. Conscrypt
JNI interfaces) to configure the curves.
configurator - the callback configuratorpublic HostnameVerifier getHostnameVerifier()
null for the default.public NetHttpTransport.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)
null for the default.public NetHttpTransport build()
NetHttpTransport based on the options.Copyright © 2011–2026 Google. All rights reserved.