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(Throwable cause) 

Source Link

Document

Constructs a new ConfigurationException with specified nested Throwable.

Usage

From source file:org.apache.qpid.server.configuration.plugins.AbstractConfiguration.java

/**
 * Provide mechanism to validate Configuration contains a Postiive Long Value
 *
 * @param property/*from  w w w  . ja va2  s .com*/
 *
 * @throws ConfigurationException
 */
protected void validatePositiveLong(String property) throws ConfigurationException {
    try {
        if (!containsPositiveLong(property)) {
            throw new ConfigurationException(
                    this.getClass().getSimpleName() + ": '" + property + "' must be a Positive Long value.");
        }
    } catch (Exception e) {
        Throwable last = e;

        // Find the first cause
        if (e instanceof ConversionException) {
            Throwable t = e.getCause();
            while (t != null) {
                last = t;
                t = last.getCause();
            }
        }

        throw new ConfigurationException(this.getClass().getSimpleName() + ": unable to configure invalid "
                + property + ":" + _config.getString(property), last);
    }
}

From source file:org.apache.qpid.server.configuration.VirtualHostConfiguration.java

@Override
public void validateConfiguration() throws ConfigurationException {
    // QPID-3249.  Support for specifying authentication name at vhost level is no longer supported.
    if (getListValue("security.authentication.name").size() > 0) {
        String message = "Validation error : security/authentication/name is no longer a supported element within the configuration xml."
                + " It appears in virtual host definition : " + _name;
        throw new ConfigurationException(message);
    }//  w  w w.j av  a 2s. c om

    // QPID-3266.  Tidy up housekeeping configuration option for scheduling frequency
    if (contains("housekeeping.expiredMessageCheckPeriod")) {
        String message = "Validation error : housekeeping/expiredMessageCheckPeriod must be replaced by housekeeping/checkPeriod."
                + " It appears in virtual host definition : " + _name;
        throw new ConfigurationException(message);
    }
}

From source file:org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore.java

@Override
public void configure(String name, Configuration storeConfig) throws Exception {
    //Mandatory configuration
    _groupName = getValidatedPropertyFromConfig("highAvailability.groupName", storeConfig);
    _nodeName = getValidatedPropertyFromConfig("highAvailability.nodeName", storeConfig);
    _nodeHostPort = getValidatedPropertyFromConfig("highAvailability.nodeHostPort", storeConfig);
    _helperHostPort = getValidatedPropertyFromConfig("highAvailability.helperHostPort", storeConfig);
    _name = name;/*  w  w  w .  ja v  a2  s.  c  o  m*/

    //Optional configuration
    String durabilitySetting = storeConfig.getString("highAvailability.durability");
    if (durabilitySetting == null) {
        _durability = DEFAULT_DURABILITY;
    } else {
        _durability = Durability.parse(durabilitySetting);
    }
    _designatedPrimary = storeConfig.getBoolean("highAvailability.designatedPrimary", Boolean.FALSE);
    _coalescingSync = storeConfig.getBoolean("highAvailability.coalescingSync", Boolean.TRUE);
    _repConfig = getConfigMap(REPCONFIG_DEFAULTS, storeConfig, "repConfig");

    if (_coalescingSync && _durability.getLocalSync() == SyncPolicy.SYNC) {
        throw new ConfigurationException(
                "Coalescing sync cannot be used with master sync policy " + SyncPolicy.SYNC
                        + "! Please set highAvailability.coalescingSync to false in store configuration.");
    }

    super.configure(name, storeConfig);
}

From source file:org.apache.qpid.server.store.berkeleydb.BDBHAMessageStore.java

private String getValidatedPropertyFromConfig(String key, Configuration config) throws ConfigurationException {
    if (!config.containsKey(key)) {
        throw new ConfigurationException(
                "BDB HA configuration key not found. Please specify configuration key with XPath: "
                        + key.replace('.', '/'));
    }//from   ww w . j  a v  a  2s .  co m
    return config.getString(key);
}

From source file:org.apache.qpid.server.virtualhost.VirtualHostImpl.java

