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

Source Link

Document

Constructs a new ConfigurationException with specified detail message and nested Throwable.

Usage

From source file:ch.admin.suis.msghandler.util.XMLValidator.java

/**
 * Validiert das sedex certificate configuration file. Dies ist mit der Klasse XMLConfiguration nicht mglich, da
 * das File keine "xsi:schemaLocation" enthlt.
 *
 * @param xmlFile File object referenceing the file to be validated.
 * @throws ConfigurationException Config problems...
 *//*from ww w .j  av a 2  s . co m*/
public static void validateSedexCertificateConfig(File xmlFile) throws ConfigurationException {
    try {
        String schemaUrl = "http://www.sedex.ch/xmlns/certificateConfiguration/1 "
                + XMLValidator.class.getResource("/conf/CertificateConfiguration-1-0.xsd").toExternalForm();

        LOG.debug("Schema location for sedex cert config: " + schemaUrl);
        validateXml(readFile(xmlFile), schemaUrl);
    } catch (SAXException | IOException ex) {
        throw new ConfigurationException("Unable to validate sedex certificate config. ex: " + ex.getMessage(),
                ex);
    }
}

From source file:com.github.mbredel.commons.configuration.YAMLConfiguration.java

@Override
@SuppressWarnings("unchecked")
public void load(Reader in) throws ConfigurationException {
    try {//from  www . j  a v  a  2s  .  c o  m
        Yaml yaml = new Yaml();
        Map<String, Object> map = (Map) yaml.load(in);
        // Construct the configuration tree.
        ConfigurationNode configurationNode = getRootNode();
        configurationNode.setName(DEFAULT_ROOT_NAME);
        constructHierarchy(configurationNode, map);
    } catch (ClassCastException e) {
        throw new ConfigurationException("Error parsing", e);
    } catch (Exception e) {
        this.getLogger().debug("Unable to load the configuration", e);
        throw new ConfigurationException("Unable to load the configuration", e);
    }
}

From source file:com.github.mbredel.commons.configuration.YAMLConfiguration.java

/**
 * Loads the configuration from the given input stream.
 *
 * @param in the input stream/*  ww  w.  j a  va2s .co m*/
 * @throws ConfigurationException if an error occurs
 */
@Override
@SuppressWarnings("unchecked")
public void load(InputStream in) throws ConfigurationException {
    try {
        Yaml yaml = new Yaml();
        Map<String, Object> map = (Map) yaml.load(in);
        // Construct the configuration tree.
        ConfigurationNode configurationNode = getRootNode();
        configurationNode.setName(DEFAULT_ROOT_NAME);
        constructHierarchy(configurationNode, map);
    } catch (ClassCastException e) {
        throw new ConfigurationException("Error parsing", e);
    } catch (Exception e) {
        this.getLogger().debug("Unable to load the configuration", e);
        throw new ConfigurationException("Unable to load the configuration", e);
    }
}

From source file:edu.kit.dama.util.DataManagerSettings.java

/**
 * Get KIT Data Manager configuration URL from one of the following sources
 * in the following order://from  w  w w  . j a va 2s  . c om
 * <ul>
 * <li>Environment variable DATAMANAGER_CONFIG</li>
 * <li>System.getProperty('datamanager.config')</li>
 * <li>File or resource 'datamanager.xml' in current folder/classpath</li>
 * </ul>
 *
 * Environment variable and system property may contain resource paths or
 * absolute/relative paths to a file on disk. If no configuration was found,
 * a ConfigurationException is thrown.
 *
 * @return The configuration URL.
 *
 * @throws ConfigurationException If no configuration was found at any
 * supported location.
 */
