List of usage examples for org.apache.commons.configuration SystemConfiguration SystemConfiguration
public SystemConfiguration()
From source file:com.kixeye.chassis.bootstrap.configuration.zookeeper.CuratorFrameworkBuilder.java
private ConcurrentCompositeConfiguration buildConfiguration() { ConcurrentCompositeConfiguration configuration = new ConcurrentCompositeConfiguration(); configuration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration())); configuration.addConfiguration(this.configuration); configuration.addConfiguration(defaults); return configuration; }
From source file:io.servicecomb.foundation.ssl.SSLOptionTest.java
@Test public void testSSLOptionYamlOption() throws Exception { DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigSource(), new NeverStartPollingScheduler()); // configuration from system properties ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration( new SystemConfiguration()); ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration(); finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig"); finalConfig.addConfiguration(configFromYamlFile, "configFromYamlFile"); SSLOption option = SSLOption.buildFromYaml("server", finalConfig); String protocols = option.getProtocols(); option.setProtocols(protocols);/*from w w w. jav a2 s.co m*/ Assert.assertEquals("TLSv1.2,TLSv1.1,TLSv1,SSLv2Hello", protocols); String ciphers = option.getCiphers(); option.setCiphers(ciphers); Assert.assertEquals( "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_DSS_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SH" + "A,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_128_CBC_SHA", ciphers); boolean authPeer = option.isAuthPeer(); option.setAuthPeer(authPeer); Assert.assertEquals(true, authPeer); boolean checkCNHost = option.isCheckCNHost(); option.setCheckCNHost(checkCNHost); Assert.assertEquals(true, checkCNHost); boolean checkCNWhite = option.isCheckCNWhite(); option.setCheckCNWhite(checkCNWhite); Assert.assertEquals(true, checkCNWhite); String checkCNWhiteFile = option.getCheckCNWhiteFile(); option.setCheckCNWhiteFile(checkCNWhiteFile); Assert.assertEquals("white.list", checkCNWhiteFile); boolean allowRenegociate = option.isAllowRenegociate(); option.setAllowRenegociate(allowRenegociate); Assert.assertEquals(false, allowRenegociate); String storePath = option.getStorePath(); option.setStorePath(storePath); Assert.assertEquals("internal", storePath); String trustStore = option.getTrustStore(); option.setTrustStore(trustStore); Assert.assertEquals("trust.jks", trustStore); String trustStoreType = option.getTrustStoreType(); option.setTrustStoreType(trustStoreType); Assert.assertEquals("JKS", trustStoreType); String trustStoreValue = option.getTrustStoreValue(); option.setTrustStoreValue(trustStoreValue); Assert.assertEquals("Changeme_123", trustStoreValue); String keyStore = option.getKeyStore(); option.setKeyStore(keyStore); Assert.assertEquals("server.p12", keyStore); String keyStoreType = option.getKeyStoreType(); option.setKeyStoreType(keyStoreType); Assert.assertEquals("PKCS12", keyStoreType); String keyStoreValue = option.getKeyStoreValue(); option.setKeyStoreValue(keyStoreValue); Assert.assertEquals("Changeme_123", keyStoreValue); String crl = option.getCrl(); option.setCrl(crl); Assert.assertEquals("revoke.crl", crl); option.setSslCustomClass("123"); SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass()); Assert.assertArrayEquals(custom.decode("123".toCharArray()), "123".toCharArray()); }
From source file:cc.kune.core.server.persist.DataSourceKunePersistModule.java
/** * Inits the./* w w w . ja v a2 s.c om*/ * * @param settedProperties * the setted properties */ private void init(final String settedProperties) { final SystemConfiguration sysConf = new SystemConfiguration(); kuneConfig = settedProperties != null ? settedProperties : sysConf.getString("kune.server.config"); kuneProperties = new KunePropertiesDefault(kuneConfig); log4Conf = sysConf.getString("log4j.configuration"); }
From source file:com.intel.mtwilson.MyConfiguration.java
private Configuration gatherConfiguration(Properties customProperties) { CompositeConfiguration composite = new CompositeConfiguration(); // first priority: custom properties take priority over any other source if (customProperties != null) { MapConfiguration customconfig = new MapConfiguration(customProperties); logConfiguration("custom", customconfig); composite.addConfiguration(customconfig); }/*from w w w .j a v a 2s .c om*/ // second priority are properties defined on the current JVM (-D switch // or through web container) SystemConfiguration system = new SystemConfiguration(); logConfiguration("system", system); composite.addConfiguration(system); // third priority: environment variables (regular and also converted from dot-notation to all-caps) EnvironmentConfiguration env = new EnvironmentConfiguration(); logConfiguration("environment", env); composite.addConfiguration(env); // AllCapsEnvironmentConfiguration envAllCaps = new AllCapsEnvironmentConfiguration(); // logConfiguration("environment_allcaps", envAllCaps); // composite.addConfiguration(envAllCaps); List<File> files = listConfigurationFiles(); // add all the files we found so far, in the priority order for (File f : files) { // System.out.println("Looking for "+f.getAbsolutePath()); try { if (f.exists() && f.canRead()) { // first check if the file is encrypted... if it is, we need to decrypt it before loading! try (FileInputStream in = new FileInputStream(f)) { String content = IOUtils.toString(in); if (Pem.isPem(content)) { // starts with something like -----BEGIN ENCRYPTED DATA----- and ends with -----END ENCRYPTED DATA----- // a pem-format file indicates it's encrypted... we could check for "ENCRYPTED DATA" in the header and footer too. String password = getApplicationConfigurationPassword(); if (password == null) { log.warn( "Found encrypted configuration file, but no password was found in system properties or environment"); } if (password != null) { ExistingFileResource resource = new ExistingFileResource(f); PasswordEncryptedFile encryptedFile = new PasswordEncryptedFile(resource, password); String decryptedContent = encryptedFile.loadString(); Properties p = new Properties(); p.load(new StringReader(decryptedContent)); MapConfiguration encrypted = new MapConfiguration(p); logConfiguration("encrypted-file:" + f.getAbsolutePath(), encrypted); composite.addConfiguration(encrypted); } } else { log.debug("FILE {} IS IN REGULAR PROPERTIES FORMAT", f.getAbsolutePath()); PropertiesConfiguration standard = new PropertiesConfiguration(f); logConfiguration("file:" + f.getAbsolutePath(), standard); composite.addConfiguration(standard); } } } } catch (FileNotFoundException ex) { // shouldn't happen since we check for f.exists() first, but must handle it because FileInputStream can throw it log.error("File not found: " + f.getAbsolutePath(), ex); } catch (IOException ex) { log.error("Cannot load configuration: " + f.getAbsolutePath(), ex); } catch (ConfigurationException ex) { log.error("Cannot load configuration from " + f.getAbsolutePath(), ex); } } // seventh priority are properties defined on the classpath (for example defaults provided with the application, or placed in the web server container) String propertiesFilename = "mtwilson.properties"; InputStream in = getClass().getResourceAsStream("/" + propertiesFilename); try { // user's home directory (assuming it's on the classpath!) if (in != null) { Properties properties = new Properties(); properties.load(in); MapConfiguration classpath = new MapConfiguration(properties); logConfiguration("classpath:" + propertiesFilename, classpath); composite.addConfiguration(classpath); } } catch (IOException ex) { log.debug("Did not find [" + propertiesFilename + "] properties on classpath", ex); } finally { if (in != null) { try { in.close(); } catch (IOException e) { log.error("Failed to close input stream for " + propertiesFilename); } } } return composite; }
From source file:com.yahoo.sshd.server.settings.SshdSettingsBuilder.java
protected Configuration createConfiguration(final String overriddenPath) { try {//from www .j ava 2 s.c o m if (LOGGER.isDebugEnabled()) { LOGGER.debug("got overriddenPath {}", overriddenPath); } CompositeConfiguration compositeConfig = new CompositeConfiguration(); // TODO: see how Systems and properties interact. compositeConfig.addConfiguration(new SystemConfiguration()); compositeConfig.addConfiguration(findPropertiesConfiguration(overriddenPath)); return compositeConfig; } catch (ConfigurationException e) { throw new RuntimeException(e); } }
From source file:com.nridge.core.app.mgr.AppMgr.java
/** * Loads the default property files ("application.properties" and * "logback.xml") from the file system and assigns default application * properties./* w w w .j av a 2 s . c o m*/ * <p> * <b>Note:</b> This method will establish a default 5 minute reloading * policy for the "application.properties" file. Therefore, any * changes to this property file while the application is running * will be recognized within a 5 minute period. * </p> * * @throws NSException Typically thrown for I/O related issues. */ public void loadPropertyFiles() throws NSException { String logFileName; try { // First, we will read our application properties. mConfiguration = new CompositeConfiguration(); mConfiguration.setDelimiterParsingDisabled(true); mConfiguration.addConfiguration(new SystemConfiguration()); mConfiguration.addConfiguration(new EnvironmentConfiguration()); PropertiesConfiguration propertyCfg = new PropertiesConfiguration(deriveCfgPathFileName()); FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy(); reloadingStrategy.setRefreshDelay(DateUtils.MILLIS_PER_MINUTE * 2L); propertyCfg.setReloadingStrategy(reloadingStrategy); mConfiguration.addConfiguration(propertyCfg); // Next, we will load our Logback properties file and configure our application logger. if (mCmdLine == null) logFileName = LOG_PROPERTY_FILE_NAME; else logFileName = mCmdLine.getOptionValue("logfile", LOG_PROPERTY_FILE_NAME); File logFile = new File(logFileName); if (!logFile.exists()) { String logPathFileName = String.format("%s%c%s", deriveCfgPathName(), File.separatorChar, logFileName); logFile = new File(logPathFileName); if (logFile.exists()) logFileName = logPathFileName; else throw new NSException("Unable to locate logging properties file: " + logFileName); } if (StringUtils.isEmpty(getString(APP_PROPERTY_INS_PATH))) mConfiguration.addProperty(APP_PROPERTY_INS_PATH, getInsPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_CFG_PATH))) mConfiguration.addProperty(APP_PROPERTY_CFG_PATH, deriveCfgPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_LOG_PATH))) mConfiguration.addProperty(APP_PROPERTY_LOG_PATH, deriveLogPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_DS_PATH))) mConfiguration.addProperty(APP_PROPERTY_DS_PATH, deriveDSPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_RDB_PATH))) mConfiguration.addProperty(APP_PROPERTY_RDB_PATH, deriveRDBMSPathName()); if (StringUtils.isEmpty(getString(APP_PROPERTY_GDB_PATH))) mConfiguration.addProperty(APP_PROPERTY_GDB_PATH, deriveGraphPathName()); LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator joranConfigurator = new JoranConfigurator(); joranConfigurator.setContext(loggerContext); loggerContext.reset(); joranConfigurator.doConfigure(logFileName); } catch (ConfigurationException e) { throw new NSException("Configuration parsing error: " + e.getMessage()); } catch (JoranException e) { throw new NSException("Logback parsing error: " + e.getMessage()); } catch (ClassCastException ignored) { /* Note that a WARNING related to java.lang.ClassCastException will trigger due to Smart GWT and NSD being dependent on different releases of the same logging framework. http://www.slf4j.org/codes.html */ } }
From source file:maltcms.ui.nb.pipelineRunner.ui.PipelineRunnerTopComponent.java
private Configuration buildCompositeConfiguration(Configuration cfg) { final CompositeConfiguration ccfg = new CompositeConfiguration(); ccfg.addConfiguration(cfg);//from w ww . j av a 2 s. c om URL defaultConfigLocation = null; defaultConfigLocation = getClass().getClassLoader().getResource("cfg/default.properties"); try { PropertiesConfiguration defaultConfig = new PropertiesConfiguration(defaultConfigLocation); ccfg.addConfiguration(defaultConfig); Logger.getLogger(getClass().getName()).log(Level.INFO, "Using default config location: {0}", defaultConfigLocation.toString()); } catch (Exception e) { Logger.getLogger(getClass().getName()).warning(e.getLocalizedMessage()); } ccfg.addConfiguration(new SystemConfiguration()); return ccfg; }
From source file:com.twitter.distributedlog.DistributedLogConfiguration.java
/** * Construct distributedlog configuration with default settings. * It also loads the settings from system properties. *///from ww w.j a va2 s. com public DistributedLogConfiguration() { super(); // add configuration for system properties addConfiguration(new SystemConfiguration()); }
From source file:org.ambraproject.configuration.ConfigurationStore.java
/** * Load/Reload the configuration from the factory config url. * * @param configURL URL to the config file for ConfigurationFactory * @throws ConfigurationException when the config factory configuration has an error *//* w w w .j a v a 2 s. c o m*/ public void loadConfiguration(URL configURL) throws ConfigurationException { root = new CombinedConfiguration(new OverrideCombiner()); // System properties override everything root.addConfiguration(new SystemConfiguration()); // Load from ambra.configuration -- /etc/... (optional) if (configURL != null) { try { root.addConfiguration(getConfigurationFromUrl(configURL)); log.info("Added URL '" + configURL + "'"); } catch (ConfigurationException ce) { if (!(ce.getCause() instanceof FileNotFoundException)) throw ce; log.info("Unable to open '" + configURL + "'"); } } // Add ambra.configuration.overrides (if defined) String overrides = System.getProperty(OVERRIDES_URL); if (overrides != null) { try { root.addConfiguration(getConfigurationFromUrl(new URL(overrides))); log.info("Added override URL '" + overrides + "'"); } catch (MalformedURLException mue) { // Must not be a URL, so it must be a resource addResources(root, overrides); } } CombinedConfiguration defaults = new CombinedConfiguration(new UnionCombiner()); // Add defaults.xml from classpath addResources(defaults, DEFAULTS_RESOURCE); // Add journal.xml from journals/journal-name/configuration/journal.xml addJournalResources(root, defaults, JOURNAL_DIRECTORY); root.addConfiguration(defaults); // Add global-defaults.xml (presumably found in this jar) addResources(root, GLOBAL_DEFAULTS_RESOURCE); if (log.isDebugEnabled()) log.debug("Configuration dump: " + System.getProperty("line.separator") + ConfigurationUtils.toString(root)); /** * This prefix is needed by the AmbraIdGenerator to create prefixes for object IDs. * Because of the way the AmbraIdGenerator class is created by hibernate, passing in values * is very difficult. If a better method is discovered... by all means use that. Until that time * I've created a system level property to store this prefix. */ String objectIDPrefix = root.getString("ambra.platform.guid-prefix"); if (objectIDPrefix == null) { throw new RuntimeException( "ambra.platform.guid-prefix node is not found in the defined configuration file."); } System.setProperty(SYSTEM_OBJECT_ID_PREFIX, objectIDPrefix); }
From source file:org.apache.accumulo.server.metrics.MetricsConfiguration.java
public Configuration getSystemConfiguration() { synchronized (MetricsConfiguration.class) { if (null == sysConfig) sysConfig = new SystemConfiguration(); return sysConfig; }/* w ww .j a v a 2 s . c o m*/ }