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.hedwig.server.common.ServerConfiguration.java

public InputStream getCertStream() throws FileNotFoundException, ConfigurationException {
    String certName = getCertName();
    String certPath = getCertPath();
    if (certName != null && !certName.isEmpty()) {
        return getClass().getResourceAsStream(certName);
    } else if (certPath != null && !certPath.isEmpty()) {
        return new FileInputStream(certPath);
    } else/*from www. j av a2  s  . c o m*/
        throw new ConfigurationException(
                "SSL Certificate configuration does not have resource name or path set!");
}

From source file:org.apache.hedwig.server.common.ServerConfiguration.java

public void validate() throws ConfigurationException {
    if (!getZkPrefix().startsWith("/")) {
        throw new ConfigurationException(ZK_PREFIX + " must start with a /");
    }/*from w w  w  .  ja v a 2 s.  c o m*/
    // Validate that if Regions exist and inter-region communication is SSL
    // enabled, that the Regions correspond to valid HedwigSocketAddresses,
    // namely that SSL ports are present.
    if (isInterRegionSSLEnabled() && getRegions().size() > 0) {
        for (String hubString : getRegions()) {
            HedwigSocketAddress hub = new HedwigSocketAddress(hubString);
            if (hub.getSSLSocketAddress() == null)
                throw new ConfigurationException(
                        "Region defined does not have required SSL port: " + hubString);
        }
    }
    // Validate that the Bookkeeper ensemble size >= quorum size.
    if (getBkEnsembleSize() < getBkWriteQuorumSize()) {
        throw new ConfigurationException("BK ensemble size (" + getBkEnsembleSize()
                + ") is less than the write quorum size (" + getBkWriteQuorumSize() + ")");
    }

    if (getBkWriteQuorumSize() < getBkAckQuorumSize()) {
        throw new ConfigurationException("BK write quorum size (" + getBkWriteQuorumSize()
                + ") is less than the ack quorum size (" + getBkAckQuorumSize() + ")");
    }
    // Validate that the rebalance tolerance percentage is not negative.
    if (getRebalanceTolerance() < 0.0) {
        throw new ConfigurationException("The rebalance tolerance percentage cannot be negative.");
    }
    // Validate that the maximum load to shed during a rebalance is not negative.
    if (getRebalanceMaxShed().getNumTopics() < 0L) {
        throw new ConfigurationException("The maximum load to shed during a rebalance cannot be negative.");
    }
    // add other checks here
}

From source file:org.apache.james.backends.es.ElasticSearchConfiguration.java

@VisibleForTesting
static void validateHostsConfigurationOptions(Optional<String> masterHost, Optional<Integer> masterPort,
        List<String> multiHosts) throws ConfigurationException {
    if (masterHost.isPresent() != masterPort.isPresent()) {
        throw new ConfigurationException(
                ELASTICSEARCH_MASTER_HOST + " and " + ELASTICSEARCH_PORT + " should be specified together");
    }/* w  w  w  .jav a 2  s  .  co  m*/
    if (!multiHosts.isEmpty() && masterHost.isPresent()) {
        throw new ConfigurationException(
                "You should choose between mono host set up and " + ELASTICSEARCH_HOSTS);
    }
    if (multiHosts.isEmpty() && !masterHost.isPresent()) {
        throw new ConfigurationException("You should specify either (" + ELASTICSEARCH_MASTER_HOST + " and "
                + ELASTICSEARCH_PORT + ") or " + ELASTICSEARCH_HOSTS);
    }
}

From source file:org.apache.james.container.spring.bean.factory.mailrepositorystore.MailRepositoryStoreBeanFactory.java

/**
 * <p>/* ww  w  .j a  va  2 s.  c  o  m*/
 * Registers a new mail repository type in the mail store's registry based
 * upon a passed in <code>Configuration</code> object.
 * </p>
 * <p/>
 * <p>
 * This is presumably synchronized to prevent corruption of the internal
 * registry.
 * </p>
 *
 * @param repConf the Configuration object used to register the repository
 * @throws ConfigurationException if an error occurs accessing the Configuration object
 */
