Search in sources :

Example 46 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project distributedlog by twitter.

the class DistributedLogServerApp method runCmd.

private void runCmd(CommandLine cmdline) throws IllegalArgumentException, IOException, ConfigurationException {
    final StatsReceiver statsReceiver = NullStatsReceiver.get();
    Optional<String> confOptional = getOptionalStringArg(cmdline, "c");
    DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
    if (confOptional.isPresent()) {
        String configFile = confOptional.get();
        try {
            dlConf.loadConf(new File(configFile).toURI().toURL());
        } catch (ConfigurationException e) {
            throw new IllegalArgumentException("Failed to load distributedlog configuration from " + configFile + ".");
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Failed to load distributedlog configuration from malformed " + configFile + ".");
        }
    }
    // load the stats provider
    final StatsProvider statsProvider = getOptionalStringArg(cmdline, "pd").transform(new Function<String, StatsProvider>() {

        @Nullable
        @Override
        public StatsProvider apply(@Nullable String name) {
            return ReflectionUtils.newInstance(name, StatsProvider.class);
        }
    }).or(new NullStatsProvider());
    final DistributedLogServer server = DistributedLogServer.runServer(getOptionalStringArg(cmdline, "u"), confOptional, getOptionalStringArg(cmdline, "sc"), getOptionalIntegerArg(cmdline, "p"), getOptionalIntegerArg(cmdline, "sp"), getOptionalIntegerArg(cmdline, "si"), getOptionalBooleanArg(cmdline, "a"), getOptionalBooleanArg(cmdline, "mx"), statsReceiver, statsProvider);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            logger.info("Closing DistributedLog Server.");
            server.close();
            logger.info("Closed DistributedLog Server.");
            statsProvider.stop();
        }
    });
    try {
        server.join();
    } catch (InterruptedException e) {
        logger.warn("Interrupted when waiting distributedlog server to be finished : ", e);
    }
    logger.info("DistributedLog Service Interrupted.");
    server.close();
    logger.info("Closed DistributedLog Server.");
    statsProvider.stop();
}
Also used : MalformedURLException(java.net.MalformedURLException) StatsReceiver(com.twitter.finagle.stats.StatsReceiver) NullStatsReceiver(com.twitter.finagle.stats.NullStatsReceiver) DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) Function(com.google.common.base.Function) ConfigurationException(org.apache.commons.configuration.ConfigurationException) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) StatsProvider(org.apache.bookkeeper.stats.StatsProvider) NullStatsProvider(org.apache.bookkeeper.stats.NullStatsProvider) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 47 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project titan by thinkaurelius.

the class ConfigurationLint method validate.

public static Status validate(String filename) throws IOException {
    Properties p = new Properties();
    FileInputStream fis = new FileInputStream(filename);
    p.load(fis);
    fis.close();
    final PropertiesConfiguration apc;
    try {
        apc = new PropertiesConfiguration(filename);
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    //        new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
    //                , BasicConfiguration.Restriction.NONE);
    Iterator<String> iter = apc.getKeys();
    int totalKeys = 0;
    int keysVerified = 0;
    while (iter.hasNext()) {
        totalKeys++;
        String key = iter.next();
        String value = apc.getString(key);
        try {
            ConfigElement.PathIdentifier pid = ConfigElement.parse(GraphDatabaseConfiguration.ROOT_NS, key);
            // ConfigElement shouldn't return null; failure here probably relates to titan-core, not the file
            Preconditions.checkState(null != pid);
            Preconditions.checkState(null != pid.element);
            if (!pid.element.isOption()) {
                log.warn("Config key {} is a namespace (only options can be keys)", key);
                continue;
            }
            final ConfigOption<?> opt;
            try {
                opt = (ConfigOption<?>) pid.element;
            } catch (RuntimeException re) {
                // This shouldn't happen given the preceding check, but catch it anyway
                log.warn("Config key {} maps to the element {}, but it could not be cast to an option", key, pid.element, re);
                continue;
            }
            try {
                Object o = new CommonsConfiguration(apc).get(key, opt.getDatatype());
                opt.verify(o);
                keysVerified++;
            } catch (RuntimeException re) {
                log.warn("Config key {} is recognized, but its value {} could not be validated", key, value);
                log.debug("Validation exception on {}={} follows", key, value, re);
            }
        } catch (RuntimeException re) {
            log.warn("Unknown config key {}", key);
        }
    }
    return new Status(totalKeys, totalKeys - keysVerified);
}
Also used : ConfigElement(com.thinkaurelius.titan.diskstorage.configuration.ConfigElement) CommonsConfiguration(com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration) IOException(java.io.IOException) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) FileInputStream(java.io.FileInputStream) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Example 48 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class MenuToolsControl method options.

