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

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

Introduction

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

Prototype

public ConfigurationException(String message, Throwable cause) 

Source Link

Document

Constructs a new ConfigurationException with specified detail message and nested Throwable.

Usage

From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java

@Override
public void save(final Writer out) throws ConfigurationException {
    try {/*from w ww  .  j a va  2s  . c  om*/
        yaml.dump(this.saveHierarchy(this.getRootNode()), out);
    } catch (Throwable e) {
        throw new ConfigurationException("Failed to save configuration: " + e.getMessage(), e);
    }
}

From source file:org.bgp4j.config.nodes.impl.PeerConfigurationParser.java

public PeerConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException {
    PeerConfigurationImpl peerConfig = new PeerConfigurationImpl();
    List<HierarchicalConfiguration> clientConfigs = config.configurationsAt("Client");
    List<HierarchicalConfiguration> capabilityConfigs = config.configurationsAt("Capabilities");

    try {/*from   www .j a  va  2 s .c o  m*/
        peerConfig.setPeerName(config.getString("[@name]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("peer name not set", e);
    }

    if (clientConfigs.size() > 1) {
        throw new ConfigurationException("duplicate <Client/> element");
    } else if (clientConfigs.size() == 0) {
        throw new ConfigurationException("missing <Client/> element");
    } else
        peerConfig.setClientConfig(clientConfigurationParser.parseConfig(clientConfigs.get(0)));

    if (capabilityConfigs.size() > 1) {
        throw new ConfigurationException("duplicate <Capabilities/> element");
    } else if (capabilityConfigs.size() == 1)
        peerConfig.setCapabilities(capabilityParser.parseConfig(capabilityConfigs.get(0)));

    try {
        peerConfig.setLocalAS(config.getInt("AutonomousSystem[@local]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("local AS number not given", e);
    }
    try {
        peerConfig.setRemoteAS(config.getInt("AutonomousSystem[@remote]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("remote AS number not given", e);
    }

    try {
        long identifier = config.getLong("BgpIdentifier[@local]");

        if (!isValidBgpIdentifier(identifier))
            throw new ConfigurationException("Invalid local BGP identifier: " + identifier);

        peerConfig.setLocalBgpIdentifier(identifier);
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("local BGP identifier not given", e);
    }
    try {
        long identifier = config.getLong("BgpIdentifier[@remote]");

        if (!isValidBgpIdentifier(identifier))
            throw new ConfigurationException("Invalid remote BGP identifier: " + identifier);

        peerConfig.setRemoteBgpIdentifier(identifier);
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("remote BGP identifier not given", e);
    }

    peerConfig.setHoldTime(config.getInt("Timers[@holdTime]", 0));
    peerConfig.setIdleHoldTime(config.getInt("Timers[@idleHoldTime]", 0));
    peerConfig.setDelayOpenTime(config.getInt("Timers[@delayOpenTime]", 0));
    peerConfig.setConnectRetryTime(config.getInt("Timers[@connectRetryTime]", 0));
    peerConfig.setAutomaticStartInterval(config.getInt("Timers[@automaticStartInterval]", 0));

    peerConfig.setAllowAutomaticStart(config.getBoolean("Options[@allowAutomaticStart]", true));
    peerConfig.setAllowAutomaticStop(config.getBoolean("Options[@allowAutomaticStop]", false));
    peerConfig.setDampPeerOscillation(config.getBoolean("Options[@dampPeerOscillation]", false));
    peerConfig.setCollisionDetectEstablishedState(
            config.getBoolean("Options[@collisionDetectEstablishedState]", false));
    peerConfig.setDelayOpen(config.getBoolean("Options[@delayOpen]", false));
    peerConfig.setPassiveTcpEstablishment(config.getBoolean("Options[@passiveTcpEstablishment]", false));
    peerConfig.setHoldTimerDisabled(config.getBoolean("Options[@holdTimerDisabled]", false));

    return peerConfig;
}

From source file:org.sonar.server.configuration.ConfigurationFactory.java

protected PropertiesConfiguration getConfigurationFromPropertiesFile(String filename)
        throws ConfigurationException {
    try {/* w w w.  jav  a  2  s  . c om*/
        return new PropertiesConfiguration(ConfigurationFactory.class.getResource(filename));

    } catch (org.apache.commons.configuration.ConfigurationException e) {
        throw new ConfigurationException("can not load the file " + filename + " from classpath", e);
    }
}

From source file:org.speechforge.cairo.server.config.ResourceConfig.java

/**
 * TODOC/*w w w .  jav  a 2  s . c  o  m*/
 * @param config
 * @param key
 * @return
 * @throws ConfigurationException
 */
public static File getConfigDir(XMLConfiguration config, String key) throws ConfigurationException {
    try {
        File dir = new File(config.getString(key));
        ensureDir(dir);
        return dir;
    } catch (RuntimeException e) {
        throw new ConfigurationException(e.getMessage(), e);
    }
}

From source file:org.ssh.comm.conf.CustomConfigurationBuilder.java

/**
 * If a property file is configured add the properties to the System
 * properties.//ww  w. j a  va 2 s. co  m
 * 
 * @throws ConfigurationException
 *             if an error occurs.
 */
protected void initSystemProperties() throws ConfigurationException {
    String fileName = getString(KEY_SYSTEM_PROPS);
    if (fileName != null) {
        try {
            SystemConfiguration.setSystemProperties(getConfigurationBasePath(), fileName);
        } catch (Exception ex) {
            throw new ConfigurationException("Error setting system properties from " + fileName, ex);
        }

    }
}

From source file:org.topology.bgp_ls.config.nodes.impl.AddressFamilyRoutingPeerConfigurationParser.java

AddressFamilyRoutingPeerConfiguration parseConfiguration(HierarchicalConfiguration config)
        throws ConfigurationException {
    AddressFamilyRoutingPeerConfigurationImpl result = new AddressFamilyRoutingPeerConfigurationImpl();
    String addressFamily = config.getString("[@addressFamily]");
    String subsequentAddressFamily = config.getString("[@subsequentAddressFamily]");
    HierarchicalConfiguration localFilterConfiguration = first(config, "Local.Filters");
    HierarchicalConfiguration remoteFilterConfiguration = first(config, "Remote.Filters");
    HierarchicalConfiguration localPathAttributes = first(config, "Local.DefaultPathAttributes");
    HierarchicalConfiguration remotePathAttributes = first(config, "Remote.DefaultPathAttributes");

    try {//from   w ww  .  j  a v a 2  s  .  co  m
        result.setAddressFamilyKey(new AddressFamilyKey(AddressFamily.fromString(addressFamily),
                SubsequentAddressFamily.fromString(subsequentAddressFamily)));
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException("Invalid AddressFamilyKey given", e);
    }

    if (localFilterConfiguration != null)
        result.setLocalRoutingFilters(parsRoutingeFilters(localFilterConfiguration));

    if (remoteFilterConfiguration != null)
        result.setRemoteRoutingFilters(parsRoutingeFilters(remoteFilterConfiguration));

    if (localPathAttributes != null)
        result.setLocalDefaultPathAttributes(pathAttributeParser.parseConfiguration(localPathAttributes));

    if (remotePathAttributes != null)
        result.setRemoteDefaultPathAttributes(pathAttributeParser.parseConfiguration(remotePathAttributes));

    return result;
}

From source file:org.topology.bgp_ls.config.nodes.impl.PeerConfigurationParser.java

public PeerConfiguration parseConfiguration(HierarchicalConfiguration config) throws ConfigurationException {
    PeerConfigurationImpl peerConfig = new PeerConfigurationImpl();
    List<HierarchicalConfiguration> clientConfigs = config.configurationsAt("Client");
    List<HierarchicalConfiguration> capabilityConfigs = config.configurationsAt("Capabilities");

    try {/*from w  w w .  j a  v  a2s .co  m*/
        peerConfig.setPeerName(config.getString("[@name]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("peer name not set", e);
    }

    if (clientConfigs.size() > 1) {
        throw new ConfigurationException("duplicate <Client/> element");
    } else if (clientConfigs.size() == 0) {
        throw new ConfigurationException("missing <Client/> element");
    } else
        peerConfig.setClientConfig(clientConfigurationParser.parseConfig(clientConfigs.get(0)));

    if (capabilityConfigs.size() > 1) {
        throw new ConfigurationException("duplicate <Capabilities/> element");
    } else if (capabilityConfigs.size() == 1)
        peerConfig.setCapabilities(capabilityParser.parseConfig(capabilityConfigs.get(0)));

    try {
        peerConfig.setLocalAS(config.getInt("AutonomousSystem[@local]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("local AS number not given", e);
    }
    try {
        peerConfig.setRemoteAS(config.getInt("AutonomousSystem[@remote]"));
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("remote AS number not given", e);
    }

    try {
        long identifier = config.getLong("BgpIdentifier[@local]");

        if (!isValidBgpIdentifier(identifier))
            throw new ConfigurationException("Invalid local BGP identifier: " + identifier);

        peerConfig.setLocalBgpIdentifier(identifier);
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("local BGP identifier not given", e);
    }
    try {
        long identifier;
        String idString = config.getString("BgpIdentifier[@remote]");
        try {
            InetAddress addr = Inet4Address.getByName(idString);
            byte[] idArray = addr.getAddress();
            identifier = ((long) idArray[3] & 0xFF) | (((long) idArray[2] & 0xFF) << 8)
                    | (((long) idArray[1] & 0xFF) << 16) | (((long) idArray[0] & 0xFF) << 24);

        } catch (Exception e) {
            identifier = Long.parseLong(idString);
        }

        if (!isValidBgpIdentifier(identifier))
            throw new ConfigurationException("Invalid remote BGP identifier: " + identifier);

        peerConfig.setRemoteBgpIdentifier(identifier);
    } catch (NoSuchElementException e) {
        throw new ConfigurationException("remote BGP identifier not given", e);
    }
    peerConfig.setHoldTime(config.getInt("Timers[@holdTime]", 0));
    peerConfig.setIdleHoldTime(config.getInt("Timers[@idleHoldTime]", 0));
    peerConfig.setDelayOpenTime(config.getInt("Timers[@delayOpenTime]", 0));
    peerConfig.setConnectRetryTime(config.getInt("Timers[@connectRetryTime]", 0));
    peerConfig.setAutomaticStartInterval(config.getInt("Timers[@automaticStartInterval]", 0));

    peerConfig.setAllowAutomaticStart(config.getBoolean("Options[@allowAutomaticStart]", true));
    peerConfig.setAllowAutomaticStop(config.getBoolean("Options[@allowAutomaticStop]", false));
    peerConfig.setDampPeerOscillation(config.getBoolean("Options[@dampPeerOscillation]", false));
    peerConfig.setCollisionDetectEstablishedState(
            config.getBoolean("Options[@collisionDetectEstablishedState]", false));
    peerConfig.setDelayOpen(config.getBoolean("Options[@delayOpen]", false));
    peerConfig.setPassiveTcpEstablishment(config.getBoolean("Options[@passiveTcpEstablishment]", false));
    peerConfig.setHoldTimerDisabled(config.getBoolean("Options[@holdTimerDisabled]", false));

    return peerConfig;
}

From source file:org.wso2.andes.configuration.AndesConfigurationManager.java

/**
 * Given the data type and the value read from a config, this returns the parsed value
 * of the property./*from  ww  w.j  a va2s .co  m*/
 *
 * @param key          The Key to the property being read (n xpath format as contained in file.)
 * @param dataType     Expected data type of the property
 * @param defaultValue This parameter should NEVER be null since we assign a default value to
 *                     every config property.
 * @param <T>          Expected data type of the property
 * @return Value of config in the expected data type.
 * @throws ConfigurationException
 */
public static <T> T deriveValidConfigurationValue(String key, Class<T> dataType, String defaultValue)
        throws ConfigurationException {

    if (log.isDebugEnabled()) {
        log.debug("Reading andes configuration value " + key);
    }

    String readValue = compositeConfiguration.getString(key);

    String validValue = defaultValue;

    // If the dataType is a Custom Config Module class, the readValue will be null (since the child properties
    // are the ones with values.). Therefore the warning is printed only in other situations.
    if (StringUtils.isBlank(readValue) && !CONFIG_MODULE_PACKAGE.equals(dataType.getPackage().getName())) {
        log.warn("Error when trying to read property : " + key + ". Switching to " + "default value : "
                + defaultValue);
    } else {
        validValue = overrideWithDecryptedValue(key, readValue);
    }

    if (log.isDebugEnabled()) {
        log.debug("Valid value read for andes configuration property " + key + " is : " + validValue);
    }

    try {

        if (Boolean.class.equals(dataType)) {
            return dataType.cast(Boolean.parseBoolean(validValue));

        } else if (Date.class.equals(dataType)) {
            // Sample date : "Sep 28 20:29:30 JST 2000"
            DateFormat df = new SimpleDateFormat("MMM dd kk:mm:ss z yyyy", Locale.ENGLISH);
            return dataType.cast(df.parse(validValue));

        } else if (dataType.isEnum()) {
            // this will indirectly forces programmer to define enum values in upper case
            return (T) Enum.valueOf((Class<? extends Enum>) dataType, validValue.toUpperCase(Locale.ENGLISH));

        } else if (CONFIG_MODULE_PACKAGE.equals(dataType.getPackage().getName())) {
            // Custom data structures defined within this package only need the root Xpath to extract the other
            // required child properties to construct the config object.
            return dataType.getConstructor(String.class).newInstance(key);

        } else {
            return dataType.getConstructor(String.class).newInstance(validValue);
        }

    } catch (NoSuchMethodException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    } catch (ParseException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    } catch (InvocationTargetException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    } catch (InstantiationException e) {
        throw new ConfigurationException(MessageFormat.format(GENERIC_CONFIGURATION_PARSE_ERROR, key), e);
    }
}

From source file:org.wso2.andes.server.plugins.PluginManager.java

public PluginManager(String pluginPath, String cachePath) throws Exception {
    // Store all non-OSGi plugins
    // A little gross that we have to add them here, but not all the plugins are OSGIfied
    for (SecurityPluginFactory<?> pluginFactory : Arrays.asList(AllowAll.FACTORY, DenyAll.FACTORY,
            LegacyAccess.FACTORY)) {/*from w w w. j  ava2s  . co  m*/
        _securityPlugins.put(pluginFactory.getPluginName(), pluginFactory);
    }
    for (ConfigurationPluginFactory configFactory : Arrays.asList(TopicConfiguration.FACTORY,
            SecurityManager.SecurityConfiguration.FACTORY, AllowAll.AllowAllConfiguration.FACTORY,
            DenyAll.DenyAllConfiguration.FACTORY, LegacyAccess.LegacyAccessConfiguration.FACTORY,
            new SlowConsumerDetectionConfigurationFactory(),
            new SlowConsumerDetectionPolicyConfigurationFactory(),
            new SlowConsumerDetectionQueueConfigurationFactory(),
            PrincipalDatabaseAuthenticationManager.PrincipalDatabaseAuthenticationManagerConfiguration.FACTORY)) {
        _configPlugins.put(configFactory.getParentPaths(), configFactory);
    }
    for (SlowConsumerPolicyPluginFactory pluginFactory : Arrays
            .asList(new TopicDeletePolicy.TopicDeletePolicyFactory())) {
        _policyPlugins.put(pluginFactory.getPluginName(), pluginFactory);
    }
    for (VirtualHostPluginFactory pluginFactory : Arrays
            .asList(new SlowConsumerDetection.SlowConsumerFactory())) {
        _vhostPlugins.put(pluginFactory.getClass().getName(), pluginFactory);
    }

    for (AuthenticationManagerPluginFactory<? extends Plugin> pluginFactory : Arrays
            .asList(PrincipalDatabaseAuthenticationManager.FACTORY)) {
        _authenticationManagerPlugins.put(pluginFactory.getPluginName(), pluginFactory);
    }
    if (_bundleContext == null) // Not running inside an OSGi environment.So start Felix.
    {
        // Check the plugin directory path is set and exist
        if (pluginPath == null) {
            return;
        }
        File pluginDir = new File(pluginPath);
        if (!pluginDir.exists()) {
            return;
        }

        // Setup OSGi configuration propery map
        StringMap configMap = new StringMap(false);

        // Add the bundle provided service interface package and the core OSGi
        // packages to be exported from the class path via the system bundle.
        configMap.put(FRAMEWORK_SYSTEMPACKAGES, "org.osgi.framework; version=1.3.0,"
                + "org.osgi.service.packageadmin; version=1.2.0,"
                + "org.osgi.service.startlevel; version=1.0.0," + "org.osgi.service.url; version=1.0.0,"
                + "org.osgi.util.tracker; version=1.0.0," + "org.wso2.andes.junit.extensions.util; "
                + QPID_VER_SUFFIX + "org.wso2.andes; " + QPID_VER_SUFFIX + "org.wso2.andes.common; "
                + QPID_VER_SUFFIX + "org.wso2.andes.exchange; " + QPID_VER_SUFFIX + "org.wso2.andes.framing; "
                + QPID_VER_SUFFIX + "org.wso2.andes.management.common.mbeans.annotations; " + QPID_VER_SUFFIX
                + "org.wso2.andes.protocol; " + QPID_VER_SUFFIX + "org.wso2.andes.server.binding; "
                + QPID_VER_SUFFIX + "org.wso2.andes.configuration.qpid; " + QPID_VER_SUFFIX
                + "org.wso2.andes.configuration.qpid.plugins; " + QPID_VER_SUFFIX
                + "org.wso2.andes.configuration.qpid.management; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.exchange; " + QPID_VER_SUFFIX + "org.wso2.andes.server.logging; "
                + QPID_VER_SUFFIX + "org.wso2.andes.server.logging.actors; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.logging.subjects; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.management; " + QPID_VER_SUFFIX + "org.wso2.andes.server.persistent; "
                + QPID_VER_SUFFIX + "org.wso2.andes.server.plugins; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.protocol; " + QPID_VER_SUFFIX + "org.wso2.andes.server.queue; "
                + QPID_VER_SUFFIX + "org.wso2.andes.server.registry; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.security; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.security.access; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.security.access.plugins; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.virtualhost; " + QPID_VER_SUFFIX
                + "org.wso2.andes.server.virtualhost.plugins; " + QPID_VER_SUFFIX + "org.wso2.andes.util; "
                + QPID_VER_SUFFIX + "org.apache.commons.configuration; version=1.0.0,"
                + "org.apache.commons.lang; version=1.0.0," + "org.apache.commons.lang.builder; version=1.0.0,"
                + "org.apache.commons.logging; version=1.0.0," + "org.apache.log4j; version=1.2.12,"
                + "javax.management.openmbean; version=1.0.0," + "javax.management; version=1.0.0,"
                + "javax.security.auth; version=1.0.0");

        // No automatic shutdown hook
        configMap.put("felix.shutdown.hook", "false");

        // Add system activator
        List<BundleActivator> activators = new ArrayList<BundleActivator>();
        _activator = new Activator();
        activators.add(_activator);
        configMap.put(SYSTEMBUNDLE_ACTIVATORS_PROP, activators);

        if (cachePath != null) {
            File cacheDir = new File(cachePath);
            if (!cacheDir.exists() && cacheDir.canWrite()) {
                _logger.info("Creating plugin cache directory: " + cachePath);
                cacheDir.mkdir();
            }

            // Set plugin cache directory and empty it
            _logger.info("Cache bundles in directory " + cachePath);
            configMap.put(FRAMEWORK_STORAGE, cachePath);
        }
        configMap.put(FRAMEWORK_STORAGE_CLEAN, FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);

        // Set directory with plugins to auto-deploy
        _logger.info("Auto deploying bundles from directory " + pluginPath);
        configMap.put(AUTO_DEPLOY_DIR_PROPERY, pluginPath);
        configMap.put(AUTO_DEPLOY_ACTION_PROPERY, AUTO_DEPLOY_INSTALL_VALUE + "," + AUTO_DEPLOY_START_VALUE);

        // Start plugin manager and trackers
        _felix = new Felix(configMap);
        try {
            _logger.info("Starting plugin manager...");
            _felix.init();
            process(configMap, _felix.getBundleContext());
            _felix.start();
            _logger.info("Started plugin manager");
        } catch (BundleException e) {
            throw new ConfigurationException("Could not start plugin manager: " + e.getMessage(), e);
        }
        // Initialize bundle context
        _bundleContext = _activator.getContext();
    }
    // TODO save trackers in a map, keyed by class name

    _exchangeTracker = new ServiceTracker(_bundleContext, ExchangeType.class.getName(), null);
    _exchangeTracker.open();

    _securityTracker = new ServiceTracker(_bundleContext, SecurityPluginFactory.class.getName(), null);
    _securityTracker.open();

    _configTracker = new ServiceTracker(_bundleContext, ConfigurationPluginFactory.class.getName(), null);
    _configTracker.open();

    _virtualHostTracker = new ServiceTracker(_bundleContext, VirtualHostPluginFactory.class.getName(), null);
    _virtualHostTracker.open();

    _policyTracker = new ServiceTracker(_bundleContext, SlowConsumerPolicyPluginFactory.class.getName(), null);
    _policyTracker.open();

    _authenticationManagerTracker = new ServiceTracker(_bundleContext,
            AuthenticationManagerPluginFactory.class.getName(), null);
    _authenticationManagerTracker.open();

    _logger.info("Opened service trackers");
}

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

private PrincipalDatabase createPrincipalDatabaseImpl(final String pdClazz) throws ConfigurationException {
    try {/* w w  w .  jav a2  s.c om*/
        return (PrincipalDatabase) Class.forName(pdClazz).newInstance();
    } catch (InstantiationException ie) {
        throw new ConfigurationException("Cannot instantiate " + pdClazz, ie);
    } catch (IllegalAccessException iae) {
        throw new ConfigurationException("Cannot access " + pdClazz, iae);
    } catch (ClassNotFoundException cnfe) {
        throw new ConfigurationException("Cannot load " + pdClazz + " implementation", cnfe);
    } catch (ClassCastException cce) {
        throw new ConfigurationException("Expecting a " + PrincipalDatabase.class + " implementation", cce);
    }
}