Example usage for org.apache.commons.configuration ConfigurationException getCause

List of usage examples for org.apache.commons.configuration ConfigurationException getCause

Introduction

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

Prototype

public Throwable getCause() 

Source Link

Usage

From source file:eu.optimis.tf.ip.service.utils.PropertiesUtils.java

public static PropertiesConfiguration getPropertiesConfiguration(String configFile) {
    String filePath = null;// w  w w  .j  a va  2  s.c  o  m
    PropertiesConfiguration config = null;
    filePath = file4OS(configFile);
    try {
        config = new PropertiesConfiguration(filePath);
    } catch (ConfigurationException e) {
        log.error("TRUST: Error reading " + filePath + " configuration file: " + e.getMessage());
        log.error(e.getCause().getMessage());
    }
    return config;
}

From source file:com.netflix.config.util.ConfigurationUtils.java

public static AbstractConfiguration getConfigFromPropertiesFile(URL startingUrl, Set<String> loaded,
        String... nextLoadKeys) throws FileNotFoundException {
    if (loaded.contains(startingUrl.toExternalForm())) {
        logger.warn(startingUrl + " is already loaded");
        return null;
    }/*from   w  w  w.  j  a  va  2  s.c o  m*/
    PropertiesConfiguration propConfig = null;
    try {
        propConfig = new OverridingPropertiesConfiguration(startingUrl);
        logger.info("Loaded properties file " + startingUrl);
    } catch (ConfigurationException e) {
        Throwable cause = e.getCause();
        if (cause instanceof FileNotFoundException) {
            throw (FileNotFoundException) cause;
        } else {
            throw new RuntimeException(e);
        }
    }

    if (nextLoadKeys == null) {
        return propConfig;
    }
    String urlString = startingUrl.toExternalForm();
    String base = urlString.substring(0, urlString.lastIndexOf("/"));
    loaded.add(startingUrl.toString());
    loadFromPropertiesFile(propConfig, base, loaded, nextLoadKeys);
    return propConfig;
}

From source file:net.yoomai.virgo.spider.Emulator.java

public Emulator() {
    try {/* w w  w.j  ava 2 s .  c o  m*/
        config = new PropertiesConfiguration("global.properties");
    } catch (ConfigurationException e) {
        log.error("?Config?: " + e.getCause());
    }
}

From source file:org.accada.reader.rprm.core.ReaderDevice.java

/**
 * Resets all internal state variables of the reader to a default
 * configuration. The documentation of the reader shall provide a definition
 * what the default settings are//from  ww w.j  a  v a  2  s. co m
 * @param propFile
 *           The location of the property file
 * @throws ReaderProtocolException
 *            "Reader not found", "Failed to read properties file",
 *            "wrong valueTrigger in property file", "wrong edgeTrigger in
 *            property file"
 */