// ZAP: added ability to select panel
public void options(String panel) {
    OptionsDialog dialog = view.getOptionsDialog(Constant.messages.getString("options.dialog.title"));
    dialog.initParam(model.getOptionsParam());
    int result = dialog.showDialog(false, panel);
    if (result == JOptionPane.OK_OPTION) {
        try {
            model.getOptionsParam().getConfig().save();
        } catch (ConfigurationException e) {
            logger.error(e.getMessage(), e);
            view.showWarningDialog(Constant.messages.getString("menu.tools.options.errorSavingOptions"));
            return;
        }
        // ZAP: Notify all OptionsChangedListener.
        control.getExtensionLoader().optionsChangedAllPlugin(model.getOptionsParam());
        view.getMainFrame().applyViewOptions();
        control.getProxy().stopServer();
        control.getProxy().startServer();
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) OptionsDialog(org.parosproxy.paros.view.OptionsDialog)

Example 49 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class OptionsParamCheckForUpdates method checkOnStart.

/**
	 * Tells whether or not a "check for updates on start up" needs to be performed.
	 * <p>
	 * A check for updates needs to be performed if the method {@code isCheckOnStart()} returns {@code true} and if no check was
	 * already done during the same day.
	 * </p>
	 * 
	 * @return {@code true} if a check for updates on start up needs to be performed, {@code false} otherwise.
	 * @see #isCheckOnStart()
	 */
@ZapApiIgnore
public boolean checkOnStart() {
    if (!checkOnStart) {
        log.debug("isCheckForStart - false");
        return false;
    }
    String today = getSdf().format(new Date());
    if (today.equals(dayLastChecked)) {
        log.debug("isCheckForStart - already checked today");
        return false;
    }
    getConfig().setProperty(DAY_LAST_CHECKED, today);
    try {
        getConfig().save();
    } catch (ConfigurationException e) {
        log.error(e.getMessage(), e);
    }
    return true;
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) Date(java.util.Date) ZapApiIgnore(org.zaproxy.zap.extension.api.ZapApiIgnore)

Example 50 with ConfigurationException

use of org.apache.commons.configuration.ConfigurationException in project zaproxy by zaproxy.

the class ExtensionActiveScan method showPolicyDialog.

protected void showPolicyDialog(PolicyManagerDialog parent, String name) throws ConfigurationException {
    ScanPolicy policy;
    if (name != null) {
        policy = this.getPolicyManager().getPolicy(name);
    } else {
        policy = this.getPolicyManager().getTemplatePolicy();
    }
    PolicyDialog dialog = new PolicyDialog(this, parent, policy);
    dialog.initParam(getModel().getOptionsParam());
    for (AbstractParamPanel panel : policyPanels) {
        dialog.addPolicyPanel(panel);
    }
    int result = dialog.showDialog(true);
    if (result == JOptionPane.OK_OPTION) {
        try {
            getModel().getOptionsParam().getConfig().save();
        } catch (ConfigurationException ce) {
            logger.error(ce.getMessage(), ce);
            getView().showWarningDialog(Constant.messages.getString("scanner.save.warning"));
        }
    }
}
Also used : AbstractParamPanel(org.parosproxy.paros.view.AbstractParamPanel) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Aggregations

ConfigurationException (org.apache.commons.configuration.ConfigurationException)66 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)31 File (java.io.File)20 IOException (java.io.IOException)19 ActionEvent (java.awt.event.ActionEvent)6 Configuration (org.apache.commons.configuration.Configuration)6 ActionListener (java.awt.event.ActionListener)5 FileInputStream (java.io.FileInputStream)5 MalformedURLException (java.net.MalformedURLException)5 ArrayList (java.util.ArrayList)5 ZapXmlConfiguration (org.zaproxy.zap.utils.ZapXmlConfiguration)5 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)4 FileNotFoundException (java.io.FileNotFoundException)3 FileWriter (java.io.FileWriter)3 HashMap (java.util.HashMap)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 CommonsConfiguration (com.thinkaurelius.titan.diskstorage.configuration.backend.CommonsConfiguration)2 BufferedWriter (java.io.BufferedWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2