private void configureQueue(QueueConfiguration queueConfiguration) throws AMQException, ConfigurationException {
    AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(queueConfiguration, this);
    String queueName = queue.getName();

    if (queue.isDurable()) {
        getMessageStore().createQueue(queue);
    }//from   w w  w  .ja v a 2 s  .co m

    //get the exchange name (returns default exchange name if none was specified)
    String exchangeName = queueConfiguration.getExchange();

    Exchange exchange = _exchangeRegistry.getExchange(exchangeName);
    if (exchange == null) {
        throw new ConfigurationException(
                "Attempt to bind queue '" + queueName + "' to unknown exchange:" + exchangeName);
    }

    Exchange defaultExchange = _exchangeRegistry.getDefaultExchange();

    //get routing keys in configuration (returns empty list if none are defined)
    List<?> routingKeys = queueConfiguration.getRoutingKeys();

    for (Object routingKeyNameObj : routingKeys) {
        String routingKey = String.valueOf(routingKeyNameObj);

        if (exchange.equals(defaultExchange) && !queueName.equals(routingKey)) {
            throw new ConfigurationException("Illegal attempt to bind queue '" + queueName
                    + "' to the default exchange with a key other than the queue name: " + routingKey);
        }

        configureBinding(queue, exchange, routingKey);
    }

    if (!exchange.equals(defaultExchange)) {
        //bind the queue to the named exchange using its name
        configureBinding(queue, exchange, queueName);
    }

    //ensure the queue is bound to the default exchange using its name
    configureBinding(queue, defaultExchange, queueName);
}

From source file:org.apache.qpid.systest.rest.SaslRestTest.java

private void configureBase64MD5FilePrincipalDatabase() throws IOException, ConfigurationException {
    // generate user password entry
    String passwordFileEntry;//w  w  w.  j  ava 2 s .  c om
    try {
        passwordFileEntry = new Passwd().getOutput("admin", "admin");
    } catch (NoSuchAlgorithmException e) {
        throw new ConfigurationException(e);
    }

    // store the entry in the file
    File passwordFile = File.createTempFile("passwd", "pwd");
    passwordFile.deleteOnExit();

    FileWriter writer = null;
    try {
        writer = new FileWriter(passwordFile);
        writer.write(passwordFileEntry);
    } finally {
        writer.close();
    }

    // configure broker to use Base64MD5PasswordFilePrincipalDatabase
    Map<String, Object> newAttributes = new HashMap<String, Object>();
    newAttributes.put(AbstractPrincipalDatabaseAuthManagerFactory.ATTRIBUTE_PATH,
            passwordFile.getAbsolutePath());
    newAttributes.put(AuthenticationManagerFactory.ATTRIBUTE_TYPE,
            Base64MD5PasswordFileAuthenticationManagerFactory.PROVIDER_TYPE);
    getBrokerConfiguration().setObjectAttributes(TestBrokerConfiguration.ENTRY_NAME_AUTHENTICATION_PROVIDER,
            newAttributes);
}

From source file:org.apache.qpid.test.utils.QpidBrokerTestCase.java

/**
 * Set a configuration Property for this test run.
 *
 * This creates a new configuration based on the current configuration
 * with the specified property change./*from w  w  w .j a  v  a 2  s  . co  m*/
 *
 * Multiple calls to this method will result in multiple temporary
 * configuration files being created.
 *
 * @param property the configuration property to set
 * @param value    the new value
 *
 * @throws ConfigurationException when loading the current config file
 */
public void setVirtualHostConfigurationProperty(String property, String value) throws ConfigurationException
{
    // Choose which file to write the property to based on prefix.
    if (property.startsWith("virtualhosts"))
    {
        _testVirtualhosts.setProperty(StringUtils.substringAfter(property, "virtualhosts."), value);
    }
    else
    {
        throw new ConfigurationException("Cannot set broker configuration as property");
    }
}

From source file:org.apache.rya.indexing.smarturi.duplication.conf.DuplicateDataConfig.java

