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;
}
}
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]"));
}
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);
}
}
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");
}
Aggregations