# Class NetHttpTransport.Builder (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.http.javanet.NetHttpTransport.Builder)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.http.javanet.NetHttpTransport.Builder)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.http.javanet.NetHttpTransport.Builder)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.http.javanet.NetHttpTransport.Builder)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.http.javanet.NetHttpTransport.Builder)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.http.javanet.NetHttpTransport.Builder)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.http.javanet.NetHttpTransport.Builder)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.http.javanet.NetHttpTransport.Builder)

    public static final class NetHttpTransport.Builder

Builder for [NetHttpTransport](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport).

Implementation is not thread-safe.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> NetHttpTransport.Builder

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Constructors

### Builder()

    public Builder()

## Methods

### build()

    public NetHttpTransport build()

Returns a new instance of [NetHttpTransport](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport) based on the options.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport` |   |

### doNotValidateCertificate()

    public NetHttpTransport.Builder doNotValidateCertificate()

[Beta](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.Beta)   

Disables validating server SSL certificates by setting the SSL socket factory using [SslUtils#trustAllSSLContext()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.SslUtils#com_google_api_client_util_SslUtils_trustAllSSLContext__) for the SSL context and [SslUtils#trustAllHostnameVerifier()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.SslUtils#com_google_api_client_util_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** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/GeneralSecurityException.html` |   |

### getHostnameVerifier()

    public HostnameVerifier getHostnameVerifier()

Returns the host name verifier or `null` for the default.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/HostnameVerifier.html` |   |

### getSslSocketFactory()

    public SSLSocketFactory getSslSocketFactory()

Returns the SSL socket factory.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLSocketFactory.html` |   |

### setConnectionFactory(ConnectionFactory connectionFactory)

    public NetHttpTransport.Builder setConnectionFactory(ConnectionFactory connectionFactory)

Sets the [ConnectionFactory](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.ConnectionFactory) or `null` to use a [DefaultConnectionFactory](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.DefaultConnectionFactory).
**This value is ignored if the [#setProxy](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder#com_google_api_client_http_javanet_NetHttpTransport_Builder_setProxy_) has been called with a non-null value.**

If you wish to use a [Proxy](https://docs.oracle.com/javase/8/docs/api/java/net/Proxy.html), it should be included in your [ConnectionFactory](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.ConnectionFactory) implementation.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `connectionFactory` | `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.ConnectionFactory` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.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` | `https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/HostnameVerifier.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.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](http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html).

For example:

setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)))

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `proxy` | `https://docs.oracle.com/javase/8/docs/api/java/net/Proxy.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder` |   |

### setSslSocketFactory(SSLSocketFactory sslSocketFactory)

    public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)

Sets the SSL socket factory or `null` for the default.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `sslSocketFactory` | `https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLSocketFactory.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.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` | `https://docs.oracle.com/javase/8/docs/api/java/security/KeyStore.html` certificate trust store (use for example [SecurityUtils#loadKeyStore](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.SecurityUtils#com_google_api_client_util_SecurityUtils_loadKeyStore_) or [SecurityUtils#loadKeyStoreFromCertificates](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.SecurityUtils#com_google_api_client_util_SecurityUtils_loadKeyStoreFromCertificates_)) |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/GeneralSecurityException.html` |   |

### trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword)

    public NetHttpTransport.Builder trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword)

[Beta](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.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` | `https://docs.oracle.com/javase/8/docs/api/java/security/KeyStore.html` certificate trust store (use for example [SecurityUtils#loadKeyStore](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.SecurityUtils#com_google_api_client_util_SecurityUtils_loadKeyStore_) or [SecurityUtils#loadKeyStoreFromCertificates](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.SecurityUtils#com_google_api_client_util_SecurityUtils_loadKeyStoreFromCertificates_)) |
| `mtlsKeyStore` | `https://docs.oracle.com/javase/8/docs/api/java/security/KeyStore.html` key store for client certificate and key to establish mutual TLS. (use for example [SecurityUtils#createMtlsKeyStore(InputStream)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.SecurityUtils#com_google_api_client_util_SecurityUtils_createMtlsKeyStore_java_io_InputStream_)) |
| `mtlsKeyStorePassword` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` password for mtlsKeyStore parameter |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/GeneralSecurityException.html` |   |

### 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` | `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` input stream to the key store (closed at the end of this method in a finally block) |
| `storePass` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` password protecting the key store file |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/GeneralSecurityException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### 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` | `https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html` certificate stream |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.Builder` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/security/GeneralSecurityException.html` |   |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |