Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

In this page you can find the example usage for java.util Properties get.

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:com.glaf.core.jdbc.connection.DruidConnectionProvider.java

public void configure(Properties props) {
    Properties properties = new Properties();
    properties.putAll(props);//from   ww  w  .  j  a v  a 2s  .com

    for (Iterator<Object> ii = props.keySet().iterator(); ii.hasNext();) {
        String key = (String) ii.next();
        if (key.startsWith("druid.")) {
            String newKey = key.substring(6);
            properties.put(newKey, props.get(key));
        }
    }

    Properties connectionProps = ConnectionProviderFactory.getConnectionProperties(properties);
    log.info("Connection properties: " + PropertiesHelper.maskOut(connectionProps, "password"));

    String jdbcDriverClass = properties.getProperty("jdbc.driver");
    String jdbcUrl = properties.getProperty("jdbc.url");

    log.info("Druid using driver: " + jdbcDriverClass + " at URL: " + jdbcUrl);

    autocommit = PropertiesHelper.getBoolean("jdbc.autocommit", properties);
    log.info("autocommit mode: " + autocommit);

    if (jdbcDriverClass == null) {
        log.warn("No JDBC Driver class was specified by property jdbc.driver");
    } else {
        try {
            Class.forName(jdbcDriverClass);
        } catch (ClassNotFoundException cnfe) {
            try {
                ReflectUtils.instantiate(jdbcDriverClass);
            } catch (Exception e) {
                String msg = "JDBC Driver class not found: " + jdbcDriverClass;
                log.error(msg, e);
                throw new RuntimeException(msg, e);
            }
        }
    }

    try {

        Integer maxPoolSize = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXACTIVE, properties);
        Integer maxStatements = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXSTATEMENTS, properties);

        Integer timeBetweenEvictionRuns = PropertiesHelper
                .getInteger(ConnectionConstants.PROP_TIMEBETWEENEVICTIONRUNS, properties);

        Integer maxWait = PropertiesHelper.getInteger(ConnectionConstants.PROP_MAXWAIT, properties);

        String validationQuery = properties.getProperty(ConnectionConstants.PROP_VALIDATIONQUERY);

        if (maxPoolSize == null) {
            maxPoolSize = 50;
        }

        if (timeBetweenEvictionRuns == null) {
            timeBetweenEvictionRuns = 60;
        }

        if (maxWait == null) {
            maxWait = 60;
        }

        String dbUser = properties.getProperty("jdbc.user");
        String dbPassword = properties.getProperty("jdbc.password");

        if (dbUser == null) {
            dbUser = "";
        }

        if (dbPassword == null) {
            dbPassword = "";
        }

        ds = new DruidDataSource();

        DruidDataSourceFactory.config(ds, properties);
        ds.setConnectProperties(properties);
        ds.setDriverClassName(jdbcDriverClass);
        ds.setUrl(jdbcUrl);
        ds.setUsername(dbUser);
        ds.setPassword(dbPassword);

        ds.setInitialSize(1);
        ds.setMinIdle(3);
        ds.setMaxActive(maxPoolSize);
        ds.setMaxWait(maxWait * 1000L);

        ds.setConnectionErrorRetryAttempts(30);
        ds.setDefaultAutoCommit(true);

        ds.setTestOnReturn(false);
        ds.setTestOnBorrow(false);
        ds.setTestWhileIdle(false);

        if (StringUtils.isNotEmpty(validationQuery)) {
            log.debug("validationQuery:" + validationQuery);
            ds.setValidationQuery(validationQuery);
            ds.setTestWhileIdle(true);// ??????
        }

        ds.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRuns * 1000L);// ??
        ds.setMinEvictableIdleTimeMillis(1000L * 60L * 120L);// ????

        if (maxStatements != null) {
            ds.setPoolPreparedStatements(true);
            ds.setMaxOpenPreparedStatements(maxStatements);
            ds.setMaxPoolPreparedStatementPerConnectionSize(200);
        }

        ds.setRemoveAbandoned(false);// ? true/false
        ds.setRemoveAbandonedTimeout(7200);// 120
        ds.setLogAbandoned(true);// ?

        ds.init();
    } catch (Exception ex) {
        ex.printStackTrace();
        log.error("could not instantiate Druid connection pool", ex);
        throw new RuntimeException("Could not instantiate Druid connection pool", ex);
    }

    String i = properties.getProperty("jdbc.isolation");
    if (i == null) {
        isolation = null;
    } else {
        isolation = new Integer(i);
    }

}

