List of usage examples for java.util Properties setProperty
public synchronized Object setProperty(String key, String value)
From source file:eu.planets_project.tb.impl.AdminManagerImpl.java
/** * Code for emails related to Approval.//from w w w . j a v a2 s . co m * */ private static void sendNotification(String username, String templateName, Experiment exp) { VelocityEngine velocityEngine = new VelocityEngine(); Properties props = new Properties(); props.setProperty("resource.loader", "class"); props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); props.setProperty("velocimacro.library", ""); try { velocityEngine.init(props); } catch (Exception e) { log.error("Failed to initialise the Velocity engine. :: " + e); } // Look up the user. User user = UserBean.getUser(username); if (user == null) return; // Create a message: PlanetsMailMessage message = new PlanetsMailMessage(); // Add the recipient in properly. message.addRecipient(user.getFullName() + "<" + user.getEmail() + ">"); // Determine the Testbed URL: // FIXME This is a HACK for the TB Service URL in emails: String testbedURL = "http://testbed.planets-project.eu/testbed/"; // String testbedURL = "http://"+AdminManagerImpl.getAuthority()+"/testbed/"; Map<String, Object> model = new HashMap<String, Object>(); model.put("user", user); model.put("exp", exp); model.put("expName", exp.getExperimentSetup().getBasicProperties().getExperimentName()); model.put("applicationURL", testbedURL); VelocityContext velocityContext; StringWriter result = new StringWriter(); try { velocityContext = new VelocityContext(model); velocityEngine.mergeTemplate("eu/planets_project/tb/" + templateName + ".vm", velocityContext, result); } catch (VelocityException ex) { log.error("Mailing failed! :: " + ex); return; } catch (RuntimeException ex) { log.error("Mailing failed! :: " + ex); return; } catch (Exception ex) { log.error("Mailing failed! :: " + ex); return; } message.setSubject(velocityContext.get("subject").toString()); message.setBody(result.toString()); try { message.send(); } catch (Exception e) { log.error("An error occured while trying to send an email to " + user.getFullName() + "! :: " + e); e.printStackTrace(); } }
From source file:gov.nih.nci.logging.api.util.HibernateUtil.java
private static void validateProperties(Properties properties) throws Exception { if (properties.containsKey("CLMDS.jndiName")) { String jndiName = properties.getProperty("CLMDS.jndiName"); String hibernateDialect = properties.getProperty("Hibernate.dialect"); properties.clear();/*from ww w . ja va2 s . c o m*/ properties.setProperty("CLMDJndiDS.jndiName", jndiName); properties.setProperty("hibernate.dialect", hibernateDialect); } if (properties.containsKey("CLMDS.url") && properties.containsKey("CLMDS.driverClassName") && properties.containsKey("CLMDS.password") && properties.containsKey("CLMDS.username")) { String driverClassName = properties.getProperty("CLMDS.driverClassName"); String url = properties.getProperty("CLMDS.url"); String username = properties.getProperty("CLMDS.username"); String password = properties.getProperty("CLMDS.password"); String hibernateDialect = properties.getProperty("Hibernate.dialect"); properties.clear(); /*properties.setProperty("CLMConnectionPoolDS.driverClassName",driverClassName); properties.setProperty("CLMConnectionPoolDS.url", url); properties.setProperty("CLMConnectionPoolDS.username", username); properties.setProperty("CLMConnectionPoolDS.password", password);*/ properties.setProperty("hibernate.connection.driver_class", driverClassName); properties.setProperty("hibernate.connection.url", url); properties.setProperty("hibernate.connection.username", username); properties.setProperty("hibernate.connection.password", password); properties.setProperty("hibernate.dialect", hibernateDialect); } }
From source file:com.edgenius.wiki.Shell.java
public static void save() { try {// w ww .j a va 2 s.c o m filelock.writeLock().lock(); //write this key to shell.properties String root = DataRoot.getDataRoot(); Properties props = FileUtil.loadProperties(root + Shell.FILE); props.setProperty("shell.key", StringUtils.trimToEmpty(Shell.key)); props.setProperty("shell.enabled", Boolean.toString(Shell.enabled)); //fix to add end slash if (!Shell.rootUrl.endsWith("/")) Shell.rootUrl += "/"; props.setProperty("shell.url", StringUtils.trimToEmpty(Shell.rootUrl)); props.setProperty("connection.timeout", String.valueOf(Shell.timeout)); updateUrl(); FileOutputStream os = FileUtil.getFileOutputStream(root + Shell.FILE); props.store(os, "Shell is update by system."); } catch (Exception e) { log.error("Unable to save shell.properties", e); } finally { filelock.writeLock().unlock(); } }
From source file:Classes.DBConnection.java
/** * Initialize the connections configuration *//*from ww w. j a v a2 s .co m*/ public static void init_BasicDataSourceFactory() { Properties propiedades = new Properties(); /* setMaxActive(): N mx de conexiones que se pueden abrir simultneamente. setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms. setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando. */ propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver"); propiedades.setProperty("url", "jdbc:mysql://localhost:3306/prog"); propiedades.setProperty("maxActive", "10"); propiedades.setProperty("maxIdle", "8"); propiedades.setProperty("minIdle", "0"); propiedades.setProperty("maxWait", "500"); propiedades.setProperty("initialSize", "5"); propiedades.setProperty("defaultAutoCommit", "true"); propiedades.setProperty("username", "root"); propiedades.setProperty("password", "12345"); propiedades.setProperty("validationQuery", "select 1"); propiedades.setProperty("validationQueryTimeout", "100"); propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2"); propiedades.setProperty("poolPreparedStatements", "true"); propiedades.setProperty("maxOpenPreparedStatements", "10"); try { dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades); } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e.toString()); } }
From source file:io.amient.yarn1.YarnClient.java
public static Properties getAppConfiguration() { try {/*from www. j a v a2 s.co m*/ Properties properties = new Properties() { { load(new FileInputStream("yarn1.configuration")); } }; for (Map.Entry<Object, Object> entry : properties.entrySet()) { properties.setProperty(entry.getKey().toString(), entry.getValue().toString()); } return properties; } catch (Exception e) { log.error("Failed to load localised configuration for yarn1 context", e); return null; } }
From source file:com.heliosapm.streams.collector.ds.pool.PoolConfig.java
/** * Creates and deploys an ObjectPool based on the passed config props * @param configProps The configuration properties file * @return the created GenericObjectPool *//*from ww w . ja va 2 s .c om*/ public static GenericObjectPool<?> deployPool(final File configProps) { if (configProps == null) throw new IllegalArgumentException("The passed file was null"); if (!configProps.canRead()) throw new IllegalArgumentException("The passed file [" + configProps + "] cannot be read"); GenericObjectPool<?> pool = pools.putIfAbsent(configProps, PLACEHOLDER); if (pool == null || pool == PLACEHOLDER) { final Properties p = URLHelper.readProperties(URLHelper.toURL(configProps)); if (!p.containsKey("name")) { p.setProperty("name", StringHelper.splitString(configProps.getName(), '.', true)[0]); } try { pool = deployPool(p); pools.replace(configProps, pool); return pool; } catch (Exception ex) { final String msg = "Failed to deploy object pool from file [" + configProps + "]"; LOG.error(msg, ex); throw new RuntimeException(msg, ex); } } else { throw new RuntimeException( "The pool defined in the file [" + configProps + "] has already been deployed"); } }
From source file:io.symcpe.hendrix.api.dao.TestRulesManager.java
@BeforeClass public static void beforeClass() throws Exception { java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.OFF); Properties config = new Properties(System.getProperties()); File db = new File(TARGET_RULES_DB); if (db.exists()) { FileUtils.deleteDirectory(db);/* w w w . java2 s .c o m*/ } config.setProperty("javax.persistence.jdbc.url", CONNECTION_STRING); try { emf = Persistence.createEntityManagerFactory("hendrix", config); } catch (Exception e) { e.printStackTrace(); throw e; } EntityManager em = emf.createEntityManager(); Tenant tenant = new Tenant(); tenant.setTenant_id(TENANT_ID_1); tenant.setTenant_name(TEST_TENANT); TenantManager.getInstance().createTenant(em, tenant); tenant = new Tenant(); tenant.setTenant_id(TENANT_ID_2); tenant.setTenant_name(TEST_TENANT); TenantManager.getInstance().createTenant(em, tenant); tenant = new Tenant(); tenant.setTenant_id(TENANT_ID_3); tenant.setTenant_name(TEST_TENANT); TenantManager.getInstance().createTenant(em, tenant); tenant = new Tenant(); tenant.setTenant_id(TENANT_ID_5); tenant.setTenant_name(TEST_TENANT); TenantManager.getInstance().createTenant(em, tenant); em.close(); }
From source file:application.bbdd.pool.java
public static void inicializa_BasicDataSourceFactory() { Properties propiedades = new Properties(); /*/*from www. j a v a 2 s . co m*/ setMaxActive(): N mx de conexiones que se pueden abrir simultneamente. setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms. setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando. */ propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver"); propiedades.setProperty("url", "jdbc:mysql://127.0.0.1:3306/application"); propiedades.setProperty("maxActive", "10"); propiedades.setProperty("maxIdle", "8"); propiedades.setProperty("minIdle", "0"); propiedades.setProperty("maxWait", "500"); propiedades.setProperty("initialSize", "5"); propiedades.setProperty("defaultAutoCommit", "true"); propiedades.setProperty("username", "root"); propiedades.setProperty("password", "1234"); propiedades.setProperty("validationQuery", "select 1"); propiedades.setProperty("validationQueryTimeout", "100"); propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2"); propiedades.setProperty("poolPreparedStatements", "true"); propiedades.setProperty("maxOpenPreparedStatements", "10"); try { //propiedades.load(new FileInputStream("src/config/datasource_config.properties")); dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString()); } }
From source file:com.srotya.tau.api.dao.TestRulesManager.java
@BeforeClass public static void beforeClass() throws Exception { java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.OFF); Properties config = new Properties(System.getProperties()); File db = new File(TARGET_RULES_DB); if (db.exists()) { FileUtils.deleteDirectory(db);/* w w w. j a v a2 s .c o m*/ } config.setProperty("javax.persistence.jdbc.url", CONNECTION_STRING); try { emf = Persistence.createEntityManagerFactory("tau", config); } catch (Exception e) { e.printStackTrace(); throw e; } EntityManager em = emf.createEntityManager(); RuleGroup ruleGroup = new RuleGroup(); ruleGroup.setRuleGroupId(RULE_GROUP_ID_1); ruleGroup.setRuleGroupName(TEST_RULE_GROUP); RuleGroupManager.getInstance().createRuleGroup(em, ruleGroup); ruleGroup = new RuleGroup(); ruleGroup.setRuleGroupId(RULE_GROUP_ID_2); ruleGroup.setRuleGroupName(TEST_RULE_GROUP); RuleGroupManager.getInstance().createRuleGroup(em, ruleGroup); ruleGroup = new RuleGroup(); ruleGroup.setRuleGroupId(RULE_GROUP_ID_3); ruleGroup.setRuleGroupName(TEST_RULE_GROUP); RuleGroupManager.getInstance().createRuleGroup(em, ruleGroup); ruleGroup = new RuleGroup(); ruleGroup.setRuleGroupId(RULE_GROUP_ID_5); ruleGroup.setRuleGroupName(TEST_RULE_GROUP); RuleGroupManager.getInstance().createRuleGroup(em, ruleGroup); em.close(); }
From source file:App.classes.BD_Connection.java
/** * public Connection AbrirConexion() {//from www . ja v a 2 s. c o m * * Connection con = null; try { Class.forName("com.mysql.jdbc.Driver"); * String urlOdbc = "jdbc:mysql://127.0.0.1:3306/db_admin"; con = * (java.sql.DriverManager.getConnection(urlOdbc, "root", "")); * * } catch (Exception e) { * * * //e.printStackTrace(); JOptionPane.showMessageDialog(null, "Ha sido * imposible establecer la conexion!"); } return con; } * * /** * cerramos la conexion en la bd * * @param con */ /* public void CerrarConexion(Connection con) { try { if (con != null) { con.close(); } } catch (SQLException e) { JOptionPane.showMessageDialog(null, "Ha sido imposible cerrar la conexion!"); } } */ public static void initialize_BasicDataSourceFactory() { Properties propiedades = new Properties(); /* setMaxActive(): N mx de conexiones que se pueden abrir simultneamente. setMinIdle(): N mn de conexiones inactivas que queremos que haya. Si el n de conexiones baja de este n, se abriran ms. setMaxIdle(): N mx de conexiones inactivas que queremos que haya. Si hay ms, se irn cerrando. */ propiedades.setProperty("driverClassName", "com.mysql.jdbc.Driver"); propiedades.setProperty("url", "jdbc:mysql://localhost:3306/mysql"); propiedades.setProperty("maxActive", "10"); propiedades.setProperty("maxIdle", "8"); propiedades.setProperty("minIdle", "0"); propiedades.setProperty("maxWait", "5000"); propiedades.setProperty("initialSize", "5"); propiedades.setProperty("defaultAutoCommit", "true"); propiedades.setProperty("username", "root"); propiedades.setProperty("password", ""); propiedades.setProperty("validationQuery", "select 1"); propiedades.setProperty("validationQueryTimeout", "10000"); propiedades.setProperty("initConnectionSqls", "SELECT 1;SELECT 2"); propiedades.setProperty("poolPreparedStatements", "true"); propiedades.setProperty("maxOpenPreparedStatements", "10"); try { //propiedades.load(new FileInputStream("src/config/datasource_config.properties")); Singleton_App.dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(propiedades); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString()); } }