@Test public final void testInvalidActionExecution() { mockery.checking(new Expectations() { { oneOf(springContextMock).getBean(ACTION_KEY); will(returnValue("String")); allowing(exceptionSanitizer).transform(with(any(Exception.class))); will(returnValue(returnException)); } }); ActionRequest results = sut.execute(defaultRequest, validUserDetailsMock); mockery.assertIsSatisfied(); assertSame(returnException, results.getResponse()); }
@SuppressWarnings("unchecked") public ActionRequest execute(final ActionRequest actionRequest, final UserDetails userDetails) { log.debug("Starting Action: " + actionRequest.getActionKey()); String userName = getUserName(userDetails); try { Object springBean = beanFactory.getBean(actionRequest.getActionKey()); Serializable result = null; if (springBean instanceof ServiceAction) { ServiceAction action = (ServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else if (springBean instanceof TaskHandlerServiceAction) { TaskHandlerServiceAction action = (TaskHandlerServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else { throw new InvalidActionException("Supplied bean is not an executable action."); } long startClone = System.currentTimeMillis(); actionRequest.setResponse((Serializable) persistentBeanManager.clone(result)); log.debug(actionRequest.getActionKey() + " gilead serialization time: " + (System.currentTimeMillis() - startClone) + " (ms)"); } catch (Exception ex) { String paramString = "null parameters"; if (actionRequest.getParam() != null) { try { paramString = actionRequest.getParam().toString(); } catch (Exception pex) { paramString = "<error retrieving parameters: " + pex.getMessage() + ">"; } } log.error("Caught exception while running " + actionRequest.getActionKey() + " for user: " + userName + ". Parameters: " + paramString + ". ", ex); actionRequest.setResponse(exceptionSanitizer.transform(ex)); } actionRequest.setParam(null); log.debug("Finished Action: " + actionRequest.getActionKey()); return actionRequest; }
ActionExecutor { @SuppressWarnings("unchecked") public ActionRequest execute(final ActionRequest actionRequest, final UserDetails userDetails) { log.debug("Starting Action: " + actionRequest.getActionKey()); String userName = getUserName(userDetails); try { Object springBean = beanFactory.getBean(actionRequest.getActionKey()); Serializable result = null; if (springBean instanceof ServiceAction) { ServiceAction action = (ServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else if (springBean instanceof TaskHandlerServiceAction) { TaskHandlerServiceAction action = (TaskHandlerServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else { throw new InvalidActionException("Supplied bean is not an executable action."); } long startClone = System.currentTimeMillis(); actionRequest.setResponse((Serializable) persistentBeanManager.clone(result)); log.debug(actionRequest.getActionKey() + " gilead serialization time: " + (System.currentTimeMillis() - startClone) + " (ms)"); } catch (Exception ex) { String paramString = "null parameters"; if (actionRequest.getParam() != null) { try { paramString = actionRequest.getParam().toString(); } catch (Exception pex) { paramString = "<error retrieving parameters: " + pex.getMessage() + ">"; } } log.error("Caught exception while running " + actionRequest.getActionKey() + " for user: " + userName + ". Parameters: " + paramString + ". ", ex); actionRequest.setResponse(exceptionSanitizer.transform(ex)); } actionRequest.setParam(null); log.debug("Finished Action: " + actionRequest.getActionKey()); return actionRequest; } }
ActionExecutor { @SuppressWarnings("unchecked") public ActionRequest execute(final ActionRequest actionRequest, final UserDetails userDetails) { log.debug("Starting Action: " + actionRequest.getActionKey()); String userName = getUserName(userDetails); try { Object springBean = beanFactory.getBean(actionRequest.getActionKey()); Serializable result = null; if (springBean instanceof ServiceAction) { ServiceAction action = (ServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else if (springBean instanceof TaskHandlerServiceAction) { TaskHandlerServiceAction action = (TaskHandlerServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else { throw new InvalidActionException("Supplied bean is not an executable action."); } long startClone = System.currentTimeMillis(); actionRequest.setResponse((Serializable) persistentBeanManager.clone(result)); log.debug(actionRequest.getActionKey() + " gilead serialization time: " + (System.currentTimeMillis() - startClone) + " (ms)"); } catch (Exception ex) { String paramString = "null parameters"; if (actionRequest.getParam() != null) { try { paramString = actionRequest.getParam().toString(); } catch (Exception pex) { paramString = "<error retrieving parameters: " + pex.getMessage() + ">"; } } log.error("Caught exception while running " + actionRequest.getActionKey() + " for user: " + userName + ". Parameters: " + paramString + ". ", ex); actionRequest.setResponse(exceptionSanitizer.transform(ex)); } actionRequest.setParam(null); log.debug("Finished Action: " + actionRequest.getActionKey()); return actionRequest; } ActionExecutor(final BeanFactory inBeanFactory, final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator, final PersistentBeanManager inPersistentBeanManager,
            final Transformer<Exception, Exception> inExceptionSanitizer); }
ActionExecutor { @SuppressWarnings("unchecked") public ActionRequest execute(final ActionRequest actionRequest, final UserDetails userDetails) { log.debug("Starting Action: " + actionRequest.getActionKey()); String userName = getUserName(userDetails); try { Object springBean = beanFactory.getBean(actionRequest.getActionKey()); Serializable result = null; if (springBean instanceof ServiceAction) { ServiceAction action = (ServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else if (springBean instanceof TaskHandlerServiceAction) { TaskHandlerServiceAction action = (TaskHandlerServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else { throw new InvalidActionException("Supplied bean is not an executable action."); } long startClone = System.currentTimeMillis(); actionRequest.setResponse((Serializable) persistentBeanManager.clone(result)); log.debug(actionRequest.getActionKey() + " gilead serialization time: " + (System.currentTimeMillis() - startClone) + " (ms)"); } catch (Exception ex) { String paramString = "null parameters"; if (actionRequest.getParam() != null) { try { paramString = actionRequest.getParam().toString(); } catch (Exception pex) { paramString = "<error retrieving parameters: " + pex.getMessage() + ">"; } } log.error("Caught exception while running " + actionRequest.getActionKey() + " for user: " + userName + ". Parameters: " + paramString + ". ", ex); actionRequest.setResponse(exceptionSanitizer.transform(ex)); } actionRequest.setParam(null); log.debug("Finished Action: " + actionRequest.getActionKey()); return actionRequest; } ActionExecutor(final BeanFactory inBeanFactory, final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator, final PersistentBeanManager inPersistentBeanManager,
            final Transformer<Exception, Exception> inExceptionSanitizer); @SuppressWarnings("unchecked") ActionRequest execute(final ActionRequest actionRequest, final UserDetails userDetails); }
ActionExecutor { @SuppressWarnings("unchecked") public ActionRequest execute(final ActionRequest actionRequest, final UserDetails userDetails) { log.debug("Starting Action: " + actionRequest.getActionKey()); String userName = getUserName(userDetails); try { Object springBean = beanFactory.getBean(actionRequest.getActionKey()); Serializable result = null; if (springBean instanceof ServiceAction) { ServiceAction action = (ServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else if (springBean instanceof TaskHandlerServiceAction) { TaskHandlerServiceAction action = (TaskHandlerServiceAction) springBean; Serializable actionParameter = actionRequest.getParam(); ServiceActionContext actionContext = new ServiceActionContext(actionParameter, principalPopulator.getPrincipal(userDetails.getUsername(), actionRequest.getSessionId())); actionContext.setActionId(actionRequest.getActionKey()); result = serviceActionController.execute(actionContext, action); } else { throw new InvalidActionException("Supplied bean is not an executable action."); } long startClone = System.currentTimeMillis(); actionRequest.setResponse((Serializable) persistentBeanManager.clone(result)); log.debug(actionRequest.getActionKey() + " gilead serialization time: " + (System.currentTimeMillis() - startClone) + " (ms)"); } catch (Exception ex) { String paramString = "null parameters"; if (actionRequest.getParam() != null) { try { paramString = actionRequest.getParam().toString(); } catch (Exception pex) { paramString = "<error retrieving parameters: " + pex.getMessage() + ">"; } } log.error("Caught exception while running " + actionRequest.getActionKey() + " for user: " + userName + ". Parameters: " + paramString + ". ", ex); actionRequest.setResponse(exceptionSanitizer.transform(ex)); } actionRequest.setParam(null); log.debug("Finished Action: " + actionRequest.getActionKey()); return actionRequest; } ActionExecutor(final BeanFactory inBeanFactory, final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator, final PersistentBeanManager inPersistentBeanManager,
            final Transformer<Exception, Exception> inExceptionSanitizer); @SuppressWarnings("unchecked") ActionRequest execute(final ActionRequest actionRequest, final UserDetails userDetails);  }