org.deegree.commons.utils
Class ProxyUtils

java.lang.Object
  extended by org.deegree.commons.config.AbstractBasicResourceManager
      extended by org.deegree.commons.utils.ProxyUtils
All Implemented Interfaces:
ResourceManager

public final class ProxyUtils
extends AbstractBasicResourceManager
implements ResourceManager

Utility class for accessing and modifying the VM's proxy configuration and for opening URL connections that respect proxy configurations which require authentication.

Please note that Java's proxy configuration is VM-global: there is a set of system properties (proxyHost, proxyPort, etc.) that determines the behaviour of network-related classes (e.g. in java.net). This makes sense, as the proxy configuration is usually defined by the network environment of the physical machine.

Version:
$Revision: $, $Date: $
Author:
Markus Schneider, last edited by: $Author: schneider $

Field Summary
 
Fields inherited from class org.deegree.commons.config.AbstractBasicResourceManager
dir, idToState, workspace
 
Constructor Summary
ProxyUtils()
           
 
Method Summary
 ResourceState activate(String id)
          Activates the resource with the given identifier.
 ResourceState deactivate(String id)
          Deactivates the resource with the given identifier.
 Class<? extends ResourceManager>[] getDependencies()
           
static String getFtpNonProxyHosts(boolean considerBaseConfig)
           
static String getFtpProxyHost(boolean considerBaseConfig)
           
static String getFtpProxyPassword(boolean considerBaseConfig)
           
static String getFtpProxyPort(boolean considerBaseConfig)
           
static String getFtpProxyUser(boolean considerBaseConfig)
           
static String getHttpNonProxyHosts(boolean considerBaseConfig)
           
static String getHttpProxyHost(boolean considerBaseConfig)
           
static String getHttpProxyPassword(boolean considerBaseConfig)
           
static String getHttpProxyPort(boolean considerBaseConfig)
           
static String getHttpProxyUser(boolean considerBaseConfig)
           
 ResourceManagerMetadata getMetadata()
           
static String getNonProxyHosts()
           
protected  ResourceProvider getProvider(File file)
           
static String getProxyHost()
           
static String getProxyPassword()
           
static String getProxyPort()
           
static String getProxyUser()
           
static void logProxyConfiguration(org.slf4j.Logger log)
           
static URLConnection openURLConnection(URL url)
          This method should be used everywhere instead of URL.openConnection(), as it copes with proxies that require user authentication.
static URLConnection openURLConnection(URL url, String user, String pass)
          This method should be used everywhere instead of URL.openConnection(), as it copes with proxies that require user authentication.
static URLConnection openURLConnection(URL url, String proxyUser, String proxyPass, String httpUser, String httpPass)
          This method should be used everywhere instead of URL.openConnection(), as it copes with proxies that require user authentication and http basic authentication.
protected  void remove(String id)
           
static void setupProxyParameters(ProxyConfiguration config)
          Sets/augments the VM's proxy configuration.
static void setupProxyParameters(String proxyHost, String httpProxyHost, String ftpProxyHost, int proxyPort, int httpProxyPort, int ftpProxyPort, String proxyUser, String httpProxyUser, String ftpProxyUser, String proxyPassword, String httpProxyPassword, String ftpProxyPassword, String nonProxyHosts, String httpNonProxyHosts, String ftpNonProxyHosts, boolean override)
          Sets/augments the VM's proxy configuration.
 void shutdown()
          Is called upon workspace shutdown.
 void startup(DeegreeWorkspace workspace)
          Sets/augments the VM's proxy configuration.
 
Methods inherited from class org.deegree.commons.config.AbstractBasicResourceManager
createResource, deleteResource, getState, getStates, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.deegree.commons.config.ResourceManager
createResource, deleteResource, getState, getStates
 

Constructor Detail

ProxyUtils

public ProxyUtils()
Method Detail

startup

public void startup(DeegreeWorkspace workspace)
             throws IllegalArgumentException
Sets/augments the VM's proxy configuration.

Specified by:
startup in interface ResourceManager
Throws:
IllegalArgumentException

setupProxyParameters

public static void setupProxyParameters(ProxyConfiguration config)
Sets/augments the VM's proxy configuration.

Parameters:
config -

setupProxyParameters

