Class ApacheHttpTransport
- java.lang.Object
-
- com.google.api.client.http.HttpTransport
-
- com.google.api.client.http.apache.v2.ApacheHttpTransport
-
public final class ApacheHttpTransport 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 Clientis 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 theApacheHttpTransport(HttpClient)constructor to override the Apache HTTP Client used. Please read the Apache HTTP Client connection management tutorial for more complex configuration options.- Since:
- 1.30
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.http.client.HttpClienthttpClientApache HTTP client.private booleanisMtlsIf the HTTP client uses mTLS channel.
-
Constructor Summary
Constructors Constructor Description ApacheHttpTransport()Constructor that usesnewDefaultHttpClient()for the Apache HTTP client.ApacheHttpTransport(org.apache.http.client.HttpClient httpClient)Constructor that allows an alternative Apache HTTP client to be used.ApacheHttpTransport(org.apache.http.client.HttpClient httpClient, boolean isMtls)Beta
Constructor that allows an alternative Apache HTTP client to be used.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ApacheHttpRequestbuildRequest(java.lang.String method, java.lang.String url)Builds a low level HTTP request for the given HTTP method.org.apache.http.client.HttpClientgetHttpClient()Returns the Apache HTTP client.booleanisMtls()Returns if the underlying HTTP client is mTLS.static org.apache.http.client.HttpClientnewDefaultHttpClient()Creates a new instance of the Apache HTTP client that is used by theApacheHttpTransport()constructor.static org.apache.http.impl.client.HttpClientBuildernewDefaultHttpClientBuilder()Creates a new Apache HTTP client builder that is used by theApacheHttpTransport()constructor.voidshutdown()Shuts down the connection manager and releases allocated resources.booleansupportsMethod(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
-
ApacheHttpTransport
public ApacheHttpTransport()
Constructor that usesnewDefaultHttpClient()for the Apache HTTP client.- Since:
- 1.30
-
ApacheHttpTransport
public ApacheHttpTransport(org.apache.http.client.HttpClient httpClient)
Constructor that allows an alternative Apache HTTP client to be used.Note that in the previous version, we overrode several settings. However, we are no longer able to do so.
If you choose to provide your own Apache HttpClient implementation, be sure that
- HTTP version is set to 1.1.
- Redirects are disabled (google-http-client handles redirects).
- Retries are disabled (google-http-client handles retries).
- Parameters:
httpClient- Apache HTTP client to use- Since:
- 1.30
-
ApacheHttpTransport
@Beta public ApacheHttpTransport(org.apache.http.client.HttpClient httpClient, boolean isMtls)
Beta
Constructor that allows an alternative Apache HTTP client to be used.Note that in the previous version, we overrode several settings. However, we are no longer able to do so.
If you choose to provide your own Apache HttpClient implementation, be sure that
- HTTP version is set to 1.1.
- Redirects are disabled (google-http-client handles redirects).
- Retries are disabled (google-http-client handles retries).
- Parameters:
httpClient- Apache HTTP client to useisMtls- If the HTTP client is mutual TLS- Since:
- 1.38
-
-
Method Detail
-
newDefaultHttpClient
public static org.apache.http.client.HttpClient newDefaultHttpClient()
Creates a new instance of the Apache HTTP client that is used by theApacheHttpTransport()constructor.Settings:
- The client connection manager is set to
PoolingHttpClientConnectionManager. HttpClientBuilder.disableRedirectHandling(). - The route planner uses
SystemDefaultRoutePlannerwithProxySelector.getDefault(), which uses the proxy settings from system properties.- The route planner uses
- Returns:
- new instance of the Apache HTTP client
- Since:
- 1.30
- The client connection manager is set to
-
newDefaultHttpClientBuilder
public static org.apache.http.impl.client.HttpClientBuilder newDefaultHttpClientBuilder()
Creates a new Apache HTTP client builder that is used by theApacheHttpTransport()constructor.Settings:
- The client connection manager is set to
PoolingHttpClientConnectionManager. HttpClientBuilder.disableRedirectHandling(). - The route planner uses
SystemDefaultRoutePlannerwithProxySelector.getDefault(), which uses the proxy settings from system properties.- The route planner uses
- Returns:
- new instance of the Apache HTTP client
- Since:
- 1.31
- The client connection manager is set to
-
supportsMethod
public boolean supportsMethod(java.lang.String method)
Description copied from class:HttpTransportReturns 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:
supportsMethodin classHttpTransport- Parameters:
method- HTTP method
-
buildRequest
protected ApacheHttpRequest buildRequest(java.lang.String method, java.lang.String url)
Description copied from class:HttpTransportBuilds a low level HTTP request for the given HTTP method.- Specified by:
buildRequestin classHttpTransport- Parameters:
method- HTTP methodurl- URL- Returns:
- new low level HTTP request
-
shutdown
public void shutdown() throws java.io.IOExceptionShuts down the connection manager and releases allocated resources. This closes all connections, whether they are currently used or not.- Overrides:
shutdownin classHttpTransport- Throws:
java.io.IOException- I/O exception- Since:
- 1.30
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()
Returns the Apache HTTP client.- Since:
- 1.30
-
isMtls
public boolean isMtls()
Returns if the underlying HTTP client is mTLS.- Overrides:
isMtlsin classHttpTransport- Returns:
- boolean indicating if the transport is mTLS.
-
-