Example usage for org.apache.commons.configuration FileOptionsProvider PROXY_HOST

List of usage examples for org.apache.commons.configuration FileOptionsProvider PROXY_HOST

Introduction

In this page you can find the example usage for org.apache.commons.configuration FileOptionsProvider PROXY_HOST.

Prototype

String PROXY_HOST

To view the source code for org.apache.commons.configuration FileOptionsProvider PROXY_HOST.

Click Source Link

Document

Key used to identify the proxy host to connect through.

Usage

From source file:org.rzo.yajsw.config.YajswConfigurationImpl.java

public void init() {
    if (_init)//from   ww w  . j  a va 2 s. co  m
        return;
    /*
    ConfigurationInterpolator in = (ConfigurationInterpolator) getSubstitutor().getVariableResolver();
    StrLookup orgLookup = in.getDefaultLookup();
    in.setDefaultLookup(new MyStrLookup(orgLookup));
    */
    _interpolator = new GInterpolator(this, true, null, _scriptUtils);
    try {
        this.setInterpolator(_interpolator);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    if (_localConfiguration != null) {
        _systemConfiguration.addConfiguration(_localConfiguration);
        if (debug)
            log.info("added local configuration ");
    }
    // order of adding configurations to composite is important
    // first added hides the others

    // load configuration from System Properties
    if (_useSystemProperties) {
        _systemProperties = ConfigurationConverter
                .getConfiguration((Properties) System.getProperties().clone());
        _systemConfiguration.addConfiguration(_systemProperties);
        if (debug)
            log.info("added system configuration ");
    }

    addConfiguration(_systemConfiguration);
    // check if we have config file
    String configFile = (String) getProperty("wrapper.config");
    if (configFile != null && configFile.contains("\""))
        configFile = configFile.replaceAll("\"", "");

    // load configuration from file
    if (configFile == null) {
        if (debug)
            log.info("configuration file not set");
    } else if (!fileExists(configFile))
        log.info("configuration file not found: " + configFile);
    else {
        //check if we have a jnlp file
        if (configFile.endsWith(".jnlp"))
            try {
                JnlpSupport jnlp = new JnlpSupport(configFile);
                _fileConfiguration = jnlp.toConfiguration((String) getProperty("wrapperx.default.config"));
                _fileConfiguration.setFileName(configFile);
                addConfiguration(_fileConfiguration);
            } catch (Exception ex) {
                ex.printStackTrace();
                return;
            }
        // else try a standard configuration
        if (_fileConfiguration == null)
            try {
                // enable VFS
                FileSystem fs = new VFSFileSystem();
                fs.setFileOptionsProvider(new FileOptionsProvider() {

                    public Map getOptions() {
                        Map result = new HashMap();
                        String httpProxy = System.getProperty("http.proxyHost");
                        String httpPort = System.getProperty("http.proxyPort");
                        if (httpProxy != null) {
                            int port = 8080;
                            if (httpPort != null)
                                try {
                                    port = Integer.parseInt(httpPort);
                                } catch (Exception ex) {
                                    ex.printStackTrace();
                                }
                            result.put(FileOptionsProvider.PROXY_HOST, httpProxy);
                            result.put(FileOptionsProvider.PROXY_PORT, port);
                        }
                        return result;

                    }

                });
                FileSystem.setDefaultFileSystem(fs);
                // allow for conditional incldues -> first createn an empty properties conf
                _fileConfiguration = new PropertiesConfiguration();
                // then set the file name and load it
                _fileConfiguration.setFileName(configFile);
                try {
                    _fileConfiguration.setBasePath(new File(".").getCanonicalPath());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                _fileConfiguration.append(_systemProperties);
                _fileConfiguration.load();
                addConfiguration(_fileConfiguration);
            } catch (ConfigurationException e) {
                e.printStackTrace();
                log.throwing("error loading configuration file", "<init>AsjwConfiguration", e);
            }
        if (!isLocalFile()) {
            // if no working dir is defined: set working dir to the cache
            if (_fileConfiguration.getProperty("wrapper.working.dir") == null)
                try {
                    _fileConfiguration.setProperty("wrapper.working.dir",
                            new File(getCache()).getCanonicalPath().replaceAll("\\\\", "/"));
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            // if no cache path is defined in the file configuration then set it, so it can be accessed by the wrapper for example to get 
            // a system tray icon
            if (_fileConfiguration.containsKey("wrapper.cache"))
                _fileConfiguration.setProperty("wrapper.cache", getCache());
        }

    }

    // load configuration from System Environement
    addConfiguration(getConfiguration(System.getenv()));
    _isStopper = this.getBoolean("wrapper.stopper", false);
    try {
        _isJavaDebug = this.getInt("wrapper.java.debug.port", -1) != -1;
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    _init = true;
}