public static URL getConfigurationURL() throws ConfigurationException {
    LOGGER.debug("Checking for configuration in environment variable DATAMANAGER_CONFIG");
    String configResource = System.getenv("DATAMANAGER_CONFIG");

    if (configResource == null) {
        LOGGER.debug("Environment variable is empty. Checking system property 'datamanager.config'");
        configResource = System.getProperty("datamanager.config");
        LOGGER.debug("System property datamanager.config is set to: {}", configResource);
    }

    URL resource = null;
    if (configResource != null) {
        LOGGER.debug("Try to read resource from {}", configResource);

        //just try if configResource is not null
        resource = Thread.currentThread().getContextClassLoader().getResource(configResource);
    }

    if (resource != null) {
        //system property/environment variable is a resource
        return resource;
    } else if (configResource != null && new File(configResource).exists()) {
        //system property is a file
        LOGGER.debug("Trying to return URL for provided configuration {}", configResource);
        try {
            //return URL to file
            return new File(configResource).toURI().toURL();
        } catch (MalformedURLException mue) {
            throw new ConfigurationException(
                    "Provided configuration file '" + configResource + "' could not be mapped to a file", mue);
        }
    } else {
        LOGGER.debug("System property is invalid. Checking file {}", SETTINGS_FILENAME);
        configResource = SETTINGS_FILENAME;
    }

    File fileToResource = new File(configResource);
    if (fileToResource.exists()) {//file exists...use it
        LOGGER.debug("Trying to return URL for provided configuration {}", configResource);
        try {
            return fileToResource.toURI().toURL();
        } catch (MalformedURLException mue) {
            throw new ConfigurationException(
                    "Provided configuration file '" + configResource + "' could not be mapped to a file", mue);
        }
    } else {//try to get from resource
        configResource = SETTINGS_FILENAME;
        LOGGER.debug("Try getting default configuration from resource '{}'", configResource);
        URL resourceURL = DataManagerSettings.class.getResource(configResource);
        if (resourceURL != null) {
            return resourceURL;
        } else {
            LOGGER.debug("Try getting default configuration from context classloader");
            resourceURL = Thread.currentThread().getContextClassLoader().getResource(SETTINGS_FILENAME);
            if (resourceURL != null) {
                return resourceURL;
            }
        }
    }

    throw new ConfigurationException(
            "Neither environment variable nor configuration file are pointing to a valid settings file.");
}

From source file:net.pms.configuration.ConfigurableProgramPaths.java

/**
 * Gets the configured custom program {@link Path} from the
 * {@link Configuration} using the specified key. If the specified key has
 * no value, {@code null} is returned.//from w  w  w .java2  s .  c  o m
 *
 * @param configurationKey the {@link Configuration} key to use.
 * @return The resulting {@link Path} or {@code null}.
 * @throws ConfigurationException If the configured value can't be parsed as
 *             a valid {@link Path}.
 */
@Nullable
public Path getCustomProgramPath(@Nullable String configurationKey) throws ConfigurationException {
    if (isBlank(configurationKey) || configuration == null) {
        return null;
    }

    try {
        String configuredPath = configuration.getString(configurationKey);
        if (isBlank(configuredPath)) {
            return null;
        }
        return Paths.get(configuredPath);
    } catch (ConversionException | InvalidPathException e) {
        throw new ConfigurationException(
                "Invalid configured custom program path in \"" + configurationKey + "\": " + e.getMessage(), e);
    }
}

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

/**
 * @see ConfigurationProvider#getConfiguration(java.lang.String)
 *//*from  w  w w.j a v a  2 s  . c  o  m*/
public HierarchicalConfiguration getConfiguration(String name) throws ConfigurationException {

    HierarchicalConfiguration conf = configurations.get(name);

    // Simply return the configuration if it is already loaded.
    if (conf != null) {
        return conf;
    }

    // Load the configuration.
    else {

        // Compute resourceName and configPart (if any, configPart can
        // remain null).
        int i = name.indexOf(".");
        String resourceName;
        String configPart = null;

        if (i > -1) {
            resourceName = name.substring(0, i);
            configPart = name.substring(i + 1);
        } else {
            resourceName = name;
        }

        Resource resource = loader.getResource(getConfigPrefix() + resourceName + CONFIGURATION_FILE_SUFFIX);

        if (resource.exists()) {
            try {
                HierarchicalConfiguration config = getConfig(resource);
                if (configPart != null) {
                    return config.configurationAt(configPart);
                } else {
                    return config;
                }

            } catch (Exception e) {
                throw new ConfigurationException("Unable to load configuration for component " + name, e);
            }
        }
    }

    // Configuration was not loaded, throw exception.
    throw new ConfigurationException("Unable to load configuration for component " + name);

}

From source file:org.apache.james.container.spring.mailbox.MaxQuotaConfigurationReader.java

@Override
public void configure(HierarchicalConfiguration config) throws ConfigurationException {
    Long defaultMaxMessage = config.configurationAt("maxQuotaManager").getLong("defaultMaxMessage", null);
    Long defaultMaxStorage = config.configurationAt("maxQuotaManager").getLong("defaultMaxStorage", null);
    Map<String, Long> maxMessage = parseMaxMessageConfiguration(config, "maxMessage");
    Map<String, Long> maxStorage = parseMaxMessageConfiguration(config, "maxStorage");
    try {//from   w ww .j av a2 s .c o m
        configureDefaultValues(defaultMaxMessage, defaultMaxStorage);
        configureQuotaRootSpecificValues(maxMessage, maxStorage);
    } catch (MailboxException e) {
        throw new ConfigurationException("Exception caught while configuring max quota manager", e);
    }
}