public final void resetToDefaultSettings(final String propFile, final String defaultPropFile)
        throws ReaderProtocolException {
    // operational status is DOWN before resetting
    setOperStatus(OperationalStatus.DOWN);

    //init lists
    sources = new Hashtable();
    dataSelectors = new Hashtable();
    notificationChannels = new Hashtable();
    triggers = new Hashtable();
    tagSelectors = new Hashtable();
    tagFields = new Hashtable();
    readPoints = new Hashtable();
    readers = new Hashtable<String, HardwareAbstraction>();
    valueTriggers = new Hashtable();
    edgeTriggers = new Hashtable();
    currentSource = null;
    alarmChannels = new Hashtable<String, AlarmChannel>();
    ioPorts = new Hashtable<String, IOPort>();

    // properties
    XMLConfiguration conf;
    URL fileurl = ResourceLocator.getURL(propFile, defaultPropFile, this.getClass());
    try {
        conf = new XMLConfiguration(fileurl);
    } catch (ConfigurationException e) {
        System.out.println(e.getMessage());
        throw new ReaderProtocolException("Failed to read properties file (" + propFile + ")",
                MessagingConstants.ERROR_UNKNOWN);
    }

    // get properties
    setEPC(conf.getString("epc"));
    setName(conf.getString("name"));
    setManufacturer(conf.getString("manufacturer"));
    setManufacturerDescription(conf.getString("manufacturerDescription"));
    setModel(conf.getString("model"));
    setHandle(conf.getInt("handle"));
    setRole(conf.getString("role"));

    setMaxSourceNumber(conf.getInt("maxSourceNumber"));
    setMaxTagSelectorNumber(conf.getInt("maxTagSelectorNumber"));
    setMaxTriggerNumber(conf.getInt("maxTriggerNumber"));

    // get readers
    SubnodeConfiguration readerConf = conf.configurationAt("readers");
    for (int i = 0; i <= readerConf.getMaxIndex("reader"); i++) {
        // key to current reader
        String key = "reader(" + i + ")";

        // reader's name
        String readerName = readerConf.getString(key + ".name");
        //System.out.println(readerName);

        // get reader
        if (!readers.containsKey(readerName)) {
            // reflection
            String rClass = readerConf.getString(key + ".class");
            String prop = readerConf.getString(key + ".properties");
            try {
                Class cls = Class.forName(rClass);
                Class[] partypes = new Class[] { String.class, String.class };
                Constructor ct = cls.getConstructor(partypes);
                Object[] arglist = new Object[] { readerName, prop };
                HardwareAbstraction ha = (HardwareAbstraction) ct.newInstance(arglist);
                readers.put(readerName, ha);

            } catch (Exception e) {
                log.error(e.getMessage() + "|" + e.getCause());
                throw new ReaderProtocolException("Reader not found", MessagingConstants.ERROR_UNKNOWN);
            }
        }
    }

    // configure readpoints
    SubnodeConfiguration rpConf = conf.configurationAt("readers");
    for (int i = 0; i <= rpConf.getMaxIndex("reader"); i++) {
        // key to current reader
        String key = "reader(" + i + ")";
        // name of the reader
        String readerName = rpConf.getString(key + ".name");
        // get reader
        HardwareAbstraction tempHardwareAbstraction = (HardwareAbstraction) readers.get(readerName);
        // get readpoints
        for (int j = 0; j <= rpConf.getMaxIndex(key + ".readpoint"); j++) {
            String rp = rpConf.getString(key + ".readpoint(" + j + ")");
            // System.out.println(" "+rps[j]);
            AntennaReadPoint.create(rp, this, tempHardwareAbstraction);
        }
    }

    // configure sources
    SubnodeConfiguration sourceConf = conf.configurationAt("sources");
    for (int i = 0; i <= sourceConf.getMaxIndex("source"); i++) {
        String key = "source(" + i + ")";
        // name of the source
        String sourceName = sourceConf.getString(key + ".name");
        // get source
        Source tempSource;
        if (!sources.containsKey(sourceName)) {
            tempSource = Source.create(sourceName, this);
        } else {
            tempSource = getSource(sourceName);
        }
        // fixed
        if (sourceConf.getString(key + ".fixed").equals("true")) {
            tempSource.setFixed(true);
        } else {
            tempSource.setFixed(false);
        }
        // reader's readpoints
        for (int j = 0; j <= sourceConf.getMaxIndex(key + ".readpoint"); j++) {
            String rp = sourceConf.getString(key + ".readpoint(" + j + ")");
            // System.out.println(" "+rp);
            tempSource.addReadPoints(new ReadPoint[] { getReadPoint(rp) });
        }
    }

    // set current Source
    setCurrentSource(getSource(conf.getString("currentSource")));

    // set defaults
    setDefaults();

    // get io triggers
    getIoTriggers(conf);

    // information used for the reader management implementation
    setDescription(conf.getString("description"));
    setLocationDescription(conf.getString("locationDescription"));
    setContact(conf.getString("contact"));
    serialNumber = conf.getString("serialNumber");
    dhcpServerFinder
            .setMacAddress(DHCPServerFinder.macAddressStringToByteArray(conf.getString("macAddress"), "-"));

    operStatusAlarmControl = new TTOperationalStatusAlarmControl("OperStatusAlarmControl", false,
            AlarmLevel.ERROR, 0, OperationalStatus.ANY, OperationalStatus.ANY);

    freeMemoryAlarmControl = new EdgeTriggeredAlarmControl("FreeMemoryAlarmControl", false, AlarmLevel.CRITICAL,
            0, 100, 1000, EdgeTriggeredAlarmDirection.FALLING);

    if ((alarmManager == null) && (mgmtAgent != null)) {
        AlarmProcessor alarmProcessor = null;
        switch (MessageLayer.mgmtAgentType) {
        case SNMP:
            alarmProcessor = new SnmpAlarmProcessor((SnmpAgent) mgmtAgent);
            break;
        // case ...:
        }
        alarmManager = new AlarmManager(alarmProcessor, this);
        alarmManager.start();
    }

    // configure alarm channels
    SubnodeConfiguration alarmChanConf = conf.configurationAt("alarmChannels");
    String host = "";
    int port = -1;
    for (int i = 0; i <= alarmChanConf.getMaxIndex("alarmChannel"); i++) {
        String key = "alarmChannel(" + i + ")";
        // name of the alarm channel
        String alarmChanName = alarmChanConf.getString(key + ".name");
        // get alarm channel
        try {
            host = alarmChanConf.getString(key + ".host");
            port = alarmChanConf.getInt(key + ".port");
            try {
                AlarmChannel.create(alarmChanName, new Address("udp://" + host + ":" + port), this);
            } catch (MalformedURLException mfue) {
                log.error(alarmChanName + ": invalid address");
            }
            host = "";
            port = -1;
        } catch (ReaderProtocolException rpe) {
            // next
        }
    }

    // operational status is UP after resetting
    setOperStatus(OperationalStatus.UP);

}