public synchronized void registerRepository(HierarchicalConfiguration repConf) throws ConfigurationException {

    String className = repConf.getString("[@class]");

    boolean infoEnabled = getLogger().isInfoEnabled();

    for (String protocol : repConf.getStringArray("protocols.protocol")) {
        HierarchicalConfiguration defConf = null;

        if (repConf.getKeys("config").hasNext()) {
            // Get the default configuration for these protocol/type
            // combinations.
            defConf = repConf.configurationAt("config");
        }

        if (infoEnabled) {
            StringBuilder infoBuffer = new StringBuilder(128);
            infoBuffer.append("Registering Repository instance of class ");
            infoBuffer.append(className);
            infoBuffer.append(" to handle ");
            infoBuffer.append(protocol);
            infoBuffer.append(" protocol requests for repositories with key ");
            infoBuffer.append(protocol);
            getLogger().info(infoBuffer.toString());
        }

        if (classes.get(protocol) != null) {
            throw new ConfigurationException(
                    "The combination of protocol and type comprise a unique key for repositories.  This constraint has been violated.  Please check your repository configuration.");
        }

        classes.put(protocol, className);

        if (defConf != null) {
            defaultConfigs.put(protocol, defConf);
        }
    }

}

From source file:org.apache.james.container.spring.bean.factorypostprocessor.EventsConfigurationBeanFactoryPostProcessor.java

private void detectInvalidValue(String registrationAlias, String message) throws ConfigurationException {
    if (Strings.isNullOrEmpty(registrationAlias)) {
        throw new ConfigurationException(message);
    }/*from w ww  .ja va  2 s .  c om*/
}

From source file:org.apache.james.container.spring.bean.factorypostprocessor.IndexerConfigurationBeanFactoryPostProcessor.java

/**
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory
 * (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
 *///from ww w  .jav a  2  s  . c o m
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class);
    try {
        HierarchicalConfiguration config = confProvider.getConfiguration("indexer");
        String provider = config.getString("provider", "lazyIndex");

        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        String indexer = null;
        String reIndexer = null;
        if (provider.equalsIgnoreCase("lazyIndex")) {
            indexer = "lazyIndex";
            reIndexer = "fake-reindexer";
        } else if (provider.equalsIgnoreCase("elasticsearch")) {
            indexer = "elasticsearch-listener";
            reIndexer = "reindexer-impl";
        }

        if (indexer == null)
            throw new ConfigurationException("Indexer provider " + provider + " not supported!");
        registry.registerAlias(indexer, "indexer");
        registry.registerAlias(reIndexer, "reindexer");

    } catch (ConfigurationException e) {
        throw new FatalBeanException("Unable to config the indexer", e);
    }

}

From source file:org.apache.james.container.spring.bean.factorypostprocessor.MailboxConfigurationBeanFactoryPostProcessor.java

/**
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory
 * (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
 *///from   w ww.  j  a  va 2s  .  c  o  m
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class);
    try {
        HierarchicalConfiguration config = confProvider.getConfiguration("mailbox");
        String provider = config.getString("provider", "jpa");

        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        String mailbox = null;
        String subscription = null;
        String messageMapperFactory = null;
        String mailboxIdDeserializer = null;
        if (provider.equalsIgnoreCase("jpa")) {
            mailbox = "jpa-mailboxmanager";
            subscription = "jpa-subscriptionManager";
            messageMapperFactory = "jpa-sessionMapperFactory";
            mailboxIdDeserializer = "jpa-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("memory")) {
            mailbox = "memory-mailboxmanager";
            subscription = "memory-subscriptionManager";
            messageMapperFactory = "memory-sessionMapperFactory";
            mailboxIdDeserializer = "memory-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("jcr")) {
            mailbox = "jcr-mailboxmanager";
            subscription = "jcr-subscriptionManager";
            messageMapperFactory = "jcr-sessionMapperFactory";
            mailboxIdDeserializer = "jcr-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("maildir")) {
            mailbox = "maildir-mailboxmanager";
            subscription = "maildir-subscriptionManager";
            messageMapperFactory = "maildir-sessionMapperFactory";
            mailboxIdDeserializer = "maildir-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("hbase")) {
            mailbox = "hbase-mailboxmanager";
            subscription = "hbase-subscriptionManager";
            messageMapperFactory = "hbase-sessionMapperFactory";
            mailboxIdDeserializer = "hbase-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("cassandra")) {
            mailbox = "cassandra-mailboxmanager";
            subscription = "cassandra-subscriptionManager";
            messageMapperFactory = "cassandra-sessionMapperFactory";
            mailboxIdDeserializer = "cassandra-mailbox-id-deserializer";
        }

        if (mailbox == null)
            throw new ConfigurationException("Mailboxmanager provider " + provider + " not supported!");
        registry.registerAlias(mailbox, "mailboxmanager");
        registry.registerAlias(subscription, "subscriptionManager");
        registry.registerAlias(messageMapperFactory, "messageMapperFactory");
        registry.registerAlias(mailboxIdDeserializer, "mailbox-id-deserializer");

    } catch (ConfigurationException e) {
        throw new FatalBeanException("Unable to config the mailboxmanager", e);
    }

}

