Example usage for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration.

Prototype

public PropertiesConfiguration(URL url) throws ConfigurationException 

Source Link

Document

Creates and loads the extended properties from the specified URL.

Usage

From source file:com.norconex.jefmon.server.JEFMonServer.java

/**
 * Set configuration type by looking for dev.properties file.
 * // w w w .  jav  a2s .  c  om
 * This method must be called very early.
 * 
 * The default behavior is to set as RuntimeConfigurationType.DEPLOYMENT 
 */
private void initRuntimeConfiguration() {

    URL resource = new DefaultClassResolver().getClassLoader().getResource("dev.properties");
    if (resource == null) {
        app.setConfigurationType(RuntimeConfigurationType.DEPLOYMENT);
        return;
    }

    try {
        PropertiesConfiguration properties = new PropertiesConfiguration(resource);
        String value = properties.getString("wicket." + Application.CONFIGURATION,
                RuntimeConfigurationType.DEPLOYMENT.toString());
        app.setConfigurationType(RuntimeConfigurationType.valueOf(value.toUpperCase()));
    } catch (ConfigurationException e) {
        throw new JEFMonException("Exception while reading dev.propeties.", e);
    }
}

From source file:com.netflix.config.WebApplicationProperties.java

protected static void initApplicationProperties() throws ConfigurationException, MalformedURLException {
    File appPropFile = new File(appConfFolder + "/" + baseConfigFileName + ".properties");
    File appEnvPropOverrideFile = new File(
            appConfFolder + "/" + baseConfigFileName + getEnvironment() + ".properties");

    // TODO awang, how do we add this to archaius default config?
    PropertiesConfiguration appConf = new PropertiesConfiguration(appPropFile);
    // apply env overrides
    PropertiesConfiguration overrideConf = new PropertiesConfiguration(appEnvPropOverrideFile);
    Properties overrideprops = ConfigurationUtils.getProperties(overrideConf);
    for (Object prop : overrideprops.keySet()) {
        appConf.setProperty("" + prop, overrideprops.getProperty("" + prop));
    }//  ww  w . j a  v a  2  s . c  o  m
    String path = appPropFile.toURI().toURL().toString();
    System.setProperty(URLConfigurationSource.CONFIG_URL, path);
    ConfigurationManager.loadPropertiesFromConfiguration(appConf);

}

From source file:at.newmedialab.ldclient.service.LDClient.java

public LDClient() {
    log.info("Initialising Linked Data Client Service ...");

    ldEndpoints = new LDEndpoints();
    try {//from  ww  w .  j a va  2 s  .  c  o m
        config = new PropertiesConfiguration("ldclient.properties");
    } catch (ConfigurationException e) {
        log.warn(
                "could not load configuration file ldclient.properties from current directory, home directory, or classpath");
    }

    httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Salzburg NewMediaLab Linked Data Client");

    httpParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, config.getInt("so_timeout", 60000));
    httpParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
            config.getInt("connection_timeout", 10000));

    httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
    httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3);
}

From source file:com.ibm.replication.iidr.utils.Settings.java

/**
 * Load the properties/*from   w  ww. j  a v a2 s .  com*/
 */