From source file:de.codesourcery.eve.skills.ui.config.AppConfig.java

public void load() throws IOException {

    log.debug("load(): Loading app config from " + file);

    if (file.exists()) {
        final Properties props = new Properties();
        final Reader instream = new FileReader(file);
        try {//from   w ww  .  j a  va2s  . co  m
            props.load(instream);
            clear();
            setDefaults();
            for (String key : props.stringPropertyNames()) {
                put(key, (String) props.get(key));
            }
        } finally {
            instream.close();
        }
    }
}

From source file:com.elasticgrid.examples.video.VideoConverterJSBTest.java

@BeforeTest
public void setupAWS() throws IOException, S3ServiceException {
    Properties awsProperties = new Properties();
    File awsPropertiesFile = new File(System.getProperty("user.home") + File.separatorChar + ".eg",
            "aws.properties");
    InputStream stream = null;/*  w  w  w.j a  v  a2  s.  c  o m*/
    try {
        stream = new FileInputStream(awsPropertiesFile);
        awsProperties.load(stream);
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Can't load Amazon Web Services property file from $HOME/.eg/aws.properties");
    } finally {
        IOUtils.closeQuietly(stream);
    }
    awsAccessId = (String) awsProperties.get("aws.accessId");
    awsSecretKey = (String) awsProperties.get("aws.secretKey");
    s3 = new RestS3Service(new AWSCredentials(awsAccessId, awsSecretKey));
}

From source file:com.atex.confluence.plugin.nexus.MavenInfoMacro.java

private String readSpecificProperty(Properties properties, String key) {
    String result = "";
    if (key != null && !key.isEmpty()) {
        result = (String) properties.get(key);
        if (result == null) {
            return "";
        }/*from   w w w.  j a  v  a 2  s  .c om*/
        return result.trim();
    }
    return result;
}

From source file:podd.util.WebappInitializationUtil.java

