List of usage examples for org.apache.commons.configuration ConfigurationException ConfigurationException
public ConfigurationException(String message, Throwable cause)
ConfigurationException
with specified detail message and nested Throwable
. From source file:org.apache.james.fetchmail.FetchMail.java
/** * Compute the dynamicAccounts for the passed parameters. Accounts for * existing users are copied and accounts for new users are created. * * @param oldAccounts/* w ww .j ava 2s. c o m*/ * @param parameters * @return Map - The current Accounts * @throws ConfigurationException */ protected Map<DynamicAccountKey, DynamicAccount> computeDynamicAccounts( Map<DynamicAccountKey, DynamicAccount> oldAccounts, ParsedDynamicAccountParameters parameters) throws ConfigurationException { Map<DynamicAccountKey, DynamicAccount> accounts; Iterator<String> usersIterator; try { accounts = new HashMap<DynamicAccountKey, DynamicAccount>(getLocalUsers().countUsers()); usersIterator = getLocalUsers().list(); } catch (UsersRepositoryException e) { throw new ConfigurationException("Unable to access UsersRepository", e); } while (usersIterator.hasNext()) { String userName = usersIterator.next(); DynamicAccountKey key = new DynamicAccountKey(userName, parameters.getSequenceNumber()); DynamicAccount account = oldAccounts.get(key); if (null == account) { // Create a new DynamicAccount account = new DynamicAccount(parameters.getSequenceNumber(), getConfiguration(), userName, parameters.getUserPrefix(), parameters.getUserSuffix(), parameters.getPassword(), parameters.getRecipientPrefix(), parameters.getRecipientSuffix(), parameters.isIgnoreRecipientHeader(), parameters.getCustomRecipientHeader(), getSession()); } accounts.put(key, account); } return accounts; }
From source file:org.apache.james.mailetcontainer.impl.JamesMailetContext.java
@Override public void configure(HierarchicalConfiguration config) throws ConfigurationException { try {/*from w w w . j av a2 s . c o m*/ // Get postmaster String postMasterAddress = config.getString("postmaster", "postmaster").toLowerCase(Locale.US); // if there is no @domain part, then add the first one from the // list of supported domains that isn't localhost. If that // doesn't work, use the hostname, even if it is localhost. if (postMasterAddress.indexOf('@') < 0) { String domainName = null; // the domain to use // loop through candidate domains until we find one or exhaust // the // list for (String dom : domains.getDomains()) { String serverName = dom.toLowerCase(Locale.US); if (!("localhost".equals(serverName))) { domainName = serverName; // ok, not localhost, so // use it } } // if we found a suitable domain, use it. Otherwise fallback to // the // host name. postMasterAddress = postMasterAddress + "@" + (domainName != null ? domainName : domains.getDefaultDomain()); } try { this.postmaster = new MailAddress(postMasterAddress); if (!domains.containsDomain(postmaster.getDomain())) { String warnBuffer = "The specified postmaster address ( " + postmaster + " ) is not a local " + "address. This is not necessarily a problem, but it does mean that emails addressed to " + "the postmaster will be routed to another server. For some configurations this may " + "cause problems."; log.warn(warnBuffer); } } catch (AddressException e) { throw new ConfigurationException("Postmaster address " + postMasterAddress + "is invalid", e); } } catch (DomainListException e) { throw new ConfigurationException("Unable to access DomainList", e); } }
From source file:org.apache.james.mailrepository.jdbc.JDBCMailRepository.java
/** * Initialises the JDBC repository./*w w w . ja v a 2s . c o m*/ * <ol> * <li>Tests the connection to the database.</li> * <li>Loads SQL strings from the SQL definition file, choosing the * appropriate SQL for this connection, and performing paramter * substitution,</li> * <li>Initialises the database with the required tables, if necessary.</li> * </ol> * * @throws Exception * if an error occurs */ @Override @PostConstruct public void init() throws Exception { StringBuffer logBuffer; if (getLogger().isDebugEnabled()) { getLogger().debug(this.getClass().getName() + ".initialize()"); } try { if (filestore != null) { // prepare Configurations for stream repositories DefaultConfigurationBuilder streamConfiguration = new DefaultConfigurationBuilder(); streamConfiguration.addProperty("[@destinationURL]", filestore); sr = new FilePersistentStreamRepository(); sr.setLog(getLogger()); sr.setFileSystem(fileSystem); sr.configure(streamConfiguration); sr.init(); if (getLogger().isDebugEnabled()) { getLogger().debug("Got filestore for JdbcMailRepository: " + filestore); } } if (getLogger().isDebugEnabled()) { String logBuf = this.getClass().getName() + " created according to " + destination; getLogger().debug(logBuf); } } catch (Exception e) { final String message = "Failed to retrieve Store component:" + e.getMessage(); getLogger().error(message, e); throw new ConfigurationException(message, e); } theJDBCUtil = new JDBCUtil() { protected void delegatedLog(String logString) { JDBCMailRepository.this.getLogger().warn("JDBCMailRepository: " + logString); } }; // Test the connection to the database, by getting the DatabaseMetaData. Connection conn = datasource.getConnection(); PreparedStatement createStatement = null; try { // Initialise the sql strings. InputStream sqlFile; try { sqlFile = fileSystem.getResource(sqlFileName); } catch (Exception e) { getLogger().error(e.getMessage(), e); throw e; } if (getLogger().isDebugEnabled()) { logBuffer = new StringBuffer(128).append("Reading SQL resources from file: ").append(sqlFileName) .append(", section ").append(this.getClass().getName()).append("."); getLogger().debug(logBuffer.toString()); } // Build the statement parameters Map<String, String> sqlParameters = new HashMap<String, String>(); if (tableName != null) { sqlParameters.put("table", tableName); } if (repositoryName != null) { sqlParameters.put("repository", repositoryName); } sqlQueries = new SqlResources(); sqlQueries.init(sqlFile, this.getClass().getName(), conn, sqlParameters); // Check if the required table exists. If not, create it. DatabaseMetaData dbMetaData = conn.getMetaData(); // Need to ask in the case that identifiers are stored, ask the // DatabaseMetaInfo. // Try UPPER, lower, and MixedCase, to see if the table is there. if (!(theJDBCUtil.tableExists(dbMetaData, tableName))) { // Users table doesn't exist - create it. createStatement = conn.prepareStatement(sqlQueries.getSqlString("createTable", true)); createStatement.execute(); if (getLogger().isInfoEnabled()) { logBuffer = new StringBuffer(64).append("JdbcMailRepository: Created table '").append(tableName) .append("'."); getLogger().info(logBuffer.toString()); } } checkJdbcAttributesSupport(dbMetaData); } finally { theJDBCUtil.closeJDBCStatement(createStatement); theJDBCUtil.closeJDBCConnection(conn); } }
From source file:org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer.java
/** * @see/*from w ww .j ava2 s . c o m*/ * org.apache.james.lifecycle.api.Configurable * #configure(org.apache.commons.configuration.HierarchicalConfiguration) */ public final void configure(HierarchicalConfiguration config) throws ConfigurationException { enabled = config.getBoolean("[@enabled]", true); final Logger logger = getLogger(); if (!enabled) { logger.info(getServiceType() + " disabled by configuration"); return; } String listen[] = config.getString("bind", "0.0.0.0:" + getDefaultPort()).split(","); List<InetSocketAddress> bindAddresses = new ArrayList<InetSocketAddress>(); for (String aListen : listen) { String bind[] = aListen.split(":"); InetSocketAddress address; String ip = bind[0].trim(); int port = Integer.parseInt(bind[1].trim()); if (!ip.equals("0.0.0.0")) { try { ip = InetAddress.getByName(ip).getHostName(); } catch (UnknownHostException unhe) { throw new ConfigurationException( "Malformed bind parameter in configuration of service " + getServiceType(), unhe); } } address = new InetSocketAddress(ip, port); String infoBuffer = getServiceType() + " bound to: " + ip + ":" + port; logger.info(infoBuffer); bindAddresses.add(address); } setListenAddresses(bindAddresses.toArray(new InetSocketAddress[bindAddresses.size()])); jmxName = config.getString("jmxName", getDefaultJMXName()); int ioWorker = config.getInt("ioWorkerCount", DEFAULT_IO_WORKER_COUNT); setIoWorkerCount(ioWorker); maxExecutorThreads = config.getInt("maxExecutorCount", DEFAULT_MAX_EXECUTOR_COUNT); configureHelloName(config); setTimeout(config.getInt(TIMEOUT_NAME, DEFAULT_TIMEOUT)); StringBuilder infoBuffer = new StringBuilder(64).append(getServiceType()) .append(" handler connection timeout is: ").append(getTimeout()); logger.info(infoBuffer.toString()); setBacklog(config.getInt(BACKLOG_NAME, DEFAULT_BACKLOG)); infoBuffer = new StringBuilder(64).append(getServiceType()).append(" connection backlog is: ") .append(getBacklog()); logger.info(infoBuffer.toString()); String connectionLimitString = config.getString("connectionLimit", null); if (connectionLimitString != null) { try { connectionLimit = new Integer(connectionLimitString); } catch (NumberFormatException nfe) { logger.error("Connection limit value is not properly formatted.", nfe); } if (connectionLimit < 0) { logger.error("Connection limit value cannot be less than zero."); throw new ConfigurationException("Connection limit value cannot be less than zero."); } else if (connectionLimit > 0) { infoBuffer = new StringBuilder(128).append(getServiceType()).append(" will allow a maximum of ") .append(connectionLimitString).append(" connections."); logger.info(infoBuffer.toString()); } } String connectionLimitPerIP = config.getString("connectionLimitPerIP", null); if (connectionLimitPerIP != null) { try { connPerIP = Integer.parseInt(connectionLimitPerIP); } catch (NumberFormatException nfe) { logger.error("Connection limit per IP value is not properly formatted.", nfe); } if (connPerIP < 0) { logger.error("Connection limit per IP value cannot be less than zero."); throw new ConfigurationException("Connection limit value cannot be less than zero."); } else if (connPerIP > 0) { infoBuffer = new StringBuilder(128).append(getServiceType()).append(" will allow a maximum of ") .append(connPerIP).append(" per IP connections for ").append(getServiceType()); logger.info(infoBuffer.toString()); } } useStartTLS = config.getBoolean("tls.[@startTLS]", false); useSSL = config.getBoolean("tls.[@socketTLS]", false); if (useSSL && useStartTLS) throw new ConfigurationException("startTLS is only supported when using plain sockets"); if (useStartTLS || useSSL) { enabledCipherSuites = config.getStringArray("tls.supportedCipherSuites.cipherSuite"); keystore = config.getString("tls.keystore", null); if (keystore == null) { throw new ConfigurationException("keystore needs to get configured"); } secret = config.getString("tls.secret", ""); x509Algorithm = config.getString("tls.algorithm", defaultX509algorithm); } doConfigure(config); }
From source file:org.apache.james.protocols.lib.ProtocolHandlerChainImpl.java
private void registerHandlersPackage(HandlersPackage handlersPackage, HierarchicalConfiguration handlerConfig, List<HierarchicalConfiguration> children) throws ConfigurationException { List<String> c = handlersPackage.getHandlers(); for (String cName : c) { try {// www . j a v a2 s.c o m CombinedConfiguration conf = new CombinedConfiguration(); HierarchicalConfiguration cmdConf = addHandler(cName); conf.addConfiguration(cmdConf); if (handlerConfig != null) { conf.addConfiguration(handlerConfig); } children.add(conf); } catch (ConfigurationException e) { throw new ConfigurationException("Unable to create configuration for handler " + cName, e); } } }
From source file:org.apache.james.utils.FileConfigurationProvider.java
private InputStream retrieveConfigInputStream(String configurationFileWithoutExtension) throws ConfigurationException { Preconditions.checkArgument(!Strings.isNullOrEmpty(configurationFileWithoutExtension), "The configuration file name should not be empty or null"); try {//ww w .jav a 2 s . c om return fileSystem.getResource( configurationPrefix + configurationFileWithoutExtension + CONFIGURATION_FILE_SUFFIX); } catch (IOException e) { throw new ConfigurationException("Unable to locate configuration file " + configurationFileWithoutExtension + CONFIGURATION_FILE_SUFFIX, e); } }
From source file:org.apache.juddi.v3.client.config.UDDIClient.java
protected void startEmbeddedServer() throws ConfigurationException { try {/* w w w . j a v a 2 s . c o m*/ String embeddedServerClass = getClientConfig().getHomeNode().getProperties() .getProperty("embeddedServer", "org.apache.juddi.v3.client.embed.JUDDIRegistry"); Class<?> clazz = ClassUtil.forName(embeddedServerClass, this.getClass()); EmbeddedRegistry embeddedRegistry = (EmbeddedRegistry) clazz.newInstance(); embeddedRegistry.start(); } catch (Exception e) { throw new ConfigurationException(e.getMessage(), e); } }
From source file:org.apache.juddi.v3.client.config.UDDIClient.java
protected void stopEmbeddedServer() throws ConfigurationException { try {/* w w w . j a va 2 s. co m*/ String embeddedServerClass = getClientConfig().getHomeNode().getProperties() .getProperty("embeddedServer", "org.apache.juddi.v3.client.embed.JUDDIRegistry"); Class<?> clazz = ClassUtil.forName(embeddedServerClass, this.getClass()); EmbeddedRegistry embeddedRegistry = (EmbeddedRegistry) clazz.newInstance(); embeddedRegistry.stop(); } catch (Exception e) { throw new ConfigurationException(e.getMessage(), e); } }
From source file:org.apache.juddi.v3.client.mapping.ServiceLocator.java
/** * Returns the selection policy in use by this instance of the ServiceLocator. * /*from w ww . j a v a2 s. c om*/ * @return SelectionPolicy - the selection policy. * @throws ConfigurationException */ public SelectionPolicy getPolicy() throws ConfigurationException { try { if (selectionPolicy == null) { if (policy == null) { //TODO move this constant to Property.class policy = properties.getProperty("juddi.client.selection.policy", "org.apache.juddi.v3.client.mapping.PolicyLocalFirst"); } @SuppressWarnings("unchecked") Class<? extends SelectionPolicy> selectionPolicyClass = (Class<? extends SelectionPolicy>) ClassUtil .forName(policy, this.getClass()); selectionPolicy = selectionPolicyClass.getConstructor(Properties.class).newInstance(properties); } return selectionPolicy; } catch (Exception e) { throw new ConfigurationException(e.getMessage(), e); } }
From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java
@Override public void load(final Reader in) throws ConfigurationException { try {/* w ww. ja v a2s.co m*/ this.loadHierarchy(this.getRootNode(), yaml.load(in)); } catch (Throwable e) { throw new ConfigurationException("Failed to load configuration: " + e.getMessage(), e); } }