private void loadProperties(String propertiesFile) throws ConfigurationException {
    PropertiesConfiguration config = new PropertiesConfiguration(
            System.getProperty("user.dir") + File.separatorChar + "conf" + File.separator + propertiesFile);

    checkFrequencySeconds = config.getInt("checkFrequencySeconds", checkFrequencySeconds);
    connectionResetFrequencyMin = config.getInt("connectionResetFrequencyMin", connectionResetFrequencyMin);

    logMetricsToDB = config.getBoolean("logMetricsToDB", logMetricsToDB);
    logSubscriptionStatusToDB = config.getBoolean("logSubscriptionStatusToDB", logSubscriptionStatusToDB);
    logEventsToDB = config.getBoolean("logEventsToDB", logEventsToDB);

    logMetricsToCsv = config.getBoolean("logMetricsToCsv", logMetricsToCsv);
    logSubscriptionStatusToCsv = config.getBoolean("logSubscriptionStatusToCsv", logSubscriptionStatusToCsv);
    logEventsToCsv = config.getBoolean("logEventsToCsv", logEventsToCsv);

    // Number of events to retrieve
    numberOfEvents = config.getInt("numberOfEvents", numberOfEvents);

    // Access Server settings
    asHostName = config.getString("asHostName");
    asUserName = config.getString("asUserName");
    String encryptedAsPassword = config.getString("asPassword");
    asPort = config.getInt("asPort", 10101);

    // Check if the password has already been encrypted
    // If not, encrypt and save the properties
    try {
        asPassword = Encryptor.decodeAndDecrypt(encryptedAsPassword);
    } catch (EncryptedDataException e) {
        logger.debug("Encrypting asPassword");
        asPassword = encryptedAsPassword;
        encryptedAsPassword = Encryptor.encryptAndEncode(encryptedAsPassword);
        config.setProperty("asPassword", encryptedAsPassword);
        config.save();
    }

    // Metrics to include
    // if (includeMetrics.isEmpty())
    // includeMetricsList = new ArrayList<String>();
    // else
    includeMetricsList = new ArrayList<String>(Arrays.asList(config.getStringArray("includeMetrics")));
    includeMetricsList.removeAll(Arrays.asList(""));

    // Metrics to exclude
    excludeMetricsList = new ArrayList<String>(Arrays.asList(config.getStringArray("excludeMetrics")));
    excludeMetricsList.removeAll(Arrays.asList(""));

    // Database connection settings
    dbHostName = config.getString("dbHostName");
    dbPort = config.getInt("dbPort");
    dbDatabase = config.getString("dbDatabase");
    dbUserName = config.getString("dbUserName");
    String encryptedDbPassword = config.getString("dbPassword");
    dbDriverName = config.getString("dbDriverName");
    dbUrl = config.getString("dbUrl");
    dbSchema = config.getString("dbSchema");

    try {
        dbPassword = Encryptor.decodeAndDecrypt(encryptedDbPassword);
    } catch (EncryptedDataException e) {
        logger.debug("Encrypting dbPassword");
        dbPassword = encryptedDbPassword;
        encryptedDbPassword = Encryptor.encryptAndEncode(encryptedDbPassword);
        config.setProperty("dbPassword", encryptedDbPassword);
        config.save();
    }

    // CSV logging settings
    csvSeparator = config.getString("csvSeparator", csvSeparator);

    // Now report the settings
    logSettings(config);
}

From source file:com.strandls.alchemy.webservices.client.ClientInitModule.java

/**
 * @return configuration for the client.
 *//*from www . j a v  a 2  s.c  o m*/
private Configuration getConfiguration() {
    final CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    try {
        config.addConfiguration(new PropertiesConfiguration(CLIENT_PROPERTIES));
    } catch (final ConfigurationException e) {
        throw new RuntimeException(e);
    }
    return config;
}

From source file:com.dattack.dbtools.drules.DrulesClient.java

private static CompositeConfiguration loadProperties(final String[] propertyFiles)
        throws ConfigurationException {

    final CompositeConfiguration configuration = new CompositeConfiguration();
    configuration.addConfiguration(GlobalConfiguration.getConfiguration());

    if (propertyFiles != null) {
        for (final String filename : propertyFiles) {
            if (StringUtils.isNotBlank(filename)) {
                configuration.addConfiguration(
                        new PropertiesConfiguration(ConfigurationUtil.interpolate(filename, configuration)));
            }// w  w  w .  j  a v  a2s  . c  o  m
        }
    }
    return configuration;
}

From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java

