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.modules.objectstorage.ObjectStorageBlobConfiguration.java

public static ObjectStorageBlobConfiguration from(Configuration configuration) throws ConfigurationException {
    String provider = configuration.getString(OBJECTSTORAGE_PROVIDER, null);
    String namespace = configuration.getString(OBJECTSTORAGE_NAMESPACE, null);
    String authApi = configuration.getString(OBJECTSTORAGE_SWIFT_AUTH_API, null);
    String codecName = configuration.getString(OBJECTSTORAGE_PAYLOAD_CODEC, null);
    Optional<String> aesSalt = Optional.ofNullable(configuration.getString(OBJECTSTORAGE_AES256_HEXSALT, null));
    Optional<char[]> aesPassword = Optional
            .ofNullable(configuration.getString(OBJECTSTORAGE_AES256_PASSWORD, null)).map(String::toCharArray);

    if (Strings.isNullOrEmpty(provider)) {
        throw new ConfigurationException("Mandatory configuration value " + OBJECTSTORAGE_PROVIDER
                + " is missing from " + OBJECTSTORAGE_CONFIGURATION_NAME + " configuration");
    }/*from  www  . ja  v a2s.co  m*/
    if (Strings.isNullOrEmpty(authApi)) {
        throw new ConfigurationException("Mandatory configuration value " + OBJECTSTORAGE_SWIFT_AUTH_API
                + " is missing from " + OBJECTSTORAGE_CONFIGURATION_NAME + " configuration");
    }
    if (Strings.isNullOrEmpty(namespace)) {
        throw new ConfigurationException("Mandatory configuration value " + OBJECTSTORAGE_NAMESPACE
                + " is missing from " + OBJECTSTORAGE_CONFIGURATION_NAME + " configuration");
    }
    if (Strings.isNullOrEmpty(codecName)) {
        throw new ConfigurationException("Mandatory configuration value " + OBJECTSTORAGE_PAYLOAD_CODEC
                + " is missing from " + OBJECTSTORAGE_CONFIGURATION_NAME + " configuration");
    }

    PayloadCodecFactory payloadCodecFactory = Arrays.stream(PayloadCodecFactory.values())
            .filter(name -> name.name().equals(codecName)).findAny()
            .orElseThrow(() -> new ConfigurationException("unknown payload codec : " + codecName));

    Builder.RequireAuthConfiguration requireAuthConfiguration = builder().codec(payloadCodecFactory).swift()
            .container(ContainerName.of(namespace));

    return defineAuthApi(configuration, authApi, requireAuthConfiguration).aesSalt(aesSalt)
            .aesPassword(aesPassword).build();
}

From source file:org.apache.james.modules.objectstorage.ObjectStorageDependenciesModule.java

@Provides
@Singleton/*www .  ja v a2  s. com*/
private ObjectStorageBlobConfiguration getObjectStorageConfiguration(PropertiesProvider propertiesProvider)
        throws ConfigurationException {
    try {
        Configuration configuration = propertiesProvider.getConfiguration(ConfigurationComponent.NAME);
        return ObjectStorageBlobConfiguration.from(configuration);
    } catch (FileNotFoundException e) {
        throw new ConfigurationException(ConfigurationComponent.NAME + " configuration was not found");
    }
}

From source file:org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer.java

/**
 * Configure the helloName for the given Configuration
 * /*from w  ww .  j av  a2  s .c  o m*/
 * @param handlerConfiguration
 * @throws ConfigurationException
 */
protected void configureHelloName(Configuration handlerConfiguration) throws ConfigurationException {
    StringBuilder infoBuffer;
    String hostName;
    try {
        hostName = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ue) {
        hostName = "localhost";
    }

    infoBuffer = new StringBuilder(64).append(getServiceType()).append(" is running on: ").append(hostName);
    getLogger().info(infoBuffer.toString());

    boolean autodetect = handlerConfiguration.getBoolean(HELLO_NAME + ".[@autodetect]", true);
    if (autodetect) {
        helloName = hostName;
    } else {
        helloName = handlerConfiguration.getString(HELLO_NAME);
        if (helloName == null || helloName.trim().length() < 1) {
            throw new ConfigurationException("Please configure the helloName or use autodetect");
        }
    }

    infoBuffer = new StringBuilder(64).append(getServiceType()).append(" handler hello name is: ")
            .append(helloName);
    getLogger().info(infoBuffer.toString());
}

