Class Apache5HttpTransport
- java.lang.Object
-
- com.google.api.client.http.HttpTransport
-
- com.google.api.client.http.apache.v5.Apache5HttpTransport
-
public final class Apache5HttpTransport extends HttpTransport
Thread-safe HTTP transport based on the Apache HTTP Client library.Implementation is thread-safe, as long as any parameter modification to the
Apache HTTP Client
is only done at initialization time. For maximum efficiency, applications should use a single globally-shared instance of the HTTP transport.Default settings are specified in
newDefaultHttpClient()
. Use theApache5HttpTransport(HttpClient)
constructor to override the Apache HTTP Client used. Please read the Apache HTTP Client 5.x configuration example for more complex configuration options.
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.hc.client5.http.classic.HttpClient
httpClient
Apache HTTP client.private boolean
isMtls
If the HTTP client uses mTLS channel.
-
Constructor Summary
Constructors Constructor Description Apache5HttpTransport()
Constructor that usesnewDefaultHttpClient()
for the Apache HTTP client.Apache5HttpTransport(org.apache.hc.client5.http.classic.HttpClient httpClient)
Constructor that allows an alternative Apache HTTP client to be used.Apache5HttpTransport(org.apache.hc.client5.http.classic.HttpClient httpClient, boolean isMtls)
Beta
Constructor that allows an alternative CLoseable Apache HTTP client to be used.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Apache5HttpRequest
buildRequest(java.lang.String method, java.lang.String url)
Builds a low level HTTP request for the given HTTP method.org.apache.hc.client5.http.classic.HttpClient
getHttpClient()
Returns the Apache HTTP client.boolean
isMtls()
Returns if the underlying HTTP client is mTLS.static org.apache.hc.client5.http.classic.HttpClient
newDefaultHttpClient()
Creates a new instance of the Apache HTTP client that is used by theApache5HttpTransport()
constructor.static org.apache.hc.client5.http.impl.classic.HttpClientBuilder
newDefaultHttpClientBuilder()
Creates a new Apache HTTP client builder that is used by theApache5HttpTransport()
constructor.void
shutdown()
Gracefully shuts down the connection manager and releases allocated resources.boolean
supportsMethod(java.lang.String method)
Returns whether a specified HTTP method is supported by this transport.-
Methods inherited from class com.google.api.client.http.HttpTransport
createRequestFactory, createRequestFactory, isShutdown
-
-
-
-
Constructor Detail
-
Apache5HttpTransport
public Apache5HttpTransport()
Constructor that usesnewDefaultHttpClient()
for the Apache HTTP client.
-
Apache5HttpTransport
public Apache5HttpTransport(org.apache.hc.client5.http.classic.HttpClient httpClient)
Constructor that allows an alternative Apache HTTP client to be used.If you choose to provide your own Apache HttpClient implementation, be sure that
- HTTP version is set to 1.1.
- Retries are disabled (google-http-client handles retries).
- Parameters:
httpClient
- Apache HTTP client to use
-
Apache5HttpTransport
@Beta public Apache5HttpTransport(org.apache.hc.client5.http.classic.HttpClient httpClient, boolean isMtls)
Beta
Constructor that allows an alternative CLoseable Apache HTTP client to be used.If you choose to provide your own Apache HttpClient implementation, be sure that
- HTTP version is set to 1.1.
- Retries are disabled (google-http-client handles retries).
- Redirects are disabled (google-http-client handles retries).
- Parameters:
httpClient
- Apache HTTP client to useisMtls
- If the HTTP client is mutual TLS
-
-
Method Detail
-
newDefaultHttpClient
public static org.apache.hc.client5.http.classic.HttpClient newDefaultHttpClient()
Creates a new instance of the Apache HTTP client that is used by theApache5HttpTransport()
constructor.Settings:
- The client connection manager is set to
PoolingHttpClientConnectionManager
. - The retry mechanism is turned off using
HttpClientBuilder.disableAutomaticRetries()
. - Redirects are turned off using
HttpClientBuilder.disableRedirectHandling()
. - The route planner uses
SystemDefaultRoutePlanner
withProxySelector.getDefault()
, which uses the proxy settings from system properties.
- Returns:
- new instance of the Apache HTTP client
- The client connection manager is set to
-
newDefaultHttpClientBuilder
public static org.apache.hc.client5.http.impl.classic.HttpClientBuilder newDefaultHttpClientBuilder()
Creates a new Apache HTTP client builder that is used by theApache5HttpTransport()
constructor.Settings:
- The client connection manager is set to
PoolingHttpClientConnectionManager
. - The retry mechanism is turned off using
HttpClientBuilder.disableAutomaticRetries()
. - Redirects are turned off using
HttpClientBuilder.disableRedirectHandling()
. - The route planner uses
SystemDefaultRoutePlanner
withProxySelector.getDefault()
, which uses the proxy settings from system properties.
- Returns:
- new instance of the Apache HTTP client builder
- The client connection manager is set to
-
supportsMethod
public boolean supportsMethod(java.lang.String method)
Description copied from class:HttpTransport
Returns whether a specified HTTP method is supported by this transport.Default implementation returns true if and only if the request method is
"DELETE"
,"GET"
,"POST"
, or"PUT"
. Subclasses should override.- Overrides:
supportsMethod
in classHttpTransport
- Parameters:
method
- HTTP method
-
buildRequest
protected Apache5HttpRequest buildRequest(java.lang.String method, java.lang.String url)
Description copied from class:HttpTransport
Builds a low level HTTP request for the given HTTP method.- Specified by:
buildRequest
in classHttpTransport
- Parameters:
method
- HTTP methodurl
- URL- Returns:
- new low level HTTP request
-
shutdown
public void shutdown() throws java.io.IOException
Gracefully shuts down the connection manager and releases allocated resources. This closes all connections, whether they are currently used or not.- Overrides:
shutdown
in classHttpTransport
- Throws:
java.io.IOException
- I/O exception
-
getHttpClient
public org.apache.hc.client5.http.classic.HttpClient getHttpClient()
Returns the Apache HTTP client.
-
isMtls
public boolean isMtls()
Returns if the underlying HTTP client is mTLS.- Overrides:
isMtls
in classHttpTransport
- Returns:
- boolean indicating if the transport is mTLS.
-
-