List of usage examples for org.apache.commons.configuration ConfigurationException ConfigurationException
public ConfigurationException(Throwable cause)
ConfigurationException
with specified nested Throwable
. From source file:org.apache.james.fetchmail.ParsedConfiguration.java
/** * Sets the blacklist.//from w w w . j a v a 2 s .c o m * * @param blacklistValue * The blacklist to set */ protected void setBlacklist(String blacklistValue) throws ConfigurationException { StringTokenizer st = new StringTokenizer(blacklistValue, ", \t", false); Set<MailAddress> blacklist = new HashSet<MailAddress>(); String token = null; while (st.hasMoreTokens()) { try { token = st.nextToken(); blacklist.add(new MailAddress(token)); } catch (ParseException pe) { throw new ConfigurationException("Invalid blacklist mail address specified: " + token); } } setBlacklist(blacklist); }
From source file:org.apache.james.fetchmail.ParsedConfiguration.java
/** * Validates the defaultDomainName./*from ww w . j a v a 2s. c o m*/ * * @param defaultDomainName * The defaultDomainName to validate */ protected void validateDefaultDomainName(String defaultDomainName) throws ConfigurationException { try { if (!getDomainList().containsDomain(defaultDomainName)) { throw new ConfigurationException("Default domain name is not a local server: " + defaultDomainName); } } catch (DomainListException e) { throw new ConfigurationException("Unable to access DomainList", e); } }
From source file:org.apache.james.imapserver.netty.IMAPServer.java
@Override public void doConfigure(HierarchicalConfiguration configuration) throws ConfigurationException { super.doConfigure(configuration); hello = softwaretype + " Server " + getHelloName() + " is ready."; compress = configuration.getBoolean("compress", false); maxLineLength = configuration.getInt("maxLineLength", DEFAULT_MAX_LINE_LENGTH); inMemorySizeLimit = configuration.getInt("inMemorySizeLimit", DEFAULT_IN_MEMORY_SIZE_LIMIT); literalSizeLimit = configuration.getInt("literalSizeLimit", DEFAULT_LITERAL_SIZE_LIMIT); plainAuthDisallowed = configuration.getBoolean("plainAuthDisallowed", false); timeout = configuration.getInt("timeout", DEFAULT_TIMEOUT); if (timeout < DEFAULT_TIMEOUT) { throw new ConfigurationException("Minimum timeout of 30 minutes required. See rfc2060 5.4 for details"); }//from w w w .j a v a2 s . c o m if (timeout < 0) { timeout = 0; } }
From source file:org.apache.james.mailetcontainer.lib.AbstractStateCompositeProcessor.java
/** * Check if all needed Processors are configured and if not throw a * {@link ConfigurationException}/*from w w w .ja v a2s .com*/ * * @throws ConfigurationException */ private void checkProcessors() throws ConfigurationException { boolean errorProcessorFound = false; boolean rootProcessorFound = false; for (String name : processors.keySet()) { if (name.equals(Mail.DEFAULT)) { rootProcessorFound = true; } else if (name.equals(Mail.ERROR)) { errorProcessorFound = true; } if (errorProcessorFound && rootProcessorFound) { return; } } if (!errorProcessorFound) { throw new ConfigurationException("You need to configure a Processor with name " + Mail.ERROR); } else if (!rootProcessorFound) { throw new ConfigurationException("You need to configure a Processor with name " + Mail.DEFAULT); } }
From source file:org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor.java
/** * @see// w w w. j av a 2 s . c o m * org.apache.james.lifecycle.api.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration) */ public void configure(HierarchicalConfiguration config) throws ConfigurationException { this.state = config.getString("[@state]", null); if (state == null) throw new ConfigurationException("Processor state attribute must be configured"); if (state.equals(Mail.GHOST)) throw new ConfigurationException( "Processor state of " + Mail.GHOST + " is reserved for internal use, choose a different one"); this.enableJmx = config.getBoolean("[@enableJmx]", true); this.config = config; }
From source file:org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor.java
/** * Load {@link CompositeMatcher} implementations and their child * {@link Matcher}'s//from w w w . ja va 2 s . c om * * CompositeMatcher were added by JAMES-948 * * @param compMap * @param compMatcherConfs * @return compositeMatchers * @throws ConfigurationException * @throws MessagingException * @throws NotCompliantMBeanException */ private List<Matcher> loadCompositeMatchers(String state, Map<String, Matcher> compMap, List<HierarchicalConfiguration> compMatcherConfs) throws ConfigurationException, MessagingException { List<Matcher> matchers = new ArrayList<Matcher>(); for (HierarchicalConfiguration c : compMatcherConfs) { String compName = c.getString("[@name]", null); String matcherName = c.getString("[@match]", null); String invertedMatcherName = c.getString("[@notmatch]", null); Matcher matcher = null; if (matcherName != null && invertedMatcherName != null) { // if no matcher is configured throw an Exception throw new ConfigurationException("Please configure only match or nomatch per mailet"); } else if (matcherName != null) { matcher = matcherLoader.getMatcher(createMatcherConfig(matcherName)); if (matcher instanceof CompositeMatcher) { CompositeMatcher compMatcher = (CompositeMatcher) matcher; List<Matcher> childMatcher = loadCompositeMatchers(state, compMap, c.configurationsAt("matcher")); for (Matcher aChildMatcher : childMatcher) { compMatcher.add(aChildMatcher); } } } else if (invertedMatcherName != null) { Matcher m = matcherLoader.getMatcher(createMatcherConfig(invertedMatcherName)); if (m instanceof CompositeMatcher) { CompositeMatcher compMatcher = (CompositeMatcher) m; List<Matcher> childMatcher = loadCompositeMatchers(state, compMap, c.configurationsAt("matcher")); for (Matcher aChildMatcher : childMatcher) { compMatcher.add(aChildMatcher); } } matcher = new MatcherInverter(m); } if (matcher == null) throw new ConfigurationException("Unable to load matcher instance"); matchers.add(matcher); if (compName != null) { // check if there is already a composite Matcher with the name // registered in the processor if (compMap.containsKey(compName)) throw new ConfigurationException( "CompositeMatcher with name " + compName + " is already defined in processor " + state); compMap.put(compName, matcher); } } return matchers; }
From source file:org.apache.james.mailetcontainer.lib.AbstractStateMailetProcessor.java
private void parseConfiguration() throws MessagingException, ConfigurationException { // load composite matchers if there are any Map<String, Matcher> compositeMatchers = new HashMap<String, Matcher>(); loadCompositeMatchers(getState(), compositeMatchers, config.configurationsAt("matcher")); final List<HierarchicalConfiguration> mailetConfs = config.configurationsAt("mailet"); // Loop through the mailet configuration, load // all of the matcher and mailets, and add // them to the processor. for (HierarchicalConfiguration c : mailetConfs) { // We need to set this because of correctly parsing comma String mailetClassName = c.getString("[@class]"); String matcherName = c.getString("[@match]", null); String invertedMatcherName = c.getString("[@notmatch]", null); Mailet mailet;// w w w . j a va2 s . c o m Matcher matcher; try { if (matcherName != null && invertedMatcherName != null) { // if no matcher is configured throw an Exception throw new ConfigurationException("Please configure only match or nomatch per mailet"); } else if (matcherName != null) { // try to load from compositeMatchers first matcher = compositeMatchers.get(matcherName); if (matcher == null) { // no composite Matcher found, try to load it via // MatcherLoader matcher = matcherLoader.getMatcher(createMatcherConfig(matcherName)); } } else if (invertedMatcherName != null) { // try to load from compositeMatchers first // matcherName is a known null value at this state matcher = compositeMatchers.get(matcherName); if (matcher == null) { // no composite Matcher found, try to load it via // MatcherLoader matcher = matcherLoader.getMatcher(createMatcherConfig(invertedMatcherName)); } matcher = new MatcherInverter(matcher); } else { // default matcher is All matcher = matcherLoader.getMatcher(createMatcherConfig("All")); } // The matcher itself should log that it's been inited. if (logger.isInfoEnabled()) { String infoBuffer = "Matcher " + matcherName + " instantiated."; logger.info(infoBuffer.toString()); } } catch (MessagingException ex) { // **** Do better job printing out exception if (logger.isErrorEnabled()) { String errorBuffer = "Unable to init matcher " + matcherName + ": " + ex.toString(); logger.error(errorBuffer.toString(), ex); if (ex.getNextException() != null) { logger.error("Caused by nested exception: ", ex.getNextException()); } } throw new ConfigurationException("Unable to init matcher " + matcherName, ex); } try { mailet = mailetLoader.getMailet(createMailetConfig(mailetClassName, c)); if (logger.isInfoEnabled()) { String infoBuffer = "Mailet " + mailetClassName + " instantiated."; logger.info(infoBuffer.toString()); } } catch (MessagingException ex) { // **** Do better job printing out exception if (logger.isErrorEnabled()) { String errorBuffer = "Unable to init mailet " + mailetClassName + ": " + ex.toString(); logger.error(errorBuffer.toString(), ex); if (ex.getNextException() != null) { logger.error("Caused by nested exception: ", ex.getNextException()); } } throw new ConfigurationException("Unable to init mailet " + mailetClassName, ex); } if (matcher != null && mailet != null) { pairs.add(new MatcherMailetPair(matcher, mailet)); } else { throw new ConfigurationException("Unable to load Mailet or Matcher"); } } }
From source file:org.apache.james.mailrepository.file.MBoxMailRepository.java
public void configure(HierarchicalConfiguration configuration) throws ConfigurationException { /*//from w ww .j a va 2 s . c om The repository configuration */ String destination; this.mList = null; BUFFERING = configuration.getBoolean("[@BUFFERING]", true); fifo = configuration.getBoolean("[@FIFO]", false); destination = configuration.getString("[@destinationURL]"); if (destination.charAt(destination.length() - 1) == '/') { // Remove the trailing / as well as the protocol marker mboxFile = destination.substring("mbox://".length(), destination.lastIndexOf("/")); } else { mboxFile = destination.substring("mbox://".length()); } if (getLogger().isDebugEnabled()) { getLogger().debug("MBoxMailRepository.destinationURL: " + destination); } String checkType = configuration.getString("[@type]"); if (!(checkType.equals("MAIL") || checkType.equals("SPOOL"))) { String exceptionString = "Attempt to configure MboxMailRepository as " + checkType; if (getLogger().isWarnEnabled()) { getLogger().warn(exceptionString); } throw new ConfigurationException(exceptionString); } }
From source file:org.apache.james.mailrepository.jdbc.JDBCMailRepository.java
protected void doConfigure(HierarchicalConfiguration configuration) throws ConfigurationException { super.doConfigure(configuration); if (getLogger().isDebugEnabled()) { getLogger().debug(this.getClass().getName() + ".configure()"); }//from w w w . ja v a 2 s.co m destination = configuration.getString("[@destinationURL]"); // normalize the destination, to simplify processing. if (!destination.endsWith("/")) { destination += "/"; } // Parse the DestinationURL for the name of the datasource, // the table to use, and the (optional) repository Key. // Split on "/", starting after "db://" List<String> urlParams = new ArrayList<String>(); int start = 5; if (destination.startsWith("dbfile")) { // this is dbfile:// instead of db:// start += 4; } int end = destination.indexOf('/', start); while (end > -1) { urlParams.add(destination.substring(start, end)); start = end + 1; end = destination.indexOf('/', start); } // Build SqlParameters and get datasource name from URL parameters if (urlParams.size() == 0) { String exceptionBuffer = "Malformed destinationURL - Must be of the format '" + "db://<data-source>[/<table>[/<repositoryName>]]'. Was passed " + configuration.getString("[@destinationURL]"); throw new ConfigurationException(exceptionBuffer); } if (urlParams.size() >= 1) { datasourceName = urlParams.get(0); } if (urlParams.size() >= 2) { tableName = urlParams.get(1); } if (urlParams.size() >= 3) { repositoryName = ""; for (int i = 2; i < urlParams.size(); i++) { if (i >= 3) { repositoryName += '/'; } repositoryName += urlParams.get(i); } } if (getLogger().isDebugEnabled()) { String logBuffer = "Parsed URL: table = '" + tableName + "', repositoryName = '" + repositoryName + "'"; getLogger().debug(logBuffer); } inMemorySizeLimit = configuration.getInt("inMemorySizeLimit", 409600000); filestore = configuration.getString("filestore", null); sqlFileName = configuration.getString("sqlFile"); }
From source file:org.apache.james.mailrepository.memory.MemoryMailRepositoryStore.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(new Protocol(protocol), usedMailRepository); registerRepositoryDefaultConfiguration(repositoryConfiguration, new Protocol(protocol)); }/* w ww .ja va 2 s . co m*/ }