Search in sources :

Example 96 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project metron by apache.

the class ConfigurationManager method getConfiguration.

/**
 * Common method to load content of all configuration resources defined in
 * 'config-definition.xml'.
 *
 * @param configDefFilePath
 *          the config def file path
 * @return Configuration
 */
public static Configuration getConfiguration(String configDefFilePath) {
    if (configurationsCache.containsKey(configDefFilePath)) {
        return configurationsCache.get(configDefFilePath);
    }
    CombinedConfiguration configuration = null;
    synchronized (configurationsCache) {
        if (configurationsCache.containsKey(configDefFilePath)) {
            return configurationsCache.get(configDefFilePath);
        }
        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        String filePath = getConfigDefFilePath(configDefFilePath);
        LOGGER.info("loading from 'configDefFilePath' : {}", filePath);
        builder.setFile(new File(filePath));
        try {
            configuration = builder.getConfiguration(true);
            configurationsCache.put(filePath, configuration);
        } catch (ConfigurationException | ConfigurationRuntimeException e) {
            LOGGER.info("Exception in loading property files.", e);
        }
    }
    return configuration;
}
Also used : DefaultConfigurationBuilder(org.apache.commons.configuration.DefaultConfigurationBuilder) ConfigurationRuntimeException(org.apache.commons.configuration.ConfigurationRuntimeException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CombinedConfiguration(org.apache.commons.configuration.CombinedConfiguration) File(java.io.File)

Example 97 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project winery by eclipse.

the class AutoSaveListener method configurationChanged.

@Override
public void configurationChanged(ConfigurationEvent event) {
    if (!event.isBeforeUpdate()) {
        try {
            if (!Files.exists(this.path.getParent())) {
                Files.createDirectories(this.path.getParent());
            }
        } catch (IOException ce) {
            AutoSaveListener.LOGGER.error("Could not update properties file", ce);
            return;
        }
        try (OutputStream out = Files.newOutputStream(this.path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
            OutputStreamWriter writer = new OutputStreamWriter(out);
            this.configuration.save(writer);
        } catch (ConfigurationException | IOException ce) {
            AutoSaveListener.LOGGER.error("Could not update properties file", ce);
        }
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException)

Example 98 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project winery by eclipse.

the class FilebasedRepository method getConfiguration.

@Override
public Configuration getConfiguration(RepositoryFileReference ref) {
    Path path = this.ref2AbsolutePath(ref);
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    if (Files.exists(path)) {
        try (Reader r = Files.newBufferedReader(path, Charset.defaultCharset())) {
            configuration.load(r);
        } catch (ConfigurationException | IOException e) {
            FilebasedRepository.LOGGER.error("Could not read config file", e);
            throw new IllegalStateException("Could not read config file", e);
        }
    }
    configuration.addConfigurationListener(new AutoSaveListener(path, configuration));
    return configuration;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 99 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project opennms by OpenNMS.

the class DefaultRemedyConfigDao method getProperties.

/**
 * Retrieves the properties defined in the remedy.properties file.
 *
 * @param remedyTicketerPlugin
 * @return a
 *         <code>java.util.Properties object containing remedy plugin defined properties
 */
private Configuration getProperties() {
    if (m_config != null)
        return m_config;
    String propsFile = new String(System.getProperty("opennms.home") + "/etc/remedy.properties");
    LOG.debug("loading properties from: {}", propsFile);
    Configuration config = null;
    try {
        config = new PropertiesConfiguration(propsFile);
    } catch (final ConfigurationException e) {
        LOG.debug("Unable to load properties from {}", propsFile, e);
    }
    m_config = config;
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 100 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project opennms by OpenNMS.

the class DroolsTicketerConfigDao method getProperties.

/**
 * Retrieves the properties defined in the drools-ticketer.properties file.
 */
private Configuration getProperties() {
    String propsFile = new String(System.getProperty("opennms.home") + "/etc/drools-ticketer.properties");
    LOG.debug("loading properties from: {}", propsFile);
    Configuration config = null;
    try {
        config = new PropertiesConfiguration(propsFile);
    } catch (final ConfigurationException e) {
        LOG.debug("Unable to load properties from {}", propsFile, e);
    }
    return config;
}
Also used : Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)168 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)64 IOException (java.io.IOException)53 File (java.io.File)40 URL (java.net.URL)17 Configuration (org.apache.commons.configuration.Configuration)14 MalformedURLException (java.net.MalformedURLException)13 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)13 BeforeClass (org.junit.BeforeClass)10 ArrayList (java.util.ArrayList)9 ActionEvent (java.awt.event.ActionEvent)8 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)8 ActionListener (java.awt.event.ActionListener)7 FileInputStream (java.io.FileInputStream)6 FileNotFoundException (java.io.FileNotFoundException)5 HashMap (java.util.HashMap)5 Properties (java.util.Properties)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 Iterator (java.util.Iterator)4 JCommander (com.beust.jcommander.JCommander)3