Package org.eclipse.sw360.http.config
Class ProxySettings
- java.lang.Object
-
- org.eclipse.sw360.http.config.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ProxySettingsdefaultProxySelector()Returns an instance ofProxySettingsthat indicates that the defaultProxySelector(obtained via theProxySelector.getDefault()method) should be queried for each request.booleanequals(Object o)static ProxySettingsfromConfig(boolean useProxy, String host, int port)Creates a new instance ofProxySettingsthat is initialized from configuration settings.StringgetProxyHost()Returns the proxy host.intgetProxyPort()Returns the proxy port.inthashCode()booleanisDefaultProxySelectorUse()Returns a flag whether the default proxy selector should be used.booleanisNoProxy()Returns a flag whether a proxy should be completely disabled.booleanisProxyUse()Returns a flag whether a proxy should be used.static ProxySettingsnoProxy()Returns an instance ofProxySettingsthat indicates that no proxy is to be used.StringtoString()static ProxySettingsuseProxy(String host, int port)Creates a new instance ofProxySettingsthat uses the specified settings for the proxy.
-
-
-
Method Detail
-
noProxy
public static ProxySettings noProxy()
Returns an instance ofProxySettingsthat indicates that no proxy is to be used.- Returns:
- an instance with an empty proxy configuration
-
defaultProxySelector
public static ProxySettings defaultProxySelector()
Returns an instance ofProxySettingsthat indicates that the defaultProxySelector(obtained via theProxySelector.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 ofProxySettingsthat uses the specified settings for the proxy.- Parameters:
host- the host address of the proxyport- the port of the proxy- Returns:
- the new
ProxySettingsinstance
-
fromConfig
public static ProxySettings fromConfig(boolean useProxy, String host, int port)
Creates a new instance ofProxySettingsthat 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 usedhost- the proxy host (may be undefined)port- the proxy port (may be undefined)- Returns:
- the new
ProxySettingsinstance
-
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 theProxySelector.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 ifisProxyUse()returns true.- Returns:
- the proxy host address
-
getProxyPort
public int getProxyPort()
Returns the proxy port. This method only returns a defined value ifisProxyUse()returns true.- Returns:
- the proxy port
-
-