From source file:org.apache.james.container.spring.lifecycle.osgi.OSGIConfigurationProvider.java

@Override
public HierarchicalConfiguration getConfiguration(String beanName) throws ConfigurationException {
    XMLConfiguration config = new XMLConfiguration();
    FileInputStream fis = null;//from  www  . j  a  va  2s.  c o  m
    config.setDelimiterParsingDisabled(true);

    // Don't split attributes which can have bad side-effects with matcher-conditions.
    // See JAMES-1233
    config.setAttributeSplittingDisabled(true);

    // Use InputStream so we are not bound to File implementations of the
    // config
    try {
        fis = new FileInputStream("/tmp/" + beanName + ".xml");
        config.load(fis);
    } catch (FileNotFoundException e) {
        throw new ConfigurationException("Bean " + beanName);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
                // Left empty on purpose
            }
        }
    }

    return config;
}

From source file:org.apache.james.fetchmail.Account.java

/**
 * Sets the recipient.//from ww  w .  ja v  a  2 s .  c  o m
 * 
 * @param recipient
 *            The recipient to set
 */
protected void setRecipient(String recipient) throws ConfigurationException {
    if (null == recipient) {
        fieldRecipient = null;
        return;
    }

    try {
        setRecipient(new MailAddress(recipient));
    } catch (ParseException pe) {
        throw new ConfigurationException("Invalid recipient address specified: " + recipient);
    }
}

From source file:org.apache.james.fetchmail.FetchMail.java

/**
 * Method configure parses and validates the Configuration data and creates
 * a new <code>ParsedConfiguration</code>, an <code>Account</code> for each
 * configured static account and a/* ww w.  j a  v a2  s .  c o  m*/
 * <code>ParsedDynamicAccountParameters</code> for each dynamic account.
 *
 * @see org.apache.james.lifecycle.api.Configurable#configure(HierarchicalConfiguration)
 */
public void configure(HierarchicalConfiguration configuration) throws ConfigurationException {
    // Set any Session parameters passed in the Configuration
    setSessionParameters(configuration);

    // Create the ParsedConfiguration used in the delegation chain
    ParsedConfiguration parsedConfiguration = new ParsedConfiguration(configuration, logger, getLocalUsers(),
            getDNSService(), getDomainList(), getMailQueue());

    setParsedConfiguration(parsedConfiguration);

    // Setup the Accounts
    List<HierarchicalConfiguration> allAccounts = configuration.configurationsAt("accounts");
    if (allAccounts.size() < 1)
        throw new ConfigurationException("Missing <accounts> section.");
    if (allAccounts.size() > 1)
        throw new ConfigurationException("Too many <accounts> sections, there must be exactly one");
    HierarchicalConfiguration accounts = allAccounts.get(0);

    if (!accounts.getKeys().hasNext())
        throw new ConfigurationException("Missing <account> section.");

    int i = 0;
    // Create an Account for every configured account
    for (ConfigurationNode accountsChild : accounts.getRoot().getChildren()) {

        String accountsChildName = accountsChild.getName();

        List<HierarchicalConfiguration> accountsChildConfig = accounts.configurationsAt(accountsChildName);
        HierarchicalConfiguration conf = accountsChildConfig.get(i);

        if ("alllocal".equals(accountsChildName)) {
            // <allLocal> is dynamic, save the parameters for accounts to
            // be created when the task is triggered
            getParsedDynamicAccountParameters().add(new ParsedDynamicAccountParameters(i, conf));
            continue;
        }

        if ("account".equals(accountsChildName)) {
            // Create an Account for the named user and
            // add it to the list of static accounts
            getStaticAccounts().add(new Account(i, parsedConfiguration, conf.getString("[@user]"),
                    conf.getString("[@password]"), conf.getString("[@recipient]"),
                    conf.getBoolean("[@ignorercpt-header]"), conf.getString("[@customrcpt-header]", ""),
                    getSession()));
            continue;
        }

        throw new ConfigurationException("Illegal token: <" + accountsChildName + "> in <accounts>");
    }
    i++;
}