Example usage for org.apache.commons.configuration ConfigurationException getMessage

List of usage examples for org.apache.commons.configuration ConfigurationException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

/**
 * Loads our SQL statements from the appropriate properties file
 * @param vendor   DB vendor string. Must be one of mysql, oracle, hsqldb
 *//*from www  .ja v  a 2 s  .c  om*/
protected void initStatements(String vendor) {

    URL url = getClass().getClassLoader().getResource(vendor + ".properties");

    try {
        statements = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
        statements.setReloadingStrategy(new InvariantReloadingStrategy()); //don't watch for reloads
        statements.setThrowExceptionOnMissing(true); //throw exception if no prop
        statements.setDelimiterParsingDisabled(true); //don't split properties
        statements.load(url); //now load our file
    } catch (ConfigurationException e) {
        log.warn(e.getClass() + ": " + e.getMessage());
        return;
    }
}

From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

/**
 * Loads our SQL statements from the appropriate properties file
         /*w  w  w  .j  a  v  a 2s  .c  om*/
 * @param vendor   DB vendor string. Must be one of mysql, oracle, hsqldb
 */
private void initStatements(String vendor) {

    URL url = getClass().getClassLoader().getResource(vendor + ".properties");

    try {
        statements = new PropertiesConfiguration(); //must use blank constructor so it doesn't parse just yet (as it will split)
        statements.setReloadingStrategy(new InvariantReloadingStrategy()); //don't watch for reloads
        statements.setThrowExceptionOnMissing(true); //throw exception if no prop
        statements.setDelimiterParsingDisabled(true); //don't split properties
        statements.load(url); //now load our file
    } catch (ConfigurationException e) {
        log.error(e.getClass() + ": " + e.getMessage(), e);
        return;
    }
}

From source file:org.soaplab.clients.BatchTestClient.java

/*************************************************************************
 *
 * Entry point.../* w  w  w .j  a  v a  2  s .c  o  m*/
 *
 *************************************************************************/
public static void main(String[] args) {
    try {
        BaseCmdLine cmd = getCmdLine(args, BatchTestClient.class);

        // service location and protocol parameters
        ServiceLocator mainLocator = InputUtils.getServiceLocator(cmd);

        // file(s) with the testing data (a list of tested
        // services and their inputs)
        String[] batchFiles = null;
        String batchFile = cmd.getParam("-batchfile");
        if (batchFile != null) {
            // take it from the command-line
            batchFiles = new String[] { batchFile };
        } else {
            // take it from the client configuration file
            batchFiles = ClientConfig.get().getStringArray(ClientConfig.PROP_BATCH_TEST_FILE);
        }
        if (batchFiles == null || batchFiles.length == 0) {
            log.error("A file with a list of service to test must be given. "
                    + "Use '-batchfile' or a property '" + ClientConfig.PROP_BATCH_TEST_FILE + "'.");
            System.exit(1);
        }

        // other arguments
        boolean tableReport = (cmd.hasOption("-table")
                || ClientConfig.isEnabled(ClientConfig.PROP_BATCH_REPORT_TABLE, false));
        boolean keepResults = (cmd.hasOption("-keep")
                || ClientConfig.isEnabled(ClientConfig.PROP_BATCH_KEEP_RESULTS, false));
        int maxThreads = -1;
        String strMaxThreads = cmd.getParam("-maxthreads");
        if (strMaxThreads == null)
            maxThreads = ClientConfig.getInt(ClientConfig.PROP_BATCH_MAX_THREADS, 25);
        else
            maxThreads = getInt(strMaxThreads);
        if (maxThreads < 0)
            maxThreads = 0;
        boolean oneByOne = (maxThreads == 1);

        // get a list of available services
        // (for validation purposes later)
        Set<String> services = new HashSet<String>();
        for (String name : new SoaplabBaseClient(mainLocator).getAvailableAnalyses()) {
            services.add(name);
        }

        // loop and do it...
        List<Properties> reports = Collections.synchronizedList(new ArrayList<Properties>());
        List<Thread> threads = Collections.synchronizedList(new ArrayList<Thread>());
        int countNotAvailable = 0;

        title("Progress");
        for (String file : batchFiles) {

            log.info("Using batch file " + file);

            // treat each batch file as a property configuration
            // file - together with a usual Soaplab Client
            // configuration file; this allows handling
            // substitutions of referenced properties, etc.
            CompositeConfiguration cfg = new CompositeConfiguration();
            cfg.addConfiguration(ClientConfig.get());
            cfg.addConfiguration(Config.get());
            try {
                cfg.addConfiguration(new PropertiesConfiguration(file));
            } catch (ConfigurationException e) {
                log.error("Loading batch file from '" + file + "' failed: " + e.getMessage());
                continue;
            }

            //
            for (Iterator it = cfg.getKeys(); it.hasNext();) {
                String propertyName = (String) it.next();
                if (!propertyName.startsWith(PREFIX_SERVICE_TO_TEST))
                    continue;
                String serviceName = StringUtils.removeStart(propertyName, PREFIX_SERVICE_TO_TEST);
                if (!services.contains(serviceName)) {
                    //          log.warn (serviceName + " is not available for testing");
                    countNotAvailable += 1;
                    continue;
                }
                String[] inputs = cfg.getStringArray(propertyName);
                for (String input : inputs) {
                    MyLocator locator = new MyLocator(serviceName, mainLocator);
                    locator.enableKeepResults(keepResults);
                    locator.setInputLine(input);
                    if (oneByOne) {
                        // sequential invocation
                        qmsg(String.format("%-50s", "Running " + serviceName + "... "));
                        Properties report = callService(locator, reports);
                        qmsgln("finished: " + report.getProperty(REPORT_JOB_STATUS));

                    } else {
                        // do it in parallel
                        startService(threads, locator, reports);
                        if (maxThreads > 0) {
                            // limit the number of threads
                            // (just wait for some to finish)
                            while (threads.size() >= maxThreads) {
                                try {
                                    Thread.sleep(1000);
                                } catch (Exception e) {
                                }
                            }
                        }
                    }
                }
            }
        }

        if (!oneByOne) {
            // wait for all the threads to finish
            while (threads.size() > 0) {
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                }
            }
        }
        msgln("");

        // report all tests
        if (tableReport)
            createTableReport(reports);

        // report results
        int countSuccessful = 0;
        int countErrors = 0;
        for (Properties report : reports) {
            if (report.containsKey(REPORT_ERROR_MESSAGE)) {
                report.remove(REPORT_STACK_TRACE);
                countErrors += 1;
                createErrorReport(report);
            } else {
                String status = report.getProperty(REPORT_JOB_STATUS);
                if (SoaplabConstants.JOB_COMPLETED.equals(status)) {
                    countSuccessful += 1;
                } else {
                    countErrors += 1;
                    createErrorReport(report);
                }
            }
        }

        // make a summary
        title("Summary");
        msgln("Successfully:  " + countSuccessful);
        msgln("Erroneously:   " + countErrors);
        msgln("Not available: " + countNotAvailable);

        exit(0);

    } catch (Throwable e) {
        processErrorAndExit(e);
    }

}

