List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:info.magnolia.cms.beans.config.ConfigLoader.java
/** * Initialize a ConfigLoader instance. All the supplied parameters will be set in * <code>info.magnolia.cms.beans.runtime.SystemProperty</code> * @param context ServletContext// ww w . j a v a 2 s . c om * @param config contains initialization parameters * @see SystemProperty */ public ConfigLoader(ServletContext context, Map config) { String rootDir = context.getRealPath(StringUtils.EMPTY); if (log.isInfoEnabled()) { log.info("Assuming paths relative to {}", rootDir); //$NON-NLS-1$ } SystemProperty.setProperty(SystemProperty.MAGNOLIA_APP_ROOTDIR, rootDir); // load mgnl-beans.properties first InputStream mgnlbeansStream = getClass().getResourceAsStream(MGNL_BEANS_PROPERTIES); if (mgnlbeansStream != null) { Properties mgnlbeans = new Properties(); try { mgnlbeans.load(mgnlbeansStream); } catch (IOException e) { log.error("Unable to load {} due to an IOException: {}", MGNL_BEANS_PROPERTIES, e.getMessage()); } finally { IOUtils.closeQuietly(mgnlbeansStream); } for (Iterator iter = mgnlbeans.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); SystemProperty.setProperty(key, mgnlbeans.getProperty(key)); } } else { log.warn( "{} not found in the classpath. Check that all the needed implementation classes are defined in your custom magnolia.properties file.", MGNL_BEANS_PROPERTIES); } Iterator it = config.entrySet().iterator(); while (it.hasNext()) { Map.Entry param = (Map.Entry) it.next(); SystemProperty.setProperty((String) param.getKey(), (String) param.getValue()); } if (StringUtils.isEmpty(System.getProperty("java.security.auth.login.config"))) { //$NON-NLS-1$ try { System.setProperty("java.security.auth.login.config", Path //$NON-NLS-1$ .getAbsoluteFileSystemPath("WEB-INF/config/jaas.config")); //$NON-NLS-1$ } catch (SecurityException se) { log.error("Failed to set java.security.auth.login.config, check application server settings"); //$NON-NLS-1$ log.error(se.getMessage(), se); log.info("Aborting startup"); return; } } else { if (log.isInfoEnabled()) { log.info("JAAS config file set by parent container or some other application"); //$NON-NLS-1$ log.info("Config in use " + System.getProperty("java.security.auth.login.config")); //$NON-NLS-1$ //$NON-NLS-2$ log.info( "Please make sure JAAS config has all necessary modules (refer config/jaas.config) configured"); //$NON-NLS-1$ } } this.load(context); }
From source file:com.haulmont.cuba.core.sys.CubaMailSender.java
protected Properties createJavaMailProperties() { long connectionTimeoutMillis = config.getSmtpConnectionTimeoutSec() * 1000; long timeoutMillis = config.getSmtpTimeoutSec() * 1000; Properties properties = new Properties(); properties.setProperty("mail.smtp.auth", String.valueOf(config.getSmtpAuthRequired())); properties.setProperty("mail.smtp.starttls.enable", String.valueOf(config.getSmtpStarttlsEnable())); properties.setProperty("mail.smtp.connectiontimeout", String.valueOf(connectionTimeoutMillis)); properties.setProperty("mail.smtp.timeout", String.valueOf(timeoutMillis)); properties.setProperty("mail.smtp.ssl.enable", String.valueOf(config.getSmtpSslEnabled())); Set excludedProperties = new HashSet<>(properties.keySet()); for (String name : AppContext.getPropertyNames()) { if (includeJavaMailProperty(name, excludedProperties)) { String value = AppContext.getProperty(name); if (value != null) { properties.put(name, value); }//w ww. j a v a 2 s. com } } return properties; }
From source file:org.apache.jcs.engine.control.CompositeCacheManager.java
/** * Configure from properties object, overriding with values from the system * properteis if instructed.// w w w . j ava 2s .co m * <p> * You can override a specif value by passing in a ssytem property: * <p> * For example, you could override this value in the cache.ccf file by * starting up your program with the argument: * -Djcs.auxiliary.LTCP.attributes.TcpListenerPort=1111 * * * @param props * @param useSystemProperties -- * if true, values starting with jcs will be put into the props * file prior to configuring the cache. */ public void configure(Properties props, boolean useSystemProperties) { if (props != null) { if (useSystemProperties) { // override any setting with values from the system properties. Properties sysProps = System.getProperties(); Set keys = sysProps.keySet(); Iterator keyIt = keys.iterator(); while (keyIt.hasNext()) { String key = (String) keyIt.next(); if (key.startsWith(SYSTEM_PROPERTY_KEY_PREFIX)) { if (log.isInfoEnabled()) { log.info("Using system property [[" + key + "] [" + sysProps.getProperty(key) + "]]"); } props.put(key, sysProps.getProperty(key)); } } } // set the props value and then configure the ThreadPoolManager ThreadPoolManager.setProps(props); ThreadPoolManager poolMgr = ThreadPoolManager.getInstance(); if (log.isDebugEnabled()) { log.debug("ThreadPoolManager = " + poolMgr); } // configure the cache CompositeCacheConfigurator configurator = new CompositeCacheConfigurator(this); configurator.doConfigure(props); this.props = props; } else { log.error("No properties found. Please configure the cache correctly."); } }
From source file:de.innovationgate.webgate.api.jdbc.pool.DBCPConnectionProvider.java
public void configure(Map propsMap) throws HibernateException { try {//from www . j av a2s . c o m log.debug("Configure DBCPConnectionProvider"); Properties props = new Properties(); props.putAll(propsMap); String jdbcUrl = (String) props.getProperty(Environment.URL); // DBCP properties used to create the BasicDataSource Properties dbcpProperties = new Properties(); // DriverClass & url String jdbcDriverClass = props.getProperty(Environment.DRIVER); // Try to determine driver by jdbc-URL if (jdbcDriverClass == null) { Driver driver = DriverManager.getDriver(jdbcUrl); if (driver != null) { jdbcDriverClass = driver.getClass().getName(); } else { throw new HibernateException("Driver class not available"); } } dbcpProperties.put("driverClassName", jdbcDriverClass); dbcpProperties.put("url", jdbcUrl); // Username / password String username = props.getProperty(Environment.USER); if (username != null) { dbcpProperties.put("username", username); } String password = props.getProperty(Environment.PASS); if (password != null) { dbcpProperties.put("password", password); } // Isolation level String isolationLevel = props.getProperty(Environment.ISOLATION); if ((isolationLevel != null) && (isolationLevel.trim().length() > 0)) { dbcpProperties.put("defaultTransactionIsolation", isolationLevel); } // Turn off autocommit (unless autocommit property is set) String autocommit = props.getProperty(AUTOCOMMIT); if ((autocommit != null) && (autocommit.trim().length() > 0)) { dbcpProperties.put("defaultAutoCommit", autocommit); } else { dbcpProperties.put("defaultAutoCommit", String.valueOf(Boolean.FALSE)); } // Pool size String poolSize = props.getProperty(Environment.POOL_SIZE); if ((poolSize != null) && (poolSize.trim().length() > 0) && (Integer.parseInt(poolSize) > 0)) { dbcpProperties.put("maxActive", poolSize); } // Copy all "driver" properties into "connectionProperties" Properties driverProps = ConnectionProviderInitiator.getConnectionProperties(props); if (driverProps.size() > 0) { StringBuffer connectionProperties = new StringBuffer(); for (Iterator iter = driverProps.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); String value = driverProps.getProperty(key); connectionProperties.append(key).append('=').append(value); if (iter.hasNext()) { connectionProperties.append(';'); } } dbcpProperties.put("connectionProperties", connectionProperties.toString()); } // Copy all DBCP properties removing the prefix for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { String key = String.valueOf(iter.next()); if (key.startsWith(PREFIX)) { String property = key.substring(PREFIX.length()); String value = props.getProperty(key); dbcpProperties.put(property, value); } } // Backward-compatibility if (props.getProperty(DBCP_PS_MAXACTIVE) != null) { dbcpProperties.put("poolPreparedStatements", String.valueOf(Boolean.TRUE)); dbcpProperties.put("maxOpenPreparedStatements", props.getProperty(DBCP_PS_MAXACTIVE)); } if (props.getProperty(DBCP_MAXACTIVE) != null) { dbcpProperties.put("maxTotal", props.getProperty(DBCP_MAXACTIVE)); } if (props.getProperty(DBCP_MAXWAIT) != null) { dbcpProperties.put("maxWaitMillis", props.getProperty(DBCP_MAXWAIT)); } // Some debug info if (log.isDebugEnabled()) { log.debug("Creating a DBCP BasicDataSource with the following DBCP factory properties:"); StringWriter sw = new StringWriter(); dbcpProperties.list(new PrintWriter(sw, true)); log.debug(sw.toString()); } String dbKey = (String) props.get("hibernate.dbcp.dbkey"); String databaseServerId = (String) props.get("hibernate.dbcp.dbserver.id"); // Enable DBCP2 JMX monitoring information if (dbKey != null) { dbcpProperties.put("jmxName", JMX_DBCP2_DBPOOLS_ADDRESS + ",pool=" + JmxManager.normalizeJmxKey(dbKey)); } else if (databaseServerId != null) { String entityTitle = props.getProperty("hibernate.dbcp.dbserver.title"); dbcpProperties.put("jmxName", JMX_DBCP2_SERVERPOOLS_ADDRESS + ",pool=" + JmxManager.normalizeJmxKey(entityTitle)); } // Let the factory create the pool _ds = BasicDataSourceFactory.createDataSource(dbcpProperties); _ds.setLogExpiredConnections(false); // The BasicDataSource has lazy initialization // borrowing a connection will start the DataSource // and make sure it is configured correctly. Connection conn = _ds.getConnection(); conn.close(); // Create Legacy JMX monitoring information, provided by WGA if ("true".equals(props.getProperty("hibernate.dbcp.legacyJMX"))) { try { if (dbKey != null) { _entityKey = dbKey; _entityTitle = dbKey; _jmxManager = new JmxManager(new DBCPPoolInformation(this), new ObjectName(JMX_DBPOOLS_ADDRESS + ",pool=" + JmxManager.normalizeJmxKey(dbKey))); } else if (databaseServerId != null) { _server = true; _entityKey = databaseServerId; _entityTitle = (String) props.get("hibernate.dbcp.dbserver.title"); _jmxManager = new JmxManager(new DBCPPoolInformation(this), new ObjectName( JMX_SERVERPOOLS_ADDRESS + ",pool=" + JmxManager.normalizeJmxKey(_entityTitle))); } } catch (Throwable e) { log.error("Error enabling JMX metrics for connection pool", e); } } } catch (Exception e) { String message = "Could not create a DBCP pool"; if (_ds != null) { try { _ds.close(); } catch (Exception e2) { // ignore } _ds = null; } throw new HibernateException(message, e); } log.debug("Configure DBCPConnectionProvider complete"); }
From source file:org.alfresco.reporting.ReportingHelper.java
public Properties propertyKeyToLowerCase(Properties p) { Properties pp = new Properties(); Iterator<Object> pIterator = p.keySet().iterator(); String key;/* w ww .j a v a2 s .co m*/ while (pIterator.hasNext()) { key = (String) pIterator.next(); pp.setProperty(key.toLowerCase(), p.getProperty(key)); } return pp; }
From source file:org.jbpm.formbuilder.server.form.GuvnorFormDefinitionService.java
@Override public List<FormRepresentation> getForms(String pkgName) throws FormServiceException { HttpClient client = helper.getHttpClient(); GetMethod method = null;/*from w w w . j a v a 2 s. c om*/ try { method = helper.createGetMethod(helper.getApiSearchUrl(pkgName)); helper.setAuth(client, method); client.executeMethod(method); Properties props = new Properties(); props.load(method.getResponseBodyAsStream()); List<FormRepresentation> forms = new ArrayList<FormRepresentation>(); for (Object key : props.keySet()) { String assetId = key.toString(); if (isFormName(assetId)) { FormRepresentation form = getForm(pkgName, assetId.replace(".formdef", "")); forms.add(form); } } return forms; } catch (IOException e) { throw new FormServiceException(e); } catch (Exception e) { if (e instanceof FormServiceException) { throw (FormServiceException) e; } throw new FormServiceException("Unexpected error", e); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:com.activequant.server.web.MainController.java
@RequestMapping("/server") public String server(Map<String, Object> map) { Properties properties = new Properties(); try {//from www . java2 s . c om properties.load(new FileInputStream("framework.properties")); } catch (IOException e) { e.printStackTrace(); } TreeMap<String, Object> tmap2 = new TreeMap<String, Object>(); for (Object s : properties.keySet()) { String key = (String) s; tmap2.put(key, properties.get(key)); } properties = new Properties(); try { properties.load(new FileInputStream("aq2server.properties")); } catch (IOException e) { e.printStackTrace(); } TreeMap<String, Object> tmap = new TreeMap<String, Object>(); for (Object s : properties.keySet()) { String key = (String) s; tmap.put(key, properties.get(key)); } map.put("framework", tmap2); map.put("aq2server", tmap); return "server"; }
From source file:org.jbpm.formbuilder.server.form.GuvnorFormDefinitionService.java
@Override public Map<String, FormItemRepresentation> getFormItems(String pkgName) throws FormServiceException { HttpClient client = helper.getHttpClient(); GetMethod method = null;/* w ww . j a v a2 s. c o m*/ try { method = helper.createGetMethod(helper.getApiSearchUrl(pkgName)); helper.setAuth(client, method); client.executeMethod(method); Properties props = new Properties(); props.load(method.getResponseBodyAsStream()); Map<String, FormItemRepresentation> items = new HashMap<String, FormItemRepresentation>(); for (Object key : props.keySet()) { String assetId = key.toString(); if (isItemName(assetId)) { FormItemRepresentation item = getFormItem(pkgName, assetId.replace(".json", "")); items.put(assetId, item); } } return items; } catch (IOException e) { throw new FormServiceException(e); } catch (Exception e) { if (e instanceof FormServiceException) { throw (FormServiceException) e; } throw new FormServiceException("Unexpected error", e); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:org.apache.geronimo.mavenplugins.geronimo.server.StartServerMojo.java
protected void doExecute() throws Exception { if (install) { installAssembly();/* w ww.j a v a2s . co m*/ } else { log.info("Skipping assembly installation"); if (!geronimoHome.exists()) { throw new MojoExecutionException("Missing pre-installed assembly directory: " + geronimoHome); } } log.info("Starting Geronimo server..."); // Setup the JVM to start the server with final Java java = (Java) createTask("java"); java.setClassname("org.apache.geronimo.cli.daemon.DaemonCLI"); Path path = java.createClasspath(); File libDir = new File(geronimoHome, "lib"); FileSet fileSet = new FileSet(); fileSet.setDir(libDir); path.addFileset(fileSet); java.setDir(geronimoHome); java.setFailonerror(true); java.setFork(true); if (javaVirtualMachine != null) { if (!javaVirtualMachine.exists()) { throw new MojoExecutionException("Java virtual machine is not valid: " + javaVirtualMachine); } log.info("Using Java virtual machine: " + javaVirtualMachine); java.setJvm(javaVirtualMachine.getCanonicalPath()); } if (timeout > 0) { java.setTimeout(new Long(timeout * 1000)); } if (maximumMemory != null) { java.setMaxmemory(maximumMemory); } if (maxPermSize != null) { java.createJvmarg().setValue("-XX:MaxPermSize=" + maxPermSize); } // Load the Java programming language agent for JPA File javaAgentJar = new File(geronimoHome, "lib/agent/transformer.jar"); if (javaAgentJar.exists()) { java.createJvmarg().setValue("-javaagent:" + javaAgentJar.getCanonicalPath()); } // Propagate some properties from Maven to the server if enabled if (propagateGeronimoProperties) { Properties props = System.getProperties(); Iterator iter = props.keySet().iterator(); while (iter.hasNext()) { String name = (String) iter.next(); String value = System.getProperty(name); if (name.equals("geronimo.bootstrap.logging.enabled")) { // Skip this property, never propagate it } else if (name.startsWith("org.apache.geronimo") || name.startsWith("geronimo")) { if (log.isDebugEnabled()) { log.debug("Propagating: " + name + "=" + value); } setSystemProperty(java, name, value); } } } // Apply option sets if (options != null && (optionSets == null || optionSets.length == 0)) { throw new MojoExecutionException("At least one optionSet must be defined to select one using options"); } else if (options == null) { options = "default"; } if (optionSets != null && optionSets.length != 0) { OptionSet[] sets = selectOptionSets(); for (int i = 0; i < sets.length; i++) { if (log.isDebugEnabled()) { log.debug("Selected option set: " + sets[i]); } else { log.info("Selected option set: " + sets[i].getId()); } String[] options = sets[i].getOptions(); if (options != null) { for (int j = 0; j < options.length; j++) { java.createJvmarg().setValue(options[j]); } } Properties props = sets[i].getProperties(); if (props != null) { Iterator iter = props.keySet().iterator(); while (iter.hasNext()) { String name = (String) iter.next(); String value = props.getProperty(name); setSystemProperty(java, name, value); } } } } // Set the properties which we pass to the JVM from the startup script setSystemProperty(java, "org.apache.geronimo.home.dir", geronimoHome); setSystemProperty(java, "karaf.home", geronimoHome); setSystemProperty(java, "karaf.base", geronimoHome); // Use relative path setSystemProperty(java, "java.io.tmpdir", "var/temp"); setSystemProperty(java, "java.endorsed.dirs", prefixSystemPath("java.endorsed.dirs", new File(geronimoHome, "lib/endorsed"))); setSystemProperty(java, "java.ext.dirs", prefixSystemPath("java.ext.dirs", new File(geronimoHome, "lib/ext"))); // set console properties setSystemProperty(java, "karaf.startLocalConsole", "false"); setSystemProperty(java, "karaf.startRemoteShell", "true"); if (quiet) { java.createArg().setValue("--quiet"); } else { java.createArg().setValue("--long"); } if (verbose) { java.createArg().setValue("--verbose"); } if (veryverbose) { java.createArg().setValue("--veryverbose"); } if (startModules != null) { if (startModules.length == 0) { throw new MojoExecutionException("At least one module name must be configured with startModule"); } log.info("Overriding the set of modules to be started"); java.createArg().setValue("--override"); for (int i = 0; i < startModules.length; i++) { java.createArg().setValue(startModules[i]); } } // // TODO: Check if this really does capture STDERR or not! // if (logOutput) { File file = getLogFile(); FileUtils.forceMkdir(file.getParentFile()); log.info("Redirecting output to: " + file); java.setOutput(file); } // Holds any exception that was thrown during startup final ObjectHolder errorHolder = new ObjectHolder(); StopWatch watch = new StopWatch(); watch.start(); // Start the server int a seperate thread Thread t = new Thread("Geronimo Server Runner") { public void run() { try { java.execute(); } catch (Exception e) { errorHolder.set(e); // // NOTE: Don't log here, as when the JVM exists an exception will get thrown by Ant // but that should be fine. // } } }; t.start(); log.info("Waiting for Geronimo server..."); // Setup a callback to time out verification final ObjectHolder verifyTimedOut = new ObjectHolder(); TimerTask timeoutTask = new TimerTask() { public void run() { verifyTimedOut.set(Boolean.TRUE); } }; if (verifyTimeout > 0) { if (log.isDebugEnabled()) { log.debug("Starting verify timeout task; triggers in: " + verifyTimeout + " seconds"); } timer.schedule(timeoutTask, verifyTimeout * 1000); } // Verify server started ServerProxy server = new ServerProxy(hostname, port, username, password); boolean started = false; while (!started) { if (verifyTimedOut.isSet()) { throw new MojoExecutionException("Unable to verify if the server was started in the given time (" + verifyTimeout + " seconds)"); } if (errorHolder.isSet()) { throw new MojoExecutionException("Failed to start Geronimo server", (Throwable) errorHolder.get()); } started = server.isFullyStarted(); if (!started) { Throwable error = server.getLastError(); if ((error != null) && (log.isDebugEnabled())) { log.debug("Server query failed; ignoring", error); } Thread.sleep(5 * 1000); } } server.closeConnection(); // Stop the timer, server should be up now timeoutTask.cancel(); log.info("Geronimo server started in " + watch); if (!background) { log.info("Waiting for Geronimo server to shutdown..."); t.join(); } }
From source file:jp.terasoluna.fw.web.struts.action.GlobalMessageResources.java
/** * ?[g?bZ?[W?AO?bZ?[W\?[Xt@C/* w w w . j a v a 2 s .c o m*/ * ?A?bZ?[W?B * Ot@C???}bvp?B * ?[gt@C??[ht@Cv???A * iv?[v?A?B * * @param prop ?[gv?peBt@C * @param rootProperty ?[gv?peBt@C * @return O?bZ?[W}bv */ private Map<String, String> getAddApplicationMap(Properties prop, String rootProperty) { Map<String, String> addApplicationMap = new HashMap<String, String>(); List<String> fileNameList = new ArrayList<String>(); for (int i = 1;; i++) { // Ot@C String fileName = prop.getProperty(ADD_MESSAGES_FILE + i); if (fileName == null) { // t@C???A?I break; } else if (fileName.equals(rootProperty)) { // ?[gt@Cv?A?I // (iv?[v) break; } fileNameList.add(fileName); } // t@C?A?Ot@C??[h?A // }bv?B Iterator fileNameIt = fileNameList.iterator(); while (fileNameIt.hasNext()) { String outerFileName = (String) fileNameIt.next(); Properties outerProp = PropertyUtil.loadProperties(outerFileName); // Ot@CK? if (outerProp == null) { if (log.isWarnEnabled()) { log.warn("\"" + outerFileName + "\" is illegal."); } continue; } // Ot@CL?[ Iterator outerFileKeyIt = outerProp.keySet().iterator(); while (outerFileKeyIt.hasNext()) { String outerMessageKey = (String) outerFileKeyIt.next(); String outerValue = outerProp.getProperty(outerMessageKey); if (log.isDebugEnabled()) { log.debug("Saving outer-file-application message key [" + outerMessageKey + "]" + "value [" + outerValue + "]"); } addApplicationMap.put(outerMessageKey, outerValue); } } return addApplicationMap; }