use of org.apache.commons.configuration.ConfigurationException in project zeppelin by apache.
the class ZeppelinConfiguration method create.
/**
* Load from resource.
*url = ZeppelinConfiguration.class.getResource(ZEPPELIN_SITE_XML);
* @throws ConfigurationException
*/
public static synchronized ZeppelinConfiguration create() {
if (conf != null) {
return conf;
}
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url;
url = ZeppelinConfiguration.class.getResource(ZEPPELIN_SITE_XML);
if (url == null) {
ClassLoader cl = ZeppelinConfiguration.class.getClassLoader();
if (cl != null) {
url = cl.getResource(ZEPPELIN_SITE_XML);
}
}
if (url == null) {
url = classLoader.getResource(ZEPPELIN_SITE_XML);
}
if (url == null) {
LOG.warn("Failed to load configuration, proceeding with a default");
conf = new ZeppelinConfiguration();
} else {
try {
LOG.info("Load configuration from " + url);
conf = new ZeppelinConfiguration(url);
} catch (ConfigurationException e) {
LOG.warn("Failed to load configuration from " + url + " proceeding with a default", e);
conf = new ZeppelinConfiguration();
}
}
LOG.info("Server Host: " + conf.getServerAddress());
if (conf.useSsl() == false) {
LOG.info("Server Port: " + conf.getServerPort());
} else {
LOG.info("Server SSL Port: " + conf.getServerSslPort());
}
LOG.info("Context Path: " + conf.getServerContextPath());
LOG.info("Zeppelin Version: " + Util.getVersion());
return conf;
}
use of org.apache.commons.configuration.ConfigurationException in project OpenAttestation by OpenAttestation.
the class TAConfig method gatherConfiguration.
private Configuration gatherConfiguration(String propertiesFilename, Properties defaults) {
CompositeConfiguration composite = new CompositeConfiguration();
// first priority are properties defined on the current JVM (-D switch or through web container)
SystemConfiguration system = new SystemConfiguration();
dumpConfiguration(system, "system");
composite.addConfiguration(system);
// second priority are properties defined on the classpath (like user's home directory)
try {
// user's home directory (assuming it's on the classpath!)
readPropertiesFile("/" + propertiesFilename, composite);
} catch (IOException ex) {
log.info("Did not find " + propertiesFilename + " on classpath", ex);
}
// third priority are properties defined in standard install location
System.out.println("TAConfig os.name=" + System.getProperty("os.name"));
ArrayList<File> files = new ArrayList<File>();
// windows-specific location
if (System.getProperty("os.name", "").toLowerCase().equals("win")) {
System.out.println("TAConfig user.home=" + System.getProperty("user.home"));
files.add(new File("C:" + File.separator + "Intel" + File.separator + "CloudSecurity" + File.separator + propertiesFilename));
files.add(new File(System.getProperty("user.home") + File.separator + propertiesFilename));
}
// linux-specific location
if (System.getProperty("os.name", "").toLowerCase().equals("linux") || System.getProperty("os.name", "").toLowerCase().equals("unix")) {
files.add(new File("./config/" + propertiesFilename));
files.add(new File("/etc/oat-client/" + propertiesFilename));
}
// this line specific to TA for backwards compatibility, not needed in AS/AH
files.add(new File(System.getProperty("app.path") + File.separator + propertiesFilename));
// add all the files we found
for (File f : files) {
try {
if (f.exists() && f.canRead()) {
PropertiesConfiguration standard = new PropertiesConfiguration(f);
dumpConfiguration(standard, "file:" + f.getAbsolutePath());
composite.addConfiguration(standard);
}
} catch (ConfigurationException ex) {
log.error(null, ex);
}
}
// last priority are the defaults that were passed in, we use them if no better source was found
if (defaults != null) {
MapConfiguration defaultconfig = new MapConfiguration(defaults);
dumpConfiguration(defaultconfig, "default");
composite.addConfiguration(defaultconfig);
}
dumpConfiguration(composite, "composite");
return composite;
}
use of org.apache.commons.configuration.ConfigurationException in project pinot by linkedin.
the class SingleNodeServerStarter method buildServerConfig.
/**
* Construct from config file path
* @param configFilePath Path to the config file
* @throws Exception
*/
public static void buildServerConfig(File configFilePath) throws Exception {
if (!configFilePath.exists()) {
LOGGER.error("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
throw new ConfigurationException("configuration file: " + configFilePath.getAbsolutePath() + " does not exist.");
}
// build _serverConf
final PropertiesConfiguration serverConf = new PropertiesConfiguration();
serverConf.setDelimiterParsingDisabled(false);
serverConf.load(configFilePath);
_serverConf = new ServerConf(serverConf);
}
use of org.apache.commons.configuration.ConfigurationException in project archaius by Netflix.
the class OverridingPropertiesConfiguration method getConfigFromPropertiesFile.
public static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl, Set<String> loaded, String... nextLoadKeys) throws FileNotFoundException {
if (loaded.contains(startingUrl.toExternalForm())) {
logger.warn(startingUrl + " is already loaded");
return null;
}
PropertiesConfiguration propConfig = null;
try {
propConfig = new OverridingPropertiesConfiguration(startingUrl);
logger.info("Loaded properties file " + startingUrl);
} catch (ConfigurationException e) {
Throwable cause = e.getCause();
if (cause instanceof FileNotFoundException) {
throw (FileNotFoundException) cause;
} else {
throw new RuntimeException(e);
}
}
if (nextLoadKeys == null) {
return propConfig;
}
String urlString = startingUrl.toExternalForm();
String base = urlString.substring(0, urlString.lastIndexOf("/"));
loaded.add(startingUrl.toString());
loadFromPropertiesFile(propConfig, base, loaded, nextLoadKeys);
return propConfig;
}
use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.
the class AddOnLoader method saveAddOnsRunState.
private static void saveAddOnsRunState(Map<AddOn, List<String>> runnableAddOns) {
HierarchicalConfiguration config = (HierarchicalConfiguration) Model.getSingleton().getOptionsParam().getConfig();
config.clearTree(ADDONS_RUNNABLE_BASE_KEY);
int i = 0;
for (Map.Entry<AddOn, List<String>> runnableAddOnEntry : runnableAddOns.entrySet()) {
String elementBaseKey = ADDONS_RUNNABLE_KEY + "(" + i + ").";
AddOn addOn = runnableAddOnEntry.getKey();
config.setProperty(elementBaseKey + ADDON_RUNNABLE_ID_KEY, addOn.getId());
config.setProperty(elementBaseKey + ADDON_RUNNABLE_VERSION_KEY, Integer.valueOf(addOn.getFileVersion()));
String extensionBaseKey = elementBaseKey + ADDON_RUNNABLE_ALL_EXTENSIONS_KEY;
for (String extension : runnableAddOnEntry.getValue()) {
config.addProperty(extensionBaseKey, extension);
}
i++;
}
try {
Model.getSingleton().getOptionsParam().getConfig().save();
} catch (ConfigurationException e) {
logger.error("Failed to save state of runnable add-ons:", e);
}
}
Aggregations