Class NetHttpTransport


  • public final class NetHttpTransport
    extends HttpTransport
    Thread-safe HTTP low-level transport based on the java.net package.

    Users should consider modifying the keep alive property on NetHttpTransport to control whether the socket should be returned to a pool of connected sockets. More information is available here.

    We honor the default global caching behavior. To change the default behavior use URLConnection.setDefaultUseCaches(boolean).

    Implementation is thread-safe. For maximum efficiency, applications should use a single globally-shared instance of the HTTP transport.

    Since:
    1.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private ConnectionFactory connectionFactory
      Factory to produce connections from URLs
      private javax.net.ssl.HostnameVerifier hostnameVerifier
      Host name verifier or null for the default.
      private javax.net.ssl.SSLSocketFactory sslSocketFactory
      SSL socket factory or null for the default.
      private static java.lang.String[] SUPPORTED_METHODS
      All valid request methods as specified in HttpURLConnection.setRequestMethod(java.lang.String), sorted in ascending alphabetical order.
    • Constructor Summary

      Constructors 
      Constructor Description
      NetHttpTransport()
      Constructor with the default behavior.
      NetHttpTransport​(ConnectionFactory connectionFactory, javax.net.ssl.SSLSocketFactory sslSocketFactory, javax.net.ssl.HostnameVerifier hostnameVerifier)  
      NetHttpTransport​(java.net.Proxy proxy, javax.net.ssl.SSLSocketFactory sslSocketFactory, javax.net.ssl.HostnameVerifier hostnameVerifier)  
    • Field Detail

      • SUPPORTED_METHODS

        private static final java.lang.String[] SUPPORTED_METHODS
        All valid request methods as specified in HttpURLConnection.setRequestMethod(java.lang.String), sorted in ascending alphabetical order.
      • connectionFactory

        private final ConnectionFactory connectionFactory
        Factory to produce connections from URLs
      • sslSocketFactory

        private final javax.net.ssl.SSLSocketFactory sslSocketFactory
        SSL socket factory or null for the default.
      • hostnameVerifier

        private final javax.net.ssl.HostnameVerifier hostnameVerifier
        Host name verifier or null for the default.
    • Constructor Detail

      • NetHttpTransport

        public NetHttpTransport()
        Constructor with the default behavior.

        Instead use NetHttpTransport.Builder to modify behavior.

      • NetHttpTransport

        NetHttpTransport​(java.net.Proxy proxy,
                         javax.net.ssl.SSLSocketFactory sslSocketFactory,
                         javax.net.ssl.HostnameVerifier hostnameVerifier)
        Parameters:
        proxy - HTTP proxy or null to use the proxy settings from system properties
        sslSocketFactory - SSL socket factory or null for the default
        hostnameVerifier - host name verifier or null for the default
      • NetHttpTransport

        NetHttpTransport​(ConnectionFactory connectionFactory,
                         javax.net.ssl.SSLSocketFactory sslSocketFactory,
                         javax.net.ssl.HostnameVerifier hostnameVerifier)
        Parameters:
        connectionFactory - factory to produce connections from URLs; if null then DefaultConnectionFactory is used
        sslSocketFactory - SSL socket factory or null for the default
        hostnameVerifier - host name verifier or null for the default
        Since:
        1.20
    • Method Detail

      • 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 class HttpTransport
        Parameters:
        method - HTTP method
      • buildRequest

        protected NetHttpRequest buildRequest​(java.lang.String method,
                                              java.lang.String url)
                                       throws java.io.IOException
        Description copied from class: HttpTransport
        Builds a low level HTTP request for the given HTTP method.
        Specified by:
        buildRequest in class HttpTransport
        Parameters:
        method - HTTP method
        url - URL
        Returns:
        new low level HTTP request
        Throws:
        java.io.IOException