Class ProxySettings


  • public final class ProxySettings
    extends Object

    A class defining proxy settings for HTTP clients.

    This class allows configuring a proxy to be used for HTTP connections. The proxy's host address and port number can be configured. It is also possible to indicate that no proxy should be used.

    • Method Detail

      • noProxy

        public static ProxySettings noProxy()
        Returns an instance of ProxySettings that indicates that no proxy is to be used.
        Returns:
        an instance with an empty proxy configuration
      • defaultProxySelector

        public static ProxySettings defaultProxySelector()
        Returns an instance of ProxySettings that indicates that the default ProxySelector (obtained via the ProxySelector.getDefault() method) should be queried for each request. In this mode, the usage of proxies can be enabled or disabled on a per URL basis.
        Returns:
        an instance enabling the default ProxySelector
      • useProxy

        public static ProxySettings useProxy​(String host,
                                             int port)
        Creates a new instance of ProxySettings that uses the specified settings for the proxy.
        Parameters:
        host - the host address of the proxy
        port - the port of the proxy
        Returns:
        the new ProxySettings instance
      • fromConfig

        public static ProxySettings fromConfig​(boolean useProxy,
                                               String host,
                                               int port)
        Creates a new instance of ProxySettings that is initialized from configuration settings. In the configuration, it can be stated explicitly whether a proxy is to be used or not. So it is possible that valid settings for the proxy host and port are provided, but the resulting settings should nevertheless refer to an undefined proxy. If proxy usage is explicitly enabled, but no valid proxy host or port are configured, the resulting settings point to the default proxy selector.
        Parameters:
        useProxy - flag whether a proxy should be used
        host - the proxy host (may be undefined)
        port - the proxy port (may be undefined)
        Returns:
        the new ProxySettings instance
      • isProxyUse

        public boolean isProxyUse()
        Returns a flag whether a proxy should be used.
        Returns:
        true if the proxy server defined by this object should be used; false for a direct Internet connection
      • isDefaultProxySelectorUse

        public boolean isDefaultProxySelectorUse()
        Returns a flag whether the default proxy selector should be used. In this mode, from the ProxySelector.getDefault() method the default proxy selector is obtained. This selector is then called for each request to obtain a proxy on a per URL basis.
        Returns:
        true if the default proxy selector should be used; false otherwise
      • isNoProxy

        public boolean isNoProxy()
        Returns a flag whether a proxy should be completely disabled. In this mode, a direct Internet connection is enforced.
        Returns:
        true if direct Internet connections are used; false whether requests go via a proxy
      • getProxyHost

        public String getProxyHost()
        Returns the proxy host. This method only returns a defined value if isProxyUse() returns true.
        Returns:
        the proxy host address
      • getProxyPort

        public int getProxyPort()
        Returns the proxy port. This method only returns a defined value if isProxyUse() returns true.
        Returns:
        the proxy port
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object