public static void setupProxyParameters(String proxyHost,
                                        String httpProxyHost,
                                        String ftpProxyHost,
                                        int proxyPort,
                                        int httpProxyPort,
                                        int ftpProxyPort,
                                        String proxyUser,
                                        String httpProxyUser,
                                        String ftpProxyUser,
                                        String proxyPassword,
                                        String httpProxyPassword,
                                        String ftpProxyPassword,
                                        String nonProxyHosts,
                                        String httpNonProxyHosts,
                                        String ftpNonProxyHosts,
                                        boolean override)
Sets/augments the VM's proxy configuration.

Parameters:
proxyHost -
httpProxyHost -
ftpProxyHost -
proxyPort -
httpProxyPort -
ftpProxyPort -
proxyUser -
httpProxyUser -
ftpProxyUser -
proxyPassword -
httpProxyPassword -
ftpProxyPassword -
nonProxyHosts -
httpNonProxyHosts -
ftpNonProxyHosts -
override -

openURLConnection

public static URLConnection openURLConnection(URL url)
                                       throws IOException
This method should be used everywhere instead of URL.openConnection(), as it copes with proxies that require user authentication. This method will retrieve the configured password and user name.

Parameters:
url -
Returns:
connection
Throws:
IOException

openURLConnection

public static URLConnection openURLConnection(URL url,
                                              String proxyUser,
                                              String proxyPass,
                                              String httpUser,
                                              String httpPass)
                                       throws IOException
This method should be used everywhere instead of URL.openConnection(), as it copes with proxies that require user authentication and http basic authentication.

Parameters:
url -
Returns:
connection
Throws:
IOException

openURLConnection

public static URLConnection openURLConnection(URL url,
                                              String user,
                                              String pass)
                                       throws IOException
This method should be used everywhere instead of URL.openConnection(), as it copes with proxies that require user authentication.

Parameters:
url -
user -
pass -
Returns:
connection
Throws:
IOException

getProxyHost

public static String getProxyHost()

getHttpProxyHost

public static String getHttpProxyHost(boolean considerBaseConfig)

getFtpProxyHost

public static String getFtpProxyHost(boolean considerBaseConfig)

getProxyPort

public static String getProxyPort()

getHttpProxyPort

public static String getHttpProxyPort(boolean considerBaseConfig)

getFtpProxyPort

public static String getFtpProxyPort(boolean considerBaseConfig)

getProxyUser

public static String getProxyUser()

getHttpProxyUser

public static String getHttpProxyUser(boolean considerBaseConfig)

getFtpProxyUser

public static String getFtpProxyUser(boolean considerBaseConfig)

getProxyPassword

public static String getProxyPassword()

getHttpProxyPassword

public static String getHttpProxyPassword(boolean considerBaseConfig)

getFtpProxyPassword

public static String getFtpProxyPassword(boolean considerBaseConfig)

getNonProxyHosts

public static String getNonProxyHosts()

getHttpNonProxyHosts

public static String getHttpNonProxyHosts(boolean considerBaseConfig)

getFtpNonProxyHosts

public static String getFtpNonProxyHosts(boolean considerBaseConfig)

logProxyConfiguration

public static void logProxyConfiguration(org.slf4j.Logger log)

getDependencies

public Class<? extends ResourceManager>[] getDependencies()
Specified by:
getDependencies in interface ResourceManager
Returns:
an empty array if there are no dependencies

shutdown

public void shutdown()
Description copied from interface: ResourceManager
Is called upon workspace shutdown.

Specified by:
shutdown in interface ResourceManager

getMetadata

public ResourceManagerMetadata getMetadata()
Specified by:
getMetadata in interface ResourceManager
Returns:
a metadata object, may be null

activate

public ResourceState activate(String id)
Description copied from interface: ResourceManager
Activates the resource with the given identifier.

Specified by:
activate in interface ResourceManager
Parameters:
id - resource identifier, must not be null
Returns:
resource state after activation (may be unsuccessful), but never null

deactivate

public ResourceState deactivate(String id)
Description copied from interface: ResourceManager
Deactivates the resource with the given identifier.

Specified by:
deactivate in interface ResourceManager
Parameters:
id - resource identifier, must not be null
Returns:
resource state after deactivation (may be unsuccessful), but never null

getProvider

protected ResourceProvider getProvider(File file)
Specified by:
getProvider in class AbstractBasicResourceManager

remove

protected void remove(String id)
Specified by:
remove in class AbstractBasicResourceManager


Copyright © 2011. All Rights Reserved.