From source file:org.apache.james.protocols.lib.ProtocolHandlerChainImpl.java

public void init() throws Exception {
    List<org.apache.commons.configuration.HierarchicalConfiguration> children = handlerchainConfig
            .configurationsAt("handler");

    // check if the coreHandlersPackage was specified in the config, if
    // not add the default
    if (handlerchainConfig.getString("[@coreHandlersPackage]") == null)
        handlerchainConfig.addProperty("[@coreHandlersPackage]", coreHandlersPackage);

    String coreHandlersPackage = handlerchainConfig.getString("[@coreHandlersPackage]");

    if (handlerchainConfig.getString("[@jmxHandlersPackage]") == null)
        handlerchainConfig.addProperty("[@jmxHandlersPackage]", jmxHandlersPackage);

    String jmxHandlersPackage = handlerchainConfig.getString("[@jmxHandlersPackage]");

    HandlersPackage handlersPackage = (HandlersPackage) loader.load(coreHandlersPackage,
            addHandler(coreHandlersPackage));
    registerHandlersPackage(handlersPackage, null, children);

    if (handlerchainConfig.getBoolean("[@enableJmx]", true)) {
        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        builder.addProperty("jmxName", jmxName);
        HandlersPackage jmxPackage = (HandlersPackage) loader.load(jmxHandlersPackage,
                addHandler(jmxHandlersPackage));

        registerHandlersPackage(jmxPackage, builder, children);
    }//from  w  ww . java 2  s.co m

    for (HierarchicalConfiguration hConf : children) {
        String className = hConf.getString("[@class]", null);
        if (className != null) {
            handlers.add(loader.load(className, hConf));
        } else {
            throw new ConfigurationException(
                    "Missing @class attribute in configuration: " + ConfigurationUtils.toString(hConf));
        }
    }
    wireExtensibleHandlers();

}

From source file:org.apache.james.repository.file.AbstractFileRepository.java