private static Tolerance parseTolerance(final String key, final XMLConfiguration xmlConfig)
        throws ConfigurationException {
    final String type = xmlConfig.getString(key + ".type", null);
    final ToleranceType toleranceType = ToleranceType.getToleranceTypeByName(type);
    Double doubleValue = null;//from w  ww.  jav  a 2s .c  o  m
    if (toleranceType != null) {
        switch (toleranceType) {
        case PERCENTAGE:
            final String value = xmlConfig.getString(key + ".value", null);
            if (value != null && value.contains("%")) {
                try {
                    final Number number = NumberFormat.getPercentInstance().parse(value);
                    doubleValue = number.doubleValue();
                } catch (final ParseException e) {
                    throw new ConfigurationException(e);
                }
            } else {
                doubleValue = xmlConfig.getDouble(key + ".value", null);
            }
            if (doubleValue != null) {
                if (doubleValue < 0) {
                    throw new ConfigurationException("The " + toleranceType + " tolerance type for \"" + key
                            + "\" must be a positive value. Found this value: " + doubleValue);
                }
                if (doubleValue > 1) {
                    throw new ConfigurationException("The " + toleranceType + " tolerance type for \"" + key
                            + "\" can NOT be greater than 100%. Found this value: " + doubleValue);
                }
            }
            break;
        case DIFFERENCE:
            doubleValue = xmlConfig.getDouble(key + ".value", null);
            if (doubleValue != null && doubleValue < 0) {
                throw new ConfigurationException("The " + toleranceType + " tolerance type for \"" + key
                        + "\" must be a positive value. Found this value: " + doubleValue);
            }
            break;
        default:
            throw new ConfigurationException(
                    "Unknown Tolerance Type specified in config for <" + type + ">: " + toleranceType);
        }
        if (doubleValue != null) {
            return new Tolerance(doubleValue, toleranceType);
        }
    }
    return null;
}

From source file:org.apache.whirr.ClusterSpec.java

protected void checkAndSetKeyPair() throws ConfigurationException {
    String pairRepresentation = "";
    try {/*from   www  .  j  ava 2 s .  co  m*/
        String privateKeyPath = getString(Property.PRIVATE_KEY_FILE);

        String publicKeyPath = getString(Property.PUBLIC_KEY_FILE);
        publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ? privateKeyPath + ".pub"
                : publicKeyPath;
        if (privateKeyPath != null && publicKeyPath != null) {
            pairRepresentation = "(" + privateKeyPath + ", " + publicKeyPath + ")";
            KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
            if (pair.isEncrypted()) {
                throw new ConfigurationException("Key pair " + pairRepresentation
                        + " is encrypted. Try generating a new passwordless SSH keypair "
                        + "(e.g. with ssh-keygen).");
            }
            if (!sameKeyPair(new File(privateKeyPath), new File(publicKeyPath))) {
                throw new ConfigurationException(
                        "Both keys should belong " + "to the same key pair: " + pairRepresentation);
            }

            setPrivateKey(new File(privateKeyPath));
            setPublicKey(new File(publicKeyPath));
        }
    } catch (JSchException e) {
        throw new ConfigurationException("Invalid key pair: " + pairRepresentation, e);

    } catch (IllegalArgumentException e) {
        throw new ConfigurationException("Invalid key: " + pairRepresentation, e);

    } catch (IOException e) {
        throw new ConfigurationException("Error reading one of key file: " + pairRepresentation, e);
    }
}

From source file:org.apache.whirr.InstanceTemplate.java

private static void validateThatWeHaveNoOtherOverrides(List<InstanceTemplate> templates,
        Configuration configuration) throws ConfigurationException {

    Set<String> groups = Sets
            .newHashSet(Iterables.transform(templates, new Function<InstanceTemplate, String>() {
                private final Joiner plusJoiner = Joiner.on("+");

                @Override//from  w  ww . j  a v  a  2  s  .co  m
                public String apply(InstanceTemplate instance) {
                    return plusJoiner.join(instance.getRoles());
                }
            }));

    Pattern pattern = Pattern.compile("^whirr\\.templates\\.([^.]+)\\..*$");
    Iterator iterator = configuration.getKeys("whirr.templates");

    while (iterator.hasNext()) {
        String key = String.class.cast(iterator.next());
        Matcher matcher = pattern.matcher(key);

        if (matcher.find() && !groups.contains(matcher.group(1))) {
            throw new ConfigurationException(String.format(
                    "'%s' is referencing a " + "template group not present in 'whirr.instance-templates'",
                    key));
        }
    }
}