Example usage for java.util Properties getProperty

List of usage examples for java.util Properties getProperty

Introduction

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

Prototype

public String getProperty(String key) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:fm.last.moji.integration.AbstractMojiIT.java

private static void initMoji() throws IOException {
    String env = System.getProperty("env", "");
    if (!"".equals(env)) {
        env = "." + env;
    }//w ww  .  j av  a 2s  .  c o  m
    Properties properties = new Properties();
    properties.load(AbstractMojiIT.class.getResourceAsStream("/moji.properties" + env));

    String hosts = properties.getProperty("moji.tracker.hosts");
    String domain = properties.getProperty("moji.domain");

    keyPrefix = properties.getProperty("test.moji.key.prefix");
    storageClassA = properties.getProperty("test.moji.class.a");
    storageClassB = properties.getProperty("test.moji.class.b");

    moji = new SpringMojiBean();
    moji.setAddressesCsv(hosts);
    moji.setDomain(domain);
    moji.initialise();
    moji.setTestOnBorrow(true);
}

From source file:gov.pnnl.cloud.KinesisApplication.java

/**
 * @param propertiesFile//  www. j a va2 s.c o m
 * @throws IOException Thrown when we run into issues reading properties
 */
private static void loadProperties(String propertiesFile) throws IOException {
    FileInputStream inputStream = new FileInputStream(propertiesFile);
    Properties properties = new Properties();
    try {
        properties.load(inputStream);
    } finally {
        inputStream.close();
    }

    String appNameOverride = properties.getProperty(ConfigKeys.APPLICATION_NAME_KEY);
    if (appNameOverride != null) {
        applicationName = appNameOverride;
    }
    LOG.info("Using application name " + applicationName);

    String streamNameOverride = properties.getProperty(ConfigKeys.STREAM_NAME_KEY);
    if (streamNameOverride != null) {
        streamName = streamNameOverride;
    }
    LOG.info("Using stream name " + streamName);

    String kinesisEndpointOverride = properties.getProperty(ConfigKeys.KINESIS_ENDPOINT_KEY);
    if (kinesisEndpointOverride != null) {
        kinesisEndpoint = kinesisEndpointOverride;
    }
    LOG.info("Using Kinesis endpoint " + kinesisEndpoint);

    String initialPositionOverride = properties.getProperty(ConfigKeys.INITIAL_POSITION_IN_STREAM_KEY);
    if (initialPositionOverride != null) {
        initialPositionInStream = InitialPositionInStream.valueOf(initialPositionOverride);
    }
    LOG.info("Using initial position " + initialPositionInStream.toString()
            + " (if a checkpoint is not found).");

    String kafkaBrokerListProperty = properties.getProperty(ConfigKeys.KAFKA_BROKER_LIST);
    if (kafkaBrokerListProperty == null) {
        throw new IOException("kafkaBrokerList cannot be null");
    }
    kafkaBrokerList = kafkaBrokerListProperty;
    LOG.info("Using Kafka broker list " + kafkaBrokerList);

}

From source file:com.leosys.core.utils.HttpServiceImpl.java

public static String getZiku(String domin) {
    Properties p = new Properties();
    String urls = getXmlPath();// w  ww . j a v  a2s .c  o m
    try {
        p.load(new FileInputStream(urls));
    } catch (Exception e) {
        e.printStackTrace();
    }
    String subUrl = p.getProperty("path");
    String restUrl = subUrl + "model=myservice&action=getwebsiteziku&domain=" + domin + "&pagesize=1000";
    StringBuffer strBuf;
    strBuf = new StringBuffer();

    try {
        URL url = new URL(restUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");

        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));//?  
        String line = null;
        while ((line = reader.readLine()) != null)
            strBuf.append(line + " ");
        reader.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println(strBuf.toString());

    return strBuf.toString();
}

From source file:com.webkruscht.wmt.DownloadFiles.java

private static void getProperties() throws IOException {
    Properties p = new Properties();
    String propFile = "wmt.properties";
    InputStream propStream = DownloadFiles.class.getClassLoader().getResourceAsStream(propFile);
    p.load(propStream);/*  w ww . ja  v  a 2  s  .co m*/
    propStream.close();
    username = p.getProperty("username");
    password = p.getProperty("password");
    filePath = p.getProperty("filePath");
}

From source file:dk.alexandra.fresco.suite.bgw.configuration.BgwConfiguration.java

public static BgwConfiguration fromCmdLine(SCEConfiguration sceConf, CommandLine cmd) throws ParseException {
    // Validate BGW specific arguments.
    Properties p = cmd.getOptionProperties("D");
    if (!p.containsKey("bgw.threshold")) {
        throw new ParseException("BGW requires setting -Dbgw.threshold=[int]");
    }/*www .  j ava 2s.  com*/

    try {
        final int threshold = Integer.parseInt(p.getProperty("bgw.threshold"));
        if (threshold < 1)
            throw new ParseException("bgw.threshold must be > 0");
        if (threshold > sceConf.getParties().size() / 2)
            throw new ParseException("bgw.threshold must be < n/2");

        final BigInteger modulus = new BigInteger(p.getProperty("bgw.modulus", "618970019642690137449562111"));
        if (!modulus.isProbablePrime(40)) {
            throw new ParseException("BGW Modulus must be a prime number");
        }

        return new BgwConfiguration() {

            @Override
            public int getThreshold() {
                return threshold;
            }

            @Override
            public BigInteger getModulus() {
                return modulus;
            }

        };
    } catch (NumberFormatException e) {
        throw new ParseException("Invalid bgw.threshold value: '" + p.getProperty("bgw.threshold") + "'");
    }
}

