List of usage examples for org.apache.commons.configuration SystemConfiguration SystemConfiguration
public SystemConfiguration()
From source file:org.apache.servicecomb.config.archaius.sources.TestYAMLConfigurationSource.java
@Test public void testFullOperation() { // configuration from system properties ConcurrentMapConfiguration configFromSystemProperties = new ConcurrentMapConfiguration( new SystemConfiguration()); // configuration from yaml file DynamicConfiguration configFromYamlFile = new DynamicConfiguration(yamlConfigSource(), new NeverStartPollingScheduler()); // create a hierarchy of configuration that makes // 1) dynamic configuration source override system properties ConcurrentCompositeConfiguration finalConfig = new ConcurrentCompositeConfiguration(); finalConfig.addConfiguration(configFromYamlFile, "yamlConfig"); finalConfig.addConfiguration(configFromSystemProperties, "systemEnvConfig"); Assert.assertEquals(0.5, finalConfig.getDouble("trace.handler.sampler.percent"), 0.5); Object o = finalConfig.getProperty("zq"); @SuppressWarnings("unchecked") List<Map<String, Object>> listO = (List<Map<String, Object>>) o; Assert.assertEquals(3, listO.size()); }
From source file:org.apache.servicecomb.config.ConfigUtil.java
public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) { ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); duplicateCseConfigToServicecomb(config, new ConcurrentMapConfiguration(new SystemConfiguration()), "configFromSystem"); duplicateCseConfigToServicecomb(config, convertEnvVariable(new ConcurrentMapConfiguration(new EnvironmentConfiguration())), "configFromEnvironment"); // If there is extra configurations, add it into config. EXTRA_CONFIG_MAP.entrySet().stream().filter(mapEntry -> !mapEntry.getValue().isEmpty()) .forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config, new ConcurrentMapConfiguration(configMapEntry.getValue()), configMapEntry.getKey())); // we have already copy the cse config to the serviceComb config when we load the config from local yaml files // hence, we do not need duplicate copy it. config.addConfiguration(new DynamicConfiguration(new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile"); duplicateCseConfigToServicecombAtFront(config, new ConcurrentMapConfiguration(ConfigMapping.getConvertedMap(config)), "configFromMapping"); return config; }
From source file:org.apereo.lap.services.ConfigurationService.java
@PostConstruct public void init() throws IOException { logger.info("INIT started"); logger.info("App Home: " + appHome().getAbsolutePath()); CompositeConfiguration config = new CompositeConfiguration(); // load internal config defaults first config.setProperty("app.name", "LAP"); File dbDefaults = resourceLoader.getResource("classpath:db.properties").getFile(); try {/*from w ww. jav a 2 s. c om*/ config.addConfiguration(new PropertiesConfiguration(dbDefaults)); } catch (ConfigurationException e) { logger.error("Unable to load default db.properties file"); } File appDefaults = resourceLoader.getResource("classpath:app.properties").getFile(); try { config.addConfiguration(new PropertiesConfiguration(appDefaults)); logger.info("Default app configuration loaded from: " + appDefaults.getAbsolutePath()); } catch (ConfigurationException e) { logger.error("Unable to load default app.properties file"); } // now try to load external config settings config.addConfiguration(new SystemConfiguration()); File lapConfigProps = new File(appHome(), "lap.properties"); if (lapConfigProps.exists() && lapConfigProps.canRead()) { try { config.addConfiguration(new PropertiesConfiguration(lapConfigProps)); } catch (ConfigurationException e) { logger.warn("Unable to load lap.properties file"); } } else { IOUtils.copy( SampleCSVInputHandlerService.class.getClassLoader() .getResourceAsStream("config" + SLASH + "lap.properties"), new FileOutputStream(new File(appHome(), "lap.properties"))); logger.info("No external LAP config found: " + lapConfigProps.getAbsolutePath() + ", copied default sample lap.properties"); } this.config = config; // verify the existence of the various dirs pipelinesDirectory = verifyDir("dir.pipelines", "piplines"); inputDirectory = verifyDir("dir.inputs", "inputs"); outputDirectory = verifyDir("dir.outputs", "outputs"); pipelineConfigs = new ConcurrentHashMap<>(); // first load the internal ones (must be listed explicitly for now) Resource pipelineSample = resourceLoader.getResource("classpath:pipelines" + SLASH + "sample.xml"); PipelineConfig plcfg = processPipelineConfigFile(pipelineSample.getFile()); if (plcfg != null) { pipelineConfigs.put(plcfg.getType(), plcfg); } // then try to load the external ones File[] pipelineFiles = pipelinesDirectory.listFiles(); if (pipelineFiles != null && pipelineFiles.length > 0) { for (final File fileEntry : pipelineFiles) { if (fileEntry.isFile()) { PipelineConfig filePLC = processPipelineConfigFile(pipelineSample.getFile()); if (filePLC != null) { pipelineConfigs.put(filePLC.getType(), filePLC); } } } } logger.info("INIT complete: " + config.getString("app.name") + ", home=" + applicationHomeDirectory.getAbsolutePath()); }
From source file:org.cesecore.config.ConfigurationHolder.java
public static synchronized Configuration instance() { if (config == null) { // Read in default values defaultValues = new CompositeConfiguration(); final URL defaultConfigUrl = ConfigurationHolder.class.getResource(DEFAULT_CONFIG_FILE); try {/*ww w. j ava2s.co m*/ defaultValues.addConfiguration(new PropertiesConfiguration(defaultConfigUrl)); } catch (ConfigurationException e) { log.error("Error encountered when loading default properties. Could not load configuration from " + defaultConfigUrl, e); } // read cesecore.properties, from config file built into jar, and see if we allow configuration by external files boolean allowexternal = false; try { final URL url = ConfigurationHolder.class.getResource("/conf/" + CONFIG_FILES[0]); if (url != null) { final PropertiesConfiguration pc = new PropertiesConfiguration(url); allowexternal = "true".equalsIgnoreCase(pc.getString(CONFIGALLOWEXTERNAL, "false")); log.info("Allow external re-configuration: " + allowexternal); } } catch (ConfigurationException e) { log.error("Error intializing configuration: ", e); } config = new CompositeConfiguration(); // Only add these config sources if we allow external configuration if (allowexternal) { // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo) config.addConfiguration(new SystemConfiguration()); log.info("Added system properties to configuration source (java -Dfoo.prop=bar)."); // Override with file in "application server home directory"/conf, this is prio 2 for (int i = 0; i < CONFIG_FILES.length; i++) { File f = null; try { f = new File("conf" + File.separator + CONFIG_FILES[i]); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } } // Override with file in "/etc/cesecore/conf/, this is prio 3 for (int i = 0; i < CONFIG_FILES.length; i++) { File f = null; try { f = new File("/etc/cesecore/conf/" + CONFIG_FILES[i]); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } } } // if (allowexternal) // Default values build into jar file, this is last prio used if no of the other sources override this for (int i = 0; i < CONFIG_FILES.length; i++) { addConfigurationResource("/conf/" + CONFIG_FILES[i]); } // Load internal.properties only from built in configuration file try { final URL url = ConfigurationHolder.class.getResource("/internal.properties"); if (url != null) { final PropertiesConfiguration pc = new PropertiesConfiguration(url); config.addConfiguration(pc); log.debug("Added url to configuration source: " + url); } } catch (ConfigurationException e) { log.error("Failed to load configuration from resource internal.properties", e); } } return config; }
From source file:org.chenillekit.core.services.impl.ConfigurationServiceImpl.java
/** * get the configuration from system (JVM). * * @return the configuration// ww w . j av a 2s .co m */ public Configuration getConfiguration() { return new SystemConfiguration(); }
From source file:org.cloudgraph.store.mapping.StoreMapping.java
private StoreMapping() { log.debug("initializing..."); try {//from ww w .j a va 2s . com configProperties = new ConfigProperties(); configProperties.addConfiguration(new SystemConfiguration()); InputStream propertiesStream = CloudGraphStoreMapping.class .getResourceAsStream(DEFAULT_PROPERTIES_FILE_NAME); if (propertiesStream == null) propertiesStream = StoreMapping.class.getClassLoader() .getResourceAsStream(DEFAULT_PROPERTIES_FILE_NAME); if (propertiesStream != null) { configProperties.addConfiguration(new PropertiesConfiguration(DEFAULT_PROPERTIES_FILE_NAME)); } } catch (ConfigurationException e) { throw new StoreMappingException(e); } try { for (Class<?> c : ClassIndex.getAnnotated(org.cloudgraph.store.mapping.annotation.Table.class)) annotatedClasses.add(c); String mappingFileName = EnvProperties.instance().getProperty(PROPERTY_NAME_CLOUDGRAPH_CONFIG); if (mappingFileName == null) mappingFileName = DEFAULT_CONFIG_FILE_NAME; InputStream stream = CloudGraphStoreMapping.class.getResourceAsStream(mappingFileName); if (stream == null) stream = StoreMapping.class.getClassLoader().getResourceAsStream(mappingFileName); if (stream != null) { if (annotatedClasses.size() > 0) { log.warn("found mapping file '" + mappingFileName + "' - ignoring " + annotatedClasses.size() + " annotated classes "); } StoreMappingDataBinding configBinding = new StoreMappingDataBinding( new StoreMappingValidationEventHandler()); this.config = unmarshalConfig(stream, configBinding); } else { if (annotatedClasses.size() > 0) { try { this.config = deriveMapping(); } catch (NoSuchFieldException | SecurityException e) { throw new StoreMappingException(e); } } else { throw new StoreMappingException("could not find configuration file resource '" + mappingFileName + "' on the current classpath and could not derive configuration from annotated classes and packages" + " - please ensure all annotated classes are on the classpath"); } } for (Property prop : config.getProperties()) propertyNameToPropertyMap.put(prop.getName(), prop); for (Table table : config.tables) { TableMapping tableConfig = new TableMapping(table, this); mapTable(tableConfig); } } catch (SAXException e) { throw new StoreMappingException(e); } catch (JAXBException e) { throw new StoreMappingException(e); } }
From source file:org.eclipse.kapua.commons.setting.AbstractKapuaSetting.java
protected AbstractKapuaSetting(String configResourceName) { // env+properties configuration CompositeConfiguration compositeConfig = new CompositeConfiguration(); compositeConfig.addConfiguration(new SystemConfiguration()); try {//from w ww .j a v a2s .com URL configLocalUrl = ResourceUtils.getResource(configResourceName); compositeConfig.addConfiguration(new PropertiesConfiguration(configLocalUrl)); } catch (Exception e) { s_logger.error("Error loading PropertiesConfiguration", e); throw new ExceptionInInitializerError(e); } this.config = new DataConfiguration(compositeConfig); }
From source file:org.ejbca.config.ConfigurationHolder.java
public static Configuration instance() { if (config == null) { // read ejbca.properties, from config file built into jar, and see if we allow configuration by external files boolean allowexternal = false; try {/*w w w . jav a 2s. co m*/ final URL url = ConfigurationHolder.class.getResource("/conf/" + CONFIG_FILES[0]); if (url != null) { final PropertiesConfiguration pc = new PropertiesConfiguration(url); allowexternal = "true".equalsIgnoreCase(pc.getString(CONFIGALLOWEXTERNAL, "false")); log.info("Allow external re-configuration: " + allowexternal); } } catch (ConfigurationException e) { log.error("Error intializing configuration: ", e); } config = new CompositeConfiguration(); // Only add these config sources if we allow external configuration if (allowexternal) { // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo) config.addConfiguration(new SystemConfiguration()); log.info("Added system properties to configuration source (java -Dfoo.prop=bar)."); // Override with file in "application server home directory"/conf, this is prio 2 for (int i = 0; i < CONFIG_FILES.length; i++) { File f = null; try { f = new File("conf" + File.separator + CONFIG_FILES[i]); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } } // Override with file in "/etc/ejbca/conf/, this is prio 3 for (int i = 0; i < CONFIG_FILES.length; i++) { File f = null; try { f = new File("/etc/ejbca/conf/" + CONFIG_FILES[i]); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } } } // if (allowexternal) // Default values build into jar file, this is last prio used if no of the other sources override this for (int i = 0; i < CONFIG_FILES.length; i++) { addConfigurationResource(CONFIG_FILES[i]); } // Load internal.properties only from built in configuration file try { final URL url = ConfigurationHolder.class.getResource("/internal.properties"); if (url != null) { final PropertiesConfiguration pc = new PropertiesConfiguration(url); config.addConfiguration(pc); log.debug("Added url to configuration source: " + url); } } catch (ConfigurationException e) { log.error("Failed to load configuration from resource internal.properties", e); } } return config; }
From source file:org.ejbca.config.EjbcaConfigurationHolder.java
public static Configuration instance() { if (config == null) { // read ejbca.properties, from config file built into jar, and see if we allow configuration by external files boolean allowexternal = false; try {/* w w w . j av a 2 s .co m*/ final URL url = EjbcaConfigurationHolder.class.getResource("/conf/" + CONFIG_FILES[0]); if (url != null) { final PropertiesConfiguration pc = new PropertiesConfiguration(url); allowexternal = "true".equalsIgnoreCase(pc.getString(CONFIGALLOWEXTERNAL, "false")); if (allowexternal) { log.info("Allow external re-configuration: " + allowexternal); } } } catch (ConfigurationException e) { log.error("Error intializing configuration: ", e); } config = new CompositeConfiguration(); // Only add these config sources if we allow external configuration if (allowexternal) { // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo) config.addConfiguration(new SystemConfiguration()); log.info("Added system properties to configuration source (java -Dfoo.prop=bar)."); // Override with file in "application server home directory"/conf, this is prio 2 for (int i = 0; i < CONFIG_FILES.length; i++) { File f = null; try { f = new File("conf" + File.separator + CONFIG_FILES[i]); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } } // Override with file in "/etc/ejbca/conf/, this is prio 3 for (int i = 0; i < CONFIG_FILES.length; i++) { File f = null; try { f = new File("/etc/ejbca/conf/" + CONFIG_FILES[i]); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); } } } // if (allowexternal) // Default values build into jar file, this is last prio used if no of the other sources override this for (int i = 0; i < CONFIG_FILES.length; i++) { addConfigurationResource(CONFIG_FILES[i]); } // Load internal.properties only from built in configuration file try { final URL url = EjbcaConfigurationHolder.class.getResource("/internal.properties"); if (url != null) { final PropertiesConfiguration pc = new PropertiesConfiguration(url); config.addConfiguration(pc); log.debug("Added url to configuration source: " + url); } } catch (ConfigurationException e) { log.error("Failed to load configuration from resource internal.properties", e); } } return config; }
From source file:org.ejbca.externalra.gui.ExternalRaGuiConfiguration.java
private static Configuration instance() { if (config == null) { try {//from w ww . ja v a 2 s . c o m // Default values build into war file, this is last prio used if no of the other sources override this boolean allowexternal = Boolean.getBoolean(new PropertiesConfiguration( ExternalRaGuiConfiguration.class.getResource("/" + PROPERTIES_FILENAME)) .getString(PROPERTY_CONFIGALLOWEXTERNAL, "false")); config = new CompositeConfiguration(); PropertiesConfiguration pc; // Only add these config sources if we allow external configuration if (allowexternal) { // Override with system properties, this is prio 1 if it exists (java -Dscep.test=foo) config.addConfiguration(new SystemConfiguration()); log.info("Added system properties to configuration source (java -Dfoo.prop=bar)."); // Override with file in "application server home directory"/conf, this is prio 2 File f1 = new File("conf/" + PROPERTIES_FILENAME); pc = new PropertiesConfiguration(f1); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f1.getAbsolutePath()); // Override with file in "/etc/ejbca/conf/extra, this is prio 3 File f2 = new File("/etc/ejbca/conf/extra/" + PROPERTIES_FILENAME); pc = new PropertiesConfiguration(f2); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config.addConfiguration(pc); log.info("Added file to configuration source: " + f2.getAbsolutePath()); } // Default values build into war file, this is last prio used if no of the other sources override this URL url = ExternalRaGuiConfiguration.class.getResource("/" + PROPERTIES_FILENAME); pc = new PropertiesConfiguration(url); config.addConfiguration(pc); log.info("Added url to configuration source: " + url); log.info("Allow external re-configuration: " + allowexternal); } catch (ConfigurationException e) { log.error("Error intializing ExtRA Configuration: ", e); } } return config; }