List of usage examples for org.apache.commons.configuration.reloading FileChangedReloadingStrategy FileChangedReloadingStrategy
FileChangedReloadingStrategy
From source file:org.dspace.servicemanager.config.DSpacePropertiesConfiguration.java
public DSpacePropertiesConfiguration(URL url) throws ConfigurationException { write = new PropertiesConfiguration(url); write.setAutoSave(true);// w ww. j a v a 2 s. com read = new PropertiesConfiguration(url); read.setAutoSave(false); FileChangedReloadingStrategy stretagy = new FileChangedReloadingStrategy(); read.setReloadingStrategy(stretagy); write.setReloadingStrategy(stretagy); }
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 {//from w w w . j a v a 2 s . 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 {/*from w w w. j a va 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 {//w w w . j av 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; }
From source file:org.ejbca.extra.util.ExtraConfiguration.java
public static Configuration instance() { if (config == null) { try {/*from w w w. j av a2 s . co 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(ExtraConfiguration.class.getResource("/" + PROPERTY_FILENAME)) .getString(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/" + PROPERTY_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/" + PROPERTY_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 = ExtraConfiguration.class.getResource("/" + PROPERTY_FILENAME); pc = new PropertiesConfiguration(url); config.addConfiguration(pc); log.info("Added url to configuration source: " + url); log.info("Allow external re-configuration: " + allowexternal); // Test log.debug("Using keystore path (1): " + config.getString(SCEPKEYSTOREPATH + ".1")); //log.debug("Using keystore pwd (1): "+config.getString(SCEPKEYSTOREPWD+".1")); //log.debug("Using authPwd: "+config.getString(SCEPAUTHPWD)); log.debug("Using certificate profile: " + config.getString(SCEPCERTPROFILEKEY)); log.debug("Using entity profile: " + config.getString(SCEPENTITYPROFILEKEY)); log.debug("Using default CA: " + config.getString(SCEPDEFAULTCA)); log.debug("Create or edit user: " + config.getBoolean(SCEPEDITUSER)); log.debug("Mapping for CN=Scep CA,O=EJBCA Sample,C=SE: " + config.getString("CN=Scep CA,O=EJBCA Sample,C=SE")); } catch (ConfigurationException e) { log.error("Error intializing ExtRA Configuration: ", e); } } return config; }
From source file:org.ejbca.ui.cli.config.cmp.UploadFileCommand.java
@Override public CommandResult execute(ParameterContainer parameters) { String filename = parameters.get(FILE_KEY); String alias = parameters.get(ALIAS_KEY); CompositeConfiguration config = null; File f = null;//w w w. j a v a 2 s.c om try { f = new File(filename); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config = new CompositeConfiguration(); config.addConfiguration(pc); log.info("Reading CMP configuration from file: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); return CommandResult.FUNCTIONAL_FAILURE; } readConfigurations(config, alias); return CommandResult.SUCCESS; }
From source file:org.ejbca.ui.cli.config.scep.UploadFileCommand.java
@Override public CommandResult execute(ParameterContainer parameters) { String filename = parameters.get(FILE_KEY); String alias = parameters.get(ALIAS_KEY); CompositeConfiguration config = null; File f = null;//ww w. j a va 2 s . com try { f = new File(filename); final PropertiesConfiguration pc = new PropertiesConfiguration(f); pc.setReloadingStrategy(new FileChangedReloadingStrategy()); config = new CompositeConfiguration(); config.addConfiguration(pc); log.info("Reading SCEP configuration from file: " + f.getAbsolutePath()); } catch (ConfigurationException e) { log.error("Failed to load configuration from file " + f.getAbsolutePath()); return CommandResult.FUNCTIONAL_FAILURE; } readConfigurations(config, alias); return CommandResult.SUCCESS; }
From source file:org.encuestame.config.startup.XMLConfigurationFileSupport.java
/** * * @param file//from w ww . j a va 2 s . c o m * @throws ConfigurationException */ private void reloadConfiguration(final File file) throws ConfigurationException { log.debug("createConfiguration " + file.exists()); log.debug("createConfiguration.... " + file.getAbsolutePath()); XMLConfigurationFileSupport.xmlConfiguration = new XMLConfiguration(file); XMLConfigurationFileSupport.xmlConfiguration.setAutoSave(true); XMLConfigurationFileSupport.xmlConfiguration.setReloadingStrategy(new FileChangedReloadingStrategy()); }
From source file:org.esco.grouperui.tools.property.PropertyManagerFactory.java
/** * iterate on each property file and add all property in manager. *//* w w w . j a va 2s . c o m*/ private void addPropertiesToManager() { String[] repertoireDeConfiguration = PropertyManager.baseDirs(); String folderWork = null; final Map<String, PropertiesConfiguration> map = new HashMap<String, PropertiesConfiguration>(); for (final Entry<String, String> property : this.properties.entrySet()) { PropertiesConfiguration config = null; for (String folderConf : repertoireDeConfiguration) { try { if (!folderConf.endsWith("/") && !folderConf.endsWith("\\")) { folderWork = folderConf + File.separator + "/"; } else { folderWork = folderConf; } final File fichierACharger = new File(folderWork + property.getValue()); if (fichierACharger.exists()) { // Chargement du fichier de properties dans un // PropertiesConfiguration config = new PropertiesConfiguration(fichierACharger); PropertyManagerFactory.LOGGER .debug("Chargement de " + folderWork + property.getValue() + " effectu"); // Rechargement chaud du fichier en cas de // modification de celui-ci config.setReloadingStrategy(new FileChangedReloadingStrategy()); map.put(property.getKey(), config); } else { PropertyManagerFactory.LOGGER .debug("Impossible de charger le fichier " + folderWork + property.getValue()); } } catch (final ConfigurationException e) { PropertyManagerFactory.LOGGER.error(e, "Le fichier de properties " + folderWork + property.getValue() + " n'a pas pu se charger correctement"); } } } final PropertyManager manager = PropertyManager.getInstance(); manager.setPropertiesConfiguration(map); }
From source file:org.freemedsoftware.shim.Configuration.java
/** * Load configuration from both template and override properties files. *///from ww w . ja va 2 s.c o m public static void loadConfiguration() { log.trace("Entered loadConfiguration"); if (servletContext == null) { log.error("servletContext not set!"); } if (compositeConfiguration == null) { log.info("Configuration object not present, instantiating"); compositeConfiguration = new CompositeConfiguration(); PropertiesConfiguration defaults = null; try { defaults = new PropertiesConfiguration( servletContext.getServletContext().getRealPath(DEFAULT_CONFIG)); log.info("Loading default configuration from " + servletContext.getServletContext().getRealPath(DEFAULT_CONFIG)); } catch (ConfigurationException e) { log.error("Could not load default configuration from " + servletContext.getServletContext().getRealPath(DEFAULT_CONFIG)); // e.printStackTrace(); } if (OVERRIDE_CONFIG != null) { PropertiesConfiguration overrides = null; try { overrides = new PropertiesConfiguration(); overrides.setFile(new File(OVERRIDE_CONFIG)); overrides.setReloadingStrategy(new FileChangedReloadingStrategy()); overrides.load(); } catch (ConfigurationException e) { log.info("Could not load overrides", e); } compositeConfiguration.addConfiguration(overrides); } // Afterwards, add defaults so they're read second. compositeConfiguration.addConfiguration(defaults); } }