Search in sources :

Example 61 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project oxCore by GluuFederation.

the class FileConfiguration method loadResourceProperties.

protected void loadResourceProperties() {
    LOG.debug(String.format("Loading '%s' configuration file from resources", this.fileName));
    try {
        this.propertiesConfiguration = new PropertiesConfiguration(this.fileName);
        this.loaded = true;
    } catch (ConfigurationException ex) {
        LOG.debug(String.format("Failed to load '%s' configuration file from resources", this.fileName));
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration)

Example 62 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 63 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 64 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 65 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project janusgraph by JanusGraph.

the class ConfigurationLint method validate.

public static Status validate(String filename) throws IOException {
    try (final FileInputStream fis = new FileInputStream(filename)) {
        new Properties().load(fis);
    }
    final PropertiesConfiguration apc;
    try {
        apc = new PropertiesConfiguration(filename);
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    // new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
    // , BasicConfiguration.Restriction.NONE);
    Iterator<String> iterator = apc.getKeys();
    int totalKeys = 0;
    int keysVerified = 0;
    while (iterator.hasNext()) {
        totalKeys++;
        String key = iterator.next();
        String value = apc.getString(key);
        try {
            ConfigElement.PathIdentifier pid = ConfigElement.parse(GraphDatabaseConfiguration.ROOT_NS, key);
            // ConfigElement shouldn't return null; failure here probably relates to janusgraph-core, not the file
            Preconditions.checkState(null != pid);
            Preconditions.checkState(null != pid.element);
            if (!pid.element.isOption()) {
                log.warn("Config key {} is a namespace (only options can be keys)", key);
                continue;
            }
            final ConfigOption<?> opt;
            try {
                opt = (ConfigOption<?>) pid.element;
            } catch (RuntimeException re) {
                // This shouldn't happen given the preceding check, but catch it anyway
                log.warn("Config key {} maps to the element {}, but it could not be cast to an option", key, pid.element, re);
                continue;
            }
            try {
                Object o = new CommonsConfiguration(apc).get(key, opt.getDatatype());
                opt.verify(o);
                keysVerified++;
            } catch (RuntimeException re) {
                log.warn("Config key {} is recognized, but its value {} could not be validated", key, value);
                log.debug("Validation exception on {}={} follows", key, value, re);
            }
        } catch (RuntimeException re) {
            log.warn("Unknown config key {}", key);
        }
    }
    return new Status(totalKeys, totalKeys - keysVerified);
}
Also used : ConfigElement(org.janusgraph.diskstorage.configuration.ConfigElement) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)66 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)31 File (java.io.File)20 IOException (java.io.IOException)19 ActionEvent (java.awt.event.ActionEvent)6 Configuration (org.apache.commons.configuration.Configuration)6 ActionListener (java.awt.event.ActionListener)5 FileInputStream (java.io.FileInputStream)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 FileNotFoundException (java.io.FileNotFoundException)3 FileWriter (java.io.FileWriter)3 HashMap (java.util.HashMap)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)2 BufferedWriter (java.io.BufferedWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2