List of usage examples for javax.ejb EJBException getCausedByException
public Exception getCausedByException()
From source file:gov.nih.nci.firebird.web.interceptor.FirebirdExceptionHandlingInterceptor.java
@Override @SuppressWarnings({ "PMD.AvoidCatchingGenericException", "PMD.SignatureDeclareThrowsException" }) // Need to handle all exceptions // possible failure from invoke. public String intercept(ActionInvocation invocation) throws Exception { try {/*from w w w . jav a 2s . c o m*/ return invocation.invoke(); } catch (EJBException exception) { handleException(exception, invocation); throw exception.getCausedByException(); } catch (Exception exception) { handleException(exception, invocation); throw exception; } }
From source file:com.sfs.ucm.controller.ProjectPackageAction.java
/** * save action//from w ww . java 2 s.c o m * * @throws UCMException */ @TransactionAttribute(TransactionAttributeType.REQUIRED) public void save() throws UCMException { try { if (validate()) { if (this.projectPackage.getId() == null) { this.project.addProjectPackage(this.projectPackage); } try { em.persist(this.project); } catch (javax.ejb.EJBException e) { if (e.getCausedByException().equals(OptimisticLockException.class)) { logger.error("OptimisticLockException {}", e.getMessage()); this.facesContextMessage.warningMessage("Another user is modifying this Artifact"); } throw new UCMException(e); } logger.info("saved {}", this.projectPackage.getName()); this.facesContextMessage.infoMessage("{0} saved successfully", StringUtils.abbreviate(this.projectPackage.getName(), 25)); // refresh list loadList(); this.selected = true; } } catch (Exception e) { throw new UCMException(e); } }
From source file:com.sfs.captor.controller.ProjectPackageAction.java
/** * save action// w ww . j a v a 2s .co m * * @throws UCMException */ public void save() throws UCMException { try { if (validate()) { configure(); if (this.projectPackage.getId() == null) { this.project.addProjectPackage(this.projectPackage); } try { em.persist(this.project); } catch (javax.ejb.EJBException e) { if (e.getCausedByException().equals(OptimisticLockException.class)) { logger.error("OptimisticLockException {}", e.getMessage()); this.facesContextMessage.warningMessage("Another user is modifying this Artifact"); } throw new UCMException(e); } logger.info("saved {}", this.projectPackage.getName()); this.facesContextMessage.infoMessage("{0} saved successfully", StringUtils.abbreviate(this.projectPackage.getName(), 25)); // update producers projectEvent.fire(this.project); projectPackageSrc.fire(this.project); // refresh list loadList(); this.selected = true; } } catch (Exception e) { throw new UCMException(e); } }
From source file:gov.nih.nci.caarray.test.api.external.v1_0.java.SearchServiceTest.java
@Test public void testGetAnnotationSet_Null() throws Exception { logForSilverCompatibility(TEST_NAME, "testGetAnnotationSet_Null"); try {/* w w w.j a v a2s.com*/ logForSilverCompatibility(TEST_OUTPUT, "null request"); AnnotationSet aset = service.getAnnotationSet(null); logForSilverCompatibility(TEST_OUTPUT, "unexpected outcome"); fail(); } catch (javax.ejb.EJBException e) { assertEquals(NullPointerException.class, e.getCausedByException().getClass()); logForSilverCompatibility(TEST_OUTPUT, "null request validation :" + e.getCause()); } }
From source file:org.rhq.enterprise.gui.admin.role.AddLdapGroupsFormPrepareAction.java
public ActionForward execute(ComponentContext context, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Log log = LogFactory.getLog(AddLdapGroupsFormPrepareAction.class.getName()); AddLdapGroupsForm addForm = (AddLdapGroupsForm) form; Integer roleId = addForm.getR(); if (roleId == null) { roleId = RequestUtils.getRoleId(request); }/* w w w .java 2s . c o m*/ Role role = (Role) request.getAttribute(Constants.ROLE_ATTR); if (role == null) { RequestUtils.setError(request, Constants.ERR_ROLE_NOT_FOUND); return null; } //use cached LDAP group list to avoid hitting ldap server each time ui pref changed. Set<Map<String, String>> cachedAvailableLdapGroups = null; cachedAvailableLdapGroups = (Set<Map<String, String>>) request.getSession().getAttribute(LDAP_GROUP_CACHE); addForm.setR(role.getId()); PageControl pca = WebUtility.getPageControl(request, "a"); PageControl pcp = WebUtility.getPageControl(request, "p"); //BZ-580127 Refactor so that all lists are initialized regardless of ldap server // availability or state of filter params List<String> pendingGroupIds = new ArrayList<String>(); Set<Map<String, String>> allGroups = new HashSet<Map<String, String>>(); PageList<LdapGroup> assignedList = new PageList<LdapGroup>(); Set<Map<String, String>> availableGroupsSet = new HashSet<Map<String, String>>(); Set<Map<String, String>> pendingSet = new HashSet<Map<String, String>>(); PageList<Map<String, String>> pendingGroups = new PageList<Map<String, String>>(pendingSet, 0, pcp); PageList<Map<String, String>> availableGroups = new PageList<Map<String, String>>(availableGroupsSet, 0, pca); /* pending groups are those on the right side of the "add * to list" widget- awaiting association with the role when the form's "ok" button is clicked. */ pendingGroupIds = SessionUtils.getListAsListStr(request.getSession(), Constants.PENDING_RESGRPS_SES_ATTR); log.trace("getting pending groups for role [" + roleId + ")"); String name = "foo"; try { //defend against ldap communication runtime difficulties. if (cachedAvailableLdapGroups == null) { // allGroups = LdapGroupManagerBean.getInstance().findAvailableGroups(); allGroups = ldapManager.findAvailableGroups(); } else {//reuse cached. allGroups = cachedAvailableLdapGroups; } //store unmodified list in session. cachedAvailableLdapGroups = allGroups; //retrieve currently assigned groups assignedList = ldapManager.findLdapGroupsByRole(role.getId(), PageControl.getUnlimitedInstance()); //trim already defined from all groups returned. allGroups = filterExisting(assignedList, allGroups); Set<String> pendingIds = new HashSet<String>(pendingGroupIds); //retrieve pending information pendingSet = findPendingGroups(pendingIds, allGroups); pendingGroups = new PageList<Map<String, String>>(pendingSet, pendingSet.size(), pcp); /* available groups are all groups in the system that are not * associated with the role and are not pending */ log.trace("getting available groups for role [" + roleId + "]"); availableGroupsSet = findAvailableGroups(pendingIds, allGroups); availableGroups = new PageList<Map<String, String>>(availableGroupsSet, availableGroupsSet.size(), pca); //We cannot reuse the PageControl mechanism as there are no database calls to retrieve list // must replicate paging using existing web params, formula etc. PageList<Map<String, String>> sizedAvailableGroups = new PageList<Map<String, String>>(); sizedAvailableGroups = paginateLdapGroupData(sizedAvailableGroups, availableGroups, pca); //make sizedAvailableGroup the new reference to return. availableGroups = sizedAvailableGroups; //populate pagination elements for loaded elements. availableGroups.setTotalSize(availableGroupsSet.size()); availableGroups.setPageControl(pca); //now do the same thing for Pending Groups. PageList<Map<String, String>> pagedPendingGroups = new PageList<Map<String, String>>(); pagedPendingGroups = paginateLdapGroupData(pagedPendingGroups, pendingGroups, pcp); pendingGroups = pagedPendingGroups; //populate pagination elements for loaded elements. pendingGroups.setTotalSize(pendingSet.size()); pendingGroups.setPageControl(pcp); } catch (EJBException ejx) { //this is the exception type thrown now that we use SLSB.Local methods // mine out other exceptions Exception cause = ejx.getCausedByException(); if (cause == null) { ActionMessages actionMessages = new ActionMessages(); actionMessages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.cam.general")); saveErrors(request, actionMessages); } else { if (cause instanceof LdapFilterException) { ActionMessages actionMessages = new ActionMessages(); actionMessages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("admin.role.LdapGroupFilterMessage")); saveErrors(request, actionMessages); } else if (cause instanceof LdapCommunicationException) { ActionMessages actionMessages = new ActionMessages(); SystemManagerLocal manager = LookupUtil.getSystemManager(); Properties options = manager .getSystemConfiguration(LookupUtil.getSubjectManager().getOverlord()); String providerUrl = options.getProperty(RHQConstants.LDAPUrl, "(unavailable)"); actionMessages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("admin.role.LdapCommunicationMessage", providerUrl)); saveErrors(request, actionMessages); } } } catch (LdapFilterException lce) { ActionMessages actionMessages = new ActionMessages(); actionMessages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("admin.role.LdapGroupFilterMessage")); saveErrors(request, actionMessages); } catch (LdapCommunicationException lce) { ActionMessages actionMessages = new ActionMessages(); SystemManagerLocal manager = LookupUtil.getSystemManager(); Properties options = manager.getSystemConfiguration(LookupUtil.getSubjectManager().getOverlord()); String providerUrl = options.getProperty(RHQConstants.LDAPUrl, "(unavailable)"); actionMessages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("admin.role.LdapCommunicationMessage", providerUrl)); saveErrors(request, actionMessages); } //place calculated values into session. request.setAttribute(Constants.PENDING_RESGRPS_ATTR, pendingGroups); request.setAttribute(Constants.NUM_PENDING_RESGRPS_ATTR, new Integer(pendingGroups.getTotalSize())); request.setAttribute(Constants.AVAIL_RESGRPS_ATTR, availableGroups); request.setAttribute(Constants.NUM_AVAIL_RESGRPS_ATTR, new Integer(allGroups.size())); //store cachedAvailableGroups in session so trim down ldap communication chatter. request.getSession().setAttribute(LDAP_GROUP_CACHE, cachedAvailableLdapGroups); return null; }
From source file:org.rhq.enterprise.server.auth.test.SubjectManagerBeanTest.java
public void nobodyCanChangeASubjectName() { executeInTransaction(new TransactionCallback() { @Override// w w w.j ava2 s. c om public void execute() throws Exception { Subject itestSubject = subjectManager.getSubjectByName(ITEST_USER); Subject changedSubject = new Subject("pipo", itestSubject.getFactive(), itestSubject.getFsystem()); changedSubject.setId(itestSubject.getId()); try { subjectManager.updateSubject(subjectManager.getOverlord(), changedSubject, "newPassword"); fail("Nobody should be able to change a subject name"); } catch (EJBException e) { Exception cause = e.getCausedByException(); assertEquals(IllegalArgumentException.class, cause.getClass()); assertTrue(cause.getMessage().equals("You cannot change a user's username.")); } } }); }
From source file:org.rhq.enterprise.server.auth.test.SubjectManagerBeanTest.java
public void nobodyCanChangeAnUnknowSubject() { executeInTransaction(new TransactionCallback() { @Override/* w w w .j a v a 2s .c o m*/ public void execute() throws Exception { try { Subject fakeSubject = new Subject("fakeUser", true, false); subjectManager.updateSubject(subjectManager.getOverlord(), fakeSubject, "newPassword"); fail("Nobody should be able to change an unknown subject"); } catch (EJBException e) { Exception cause = e.getCausedByException(); assertEquals(IllegalArgumentException.class, cause.getClass()); assertTrue(cause.getMessage().startsWith("No user exists with id")); } } }); }
From source file:org.rhq.enterprise.server.operation.ResourceOperationJob.java
private boolean isResourceUncommitted(JobDetail jobDetail) { ResourceManagerLocal resourceMgr = LookupUtil.getResourceManager(); int resourceId = getResourceId(jobDetail); try {//from w ww.j a v a2s.c om Resource resource = resourceMgr.getResource(getOverlord(), resourceId); return isResourceUncommitted(resource); } catch (EJBException e) { if (e.getCausedByException() instanceof ResourceNotFoundException) { return true; } throw e; } }
From source file:org.signserver.admin.cli.defaultimpl.AbstractWSClientsCommand.java
@Override public int execute(String... args) throws IllegalCommandArgumentsException, CommandFailureException, UnexpectedCommandFailureException { try {//from w w w . ja v a2 s . c o m // Parse the command line parseCommandLine(new GnuParser().parse(OPTIONS, args)); } catch (ParseException ex) { throw new IllegalCommandArgumentsException(ex.getMessage()); } catch (IllegalCommandArgumentsException e) { throw e; } validateOptions(); try { final String admins = getGlobalConfigurationSession().getGlobalConfiguration() .getProperty(GlobalConfiguration.SCOPE_GLOBAL, getClientsProperty()); final Set<ClientEntry> entries; if (admins != null) { entries = ClientEntry.clientEntriesFromProperty(admins); } else { entries = new HashSet<ClientEntry>(); } if (LIST.equals(operation)) { final StringBuilder buff = new StringBuilder(); buff.append("Authorized auditors:"); buff.append("\n"); 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, getClientsProperty(), ClientEntry.serializeClientEntries(entries)); getOutputStream().println("Auditor added"); } else { getOutputStream().println("Auditor already exists"); } } else if (REMOVE.equals(operation)) { if (entries.remove(new ClientEntry(certSerialNo, issuerDN))) { getGlobalConfigurationSession().setProperty(GlobalConfiguration.SCOPE_GLOBAL, getClientsProperty(), ClientEntry.serializeClientEntries(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:org.signserver.admin.cli.defaultimpl.GenerateKeyCommand.java
@Override public int execute(String... args) throws IllegalCommandArgumentsException, CommandFailureException, UnexpectedCommandFailureException { if (args.length < 1) { throw new IllegalCommandArgumentsException("Missing arguments"); }//from w ww . j a v a2 s. co m try { try { // Parse the command line parseCommandLine(new GnuParser().parse(OPTIONS, args)); } catch (ParseException ex) { throw new IllegalCommandArgumentsException(ex.getMessage()); } validateOptions(); int signerId = getWorkerId(args[0]); checkThatWorkerIsProcessable(signerId); LOG.info("Requesting key generation..."); String newAlias = getWorkerSession().generateSignerKey(signerId, keyAlg, keySpec, alias, null); if (newAlias == null) { out.println("Could not generate key"); } else { out.println("Created key : " + newAlias); } return 0; } catch (IllegalCommandArgumentsException ex) { throw ex; } catch (EJBException eJBException) { if (eJBException.getCausedByException() instanceof IllegalArgumentException) { err.println(eJBException.getMessage()); return -1; } else { throw new UnexpectedCommandFailureException(eJBException); } } catch (Exception e) { throw new UnexpectedCommandFailureException(e); } }