use of io.jans.ca.server.service.RpService in project jans by JanssenProject.
the class Cli method main.
public static void main(String[] args) {
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
String rpId;
switchOffLogging();
try {
cmd = parser.parse(options(), args);
rpId = cmd.getOptionValue("rp_id");
Injector injector = ServerLauncher.getInjector();
final RpServerConfiguration conf = parseConfiguration(cmd.getOptionValue("c"));
injector.getInstance(ConfigurationService.class).setConfiguration(conf);
injector.getInstance(PersistenceService.class).create();
RpService rpService = injector.getInstance(RpService.class);
RpSyncService rpSyncService = injector.getInstance(RpSyncService.class);
rpService.load();
// check multiple options
if (hasMultipleActionOptions(cmd)) {
System.out.println("Multiple parameters in command is not allowed.");
printHelpAndExit();
return;
}
// list
if (cmd.hasOption("l")) {
if (hasListParameterValue(args)) {
System.out.println("Warning: Arguments after list parameter is not required, hence will be ignored.");
}
final Collection<Rp> values = rpService.getRps().values();
if (values.isEmpty()) {
System.out.println("There are no any entries yet in database.");
return;
}
System.out.println("rp_id client_name");
for (Rp rp : values) {
System.out.println(String.format("%s %s", rp.getRpId(), rp.getClientName() != null ? rp.getClientName() : ""));
}
return;
}
// view by oxd_id
if (cmd.hasOption("rp_id")) {
print(rpId, rpSyncService.getRp(rpId));
return;
}
if (cmd.hasOption("d")) {
// delete
if (rpService.remove(cmd.getOptionValue("d"))) {
System.out.println("Entry removed successfully.");
} else {
System.out.println("Failed to remove entry from database.");
}
return;
}
System.out.println("Unable to recognize valid parameter.");
printHelpAndExit();
} catch (ParseException e) {
System.out.println(e.getMessage());
printHelpAndExit();
} catch (RuntimeException e) {
// oxd is running and keeps h2 database locked, so we connect to oxd-server and fetch RP via client connection
if (cmd != null) {
tryToConnectToRunningRp(cmd);
} else {
printHelpAndExit();
}
} catch (Throwable e) {
System.out.println("Failed to run jans_client_api CLI (make sure jans_client_api was run at least one time and database file is created). Error: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
}
Aggregations