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:eu.eco2clouds.accounting.conf.ConfigurationTest.java

@Test
public void loadMonitoringPropertiesFile() {

    String propertiesFile = "MonitoringCollector.properties";

    File f = new File(etcConfiguration);
    if (f.exists()) {
        propertiesFile = etcConfiguration;
    }// w w  w  . j a v a  2 s .  c o  m

    org.apache.commons.configuration.Configuration config;
    try {
        config = new PropertiesConfiguration(propertiesFile);

        assertEquals("root", config.getString("mysql.username"));
        assertEquals("1234", config.getString("mysql.password"));
        assertEquals("localhost/metricsdb", config.getString("mysql.host"));

    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:hu.netmind.beankeeper.config.impl.ConfigurationTrackerImpl.java

public void init(Map parameters) {
    try {/*from  ww w  .  jav  a 2s . co m*/
        // Initialize with property reader configuration
        setConfiguration(new PropertiesConfiguration("beankeeper.properties"));
    } catch (Exception e) {
        throw new StoreException("fatal error, could not load default configuration", e);
    }
}

From source file:dk.itst.oiosaml.configuration.SAMLConfiguration.java

/**
 * Get the current system configuration. 
 * The configuration is stored in {@link SAMLUtil#OIOSAML_HOME}. The property is normally set in {@link SPFilter}.
 * @throws IllegalStateException When the system has not been configured properly yet.
 *///from w w w . j  a  v  a2 s  .  c om
public static Configuration getSystemConfiguration() throws IllegalStateException {
    if (systemConfiguration != null)
        return systemConfiguration;

    if (home == null || !isConfigured()) {
        throw new IllegalStateException("System not configured");
    }

    CompositeConfiguration conf = new CompositeConfiguration();
    conf.setProperty("oiosaml.home", home);

    try {
        conf.addConfiguration(new PropertiesConfiguration(new File(home, name + ".properties")));
        conf.addConfiguration(getCommonConfiguration());

        systemConfiguration = conf;
        return systemConfiguration;
    } catch (ConfigurationException e) {
        log.error("Cannot load the configuration file", e);
        throw new WrappedException(Layer.DATAACCESS, e);
    } catch (IOException e) {
        log.error("Unable to load oiosaml-common.propeties from classpath", e);
        throw new WrappedException(Layer.DATAACCESS, e);
    }
}

From source file:fr.dudie.acrachilisync.utils.IssueDescriptionReaderTest.java

/**
 * Load the application test configuration before the tests.
 * //from   w ww.  j a  v a 2  s .  c  om
 * @throws ConfigurationException
 *             the configuration cannot be loaded
 */
@BeforeClass
public static void loadConfiguration() throws ConfigurationException {

    configuration = ConfigurationManager.getInstance(new PropertiesConfiguration("acrachilisync.properties"));
}

From source file:com.denimgroup.threadfix.cli.HttpRestUtilsTests.java

@Test
public void testSetUrl() {
    PropertiesManager utils = new PropertiesManager();
    utils.setUrl(TestPropertiesManager.URL);
    try {/* www. j  ava  2 s.  c  o m*/
        Configuration properties = new PropertiesConfiguration("threadfix.properties");
        assertEquals(TestPropertiesManager.URL, properties.getString("url"));
    } catch (ConfigurationException e) {
        assertFalse(true);
    }
}

From source file:net.cheesecan.cheeselobby.io.SettingsFile.java

public SettingsFile() {
    filename = "cheeselobby.properties";

    // Does file exist, if not, create
    boolean exists = true;
    File file = new File(filename);
    if (!file.exists()) {
        try {//w  ww.  ja v  a 2 s  . c om
            exists = false;
            file.createNewFile();
        } catch (IOException ex) {
            Logger.getLogger(SettingsFile.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    // Load file
    try {
        config = new PropertiesConfiguration(filename);
    } catch (ConfigurationException ex) {
        Logger.getLogger(SettingsFile.class.getName()).log(Level.SEVERE, null, ex);
    }

    // If did not exist
    if (!exists) {
        createFile();
    }
}

From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NameBeginsFilter.java

/**
 * This creates a name filter that checks to see if the start of a host name
 * matches particular criteria or not. if it does then it will indicate accordingly
 * that the "Zabbix JSON API host" is a host or VM.
 *//*  w  w  w  .  j a v  a 2 s  . c o  m*/
public NameBeginsFilter() {
    try {
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {
            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        begins = config.getString("data.logger.filter.begins", begins);
        config.setProperty("data.logger.filter.begins", begins);
        isHost = config.getBoolean("data.logger.filter.isHost", isHost);
        config.setProperty("data.logger.filter.isHost", isHost);
    } catch (ConfigurationException ex) {
        Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO,
                "Error loading the configuration of the name begins filter");
    }
}

From source file:com.cisco.oss.foundation.monitoring.service.TestMultiService.java

@Test
public void testManyServices() throws Exception {

    MonitoringAgentFactory.getInstance().register(
            new PropertiesConfiguration(TestMultiService.class.getResource("/config.properties").getPath()));

    ExecutorService threadPool = Executors.newFixedThreadPool(10);

    int numOfServices = 1234;

    final CountDownLatch latch = new CountDownLatch(numOfServices);

    final ServiceDetails serviceDetails = new ServiceDetails("default desc", "test", "junit", 12345);
    for (int i = 0; i < numOfServices; i++) {

        final int index = i;

        threadPool.execute(new Runnable() {

            @Override//from   w w w  . j a v a 2s  . c om
            public void run() {
                String apiName = (index % 3) + "";
                CommunicationInfo.getCommunicationInfo().transactionStarted(serviceDetails, apiName, 125);
                try {
                    Thread.sleep(2);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, apiName,
                        (index % 2 == 0) ? false : true, "kuku");
                latch.countDown();
            }
        });
    }

    try {
        latch.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    int numberOfThreads = Thread.getAllStackTraces().keySet().size();
    Assert.assertTrue(numberOfThreads <= 30);

    try {
        Thread.sleep(1500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    Collection<Service> services = ServiceInfo.INSTANCE.getServices();
    System.out.println("services: " + services.size());

    for (Service service : services) {
        System.out.println("service: " + service + ". total: " + service.getTotalRequestCount());
    }

    Assert.assertEquals(3, services.size());

    //        try {
    //            Thread.sleep(60000);
    //        } catch (InterruptedException e) {
    //            e.printStackTrace();
    //        }

}

From source file:com.lehman.ic9.io.config.java

/**
 * Loads the configuration from the provided file name.
 * @param FileName is a String with the config file to load.
 * @throws ic9exception if something goes wrong.
 *///from   www  .j ava  2  s  . c  o m
public void load(String FileName) throws ic9exception {
    try {
        this.config = new PropertiesConfiguration(FileName);
    } catch (ConfigurationException e) {
        throw new ic9exception("config.load(): ConfigurationException: " + e.getMessage());
    }
}

From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NameEndsFilter.java

/**
 * This creates a name filter that checks to see if the end of a host name
 * matches particular criteria or not. if it does then it will indicate accordingly
 * that the "Zabbix JSON API host" is a host or VM.
 *///from   w ww . j ava  2s  . c  om
public NameEndsFilter() {
    try {
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {
            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        ends = config.getString("data.logger.filter.begins", ends);
        config.setProperty("data.logger.filter.begins", ends);
        isHost = config.getBoolean("data.logger.filter.isHost", isHost);
        config.setProperty("data.logger.filter.isHost", isHost);
    } catch (ConfigurationException ex) {
        Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO,
                "Error loading the configuration of the name ends filter");
    }
}