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.james.smtpserver.fastfail.JDBCGreylistHandler.java

@Override
public void init(Configuration handlerConfiguration) throws ConfigurationException {
    try {//from   ww  w.j  av  a 2s  . c o  m
        setTempBlockTime(handlerConfiguration.getString("tempBlockTime"));
    } catch (NumberFormatException e) {
        throw new ConfigurationException(e.getMessage());
    }

    try {
        setAutoWhiteListLifeTime(handlerConfiguration.getString("autoWhiteListLifeTime"));
    } catch (NumberFormatException e) {
        throw new ConfigurationException(e.getMessage());
    }

    try {
        setUnseenLifeTime(handlerConfiguration.getString("unseenLifeTime"));
    } catch (NumberFormatException e) {
        throw new ConfigurationException(e.getMessage());
    }
    String nets = handlerConfiguration.getString("whitelistedNetworks");
    if (nets != null) {
        String[] whitelistArray = nets.split(",");
        List<String> wList = new ArrayList<String>(whitelistArray.length);
        for (String aWhitelistArray : whitelistArray) {
            wList.add(aWhitelistArray.trim());
        }
        initWhiteListedNetworks(new NetMatcher(wList, dnsService));
        serviceLog.info("Whitelisted addresses: " + getWhiteListedNetworks().toString());

    }

    // Get the SQL file location
    String sFile = handlerConfiguration.getString("sqlFile", null);
    if (sFile != null) {

        setSqlFileUrl(sFile);

        if (!sqlFileUrl.startsWith("file://") && !sqlFileUrl.startsWith("classpath:")) {
            throw new ConfigurationException(
                    "Malformed sqlFile - Must be of the format \"file://<filename>\".");
        }
    } else {
        throw new ConfigurationException("sqlFile is not configured");
    }
    try {
        initSqlQueries(datasource.getConnection(), sqlFileUrl);

        // create table if not exist
        createTable("greyListTableName", "createGreyListTable");
    } catch (Exception e) {
        throw new RuntimeException("Unable to init datasource", e);
    }
}

From source file:org.apache.james.smtpserver.fastfail.SpamTrapHandler.java

@Override
public void init(Configuration config) throws ConfigurationException {
    String[] rcpts = config.getStringArray("spamTrapRecip");

    if (rcpts.length == 0) {
        setSpamTrapRecipients(Arrays.asList(rcpts));
    } else {// w ww .  j av  a 2 s .  co  m
        throw new ConfigurationException("Please configure a spamTrapRecip.");
    }

    setBlockTime(config.getLong("blockTime", blockTime));
}

From source file:org.apache.james.smtpserver.fastfail.URIRBLHandler.java

@Override
public void init(Configuration config) throws ConfigurationException {
    String[] servers = config.getStringArray("uriRblServers.server");
    Collection<String> serverCollection = new ArrayList<String>();
    for (String rblServerName : servers) {
        serverCollection.add(rblServerName);
        if (serviceLog.isInfoEnabled()) {
            serviceLog.info("Adding uriRBL server: " + rblServerName);
        }// ww w. j av a  2  s  .  c  om
    }
    if (serverCollection != null && serverCollection.size() > 0) {
        setUriRblServer(serverCollection);
    } else {
        throw new ConfigurationException("Please provide at least one server");
    }

    setGetDetail(config.getBoolean("getDetail", false));
}

From source file:org.apache.james.smtpserver.fastfail.ValidRcptMX.java

@Override
public void init(Configuration config) throws ConfigurationException {

    String[] networks = config.getStringArray("invalidMXNetworks");

    if (networks.length == 0) {

        Collection<String> bannedNetworks = new ArrayList<String>();
        for (String network : networks) {
            bannedNetworks.add(network.trim());
        }/* ww  w. j  av a 2 s. c  o  m*/

        setBannedNetworks(bannedNetworks, dnsService);

        serviceLog.info("Invalid MX Networks: " + bNetwork.toString());

    } else {
        throw new ConfigurationException("Please configure at least on invalid MX network");
    }
}

From source file:org.apache.james.smtpserver.MailPriorityHandler.java