From source file:org.apache.james.dnsservice.dnsjava.DNSJavaService.java

@Override
public void configure(HierarchicalConfiguration configuration) throws ConfigurationException {

    boolean autodiscover = configuration.getBoolean("autodiscover", true);

    List<Name> sPaths = new ArrayList<Name>();
    if (autodiscover) {
        logger.info("Autodiscovery is enabled - trying to discover your system's DNS Servers");
        String[] serversArray = ResolverConfig.getCurrentConfig().servers();
        if (serversArray != null) {
            for (String aServersArray : serversArray) {
                dnsServers.add(aServersArray);
                logger.info("Adding autodiscovered server " + aServersArray);
            }//  w w w  .j a  va2 s.c  om
        }
        Name[] systemSearchPath = ResolverConfig.getCurrentConfig().searchPath();
        if (systemSearchPath != null && systemSearchPath.length > 0) {
            sPaths.addAll(Arrays.asList(systemSearchPath));
        }
        if (logger.isInfoEnabled()) {
            for (Name searchPath : sPaths) {
                logger.info("Adding autodiscovered search path " + searchPath.toString());
            }
        }
    }

    // singleIPPerMX = configuration.getBoolean( "singleIPperMX", false );

    setAsDNSJavaDefault = configuration.getBoolean("setAsDNSJavaDefault", true);

    // Get the DNS servers that this service will use for lookups
    Collections.addAll(dnsServers, configuration.getStringArray("servers.server"));

    // Get the DNS servers that this service will use for lookups
    for (String aSearchPathsConfiguration : configuration.getStringArray("searchpaths.searchpath")) {
        try {
            sPaths.add(Name.fromString(aSearchPathsConfiguration));
        } catch (TextParseException e) {
            throw new ConfigurationException("Unable to parse searchpath host: " + aSearchPathsConfiguration,
                    e);
        }
    }

    searchPaths = sPaths.toArray(new Name[sPaths.size()]);

    if (dnsServers.isEmpty()) {
        logger.info("No DNS servers have been specified or found by autodiscovery - adding 127.0.0.1");
        dnsServers.add("127.0.0.1");
    }

    boolean authoritative = configuration.getBoolean("authoritative", false);
    // TODO: Check to see if the credibility field is being used correctly.
    // From the
    // docs I don't think so
    dnsCredibility = authoritative ? Credibility.AUTH_ANSWER : Credibility.NONAUTH_ANSWER;

    maxCacheSize = configuration.getInt("maxcachesize", maxCacheSize);
}

From source file:org.apache.james.domainlist.xml.XMLDomainList.java

@Override
public void configure(HierarchicalConfiguration config) throws ConfigurationException {
    super.configure(config);
    for (String serverNameConf : config.getStringArray("domainnames.domainname")) {
        try {//  w  w  w  .  ja  v  a 2s  . com
            addToServedDomains(serverNameConf);
        } catch (DomainListException e) {
            throw new ConfigurationException("Unable to add domain to memory", e);
        }
    }
}

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

/**
 * Computes the dynamicAccounts./*from  www .j ava 2  s .  com*/
 */
protected Map<DynamicAccountKey, DynamicAccount> computeDynamicAccounts() throws ConfigurationException {
    Map<DynamicAccountKey, DynamicAccount> newAccounts;
    try {
        newAccounts = new HashMap<DynamicAccountKey, DynamicAccount>(
                getLocalUsers().countUsers() * getParsedDynamicAccountParameters().size());
    } catch (UsersRepositoryException e) {
        throw new ConfigurationException("Unable to acces UsersRepository", e);
    }
    Map<DynamicAccountKey, DynamicAccount> oldAccounts = getDynamicAccountsBasic();
    if (null == oldAccounts)
        oldAccounts = new HashMap<DynamicAccountKey, DynamicAccount>(0);

    // Process each ParsedDynamicParameters
    for (ParsedDynamicAccountParameters parsedDynamicAccountParameters : getParsedDynamicAccountParameters()) {
        Map<DynamicAccountKey, DynamicAccount> accounts = computeDynamicAccounts(oldAccounts,
                parsedDynamicAccountParameters);
        // Remove accounts from oldAccounts.
        // This avoids an average 2*N increase in heapspace used as the
        // newAccounts are created.
        Iterator<DynamicAccountKey> oldAccountsIterator = oldAccounts.keySet().iterator();
        while (oldAccountsIterator.hasNext()) {
            if (accounts.containsKey(oldAccountsIterator.next()))
                oldAccountsIterator.remove();
        }
        // Add this parameter's accounts to newAccounts
        newAccounts.putAll(accounts);
    }
    return newAccounts;
}