From source file:org.ambraproject.configuration.ConfigurationStore.java

/**
 * Load/Reload the configuration from the factory config url.
 *
 * @param configURL URL to the config file for ConfigurationFactory
 * @throws ConfigurationException when the config factory configuration has an error
 *///from   w w  w.  j a  va2 s  .c o  m
public void loadConfiguration(URL configURL) throws ConfigurationException {
    root = new CombinedConfiguration(new OverrideCombiner());

    // System properties override everything
    root.addConfiguration(new SystemConfiguration());

    // Load from ambra.configuration -- /etc/... (optional)
    if (configURL != null) {
        try {
            root.addConfiguration(getConfigurationFromUrl(configURL));
            log.info("Added URL '" + configURL + "'");
        } catch (ConfigurationException ce) {
            if (!(ce.getCause() instanceof FileNotFoundException))
                throw ce;
            log.info("Unable to open '" + configURL + "'");
        }
    }

    // Add ambra.configuration.overrides (if defined)
    String overrides = System.getProperty(OVERRIDES_URL);
    if (overrides != null) {
        try {
            root.addConfiguration(getConfigurationFromUrl(new URL(overrides)));
            log.info("Added override URL '" + overrides + "'");
        } catch (MalformedURLException mue) {
            // Must not be a URL, so it must be a resource
            addResources(root, overrides);
        }
    }

    CombinedConfiguration defaults = new CombinedConfiguration(new UnionCombiner());
    // Add defaults.xml from classpath
    addResources(defaults, DEFAULTS_RESOURCE);
    // Add journal.xml from journals/journal-name/configuration/journal.xml
    addJournalResources(root, defaults, JOURNAL_DIRECTORY);
    root.addConfiguration(defaults);

    // Add global-defaults.xml (presumably found in this jar)
    addResources(root, GLOBAL_DEFAULTS_RESOURCE);

    if (log.isDebugEnabled())
        log.debug("Configuration dump: " + System.getProperty("line.separator")
                + ConfigurationUtils.toString(root));

    /**
     * This prefix is needed by the AmbraIdGenerator to create prefixes for object IDs.
     * Because of the way the AmbraIdGenerator class is created by hibernate, passing in values
     * is very difficult.  If a better method is discovered... by all means use that.  Until that time
     * I've created a system level property to store this prefix.
     */
    String objectIDPrefix = root.getString("ambra.platform.guid-prefix");

    if (objectIDPrefix == null) {
        throw new RuntimeException(
                "ambra.platform.guid-prefix node is not found in the defined configuration file.");
    }

    System.setProperty(SYSTEM_OBJECT_ID_PREFIX, objectIDPrefix);
}

