List of usage examples for javax.ejb EJBException getCausedByException
public Exception getCausedByException()
From source file:org.signserver.admin.cli.defaultimpl.RenewSignerCommand.java
@Override public int execute(String... args) throws IllegalCommandArgumentsException, CommandFailureException, UnexpectedCommandFailureException { try {/*w w w.j av a 2s .c o m*/ // Parse the command line parseCommandLine(new GnuParser().parse(OPTIONS, args)); } catch (ParseException ex) { throw new IllegalCommandArgumentsException(ex.getMessage()); } validateOptions(); if (args.length < 2) { throw new IllegalCommandArgumentsException(USAGE); } try { if (authCode == null) { getOutputStream().print("Enter authorization code: "); // Read the password, but mask it so we don't display it on the console ConsolePasswordReader r = new ConsolePasswordReader(); authCode = String.valueOf(r.readPassword()); } String workerName = args[0]; checkThatWorkerIsProcessable(getWorkerId(workerName)); final Properties requestProperties = new Properties(); requestProperties.setProperty(RenewalWorkerProperties.REQUEST_WORKER, workerName); requestProperties.setProperty(RenewalWorkerProperties.REQUEST_AUTHCODE, String.valueOf(authCode)); // requestProperties.setProperty( // RenewalWorkerProperties.REQUEST_RENEWKEY, // RenewalWorkerProperties.REQUEST_RENEWKEY_TRUE); final GenericPropertiesRequest request = new GenericPropertiesRequest(requestProperties); final GenericPropertiesResponse response = (GenericPropertiesResponse) getWorkerSession() .process(getWorkerId(renewalWorker), request, new RequestContext(true)); final Properties responseProperties = response.getProperties(); if (RenewalWorkerProperties.RESPONSE_RESULT_OK .equals(responseProperties.getProperty(RenewalWorkerProperties.RESPONSE_RESULT))) { out.println("Renewed successfully"); return 0; } else { err.println("Renewal failed: " + responseProperties.getProperty(RenewalWorkerProperties.RESPONSE_MESSAGE)); return -2; } } catch (EJBException eJBException) { if (eJBException.getCausedByException() instanceof IllegalArgumentException) { err.println(eJBException.getMessage()); return -2; } else { throw new UnexpectedCommandFailureException(eJBException); } } catch (IllegalCommandArgumentsException ex) { throw ex; } catch (Exception e) { throw new UnexpectedCommandFailureException(e); } }
From source file:org.signserver.admin.cli.defaultimpl.WSAdminsCommand.java
@Override public int execute(String... args) throws IllegalCommandArgumentsException, CommandFailureException, UnexpectedCommandFailureException { final CommandLine line; try {/*from www .j ava 2 s .c o m*/ // Parse the command line line = new GnuParser().parse(OPTIONS, args); parseCommandLine(line); } catch (ParseException ex) { throw new IllegalCommandArgumentsException(ex.getMessage()); } catch (IllegalCommandArgumentsException e) { throw e; } validateOptions(); try { final String admins = getGlobalConfigurationSession().getGlobalConfiguration() .getProperty(GlobalConfiguration.SCOPE_GLOBAL, "WSADMINS"); final Set<ClientEntry> entries; if (admins != null) { entries = ClientEntry.clientEntriesFromProperty(admins); } else { entries = new HashSet<ClientEntry>(); } if (LIST.equals(operation)) { final String allowAnyWSAdminProp = getGlobalConfigurationSession().getGlobalConfiguration() .getProperty(GlobalConfiguration.SCOPE_GLOBAL, ALLOWANYWSADMIN); final boolean allowAnyWSAdmin = allowAnyWSAdminProp != null ? Boolean.parseBoolean(allowAnyWSAdminProp) : false; final StringBuilder buff = new StringBuilder(); buff.append("Authorized administrators:"); buff.append("\n"); if (allowAnyWSAdmin) { buff.append("ANY CERTIFICATE ACCEPTED FOR WS ADMINISTRATORS"); buff.append("\n"); buff.append( "Use the command \"signserver wsadmins -allowany false\" to enable the administrator list"); buff.append("\n"); } else { for (ClientEntry entry : entries) { buff.append(String.format("%-20s %s", entry.getSerialNumber().toString(16), entry.getIssuerDN())); buff.append("\n"); } } getOutputStream().println(buff.toString()); } else if (ADD.equals(operation)) { final boolean added; if (cert == null) { // serial number and issuer DN was entered manually added = entries.add(new ClientEntry(certSerialNo, issuerDN)); } else { // read serial number and issuer DN from cert file X509Certificate certificate = SignServerUtil.getCertFromFile(cert); added = entries.add(new ClientEntry(certificate.getSerialNumber(), SignServerUtil.getTokenizedIssuerDNFromCert(certificate))); } if (added) { getGlobalConfigurationSession().setProperty(GlobalConfiguration.SCOPE_GLOBAL, "WSADMINS", ClientEntry.serializeClientEntries(entries)); getOutputStream().println("Administrator added"); } else { getOutputStream().println("Administrator already exists"); } } else if (REMOVE.equals(operation)) { if (entries.remove(new ClientEntry(certSerialNo, issuerDN))) { getGlobalConfigurationSession().setProperty(GlobalConfiguration.SCOPE_GLOBAL, "WSADMINS", ClientEntry.serializeClientEntries(entries)); getOutputStream().println("Administrator removed"); } else { getErrorStream().println("No such administrator"); } } else if (ALLOWANY.equals(operation)) { boolean allowAny = true; final String value = line.getOptionValue(ALLOWANY); if (value != null) { allowAny = Boolean.parseBoolean(value); } if (allowAny) { getGlobalConfigurationSession().setProperty(GlobalConfiguration.SCOPE_GLOBAL, ALLOWANYWSADMIN, "true"); getOutputStream().println("Set to allow any WS admin"); } else { getGlobalConfigurationSession().removeProperty(GlobalConfiguration.SCOPE_GLOBAL, ALLOWANYWSADMIN); getOutputStream().println("Set to not allow any WS admin"); } } return 0; } catch (EJBException eJBException) { if (eJBException.getCausedByException() instanceof IllegalArgumentException) { getErrorStream().println(eJBException.getMessage()); return -2; } else { throw new UnexpectedCommandFailureException(eJBException); } } catch (Exception e) { throw new UnexpectedCommandFailureException(e); } }
From source file:org.signserver.admin.cli.defaultimpl.WSAuditorsCommand.java
@Override public int execute(String... args) throws IllegalCommandArgumentsException, CommandFailureException, UnexpectedCommandFailureException { try {// w w w . j a va 2s. c o m // Parse the command line parseCommandLine(new GnuParser().parse(OPTIONS, args)); } catch (ParseException ex) { throw new IllegalCommandArgumentsException(ex.getMessage()); } validateOptions(); try { final String admins = getGlobalConfigurationSession().getGlobalConfiguration() .getProperty(GlobalConfiguration.SCOPE_GLOBAL, "WSAUDITORS"); final List<Entry> entries = parseAdmins(admins); if (LIST.equals(operation)) { final StringBuilder buff = new StringBuilder(); buff.append("Authorized auditors:"); buff.append("\n"); for (Entry entry : entries) { buff.append(String.format("%-20s %s", entry.getCertSerialNo(), entry.getIssuerDN())); buff.append("\n"); } getOutputStream().println(buff.toString()); } else if (ADD.equals(operation)) { if (cert == null) { // serial number and issuer DN was entered manually entries.add(new Entry(certSerialNo, issuerDN)); } else { // read serial number and issuer DN from cert file X509Certificate certificate = SignServerUtil.getCertFromFile(cert); String sn = certificate.getSerialNumber().toString(16); String dn = certificate.getIssuerX500Principal().getName(); CertTools.BasicX509NameTokenizer tok = new CertTools.BasicX509NameTokenizer(dn); StringBuilder buf = new StringBuilder(); while (tok.hasMoreTokens()) { final String token = tok.nextToken(); buf.append(token); if (tok.hasMoreTokens()) { buf.append(", "); } } entries.add(new Entry(sn, buf.toString())); } getGlobalConfigurationSession().setProperty(GlobalConfiguration.SCOPE_GLOBAL, "WSAUDITORS", serializeAdmins(entries)); getOutputStream().println("Auditor added"); } else if (REMOVE.equals(operation)) { if (entries.remove(new Entry(certSerialNo, issuerDN))) { getGlobalConfigurationSession().setProperty(GlobalConfiguration.SCOPE_GLOBAL, "WSAUDITORS", serializeAdmins(entries)); getOutputStream().println("Auditor removed"); } else { getErrorStream().println("No such auditor"); } } return 0; } catch (EJBException eJBException) { if (eJBException.getCausedByException() instanceof IllegalArgumentException) { getErrorStream().println(eJBException.getMessage()); return -2; } else { throw new UnexpectedCommandFailureException(eJBException); } } catch (Exception e) { throw new UnexpectedCommandFailureException(e); } }
From source file:ru.codeinside.gses.manager.ManagerService.java
public Procedure createProcedure(String name, String description, String serviceId, Long code, String login, ProcedureType type) {//from w w w . java2 s. c o m try { if (hasProcedureWithSameRegisterCode(code)) { throw new RuntimeException( " ? ??"); } final Procedure procedure = new Procedure(); mergeProcedure(procedure, name, description, serviceId, code, type); procedure.setCreator(em.find(Employee.class, login)); em.persist(procedure); return procedure; } catch (EJBException e) { final String message; if (e.getMessage() != null) { message = e.getMessage(); } else if (e.getCausedByException() != null) { message = e.getCausedByException().getMessage(); } else { message = e.getCause() != null ? e.getCause().getMessage() : e.getClass().toString(); } throw new RuntimeException(message); } }