@Override
public void init(Configuration config) throws ConfigurationException {
    List<HierarchicalConfiguration> entries = ((HierarchicalConfiguration) config)
            .configurationsAt("priorityEntries.priorityEntry");
    for (HierarchicalConfiguration prioConf : entries) {
        String domain = prioConf.getString("domain");
        int prio = prioConf.getInt("priority", MailPrioritySupport.NORMAL_PRIORITY);
        if (prio > MailPrioritySupport.HIGH_PRIORITY || prio < MailPrioritySupport.LOW_PRIORITY) {
            throw new ConfigurationException("configured priority must be >= "
                    + MailPrioritySupport.LOW_PRIORITY + " and <= " + MailPrioritySupport.HIGH_PRIORITY);
        }//from  w ww.j  a  va2 s. com
        prioMap.put(domain, prio);
    }
}

From source file:org.apache.james.smtpserver.POP3BeforeSMTPHandler.java

public void configure(HierarchicalConfiguration config) throws ConfigurationException {
    try {//  w  w  w  .  java 2s  .  com
        setExpireTime(config.getString("expireTime", null));
    } catch (NumberFormatException e) {
        throw new ConfigurationException("Please configure a valid expireTime: " + e.getMessage());
    }
}

From source file:org.apache.james.user.jdbc.AbstractJdbcUsersRepository.java

/**
 * <p>//from   w w  w.jav a 2 s  . c  om
 * Configures the UserRepository for JDBC access.
 * </p>
 * <p>
 * Requires a configuration element in the .conf.xml file of the form:
 * </p>
 * 
 * <pre>
 *   &lt;repository name=&quot;so even &quot;
 *       class=&quot;org.apache.james.userrepository.JamesUsersJdbcRepository&quot;&gt;
 *       &lt;!-- Name of the datasource to use --&gt;
 *       &lt;data-source&gt;MailDb&lt;/data-source&gt;
 *       &lt;!-- File to load the SQL definitions from --&gt;
 *       &lt;sqlFile&gt;dist/conf/sqlResources.xml&lt;/sqlFile&gt;
 *       &lt;!-- replacement parameters for the sql file --&gt;
 *       &lt;sqlParameters table=&quot;JamesUsers&quot;/&gt;
 *   &lt;/repository&gt;
 * </pre>
 * 
 * @see org.apache.james.user.lib.AbstractJamesUsersRepository#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)
 */
protected void doConfigure(HierarchicalConfiguration configuration) throws ConfigurationException {
    StringBuffer logBuffer;
    if (getLogger().isDebugEnabled()) {
        logBuffer = new StringBuffer(64).append(this.getClass().getName()).append(".configure()");
        getLogger().debug(logBuffer.toString());
    }

    // Parse the DestinationURL for the name of the datasource,
    // the table to use, and the (optional) repository Key.
    String destUrl = configuration.getString("[@destinationURL]", null);
    // throw an exception if the attribute is missing
    if (destUrl == null)
        throw new ConfigurationException("destinationURL attribute is missing from Configuration");

    // normalise the destination, to simplify processing.
    if (!destUrl.endsWith("/")) {
        destUrl += "/";
    }
    // Split on "/", starting after "db://"
    List<String> urlParams = new ArrayList<String>();
    int start = 5;
    int end = destUrl.indexOf('/', start);
    while (end > -1) {
        urlParams.add(destUrl.substring(start, end));
        start = end + 1;
        end = destUrl.indexOf('/', start);
    }

    // Build SqlParameters and get datasource name from URL parameters
    m_sqlParameters = new HashMap<String, String>();
    switch (urlParams.size()) {
    case 3:
        m_sqlParameters.put("key", urlParams.get(2));
    case 2:
        m_sqlParameters.put("table", urlParams.get(1));
    case 1:
        urlParams.get(0);
        break;
    default:
        throw new ConfigurationException("Malformed destinationURL - "
                + "Must be of the format \"db://<data-source>[/<table>[/<key>]]\".");
    }

    if (getLogger().isDebugEnabled()) {
        logBuffer = new StringBuffer(128).append("Parsed URL: table = '").append(m_sqlParameters.get("table"))
                .append("', key = '").append(m_sqlParameters.get("key")).append("'");
        getLogger().debug(logBuffer.toString());
    }

    // Get the SQL file location
    m_sqlFileName = configuration.getString("sqlFile", null);

    // Get other sql parameters from the configuration object,
    // if any.
    Iterator<String> paramIt = configuration.getKeys("sqlParameters");
    while (paramIt.hasNext()) {
        String rawName = paramIt.next();
        String paramName = paramIt.next().substring("sqlParameters.[@".length(), rawName.length() - 1);
        String paramValue = configuration.getString(rawName);
        m_sqlParameters.put(paramName, paramValue);
    }
}

From source file:org.apache.james.user.ldap.LdapRepositoryConfiguration.java