From source file:org.soaplab.clients.ClientConfig.java

/**************************************************************************
 * Add given property files as a new configuration to 'cfg'
 * composite configuration. Return true on success.
 **************************************************************************/
private static boolean addPropertiesConfiguration(CompositeConfiguration cfg, String configFilename) {
    try {//from   w  ww  . java  2 s. c  o  m
        PropertiesConfiguration propsConfig = new PropertiesConfiguration(configFilename);
        propsConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
        cfg.addConfiguration(propsConfig);
        return true;
    } catch (ConfigurationException e) {
        log.error("Loading properties configuration from '" + configFilename + "' failed: " + e.getMessage());
        return false;
    }
}

From source file:org.soaplab.services.Config.java

/**************************************************************************
 * Add given property files as a new configuration to 'cfg'
 * composite configuration. Return true on success.
 **************************************************************************/
private static boolean addPropertiesConfiguration(CompositeConfiguration cfg, String configFilename) {
    try {//from w w  w.j a  v a2s  .  c o m
        PropertiesConfiguration propsConfig = new PropertiesConfiguration(configFilename);
        if (isExistingConfig(propsConfig))
            return true;
        propsConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
        cfg.addConfiguration(propsConfig);
        return true;
    } catch (ConfigurationException e) {
        log.error("Loading properties configuration from '" + configFilename + "' failed: " + e.getMessage());
        return false;
    }
}

From source file:org.soaplab.services.Config.java

/**************************************************************************
 * Add given XML files as a new configuration to 'cfg' composite
 * configuration. Return true on success.
 **************************************************************************/
private static boolean addXMLConfiguration(CompositeConfiguration cfg, String configFilename) {
    try {/*from w w  w.  j  ava 2 s.c  o  m*/
        XMLConfiguration xmlConfig = new XMLConfiguration(configFilename);
        if (isExistingConfig(xmlConfig))
            return true;
        xmlConfig.setReloadingStrategy(new FileChangedReloadingStrategy());
        cfg.addConfiguration(xmlConfig);
        return true;
    } catch (ConfigurationException e) {
        log.error("Loading XML configuration from '" + configFilename + "' failed: " + e.getMessage());
        return false;
    }
}

