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