@PostConstruct
public void init() throws Exception {

    getLogger().info("Init " + getClass().getName() + " Store");
    setDestination(destination);//from  w  w  w.ja va  2 s  .  c o  m

    File directory;

    try {
        directory = m_baseDirectory.getCanonicalFile();
    } catch (IOException ioe) {
        throw new ConfigurationException("Unable to form canonical representation of " + m_baseDirectory);
    }

    m_name = "Repository";
    String m_postfix = getExtensionDecorator();
    m_extension = "." + m_name + m_postfix;
    m_filter = new ExtensionFileFilter(m_extension);
    // m_filter = new NumberedRepositoryFileFilter(getExtensionDecorator());

    FileUtils.forceMkdir(directory);

    getLogger().info(getClass().getName() + " opened in " + m_baseDirectory);

    // We will look for all numbered repository files in this
    // directory and rename them to non-numbered repositories,
    // logging all the way.

    FilenameFilter num_filter = new NumberedRepositoryFileFilter(getExtensionDecorator());
    final String[] names = directory.list(num_filter);

    try {
        for (String origFilename : names) {
            // This needs to handle (skip over) the possible repository
            // numbers
            int pos = origFilename.length() - m_postfix.length();
            while (pos >= 1 && Character.isDigit(origFilename.charAt(pos - 1))) {
                pos--;
            }
            pos -= ".".length() + m_name.length();
            String newFilename = origFilename.substring(0, pos) + m_extension;

            File origFile = new File(directory, origFilename);
            File newFile = new File(directory, newFilename);

            if (origFile.renameTo(newFile)) {
                getLogger().info("Renamed " + origFile + " to " + newFile);
            } else {
                getLogger().info("Unable to rename " + origFile + " to " + newFile);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }

}

From source file:org.apache.james.repository.file.AbstractFileRepository.java

/**
 * Set the destination for the repository
 * //from  w ww . j  a va 2s  .c  o  m
 * @param destination
 *            the destination under which the repository get stored
 * @throws ConfigurationException
 * @throws ConfigurationException
 *             get thrown on invalid destintion syntax
 */
protected void setDestination(String destination) throws ConfigurationException {

    if (!destination.startsWith(FileSystem.FILE_PROTOCOL)) {
        throw new ConfigurationException("cannot handle destination " + destination);
    }

    try {
        m_baseDirectory = fileSystem.getFile(destination);
    } catch (FileNotFoundException e) {
        throw new ConfigurationException("Unable to acces destination " + destination, e);
    }

}

From source file:org.apache.james.rrt.file.XMLRecipientRewriteTable.java

@Override
protected void doConfigure(HierarchicalConfiguration arg0) throws ConfigurationException {
    String[] mapConf = arg0.getStringArray("mapping");
    mappings = Maps.newHashMap();/*from w w w  .  j  ava  2s.  com*/
    if (mapConf != null && mapConf.length > 0) {
        for (String aMapConf : mapConf) {
            mappings.putAll(RecipientRewriteTableUtil.getXMLMappings(aMapConf));
        }
    } else {
        throw new ConfigurationException("No mapping configured");
    }
}

From source file:org.apache.james.rrt.jdbc.JDBCRecipientRewriteTable.java

protected void doConfigure(HierarchicalConfiguration conf) throws ConfigurationException {

    String destination = conf.getString("[@destinationURL]", null);

    if (destination == null) {
        throw new ConfigurationException("destinationURL must configured");
    }/*from  ww w. j av  a  2 s.  co m*/

    // 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;

    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>'.  Was passed " + conf.getString("[@destinationURL]");
        throw new ConfigurationException(exceptionBuffer);
    }

    if (urlParams.size() >= 2) {
        tableName = urlParams.get(1);
    }

    if (getLogger().isDebugEnabled()) {
        String logBuffer = "Parsed URL: table = '" + tableName + "'";
        getLogger().debug(logBuffer);
    }

    sqlFileName = conf.getString("sqlFile");

}

From source file:org.apache.james.rrt.lib.AbstractRecipientRewriteTable.java

/**
 * @see org.apache.james.lifecycle.api.Configurable#configure(HierarchicalConfiguration)
 *//*from  w ww. ja  va2 s  . co m*/
public void configure(HierarchicalConfiguration config) throws ConfigurationException {
    setRecursiveMapping(config.getBoolean("recursiveMapping", true));
    try {
        setMappingLimit(config.getInt("mappingLimit", 10));
    } catch (IllegalArgumentException e) {
        throw new ConfigurationException(e.getMessage());
    }
    doConfigure(config);
}

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

@Override
public void init(Configuration config) throws ConfigurationException {
    boolean validConfig = false;
    HierarchicalConfiguration handlerConfiguration = (HierarchicalConfiguration) config;
    ArrayList<String> rblserverCollection = new ArrayList<String>();

    Collections.addAll(rblserverCollection, handlerConfiguration.getStringArray("rblservers.whitelist"));
    if (rblserverCollection.size() > 0) {
        setWhitelist(rblserverCollection.toArray(new String[rblserverCollection.size()]));
        rblserverCollection.clear();/*  w w w  . jav  a  2  s.co m*/
        validConfig = true;
    }
    Collections.addAll(rblserverCollection, handlerConfiguration.getStringArray("rblservers.blacklist"));
    if (rblserverCollection.size() > 0) {
        setBlacklist(rblserverCollection.toArray(new String[rblserverCollection.size()]));
        rblserverCollection.clear();
        validConfig = true;
    }

    // Throw an ConfiigurationException on invalid config
    if (!validConfig) {
        throw new ConfigurationException("Please configure whitelist or blacklist");
    }

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