List of usage examples for org.apache.commons.configuration ConfigurationException toString
public String toString()
From source file:eu.matejkormuth.ts3bot.Bot.java
/** * Shutdowns all services and disconnects from ServerQuery. *///from w ww. j av a 2s . c o m public void shutdown() { // Disable reading of commands. this.consoleReader.disable(); this.logger.info("Shutting down..."); try { if (this.configuration.getBoolean("config.useExternal", true)) { this.configuration.setFile(new File("/bot.properties")); this.configuration.save(); this.logger.info("Configuration saved!"); } } catch (ConfigurationException e) { this.logger.error("Couldn't save configuration: {}", e.getMessage()); } this.logger.info("Shutting down services..."); // Shutdown services. for (Service service : this.services) { try { this.eventBus.unregister(service); service.disable(); } catch (Exception e) { this.logger.error("Can't disable service! Problem: {}", e.getMessage()); this.logger.error(e.toString()); } } this.logger.info("Disconnecting..."); // Close connection. this.queryConnection.disconnect(); // Bye! this.logger.info("Thanks for using!"); this.logger.info("Bye!"); }
From source file:eu.matejkormuth.ts3bot.Bot.java
/** * Boots up Bot./*from www . jav a 2 s . c om*/ */ public void boot() { if (this.configuration != null) { throw new RuntimeException("Bot is already booted up!"); } this.logger.info("Booting up..."); this.logger.info("Reading configuration..."); try { this.configuration = new PropertiesConfiguration("bot.properties"); } catch (ConfigurationException e) { this.logger.error("Error while loading configuration from bot.properties: {}", e.getMessage()); try { this.configuration = new PropertiesConfiguration( this.getClass().getClassLoader().getResource("bot.properties")); } catch (ConfigurationException e2) { this.logger.error("Error while loading configuration from jar: {}", e2.getMessage()); this.configuration = new PropertiesConfiguration(); this.configuration.setHeader("TS3 Bot configuration."); this.configuration.setFileName("bot.properties"); } } // Connect to teamspeak server. String name = this.configuration.getString("query.login"); String pass = this.configuration.getString("query.password"); String ip = this.configuration.getString("server.ip"); if (name == null || pass == null || ip == null) { // Can't continue without these values. throw new RuntimeException( "Can't get query login, query password or server ip address from config! Can't continue!"); } boolean flood = this.configuration.getBoolean("server.preventflood", false); boolean autoRegister = this.configuration.getBoolean("server.autoRegisterChannelEvents", true); String nickname = this.configuration.getString("bot.name", "TS3Bot"); this.logger.info("Connecting to teamspeak server {}...", ip); QueryCreditnals creds = new QueryCreditnals(name, pass); this.queryConnection = new QueryConnection(creds, ip, nickname, flood, autoRegister); // nickname will never be null... // Connect to server. this.queryConnection.connect(); // Some default services. List<Object> services = this.configuration.getList("bot.services"); // In case we have only one service. if (services.size() == 0) { if (this.configuration.getString("bot.service") != null) { services.add(this.configuration.getString("bot.service")); } } // Create all services. this.logger.info("Loading services..."); for (Object o : services) { try { Class<?> clazz = Class.forName(o.toString()); if (Service.class.isAssignableFrom(clazz)) { Service service = (Service) clazz.getConstructor().newInstance(); this.services.add(service); } else { this.logger.error( "Specified service " + o.toString() + " does not extend Service class! Can't load it."); } } catch (Exception e) { this.logger.error("Can't load service {}! Problem: {}", o.toString(), e.getMessage()); this.logger.error(e.toString()); } } this.logger.info("Starting services..."); // Start services. for (Service service : this.services) { if (service.isAsynchronous()) { this.logger.info("Enabling service asynchronously " + service.getClass().getSimpleName() + "..."); final Service s = service; // Start thread for service. new Thread(new Runnable() { public void run() { s.setBot(Bot.this); Bot.this.eventBus.register(s); s.enable(); } }, "service/" + service.getClass().getSimpleName()).run(); } else { try { this.logger .info("Enabling service synchronously " + service.getClass().getSimpleName() + "..."); service.setBot(this); this.eventBus.register(service); service.enable(); } catch (Exception e) { this.logger.error("Can't enable service! Problem: {}", e.getMessage()); this.logger.error(e.toString()); } } } this.logger.info("Finished loading!"); // Start reading commands from console. this.consoleReader = new ConsoleReader(); this.consoleReader.setBot(this); this.consoleReader.enable(); }
From source file:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java
public static void main(String[] args) { logger.info("Starting application [ rtd ] ..."); try {/* ww w . ja va 2 s. com*/ config.addConfiguration( new XMLConfiguration(RetrieveTestData.class.getClassLoader().getResource(CONFIG_FILENAME))); HierarchicalConfiguration appConfig = config.configurationAt(APPLICATION_CONFIG_ROOT); EodDataProvider eodDataProvider = null; OutputStream out = new FileOutputStream(OUTPUT_FILENAME); XMLOutputFactory factory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = factory.createXMLStreamWriter(out); eodDataProvider = EodDataProviderFactory.create(appConfig, EODDATA_PROVIDER_NAME); writer.writeStartDocument("utf-8", "1.0"); writer.writeCharacters(NEWLINE); writer.writeComment("Test data for running DataScraper unit tests against"); writer.writeCharacters(NEWLINE); writer.setPrefix(XML_PREFIX, XML_NAMESPACE_URI); writer.writeStartElement(XML_NAMESPACE_URI, TESTDATA_LOCALNAME); writer.writeNamespace(XML_PREFIX, XML_NAMESPACE_URI); writer.writeCharacters(NEWLINE); serializeExchanges(eodDataProvider, writer); serializeSymbols(eodDataProvider, writer); serializeQuotes(eodDataProvider, writer); writer.writeEndElement(); writer.writeCharacters(NEWLINE); writer.writeEndDocument(); writer.flush(); writer.close(); } catch (ConfigurationException ce) { logger.error(ce.toString()); ce.printStackTrace(); } catch (Exception e) { logger.error(e.toString()); logger.error(e); } logger.info("Exiting application [ rtd ] ..."); }
From source file:org.apache.qpid.server.configuration.plugins.AbstractConfigurationTest.java
@Override public void setUp() throws Exception { // Test does not directly use the AppRegistry but the configured broker // is required for the correct ConfigurationPlugin processing super.setUp(); XMLConfiguration xmlconfig = new XMLConfiguration(); xmlconfig.addProperty("base.element[@property]", "property"); xmlconfig.addProperty("base.element.name", "name"); // We make these strings as that is how they will be read from the file. xmlconfig.addProperty("base.element.positiveLong", String.valueOf(POSITIVE_LONG)); xmlconfig.addProperty("base.element.negativeLong", String.valueOf(NEGATIVE_LONG)); xmlconfig.addProperty("base.element.boolean", String.valueOf(true)); xmlconfig.addProperty("base.element.double", String.valueOf(DOUBLE)); for (int i = 0; i < LIST_SIZE; i++) { xmlconfig.addProperty("base.element.list", i); }//from w w w .ja v a 2 s .co m //Use a composite configuration as this is what our broker code uses. CompositeConfiguration composite = new CompositeConfiguration(); composite.addConfiguration(xmlconfig); _plugin = new TestConfigPlugin(); try { _plugin.setConfiguration("base.element", composite.subset("base.element")); } catch (ConfigurationException e) { e.printStackTrace(); fail(e.toString()); } }
From source file:org.apache.wookie.server.ContextListener.java
public void contextInitialized(ServletContextEvent event) { try {/*w ww.j av a 2 s . c o m*/ ServletContext context = event.getServletContext(); /* * load the widgetserver.properties file and put it into this context * as an attribute 'properties' available to all resources */ PropertiesConfiguration configuration; File localPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.widgetserver.properties"); if (localPropsFile.exists()) { configuration = new PropertiesConfiguration(localPropsFile); _logger.info("Using local widget server properties file: " + localPropsFile.toString()); } else { configuration = new PropertiesConfiguration("widgetserver.properties"); configuration.setFile(localPropsFile); configuration.save(); _logger.info("Using default widget server properties, configure your local server using: " + localPropsFile.toString()); } context.setAttribute("properties", (Configuration) configuration); /* * Merge in system properties overrides */ Iterator<Object> systemKeysIter = System.getProperties().keySet().iterator(); while (systemKeysIter.hasNext()) { String key = systemKeysIter.next().toString(); if (configuration.containsKey(key) || key.startsWith("widget.")) { String setting = configuration.getString(key); String override = System.getProperty(key); if ((override != null) && (override.length() > 0) && !override.equals(setting)) { configuration.setProperty(key, override); if (setting != null) { _logger.info("Overridden server configuration property: " + key + "=" + override); } } } } /* * Initialize persistence manager factory now, not on first request */ PersistenceManagerFactory.initialize(configuration); /* * Initialise the locale handler */ LocaleHandler.getInstance().initialize(configuration); final Locale locale = new Locale(configuration.getString("widget.default.locale")); final Messages localizedMessages = LocaleHandler.getInstance().getResourceBundle(locale); /* * load the opensocial.properties file and put it into this context * as an attribute 'opensocial' available to all resources */ PropertiesConfiguration opensocialConfiguration; File localOpenSocialPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.opensocial.properties"); if (localOpenSocialPropsFile.exists()) { opensocialConfiguration = new PropertiesConfiguration(localOpenSocialPropsFile); _logger.info("Using local open social properties file: " + localOpenSocialPropsFile.toString()); } else { opensocialConfiguration = new PropertiesConfiguration("opensocial.properties"); opensocialConfiguration.setFile(localOpenSocialPropsFile); opensocialConfiguration.save(); _logger.info("Using default open social properties, configure your local server using: " + localOpenSocialPropsFile.toString()); } context.setAttribute("opensocial", (Configuration) opensocialConfiguration); /* * Load installed features */ PropertiesConfiguration featuresConfiguration; File localFeaturesPropsFile = new File( System.getProperty("user.dir") + File.separator + "local.features.properties"); if (localFeaturesPropsFile.exists()) { featuresConfiguration = new PropertiesConfiguration(localFeaturesPropsFile); _logger.info("Loading local features file: " + localOpenSocialPropsFile.toString()); } else { featuresConfiguration = new PropertiesConfiguration("features.properties"); featuresConfiguration.setFile(localFeaturesPropsFile); featuresConfiguration.save(); _logger.info("Loading default features, configure your local server using: " + localFeaturesPropsFile.toString()); } FeatureLoader.loadFeatures(featuresConfiguration); /* * Run diagnostics */ Diagnostics.run(context, configuration); /* * Start hot-deploy widget watcher */ if (configuration.getBoolean("widget.hot_deploy")) { startWatcher(context, configuration, localizedMessages); } else { _logger.info(localizedMessages.getString("WidgetHotDeploy.0")); } } catch (ConfigurationException ex) { _logger.error("ConfigurationException thrown: " + ex.toString()); } }
From source file:org.powertac.server.ServerPropertiesService.java
/** * Loads the properties from classpath, default config file, * and user-specified config file, just in case it's not already been * loaded. This is done when properties are first requested, to ensure * that the logger has been initialized. Because the CompositeConfiguration * treats its config sources in FIFO order, this should be called <i>after</i> * any user-specified config is loaded./*from w w w. j a v a2 s . co m*/ */ void lazyInit() { // only do this once if (initialized) return; initialized = true; // find and load the default properties file log.info("lazyInit"); try { File defaultProps = new File("config/server.properties"); if (defaultProps.canRead()) { log.debug("adding " + defaultProps.getName()); config.addConfiguration(new PropertiesConfiguration(defaultProps)); } } catch (Exception e1) { log.warn("config/server.properties not found: " + e1.toString()); } // set up the classpath props try { Resource[] xmlResources = context.getResources("classpath*:config/properties.xml"); for (Resource xml : xmlResources) { if (validXmlResource(xml)) { log.info("loading config from " + xml.getURI()); XMLConfiguration xconfig = new XMLConfiguration(); xconfig.load(xml.getInputStream()); config.addConfiguration(xconfig); } } Resource[] propResources = context.getResources("classpath*:config/*.properties"); for (Resource prop : propResources) { if (validPropResource(prop)) { log.info("loading config from " + prop.getURI()); PropertiesConfiguration pconfig = new PropertiesConfiguration(); pconfig.load(prop.getInputStream()); config.addConfiguration(pconfig); } } } catch (ConfigurationException e) { log.error("Error loading configuration: " + e.toString()); } catch (Exception e) { log.error("Error loading configuration: " + e.toString()); } // set up the configurator configurator.setConfiguration(config); }
From source file:org.wso2.andes.configuration.qpid.plugins.ConfigurationPluginTest.java
@Override public void setUp() throws Exception { // Test does not directly use the AppRegistry but the configured broker // is required for the correct ConfigurationPlugin processing super.setUp(); XMLConfiguration xmlconfig = new XMLConfiguration(); xmlconfig.addProperty("base.element[@property]", "property"); xmlconfig.addProperty("base.element.name", "name"); // We make these strings as that is how they will be read from the file. xmlconfig.addProperty("base.element.positiveLong", String.valueOf(POSITIVE_LONG)); xmlconfig.addProperty("base.element.negativeLong", String.valueOf(NEGATIVE_LONG)); xmlconfig.addProperty("base.element.boolean", String.valueOf(true)); xmlconfig.addProperty("base.element.double", String.valueOf(DOUBLE)); for (int i = 0; i < LIST_SIZE; i++) { xmlconfig.addProperty("base.element.list", i); }//from w ww. j a v a 2 s . c o m //Use a composite configuration as this is what our broker code uses. CompositeConfiguration composite = new CompositeConfiguration(); composite.addConfiguration(xmlconfig); _plugin = new ConfigPlugin(); try { _plugin.setConfiguration("base.element", composite.subset("base.element")); } catch (ConfigurationException e) { e.printStackTrace(); fail(e.toString()); } }
From source file:uk.ac.edukapp.service.WidgetProfileService.java
public WidgetProfileService(ServletContext ctx) { super(ctx);/*from ww w. j av a2 s . c o m*/ tagService = new TagService(ctx); try { properties = new PropertiesConfiguration("store.properties"); if (properties.containsKey("popularity.factor.embeds")) { EmbedFactor = properties.getInt("popularity.factor.embeds"); } if (properties.containsKey("popularity.factor.downloads")) { DownloadFactor = properties.getInt("popularity.factor.downloads"); } if (properties.containsKey("popularity.factor.views")) { ViewFactor = properties.getInt("popularity.factor.views"); } } catch (ConfigurationException e) { logger.debug(e.toString()); // leave defaults } }
From source file:util.AbstractReadSystemConfigurations.java
private static String readSystemTimezone() { String systemTimezone = ""; try {//from ww w . j a v a2 s. c o m final Configuration config = new PropertiesConfiguration(PATH); systemTimezone = config.getString("system.timezone"); } catch (final ConfigurationException e) { LOG.error(e.toString()); } return systemTimezone; }
From source file:util.AbstractReadSystemConfigurations.java
private static String readLocale() { String locale = ""; try {//www. jav a2 s . co m final Configuration config = new PropertiesConfiguration(PATH); locale = config.getString("locale"); } catch (final ConfigurationException e) { LOG.error(e.toString()); } return locale; }