public synchronized static Configuration getConfiguration(ClusterSpec clusterSpec) throws IOException {
    try {/*from w w w.  j a  va  2 s . c  o m*/
        CompositeConfiguration configuration = new CompositeConfiguration();
        if (clusterSpec != null) {
            configuration.addConfiguration(clusterSpec.getConfiguration());
        }
        configuration.addConfiguration(new PropertiesConfiguration(
                CmServerClusterInstance.class.getClassLoader().getResource(CONFIG_WHIRR_DEFAULT_FILE)));
        return configuration;
    } catch (ConfigurationException e) {
        throw new IOException("Error loading " + CONFIG_WHIRR_DEFAULT_FILE, e);
    }
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.resources.BlueprintsResourceSaveTest.java

@Test
public void testSaveGraphResourceNoOption() throws IOException, ConfigurationException {
    resource.save(Collections.EMPTY_MAP);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists() : "Config file does not exist";
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration.containsKey(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE);
    assert configuration.getString(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE)
            .equals(BlueprintsResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE_DEFAULT);
    assert getKeyCount(configuration) == 3 : "Too much content in the .properties file";
}

From source file:gov.nih.nci.cacisweb.action.SecureFTPAddAction.java

@Override
public String execute() throws Exception {
    log.debug("execute() - START");
    String secureFTPPropertyFileLocation = CaCISUtil
            .getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_PROPERTIES_FILE_LOCATION);
    String secureFTPKeystoreLocation = CaCISUtil.getPropertyFromPropertiesFile(secureFTPPropertyFileLocation,
            CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_TRUSTSTORE_LOCATION_PROP_NAME));
    String secureFTPKeystorePassword = CaCISUtil.getPropertyFromPropertiesFile(secureFTPPropertyFileLocation,
            CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_TRUSTSTORE_PASSWORD_PROP_NAME));
    try {//  ww  w.j av  a  2  s .  com
        CaCISUtil caCISUtil = new CaCISUtil();
        KeyStore keystore = caCISUtil.getKeystore(secureFTPKeystoreLocation,
                CaCISWebConstants.COM_KEYSTORE_TYPE_JKS, secureFTPKeystorePassword);

        if (keystore.containsAlias(secureFTPBean.getCertificateAlias())) {
            log.error(getText("secureFTPBean.duplicateKey"));
            addFieldError("secureFTPBean.certificateAlias", getText("secureFTPBean.duplicateKey"));
        }

        if (StringUtils.contains(secureFTPBean.getCertificateAlias(), "ftps")) {
            if (StringUtils.isBlank(secureFTPBean.getCertificateFileName())) {
                log.error(getText("secureFTPBean.certificateRequired"));
                addFieldError("secureFTPBean.certificateFileName",
                        getText("secureFTPBean.certificateRequired"));
                caCISUtil.releaseKeystore();
                return INPUT;
            } else {
                caCISUtil.releaseKeystore();
                FileInputStream certificateStream = new FileInputStream(secureFTPBean.getCertificate());

                CertificateFactory cf = CertificateFactory.getInstance("X.509");
                java.security.cert.Certificate cert = cf.generateCertificate(certificateStream);
                // Add the certificate
                keystore.setCertificateEntry(secureFTPBean.getCertificateAlias(), cert);

                // Save the new keystore contents
                FileOutputStream out = new FileOutputStream(new File(secureFTPKeystoreLocation));
                keystore.store(out, secureFTPKeystorePassword.toCharArray());
                out.close();
            }
        }

        // add the new entry to FTP configuration properties file
        PropertiesConfiguration config = new PropertiesConfiguration(
                CaCISUtil.getProperty(CaCISWebConstants.COM_PROPERTY_NAME_SECFTP_CONFIG_FILE_LOCATION));
        config.setProperty(secureFTPBean.getCertificateAlias(), "");
        config.save();
    } catch (KeystoreInstantiationException kie) {
        log.error(kie.getMessage());
        addActionError(getText("exception.keystoreInstantiation"));
        return ERROR;
    } catch (CertificateException ce) {
        log.error(CaCISUtil.getStackTrace(ce));
        addActionError(getText("exception.certification"));
        return INPUT;
    }
    addActionMessage(getText("secureFTPBean.addCertificateSuccessful"));
    log.debug("execute() - END");
    return SUCCESS;
}

From source file:de.ingrid.portal.interfaces.impl.WMSInterfaceImpl.java

private WMSInterfaceImpl() throws Exception {
    super();//from  w ww .j  a v  a 2  s .  c o m
    String configFilename = getResourceAsStream("/wms_interface.properties");
    config = new PropertiesConfiguration(configFilename);
    mapBenderVersion = config.getString("mapbender_version", MAPBENDER_VERSION_2_1);
}