Search in sources :

Example 11 with XMLConfiguration

use of org.apache.commons.configuration.XMLConfiguration in project accumulo by apache.

the class MetricsConfiguration method loadConfiguration.

private void loadConfiguration() {
    URL metricsUrl = MetricsConfiguration.class.getClassLoader().getResource("accumulo-metrics.xml");
    if (metricsUrl == null) {
        if (!alreadyWarned)
            log.warn("accumulo-metrics.xml was not found on classpath. Metrics collection will be disabled.");
        alreadyWarned = true;
        notFound = true;
        return;
    }
    try {
        xConfig = new XMLConfiguration(metricsUrl);
        xConfig.append(getEnvironmentConfiguration());
        xConfig.addConfigurationListener(new MetricsConfigListener());
        xConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
        // every so often to force the FileChangedReloadingStrategy to fire.
        if (null == watcher || !watcher.isAlive()) {
            watcher = new MetricsConfigWatcher();
            watcher.start();
        }
        notFound = false;
        alreadyWarned = false;
    } catch (ConfigurationException ce) {
        log.error("Error reading accumulo-metrics.xml file.");
        notFound = true;
        return;
    }
    if (xConfig != null) {
        config = xConfig.interpolatedConfiguration();
        // set the enabled boolean from the configuration
        enabled = config.getBoolean(enabledName);
        if (log.isDebugEnabled())
            log.debug("Metrics collection enabled={}", enabled);
    } else {
        enabled = false;
    }
}
Also used : FileChangedReloadingStrategy(org.apache.commons.configuration.reloading.FileChangedReloadingStrategy) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) URL(java.net.URL)

Example 12 with XMLConfiguration

use of org.apache.commons.configuration.XMLConfiguration in project OA4MP by ncsa.

the class ServiceConfigTest method testConfig.

@Test
public void testConfig() throws Exception {
    XMLConfiguration c = getConfiguration();
    Iterator iterator = c.getKeys();
    say("echoing configuration to console:");
    ConfigurationNode root = c.getRootNode();
    say("name of root = " + root.getName());
    say("child count = " + root.getChildren().size());
    while (iterator.hasNext()) {
        String key = iterator.next().toString();
        say("(k, v)=(" + key + ", " + c.getString(key) + ")");
    }
    SubnodeConfiguration mailC = c.configurationAt("service.mail");
    say("mail configured? " + mailC.getString("[@enabled]"));
}
Also used : SubnodeConfiguration(org.apache.commons.configuration.SubnodeConfiguration) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode) Iterator(java.util.Iterator) ConfigTest(edu.uiuc.ncsa.security.core.configuration.ConfigTest) Test(org.junit.Test)

Example 13 with XMLConfiguration

use of org.apache.commons.configuration.XMLConfiguration in project OA4MP by ncsa.

the class TestUtils method findConfigNode.

/**
 * Loads a given configuration from a specified (on the command line) file.
 * Generally you should stick all of your configurations for a test run in a single
 * file then use this to pull off the ones you need, by name. If you do not specify a name
 * this will try to get a configuration with the name specified at the command line.
 *
 * @param configName
 * @return
 */
public static ConfigurationNode findConfigNode(String configName) {
    try {
        String fileName = System.getProperty(getBootstrapper().getOa4mpConfigFileKey());
        if (fileName == null) {
            throw new MyConfigurationException("Error: No configuration file specified");
        }
        XMLConfiguration cfg = null;
        if (fileName.length() != 0) {
            // A properties file is supplied. Use that.
            try {
                cfg = Configurations.getConfiguration(new File(fileName));
            } catch (MyConfigurationException cx) {
                cx.printStackTrace();
                // plan B, maybe it's in the deployment itself? try to get as a resource
                URL url = TestUtils.class.getResource(fileName);
                if (url == null) {
                    throw new MyConfigurationException("Error:No configuration found. for \"" + fileName + "\"");
                }
                cfg = Configurations.getConfiguration(url);
            }
        } else {
            throw new MyConfigurationException("Error:No configuration file found.");
        }
        ConfigurationNode cn = null;
        if (configName == null) {
            // try to find a specified configuration.
            String cfgName = System.getProperty(getBootstrapper().getOa4mpConfigNameKey());
            if (cfgName == null) {
                System.out.println("no name for a configuration given");
                cn = cfg.configurationAt(COMPONENT).getRootNode();
            } else {
                System.out.println("getting named configuration \"" + cfgName + "\"");
                cn = Configurations.getConfig(cfg, COMPONENT, cfgName);
            }
        } else {
            cn = Configurations.getConfig(cfg, COMPONENT, configName);
        }
        return cn;
    } catch (Exception x) {
        throw new MyConfigurationException("Error loading configuration", x);
    }
}
Also used : MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ConfigurationNode(org.apache.commons.configuration.tree.ConfigurationNode) File(java.io.File) URL(java.net.URL) MyConfigurationException(edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException)

Example 14 with XMLConfiguration

use of org.apache.commons.configuration.XMLConfiguration in project zaproxy by zaproxy.

the class Constant method upgradeFrom1_2_0.

private void upgradeFrom1_2_0(XMLConfiguration config) throws ConfigurationException {
    // Upgrade the regexs
    // ZAP: Changed to use ZapXmlConfiguration, to enforce the same character encoding when
    // reading/writing configurations.
    XMLConfiguration newConfig = new ZapXmlConfiguration(getUrlDefaultConfigFile());
    newConfig.setAutoSave(false);
    copyProperty(newConfig, config, "view.brkPanelView");
    copyProperty(newConfig, config, "view.showMainToolbar");
}
Also used : XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ZapXmlConfiguration(org.zaproxy.zap.utils.ZapXmlConfiguration)

Aggregations

XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)14 ConfigurationException (org.apache.commons.configuration.ConfigurationException)6 File (java.io.File)5 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)5 IOException (java.io.IOException)3 InvalidParameterException (java.security.InvalidParameterException)3 ParseException (java.text.ParseException)3 ArrayList (java.util.ArrayList)3 Locale (java.util.Locale)3 NoSuchElementException (java.util.NoSuchElementException)3 ConversionException (org.apache.commons.configuration.ConversionException)3 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 Iterator (java.util.Iterator)2 ConfigurationNode (org.apache.commons.configuration.tree.ConfigurationNode)2 FileCopier (org.parosproxy.paros.model.FileCopier)2 I18N (org.zaproxy.zap.utils.I18N)2 ConfigTest (edu.uiuc.ncsa.security.core.configuration.ConfigTest)1 MyConfigurationException (edu.uiuc.ncsa.security.core.exceptions.MyConfigurationException)1