private void checkState() throws ConfigurationException {
    if (userBase == null) {
        throw new ConfigurationException("[@userBase] is mandatory");
    }/*from ww w.j a  va 2s. c o m*/
    if (userIdAttribute == null) {
        throw new ConfigurationException("[@userIdAttribute] is mandatory");
    }
    if (userObjectClass == null) {
        throw new ConfigurationException("[@userObjectClass] is mandatory");
    }
}

From source file:org.apache.james.utils.InMemoryMailRepositoryStore.java

private void readConfigurationEntry(HierarchicalConfiguration repositoryConfiguration)
        throws ConfigurationException {
    String className = repositoryConfiguration.getString("[@class]");
    MailRepositoryProvider usedMailRepository = mailRepositories.stream()
            .filter(mailRepositoryProvider -> mailRepositoryProvider.canonicalName().equals(className))
            .findAny().orElseThrow(() -> new ConfigurationException(
                    "MailRepository " + className + " has not been registered"));
    for (String protocol : repositoryConfiguration.getStringArray("protocols.protocol")) {
        protocolToRepositoryProvider.put(protocol, usedMailRepository);
        registerRepositoryDefaultConfiguration(repositoryConfiguration, protocol);
    }//from  w ww .java  2 s  .  c o m
}

From source file:org.apache.juddi.config.AppConfig.java

private Properties getPersistentConfiguration(Configuration config) throws ConfigurationException {
    Properties result = new Properties();

    EntityManager em = PersistenceManager.getEntityManager();
    EntityTransaction tx = em.getTransaction();
    try {//from   ww  w.  j a v a  2  s . com
        boolean seedAlways = config.getBoolean("juddi.seed.always", false);
        if (seedAlways || !Install.alreadyInstalled(config)) {
            if (seedAlways) {
                log.info("Installing UDDI seed data, loading...");
            } else {
                log.info("The 'root' publisher was not found, loading...");
            }
            try {
                Install.install(config);
            } catch (Exception e) {
                throw new ConfigurationException(e);
            } catch (Throwable t) {
                throw new ConfigurationException(t);
            }
        }

        tx.begin();

        String rootPublisherStr = config.getString(Property.JUDDI_ROOT_PUBLISHER);
        UddiEntityPublisher rootPublisher = new UddiEntityPublisher(rootPublisherStr);
        rootPublisher.populateKeyGeneratorKeys(em);
        List<String> rootKeyGenList = rootPublisher.getKeyGeneratorKeys();
        if (rootKeyGenList == null || rootKeyGenList.size() == 0)
            throw new ConfigurationException(
                    "The 'root' publisher key generator was not found.  Please make sure that the application is properly installed.");

        String rootKeyGen = rootKeyGenList.iterator().next();
        //rootKeyGen = rootKeyGen.substring((KeyGenerator.UDDI_SCHEME + KeyGenerator.PARTITION_SEPARATOR).length());
        rootKeyGen = rootKeyGen.substring(0, rootKeyGen.length()
                - (KeyGenerator.PARTITION_SEPARATOR + KeyGenerator.KEYGENERATOR_SUFFIX).length());
        log.debug("root partition:  " + rootKeyGen);

        result.setProperty(Property.JUDDI_ROOT_PARTITION, rootKeyGen);

        // The node Id is defined as the business key of the business entity categorized as a node.  This entity is saved as part of the install.
        // Only one business entity should be categorized as a node.
        String nodeId = "";
        CategoryBag categoryBag = new CategoryBag();
        KeyedReference keyedRef = new KeyedReference();
        keyedRef.setTModelKey(Constants.NODE_CATEGORY_TMODEL);
        keyedRef.setKeyValue(Constants.NODE_KEYVALUE);
        categoryBag.getKeyedReference().add(keyedRef);
        List<?> keyList = FindBusinessByCategoryQuery.select(em, new FindQualifiers(), categoryBag, null);
        if (keyList != null && keyList.size() > 1)
            throw new ConfigurationException("Only one business entity can be categorized as the node.");

        if (keyList != null && keyList.size() > 0) {
            nodeId = (String) keyList.get(0);
        } else
            throw new ConfigurationException(
                    "A node business entity was not found.  Please make sure that the application is properly installed.");
        result.setProperty(Property.JUDDI_NODE_ID, nodeId);

        //result.setProperty(Property.JUDDI_NODE_ROOT_BUSINESS, nodeId);

        tx.commit();
        return result;
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        em.close();
    }
}