Class GnomeProxySearchStrategy

  • All Implemented Interfaces:
    ProxySearchStrategy

    public class GnomeProxySearchStrategy
    extends java.lang.Object
    implements ProxySearchStrategy
    Loads the Gnome proxy settings from the Gnome GConf settings.

    The following settings are extracted from the configuration that is stored in .gconf folder found in the user's home directory:

    • /system/http_proxy/use_http_proxy -> bool used only by gnome-vfs
    • /system/http_proxy/host -> string "my-proxy.example.com" without "http://"
    • /system/http_proxy/port -> int
    • /system/http_proxy/use_authentication -> bool
    • /system/http_proxy/authentication_user -> string
    • /system/http_proxy/authentication_password -> string
    • /system/http_proxy/ignore_hosts -> list-of-string
    • /system/proxy/mode -> string THIS IS THE CANONICAL KEY; SEE BELOW
    • /system/proxy/secure_host -> string "proxy-for-https.example.com"
    • /system/proxy/secure_port -> int
    • /system/proxy/ftp_host -> string "proxy-for-ftp.example.com"
    • /system/proxy/ftp_port -> int
    • /system/proxy/socks_host -> string "proxy-for-socks.example.com"
    • /system/proxy/socks_port -> int
    • /system/proxy/autoconfig_url -> string "http://proxy-autoconfig.example.com"
    /system/proxy/mode can be either:
    "none" -> No proxy is used
    "manual" -> The user's configuration values are used (/system/http_proxy/{host,port,etc.})
    "auto" -> The "/system/proxy/autoconfig_url" key is used

    GNOME Proxy_configuration settings are explained here in detail

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.io.File findSettingsFile​(java.lang.String context)
      Finds the Gnome GConf settings file.
      private java.lang.String getEntryValue​(org.w3c.dom.Element entry)
      Parse an entry value from a given entry node.
      java.lang.String getName()
      Gets the printable name of the search strategy.
      java.net.ProxySelector getProxySelector()
      Loads the proxy settings and initializes a proxy selector for the Gnome proxy settings.
      private boolean hasProxySettings​(java.util.Properties settings)
      Checks if we have Proxy configuration settings in the properties.
      private void installFtpSelector​(java.util.Properties settings, ProtocolDispatchSelector ps)  
      private void installHttpSelector​(java.util.Properties settings, ProtocolDispatchSelector ps)
      Install a http proxy from the given settings.
      private void installSecureSelector​(java.util.Properties settings, ProtocolDispatchSelector ps)  
      private void installSocksSelector​(java.util.Properties settings, ProtocolDispatchSelector ps)
      Install a socks proxy from the given settings.
      private java.util.Properties parseSettings​(java.lang.String context, java.util.Properties settings)
      Parse the settings file and extract all network.proxy.* settings from it.
      java.util.Properties readSettings()
      Load the proxy settings from the gconf settings XML file.
      private java.net.ProxySelector setupFixedProxySelector​(java.util.Properties settings)
      Parse the fixed proxy settings and build an ProxySelector for this a chained configuration.
      private boolean useForAllProtocols​(java.util.Properties settings)
      Check if the http proxy should also be used for all other protocols.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GnomeProxySearchStrategy

        public GnomeProxySearchStrategy()
        ProxySelector
        See Also:
        ProxySelector()
    • Method Detail

      • getProxySelector

        public java.net.ProxySelector getProxySelector()
                                                throws ProxyException
        Loads the proxy settings and initializes a proxy selector for the Gnome proxy settings.
        Specified by:
        getProxySelector in interface ProxySearchStrategy
        Returns:
        a configured ProxySelector, null if none is found.
        Throws:
        ProxyException - on file reading error.
      • getName

        public java.lang.String getName()
        Gets the printable name of the search strategy.
        Specified by:
        getName in interface ProxySearchStrategy
        Returns:
        the printable name of the search strategy
      • readSettings

        public java.util.Properties readSettings()
                                          throws ProxyException
        Load the proxy settings from the gconf settings XML file.
        Returns:
        the loaded settings stored in a properties object.
        Throws:
        ProxyException - on processing error.
      • findSettingsFile

        private java.io.File findSettingsFile​(java.lang.String context)
        Finds the Gnome GConf settings file.
        Parameters:
        context - the gconf context to parse.
        Returns:
        a file or null if does not exist.
      • setupFixedProxySelector

        private java.net.ProxySelector setupFixedProxySelector​(java.util.Properties settings)
        Parse the fixed proxy settings and build an ProxySelector for this a chained configuration.
        Parameters:
        settings - the proxy settings to evaluate.
      • useForAllProtocols

        private boolean useForAllProtocols​(java.util.Properties settings)
        Check if the http proxy should also be used for all other protocols.
        Parameters:
        settings - to inspect.
        Returns:
        true if only one proxy is configured else false.
      • hasProxySettings

        private boolean hasProxySettings​(java.util.Properties settings)
        Checks if we have Proxy configuration settings in the properties.
        Parameters:
        settings - to inspect.
        Returns:
        true if we have found Proxy settings.
      • installHttpSelector

        private void installHttpSelector​(java.util.Properties settings,
                                         ProtocolDispatchSelector ps)
                                  throws java.lang.NumberFormatException
        Install a http proxy from the given settings.
        Parameters:
        settings - to inspect
        ps - the dispatch selector to configure.
        Throws:
        java.lang.NumberFormatException
      • installSocksSelector

        private void installSocksSelector​(java.util.Properties settings,
                                          ProtocolDispatchSelector ps)
                                   throws java.lang.NumberFormatException
        Install a socks proxy from the given settings.
        Parameters:
        settings - to inspect
        ps - the dispatch selector to configure.
        Throws:
        java.lang.NumberFormatException
      • installFtpSelector

        private void installFtpSelector​(java.util.Properties settings,
                                        ProtocolDispatchSelector ps)
                                 throws java.lang.NumberFormatException
        Parameters:
        settings -
        ps -
        Throws:
        java.lang.NumberFormatException
      • installSecureSelector

        private void installSecureSelector​(java.util.Properties settings,
                                           ProtocolDispatchSelector ps)
                                    throws java.lang.NumberFormatException
        Parameters:
        settings -
        ps -
        Throws:
        java.lang.NumberFormatException
      • parseSettings

        private java.util.Properties parseSettings​(java.lang.String context,
                                                   java.util.Properties settings)
                                            throws java.io.IOException
        Parse the settings file and extract all network.proxy.* settings from it.
        Parameters:
        context - the gconf context to parse.
        settings - the settings object to fill.
        Returns:
        the parsed properties.
        Throws:
        java.io.IOException - on read error.
      • getEntryValue

        private java.lang.String getEntryValue​(org.w3c.dom.Element entry)
        Parse an entry value from a given entry node.
        Parameters:
        entry - the XML node to inspect.
        Returns:
        the value, null if it has no value.