private User createRepoAdminUser(Resource resource) {
    try {//from   www.  jav a 2 s  .  co  m
        File propertyFile = resource.getFile();
        final FileReader fileReader = new FileReader(propertyFile);
        Properties properties = new Properties();
        properties.load(fileReader);

        // try to load the user and if it doesn't exist create a new one
        String username = properties.get(USERNAME_KEY).toString();
        User admin = userDao.loadByUserName(username);
        if (null == admin) {
            admin = entityFactory.createUser(null);
        }
        // add properties to the user
        for (Object key : properties.keySet()) {
            final String value = properties.get(key).toString();
            String methodName = getSetterMethodName((String) key);
            final Method method = User.class.getDeclaredMethod(methodName, String.class);
            method.invoke(admin, value);
        }
        admin.setStatus(ACTIVE);
        admin.setRepositoryRole(rrDao.getRepositoryRole(REPOSITORY_ADMINISTRATOR.getName()));
        LOGGER.info("Creating repository administrator user: " + admin.getUserName());
        userDao.saveOrUpdate(admin);
        return admin;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:podd.util.WebappInitializationUtil.java

private void createDefaultDatastore(Resource resource) {
    if (null == resource)
        return;//  w  w  w . ja va 2  s  .co  m
    try {
        File propertyFile = resource.getFile();
        final FileReader fileReader = new FileReader(propertyFile);
        Properties properties = new Properties();
        properties.load(fileReader);

        // try to load the datastore and if it doesn't exist create a new one
        String ip = properties.get("ip").toString();
        int port = Integer.parseInt(properties.get("port").toString());
        String login = properties.get("login").toString();
        String defaultDirectory = properties.get("defaultDirectory").toString();
        Datastore datastore = datastoreRegistryDao.loadByIP(ip);
        if (null == datastore) {
            datastore = new Datastore(ip, port, login, defaultDirectory);
        } else {
            datastore.setPort(port);
            datastore.setLoginId(login);
            datastore.setDefaultDirectory(defaultDirectory);
        }
        datastore.setAccessMethod(properties.get("accessMethod").toString());
        LOGGER.info("Creating default datastore: " + datastore.getLoginId() + "@" + datastore.getIp() + ":"
                + datastore.getPort());
        datastoreRegistryDao.saveOrUpdate(datastore);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:dk.netarkivet.harvester.harvesting.controller.AbstractJMXHeritrixController.java

/**
 * Write various info on the system we're using into the given file. This
 * info will later get put into metadata for the crawl.
 *
 * @param outputFile/*  w ww.  j  a v  a2 s .  c  o m*/
 *            A file to write to.
 * @param builder
 *            The ProcessBuilder being used to start the Heritrix process
 */
@SuppressWarnings("unchecked")
private void writeSystemInfo(File outputFile, ProcessBuilder builder) {
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(new FileWriter(outputFile));
        writer.println("The Heritrix process is started in the following"
                + " environment\n (note that some entries will be" + " changed by the starting JVM):");
        Map<String, String> env = builder.environment();
        List<String> keyList = new ArrayList<String>(env.keySet());
        Collections.sort(keyList);
        for (String key : keyList) {
            writer.println(key + "=" + env.get(key));
        }
        writer.println("Process properties:");
        Properties properties = System.getProperties();
        keyList = new ArrayList<String>((Set) properties.keySet());
        Collections.sort(keyList);
        for (String key : keyList) {
            writer.println(key + "=" + properties.get(key));
        }
    } catch (IOException e) {
        log.warn("Error writing basic properties to output file.", e);
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}

From source file:podd.util.WebappInitialisationUtil.java

private User createRepoAdminUser(Resource resource) {
    try {/*from  w  w w.  j  av a2s .c o  m*/
        File propertyFile = resource.getFile();
        final FileReader fileReader = new FileReader(propertyFile);
        Properties properties = new Properties();
        properties.load(fileReader);

        // try to load the user and if it doesn't exist create a new one
        String username = properties.get(USERNAME_KEY).toString();
        User admin = userDao.loadByUserName(username);
        if (null == admin) {
            admin = entityFactory.createUser(null);
        }
        // add properties to the user
        for (Object key : properties.keySet()) {
            final String value = properties.get(key).toString();
            String methodName = getSetterMethodName((String) key);
            final Method method = User.class.getDeclaredMethod(methodName, String.class);
            method.invoke(admin, value);
        }
        admin.setStatus(ACTIVE);
        admin.setRepositoryRole(rrDao.getRepositoryRole(RepositoryRole.REPOSITORY_ADMINISTRATOR.getName()));
        logger.info("Creating repository administrator user: " + admin.getUserName());
        userDao.saveOrUpdate(admin);
        return admin;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:podd.util.WebappInitialisationUtil.java

private void createDefaultDatastore(Resource resource) {
    if (null == resource)
        return;/* ww w  .j  a  v a2  s. c o m*/
    try {
        File propertyFile = resource.getFile();
        final FileReader fileReader = new FileReader(propertyFile);
        Properties properties = new Properties();
        properties.load(fileReader);

        // try to load the datastore and if it doesn't exist create a new one
        String ip = properties.get("ip").toString();
        int port = Integer.parseInt(properties.get("port").toString());
        String login = properties.get("login").toString();
        String defaultDirectory = properties.get("defaultDirectory").toString();
        Datastore datastore = datastoreRegistryDao.loadByIP(ip);
        if (null == datastore) {
            datastore = new Datastore(ip, port, login, defaultDirectory);
        } else {
            datastore.setPort(port);
            datastore.setLoginId(login);
            datastore.setDefaultDirectory(defaultDirectory);
        }
        datastore.setAccessMethod(properties.get("accessMethod").toString());
        logger.info("Creating default datastore: " + datastore.getLoginId() + "@" + datastore.getIp() + ":"
                + datastore.getPort());
        datastoreRegistryDao.saveOrUpdate(datastore);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.vmware.vfabric.hyperic.plugin.vfws.VfwsServerDetector.java

private List<ServerResource> getServers(List<String> ptqlQueries) {
    List<ServerResource> servers = new ArrayList<ServerResource>();
    // Flag to track success
    Boolean success = false;/*ww w.j a va 2  s.co m*/
    for (final Iterator<String> it = ptqlQueries.iterator(); it.hasNext();) {
        String ptql = (String) it.next();
        final long[] pids = getPids(ptql);
        if (null != pids && pids.length > 0) {
            for (int i = 0; i < pids.length; i++) {
                Long pid = pids[i];
                String installPath = getInstallPath(pid);
                if (null == installPath) {
                    _log.debug("Found pid " + pid + ", but couldn't identify installpath");
                    continue;
                }
                URL bmxUrl = findBmxUrl(installPath, HTTPD_CONF);
                if (bmxUrl == null) {
                    _log.debug("Parsing " + installPath + HTTPD_CONF + " failed to find "
                            + "usable Listen directive.");
                    continue;
                }
                URL bmxQueryUrl = getBmxQueryUrl(bmxUrl, QUERY_BMX + SERVER_STATUS);
                BmxQuery query = new BmxQuery(bmxQueryUrl);
                BmxResult result = query.getResult();
                try {
                    result.parseToProperties();
                    success = true;
                } catch (IOException e) {
                    _log.debug("Unable to parse results", e);
                    continue;
                }
                Properties serverStatus = result.getProperties();
                ServerResource server = createServerResource(installPath);
                ConfigResponse cprop = new ConfigResponse();
                String version = getVersion((String) serverStatus.get("ServerVersion"));
                if (version == null) {
                    // avoid java.lang.NullPointerException when PivotalWebServer 
                    continue;
                }
                if (!version.equals(getTypeInfo().getVersion())) {
                    // Version not matched
                    continue;
                }
                cprop.setValue("version", version);
                cprop.setValue("ServerVersion", (String) serverStatus.get("ServerVersion"));
                server.setCustomProperties(cprop);
                ConfigResponse productConfig = new ConfigResponse();
                productConfig.setValue("process.query", getProcessQuery(ptql, installPath));
                productConfig.setValue("protocol", bmxUrl.getProtocol());
                productConfig.setValue("port", bmxUrl.getPort());
                productConfig.setValue("hostname", bmxUrl.getHost());
                productConfig.setValue("path", bmxUrl.getPath() + QUERY_BMX + SERVER_STATUS);
                setProductConfig(server, productConfig);
                // sets a default Measurement Config property with no values
                setMeasurementConfig(server, new ConfigResponse());
                ConfigResponse controlConfig = getControlConfig(installPath);
                String instanceName = getInstanceName(installPath);
                setControlConfig(server, controlConfig);
                server.setName(getPlatformName() + " " + getServerName(RESOURCE_TYPE) + " " + version + " "
                        + instanceName);
                server.setDescription(getServerDescription(server.getInstallPath()));
                servers.add(server);
            }
            if (!success) {
                // may not be an error.
                _log.debug(
                        "[getServers] Found potential VFWS process however was unable to determine URL of mod_bmx");
                _log.debug(
                        "[getServers] Make sure -d is specified on command line and that proxying or redirecting isn't including /bmx");
            }
        }
    }
    return servers;
}