List of usage examples for org.apache.commons.configuration XMLConfiguration load
private void load(InputSource source) throws ConfigurationException
From source file:edu.cornell.med.icb.R.TestRConnectionPool.java
/** * Validates that the connections that have been invalidated are removed from the pool properly. * @throws ConfigurationException if there is a problem setting up the default test connection * @throws RserveException if there is an issue connecting with an Rserver */// w ww . j a v a 2 s . co m @Test public void invalidateConnection() throws ConfigurationException, RserveException { final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(POOL_CONFIGURATION_XML)); pool = new RConnectionPool(configuration); final RConnection connection = pool.borrowConnection(); assertNotNull("Connection should not be null", connection); assertTrue("The connection should be connected to the server", connection.isConnected()); assertFalse("The pool should be open", pool.isClosed()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("The connection should active", 1, pool.getNumberOfActiveConnections()); assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections()); pool.invalidateConnection(connection); // the connection should no longer be connected assertNotNull("Connection should not be null", connection); assertFalse("The connection should not be connected to the server", connection.isConnected()); assertEquals("There should be no connections", 0, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("No connections should be idle", 0, pool.getNumberOfIdleConnections()); assertTrue("The pool should be closed", pool.isClosed()); }
From source file:edu.cornell.med.icb.R.TestRConnectionPool.java
/** * Tests re-establishing connections to embedded Rserve instances. * @throws ConfigurationException/*from w w w . j ava2 s . c o m*/ * @throws RserveException */ // @Test - TODO - disabled for now since the command is different on each platform public void embeddedServer() throws ConfigurationException, RserveException { final String xml = "<RConnectionPool><RConfiguration><RServer host=\"localhost\" port=\"6312\" embedded=\"true\" command=\"C:\\\\Program\\ Files\\\\R\\\\R-2.6.0\\\\library\\\\Rserve\\\\Rserve_d.exe\"/></RConfiguration></RConnectionPool>"; final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(xml)); pool = new RConnectionPool(configuration); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections()); final RConnection connection = pool.borrowConnection(); assertNotNull(connection); assertTrue(connection.isConnected()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("The connections should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("The connections should not be idle", 0, pool.getNumberOfIdleConnections()); final RConnection newConnection = pool.reEstablishConnection(connection); assertNotNull(newConnection); assertFalse(connection.isConnected()); assertTrue(newConnection.isConnected()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("The connections should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("The connections should not be idle", 0, pool.getNumberOfIdleConnections()); pool.returnConnection(newConnection); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connections should be idle", 1, pool.getNumberOfIdleConnections()); }
From source file:edu.cornell.med.icb.R.TestRConnectionPool.java
/** * Validates that attempting to return a connection that has been closed throws no error. * @throws ConfigurationException if there is a problem setting up the default test connection * @throws RserveException if there is a problem with the connection to the Rserve process *///from w ww . ja v a 2s .c om @Test public void returnClosedConnection() throws ConfigurationException, RserveException { final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(POOL_CONFIGURATION_XML)); pool = new RConnectionPool(configuration); assertNotNull("Connection pool should never be null", pool); assertFalse("Everybody in - the pool should be open!", pool.isClosed()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections()); // get a connection from the pool final RConnection connection = pool.borrowConnection(); assertNotNull("Connection should not be null", connection); assertTrue("The connection should be connected to the server", connection.isConnected()); connection.close(); assertFalse("The connection should not be connected to the server anymore", connection.isConnected()); // return the connection to the pool pool.returnConnection(connection); // and the connection should remain closed assertFalse("The connection should not be connected to the server anymore", connection.isConnected()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connections should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections()); // get another connection from the pool final RConnection connection2 = pool.borrowConnection(); assertNotNull("Connection should not be null", connection2); assertTrue("The connection should be connected to the server", connection2.isConnected()); }
From source file:edu.cornell.med.icb.R.TestRConnectionPool.java
/** * Validates that the connection pool will properly hand out a connection * to an active Rserve process. Note: this test assumes that a Rserve * process is already running on localhost using the default port. * @throws ConfigurationException if there is a problem setting up the default test connection * @throws RserveException if there is a problem with the connection to the Rserve process *///from ww w .j a v a2 s .c om @Test public void validConnection() throws ConfigurationException, RserveException { final XMLConfiguration configuration = new XMLConfiguration(); configuration.load(new StringReader(POOL_CONFIGURATION_XML)); pool = new RConnectionPool(configuration); assertNotNull("Connection pool should never be null", pool); assertFalse("Everybody in - the pool should be open!", pool.isClosed()); assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connection should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections()); // get a connection from the pool final RConnection connection = pool.borrowConnection(); assertNotNull("Connection should not be null", connection); assertTrue("The connection should be connected to the server", connection.isConnected()); // there should be no more connections available assertEquals("There should be one connections", 1, pool.getNumberOfConnections()); assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections()); // but try and get another final RConnection connection2 = pool.borrowConnection(100, TimeUnit.MILLISECONDS); assertNull("The first connection hasn't been returned - it should be null", connection2); // it didn't give us a connection, but make sure the counts didn't change assertEquals("There should be one connections", 1, pool.getNumberOfConnections()); assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections()); // return the connection to the pool pool.returnConnection(connection); // now there should be one available in the pool assertEquals("There should be one connection", 1, pool.getNumberOfConnections()); assertEquals("No connection should be active", 0, pool.getNumberOfActiveConnections()); assertEquals("The connection should be idle", 1, pool.getNumberOfIdleConnections()); // make sure we can get another good connection after returning the previous one final RConnection connection3 = pool.borrowConnection(100, TimeUnit.MILLISECONDS); assertNotNull("Connection should not be null", connection3); assertTrue("The connection should be connected to the server", connection3.isConnected()); // there should be no more connections available assertEquals("There should be one connections", 1, pool.getNumberOfConnections()); assertEquals("The connection should be active", 1, pool.getNumberOfActiveConnections()); assertEquals("There should be no idle connections", 0, pool.getNumberOfIdleConnections()); pool.returnConnection(connection3); }
From source file:com.aol.advertising.qiao.config.AgentXmlConfiguration.java
/** * Load configuration file and interpolate variables. Note that due to the * way Apache Commons Configuration treats property keys, user should avoid * using dot ('.') in the property key. Otherwise ACC may not substitute * some value if the variable contains valid element name(s). * * @param xmlConfigFile//from ww w. ja va2s . co m * @param propConfigFiles * @return * @throws ConfigurationException */ protected HierarchicalConfiguration readConfigurationFiles(String xmlConfigFile, String propConfigFiles) throws ConfigurationException { try { // convert URI to URL URL[] prop_urls = null; URL xml_url = CommonUtils.uriToURL(xmlConfigFile); if (propConfigFiles != null) { String[] prop_files = propConfigFiles.split(","); prop_urls = new URL[prop_files.length]; for (int i = 0; i < prop_files.length; i++) { prop_urls[i] = CommonUtils.uriToURL(prop_files[i]); } } // combine xml and properties configurations CombinedConfiguration combined_cfg = new CombinedConfiguration(new OverrideCombiner()); XMLConfiguration cfg_xml = new XMLConfiguration(); cfg_xml.setDelimiterParsingDisabled(true); cfg_xml.setAttributeSplittingDisabled(true); cfg_xml.load(xml_url); combined_cfg.addConfiguration(cfg_xml); if (prop_urls != null) { // properties in the earlier files take precedence if duplicate for (int i = 0; i < prop_urls.length; i++) { PropertiesConfiguration cfg_props = new PropertiesConfiguration(); cfg_props.setDelimiterParsingDisabled(true); cfg_props.load(prop_urls[i]); combined_cfg.addConfiguration(cfg_props); } } HierarchicalConfiguration config = (HierarchicalConfiguration) combined_cfg.interpolatedConfiguration(); // !!! resolve variables return config; } catch (Exception e) { throw new ConfigurationException(e.getMessage(), e); } }
From source file:com.flexoodb.FlexManager.java
public FlexManager(String conf) throws Exception { XMLConfiguration config = new XMLConfiguration(); config.setDelimiterParsingDisabled(true); String dbimplementation = null; if (conf == null) { byte[] b = FlexUtils .getBytesFromInputStream(this.getClass().getClassLoader().getResourceAsStream("flexoodb.xml")); if (b != null) { config.load(new ByteArrayInputStream(b)); dbimplementation = config.getString("flexoodb[@engine]"); }/*from ww w .ja v a2 s .c om*/ } else { config.load(conf); dbimplementation = config.getString("flexoodb[@engine]"); } // use the default impl if (dbimplementation == null) { dbimplementation = "com.flexoodb.engines.FlexJAXBDBDataEngine"; } //_flexdb = (FlexDataInterface) Class.forName(dbimplementation).newInstance(); _flexdb = (FlexDataInterface) ClassLoader.getSystemClassLoader().loadClass((dbimplementation)) .newInstance(); _flexdb.initialize(config); }
From source file:cn.quickj.Setting.java
/** * setting.xml???/*from w w w .ja va2s .c om*/ * * @param rootPath * @throws Exception * */ public static void load(String rootPath) throws Exception { if (initFinished == true) return; XMLConfiguration config; String settingPath = ""; if (rootPath == null) { // WebApplication Setting.xml String classPath = Thread.currentThread().getContextClassLoader().getResource("").getPath(); Pattern p = Pattern.compile("([\\S]+/)WEB-INF[\\S]+"); Matcher m = p.matcher(classPath); if (m.find()) webRoot = m.group(1); } else webRoot = rootPath; try { webRoot = URLDecoder.decode(webRoot, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (webRoot.endsWith(".xml")) { settingPath = webRoot; int lastPos = webRoot.lastIndexOf('\\'); if (lastPos == -1) lastPos = webRoot.lastIndexOf('/'); webRoot = webRoot.substring(0, lastPos); } else { if (!webRoot.endsWith("/") && !webRoot.endsWith("\\")) webRoot = webRoot + "/"; settingPath = webRoot + "WEB-INF/setting.xml"; } log.info("Loading setting file:" + settingPath); config = new XMLConfiguration(); // ?????? config.setDelimiterParsingDisabled(true); config.load(settingPath); /* * @Deprecated * ????unittest?runserver? * war?XML? String strRunMode = * config.getString("runmode", "development"); if * (strRunMode.equals("production")) runMode = PROD_MODE; else if * (strRunMode.equals("test")) runMode = TEST_MODE; else runMode = * DEV_MODE; */ String strRunMode = getRunMode(); packageRoot = config.getString("package", packageRoot); fieldBySetter = config.getBoolean("web.fieldBySetter", false); DEFAULT_CHARSET = config.getString("web.charset", "utf-8"); longDateFormat = config.getString("web.long-dateformat", "yyyy-MM-dd HH:mm:ss"); license = config.getString("license"); shortDateFormat = config.getString("web.short-dateformat", "yyyy-MM-dd"); String strLocale = config.getString("web.locale", Locale.getDefault().getDisplayName()); theme = config.getString("web.theme"); locale = new Locale(strLocale); sessionClass = config.getString("web.session.class", "cn.quickj.session.MemHttpSession"); sessionDomain = config.getString("web.session.domain", null); sessionTimeOut = config.getInt("web.session.timeout", 30 * 60); defaultUri = config.getString("web.defaultUri"); uploadDir = config.getString("web.upload.directory", System.getProperty("java.io.tmpdir")); uploadMaxSize = config.getInt("web.upload.max-size", 4096); jdbcDriver = config.getString("database." + strRunMode + ".driver", ""); usedb = (jdbcDriver.length() != 0); jdbcUser = config.getString("database." + strRunMode + ".user", "root"); jdbcUrl = config.getString("database." + strRunMode + ".url", ""); jdbcPassword = config.getString("database." + strRunMode + ".password", ""); maxActive = config.getInt("database." + strRunMode + ".pool.maxActive", 10); initActive = config.getInt("database." + strRunMode + ".pool.initActive", 2); maxIdle = config.getInt("database." + strRunMode + ".pool.maxIdle", 1800); dialect = config.getString("database." + strRunMode + ".dialect", null); tablePrefix = config.getString("database.prefix", ""); cacheClass = config.getString("cache.class", "cn.quickj.cache.SimpleCache"); cacheParam = config.getString("cache.param", "capacity=50000"); // ?? queueEnabled = "true".equalsIgnoreCase(config.getString("queue.enable", "false")); queueParam = config.getString("queue.param", "capacity=50000"); loadPlugin(config); loadApplicationConfig(); initFinished = true; }
From source file:net.lmxm.ute.beans.configuration.ApplicationPreferences.java
/** * Instantiates a new application preferences. * * @param configurationFile the configuration file *//*from w ww . jav a 2 s . co m*/ public ApplicationPreferences(final File configurationFile) { final String prefix = "ApplicationPreferences() :"; LOGGER.debug("{} entered. configurationFile={}", prefix, configurationFile); XMLConfiguration xmlConfiguration = null; try { xmlConfiguration = new XMLConfiguration(); final File preferencesFile = new File(configurationFile.getParent(), PREFERENCES_FILE_NAME); if (!preferencesFile.exists()) { LOGGER.debug("{} preferences file does not exist, creating a new file", prefix); createEmptyPreferencesFile(preferencesFile); } LOGGER.debug("{} loading preferences", prefix); xmlConfiguration.load(preferencesFile); } catch (final org.apache.commons.configuration.ConfigurationException e) { LOGGER.debug(prefix + " ConfigurationException caught trying to load configuration", e); throw new ConfigurationException(ExceptionResourceType.ERROR_LOADING_PREFERENCES_FILE, e); } configuration = xmlConfiguration; LOGGER.debug("{} leaving", prefix); }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java
public void read(InputStream fileContents) { XMLConfiguration xmlConfig = createXMLConfiguration(); try {/*from www . j a va 2 s .c om*/ xmlConfig.load(fileContents); } catch (ConfigurationException e) { throw new RuntimeException(e); } read(xmlConfig); }
From source file:com.graphhopper.jsprit.core.problem.io.VrpXMLReader.java
public void read(String filename) { logger.debug("read vrp: {}", filename); XMLConfiguration xmlConfig = createXMLConfiguration(); try {/* www . ja v a2s .c o m*/ xmlConfig.load(filename); } catch (ConfigurationException e) { throw new RuntimeException(e); } read(xmlConfig); }