From source file:org.soaplab.services.DefaultAnalysisInventory.java

/**************************************************************************
 * Check if the property containing filename with an analysis list
 * (or filenames, actually) has changed since the last time we saw
 * it. If yes, reload analysis list(s) defined in this property.
 *************************************************************************/
protected synchronized void reloadConfig() {

    // find the filename(s) with our analysis list(s)
    String[] fileNames = Config.get().getStringArray(Config.PROP_APPLIST_FILENAME);
    if (fileNames == null || fileNames.length == 0) {
        if (!warningIssued) {
            log.warn("Property '" + Config.PROP_APPLIST_FILENAME + "' not found.");
            warningIssued = true;/*  ww w . j  a va 2s.c om*/
        }
        configs = null;
        lastUsedFileNames = null;
        appList = new Hashtable<String, Vector<AnalysisInstallation>>();
        return;
    }

    // has PROP_APPLIST_FILENAME changed since last visit?
    String joined = StringUtils.join(fileNames, ",");
    if (!joined.equals(lastUsedFileNames)) {
        warningIssued = false;
        List<XMLConfiguration> configsList = new ArrayList<XMLConfiguration>();
        for (int i = 0; i < fileNames.length; i++) {
            try {
                XMLConfiguration config = new XMLConfiguration(fileNames[i]);
                config.setReloadingStrategy(new FileChangedReloadingStrategy() {
                    public void reloadingPerformed() {
                        super.reloadingPerformed(); // because of updateLastModified();
                        readConfigs();
                    }
                });
                configsList.add(config);
                log.info("Using analysis list file '" + fileNames[i] + "'");
            } catch (ConfigurationException e) {
                log.error("Loading analysis list from '" + fileNames[i] + "' failed: " + e.getMessage());
            }
        }
        if (configsList.size() > 0) {
            configs = configsList.toArray(new XMLConfiguration[] {});
            readConfigs();
            lastUsedFileNames = joined;
        } else {
            configs = null;
            lastUsedFileNames = null;
            appList = new Hashtable<String, Vector<AnalysisInstallation>>();
        }
    }

    // try to trigger reloading of individual XML file names (if
    // they changed)
    if (configs != null) {
        for (int i = 0; i < configs.length; i++)
            configs[i].isEmpty();
    }

}

From source file:org.soitoolkit.tools.generator.util.PropertyFileUtil.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void updateMuleDeployPropertyFileConfigFile(String outputFolder, String configFilename) {

    String muleDeployPropertyFile = outputFolder + "/src/main/app/mule-deploy.properties";
    System.err.println("Open muleDeployPropertyFile: " + muleDeployPropertyFile);

    try {//from  w  w  w.j  av a2  s.c  o  m
        PropertiesConfiguration config = new PropertiesConfiguration(muleDeployPropertyFile);
        String key = "config.resources";
        List value = config.getList(key);
        value.add(configFilename);
        System.err.println("Update muleDeployPropertyFile: " + key + " = " + value);
        config.setProperty(key, value);
        config.save();
        System.err.println("Saved muleDeployPropertyFile");

    } catch (ConfigurationException e1) {
        System.err.println("Error with muleDeployPropertyFile: " + e1.getMessage());
        throw new RuntimeException(e1);
    }
}

From source file:org.sourceforge.net.javamail4ews.util.Util.java

public static Configuration getConfiguration(Session pSession) {
    try {/* w w w  .j  a  v a  2 s .  c  o m*/
        PropertiesConfiguration prop = new PropertiesConfiguration();
        for (Object aKey : pSession.getProperties().keySet()) {
            Object aValue = pSession.getProperties().get(aKey);

            prop.addProperty(aKey.toString(), aValue);
        }

        CompositeConfiguration config = new CompositeConfiguration();
        config.addConfiguration(prop);
        URL lURL = Thread.currentThread().getContextClassLoader()
                .getResource("javamail-ews-bridge.default.properties");
        config.addConfiguration(new PropertiesConfiguration(lURL));
        return config;
    } catch (ConfigurationException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:org.springframework.data.hadoop.admin.cli.commands.InfoCommand.java

/**
 * show the current service URL/*from w ww.  j  a  v a  2 s  .c  o m*/
 * 
 */
@CliCommand(value = "info", help = "list Spring Hadoop Admin CLI information")
public void getCLIInfo() {
    try {
        String serviceUrl = PropertyUtil.getTargetUrl();
        Log.show("    service url:    " + serviceUrl);
        String dfsName = PropertyUtil.getDfsName();
        Log.show("    fs default name:    " + dfsName);
    } catch (ConfigurationException e) {
        Log.error("set target url failed. " + e.getMessage());
    }
}