From source file:cn.edu.zju.acm.onlinejudge.persistence.sql.Database.java

/**
 * Gets the given string property/* w w w. java 2 s . co  m*/
 * 
 * @param properties
 *            properties
 * @param key
 *            property key
 * @return the property value in string
 */
private static String getStringProperty(Properties properties, String key) throws PersistenceException {
    String value = properties.getProperty(key);
    if (value == null) {
        throw new PersistenceException(key + " property is missing in " + Database.CONFIG_FILE);
    }
    return value;
}

From source file:com.leosys.core.utils.HttpServiceImpl.java

public static String getMyitem(String letter, Integer page) {
    Properties p = new Properties();
    String urls = getXmlPath();/* w w  w  .  j ava2s .  co  m*/
    try {
        p.load(new FileInputStream(urls));
    } catch (Exception e) {
        e.printStackTrace();
    }
    String subUrl = p.getProperty("path");
    String restUrl = subUrl + "model=myservice&action=getwebdomainsitebypage&page=" + page + "&pagesize=10";
    if (StringUtils.isNotEmpty(letter)) {
        restUrl += "&letter=" + letter;
    }
    StringBuffer strBuf;
    strBuf = new StringBuffer();

    try {
        URL url = new URL(restUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));//?  
        String line = null;
        while ((line = reader.readLine()) != null)
            strBuf.append(line + " ");
        reader.close();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println(strBuf.toString());
    return strBuf.toString();
}

From source file:org.eclipse.lyo.testsuite.server.trsutils.FetchUtil.java

/**
 * This method attempts to authenticate with a server using OAuth two 
 * legged authentication.  A functional user with a consumer key and secret
 * must have already been created on the resource server and specified in
 * the config.properties file./*from  w  ww . jav  a2  s.c  om*/
 * 
 * @param httpClient
 * @param httpContext
 * @param get
 * @param uri
 * @return
 * @throws ClientProtocolException
 * @throws IOException
 * @throws URISyntaxException
 */
private static Model perform2LeggedOauth(HttpClient httpClient, HttpContext httpContext, HttpGet get,
        String uri) throws ClientProtocolException, IOException, URISyntaxException {
    // Get the necessary OAuth values from the config.properties file
    Properties prop = TestCore.getConfigPropertiesInstance();
    String consumerKey = prop.getProperty("consumerKey");
    String consumerSecret = prop.getProperty("consumerSecret");
    String authorizationTokenURL = prop.getProperty("OAuthURL");
    String oAuthRealm = prop.getProperty("OAuthRealm");

    // Using the information from the config.properties file
    // construct the authentication header to use in our GET request
    OAuthServiceProvider provider = new OAuthServiceProvider(null, authorizationTokenURL, null);
    OAuthConsumer consumer = new OAuthConsumer("", consumerKey, consumerSecret, provider);
    OAuthAccessor accessor = new OAuthAccessor(consumer);
    accessor.accessToken = "";

    Model model = null;

    try {
        OAuthMessage message = accessor.newRequestMessage(HttpMethod.GET, uri, null);
        String authHeader = message.getAuthorizationHeader(oAuthRealm);

        get.setHeader("Authorization", authHeader);
        get.setHeader("OSLC-Core-Version", "2.0");

        model = httpClient.execute(get, new RDFModelResponseHandler(uri), httpContext);
    } catch (OAuthException e) {
        TestCore.terminateTest(Messages.getServerString("fetch.util.authentication.failure"), e);
    }

    return model;
}

From source file:com.mgmtp.jfunk.core.config.ModulesLoader.java

/**
 * Loads Guice modules whose class names are specified as properties. All properties starting
 * with "module." are considered to have a fully qualified class name representing a Guice
 * module. The modules are combined and override thespecified jFunkModule.
 * /*from  w  w w  .  j  a  v  a  2s.co  m*/
 * @param propertiesFile
 *            The properties file
 * @return the combined module
 */
public static Module loadModulesFromProperties(final Module jFunkModule, final String propertiesFile)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    final List<Module> modules = Lists.newArrayList();

    LOG.debug("Using jfunk.props.file=" + propertiesFile);
    Properties props = loadProperties(propertiesFile);

    for (final Enumeration<?> en = props.propertyNames(); en.hasMoreElements();) {
        String name = (String) en.nextElement();
        if (name.startsWith("module.")) {
            String className = props.getProperty(name);
            LOG.info("Loading " + name + "=" + className);
            Class<? extends Module> moduleClass = Class.forName(className).asSubclass(Module.class);
            Module module = moduleClass.newInstance();
            modules.add(module);
        }
    }
    return Modules.override(jFunkModule).with(modules);
}

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  www  . ja  v  a2s . c  om
        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);

    }

}