From source file:org.apache.hawq.pxf.api.utilities.ProfilesConf.java

private void loadConf(String fileName, boolean isMandatory) {
    URL url = getClassLoader().getResource(fileName);
    if (url == null) {
        LOG.warn(fileName + " not found in the classpath");
        if (isMandatory) {
            throw new ProfileConfException(PROFILES_FILE_NOT_FOUND, fileName);
        }//from ww  w.j a  va  2  s. c  o m
        return;
    }
    try {
        XMLConfiguration conf = new XMLConfiguration(url);
        loadMap(conf);
    } catch (ConfigurationException e) {
        throw new ProfileConfException(PROFILES_FILE_LOAD_ERR, url.getFile(), String.valueOf(e.getCause()));
    }
}

From source file:org.jbpcc.admin.util.ApplicationProperties.java

public static void init(String fileName) {
    try {/*from  www  .j  av  a 2  s.c  o m*/
        config = new PropertiesConfiguration(fileName);
    } catch (ConfigurationException ex) {
        LOGGER.error(ex, ex.getCause());
    }

}

From source file:org.wso2.andes.server.security.access.plugins.PlainConfigurationTest.java

public void testMissingACLConfig() throws Exception {
    try {//from  ww  w.j a va  2  s  . co  m
        // Load ruleset
        ConfigurationFile configFile = new PlainConfiguration(new File("doesnotexist"));
        configFile.load();

        fail("fail");
    } catch (ConfigurationException ce) {
        assertEquals(String.format(PlainConfiguration.CONFIG_NOT_FOUND_MSG, "doesnotexist"), ce.getMessage());
        assertTrue(ce.getCause() instanceof FileNotFoundException);
        assertEquals("doesnotexist (No such file or directory)", ce.getCause().getMessage());
    }
}

From source file:org.wso2.andes.server.security.access.plugins.PlainConfigurationTest.java

public void testACLFileSyntaxTokens() throws Exception {
    try {/*from   w  ww . j a  v  a2  s  . c  om*/
        writeACLConfig("ACL unparsed ALL ALL");
        fail("fail");
    } catch (ConfigurationException ce) {
        assertEquals(String.format(PlainConfiguration.PARSE_TOKEN_FAILED_MSG, 1), ce.getMessage());
        assertTrue(ce.getCause() instanceof IllegalArgumentException);
        assertEquals("Not a valid permission: unparsed", ce.getCause().getMessage());
    }
}

From source file:org.wso2.andes.server.security.auth.manager.PrincipalDatabaseAuthenticationManagerTest.java

/**
 * QPID-1347. Make sure the exception message and stack trace is reasonable for an absent password file.
 *//*from w  w  w  .j  av a 2s. c  o  m*/
public void testPrincipalDatabaseThrowsSetterFileNotFound() throws Exception {
    try {
        _manager = PrincipalDatabaseAuthenticationManager.FACTORY.newInstance(
                getConfig(PlainPasswordFilePrincipalDatabase.class.getName(), "passwordFile", "/not/found"));
        fail("Exception not thrown");
    } catch (ConfigurationException ce) {
        // PASS
        assertNotNull("Expected an underlying cause", ce.getCause());
        assertEquals(FileNotFoundException.class, ce.getCause().getClass());
    }
}