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();
}
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);
}
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();
}
}
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;
}
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"));
}
}
}
Aggregations