/** * Returns true if the passed <code>exceptionClass</code> is an application exception. Else returns false. * * @param ejbComponent The EJB component * @param exceptionClass The exception class * @return */ private boolean isApplicationException(final EJBComponent ejbComponent, final Class<?> exceptionClass, final Method invokedMethod) { return ejbComponent.getApplicationException(exceptionClass, invokedMethod) != null; }
/** * Checks if the passed exception is an application exception. If yes, then throws back the * exception as-is. Else, wraps the exception in a {@link javax.ejb.EJBException} and throws the EJBException * * @param ex The exception to handle * @throws Exception Either the passed exception or an EJBException */ protected Exception handleException(final InterceptorContext invocation, Throwable ex) throws Exception { ApplicationExceptionDetails ae = component.getApplicationException(ex.getClass(), invocation.getMethod()); // it's an application exception, so just throw it back as-is if (ae != null) { throw (Exception)ex; } if (ex instanceof EJBException) { throw (EJBException) ex; } else if(ex instanceof Exception){ throw new EJBException((Exception)ex); } else { throw new EJBException(new RuntimeException(ex)); } }
protected Object invokeInNoTx(InterceptorContext invocation, final EJBComponent component) throws Exception { try { return invocation.proceed(); } catch (Error e) { throw EjbLogger.ROOT_LOGGER.unexpectedError(e); } catch (EJBException e) { throw e; } catch (RuntimeException e) { ApplicationExceptionDetails ae = component.getApplicationException(e.getClass(), invocation.getMethod()); throw ae != null ? e : new EJBException(e); } catch (Exception e) { throw e; } catch (Throwable t) { throw new EJBException(new UndeclaredThrowableException(t)); } }
final EJBComponent ejbComponent = component; if (ejbComponent.getApplicationException(ex.getClass(), context.getMethod()) != null) {
protected Object invokeInCallerTx(InterceptorContext invocation, Transaction tx, final EJBComponent component) throws Exception { try { return invocation.proceed(); } catch (Error e) { final EJBTransactionRolledbackException e2 = EjbLogger.ROOT_LOGGER.unexpectedErrorRolledBack(e); setRollbackOnly(tx, e2); throw e2; } catch (Exception e) { ApplicationExceptionDetails ae = component.getApplicationException(e.getClass(), invocation.getMethod()); if (ae != null) { if (ae.isRollback()) setRollbackOnly(tx, e); throw e; } try { throw e; } catch (EJBTransactionRolledbackException | NoSuchEJBException | NoSuchEntityException e2) { setRollbackOnly(tx, e2); throw e2; } catch (RuntimeException e2) { final EJBTransactionRolledbackException e3 = new EJBTransactionRolledbackException(e2.getMessage(), e2); setRollbackOnly(tx, e3); throw e3; } } catch (Throwable t) { final EJBException e = new EJBException(new UndeclaredThrowableException(t)); setRollbackOnly(tx, e); throw e; } }
final Method invokedMethod = interceptorContext.getMethod(); final ApplicationExceptionDetails appException = component.getApplicationException(t.getClass(), invokedMethod); if (appException == null) { EjbLogger.EJB3_INVOCATION_LOGGER.invocationFailed(component.getComponentName(), invokedMethod, t);
result = invocation.proceed(); } catch (Throwable t) { ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod()); try { try {
final EJBComponent ejbComponent = (EJBComponent)component; if (ejbComponent.getApplicationException(ex.getClass(), context.getMethod()) != null) {
/** * Returns true if the passed <code>exceptionClass</code> is an application exception. Else returns false. * * @param ejbComponent The EJB component * @param exceptionClass The exception class * @return */ private boolean isApplicationException(final EJBComponent ejbComponent, final Class<?> exceptionClass, final Method invokedMethod) { return ejbComponent.getApplicationException(exceptionClass, invokedMethod) != null; }
/** * Checks if the passed exception is an application exception. If yes, then throws back the * exception as-is. Else, wraps the exception in a {@link javax.ejb.EJBException} and throws the EJBException * * @param ex The exception to handle * @throws Exception Either the passed exception or an EJBException */ protected Exception handleException(final InterceptorContext invocation, Throwable ex) throws Exception { ApplicationExceptionDetails ae = component.getApplicationException(ex.getClass(), invocation.getMethod()); // it's an application exception, so just throw it back as-is if (ae != null) { throw (Exception)ex; } if (ex instanceof EJBException) { throw (EJBException) ex; } else if(ex instanceof Exception){ throw new EJBException((Exception)ex); } else { throw new EJBException(new RuntimeException(ex)); } }
public void handleExceptionInNoTx(InterceptorContext invocation, Throwable t, final EJBComponent component) throws Exception { ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod()); if (ae != null) { throw (Exception) t; } // if it's neither EJBException nor RemoteException if (!(t instanceof EJBException || t instanceof RemoteException)) { // errors and unchecked are wrapped into EJBException if (t instanceof Error) { //t = new EJBException(formatException("Unexpected Error", t)); Throwable cause = t; t = EjbMessages.MESSAGES.unexpectedError(); t.initCause(cause); } else if (t instanceof RuntimeException) { t = new EJBException((Exception) t); } else { // an application exception throw (Exception) t; } } throw (Exception) t; }
@Override public Object processInvocation(InterceptorContext interceptorContext) throws Exception { try { // we just pass on the control and do our work only when an exception occurs return interceptorContext.proceed(); } catch (Throwable t) { final EJBComponent component = (EJBComponent) interceptorContext.getPrivateData(Component.class); final Method invokedMethod = interceptorContext.getMethod(); // check if it's an application exception. If yes, then *don't* log final ApplicationExceptionDetails appException = component.getApplicationException(t.getClass(), invokedMethod); if (appException == null) { EjbLogger.EJB3_INVOCATION_LOGGER.invocationFailed(component.getComponentName(), invokedMethod, t); } if (t instanceof Exception) { throw (Exception) t; } // Typically, this interceptor (which would be the first one in the chain) would catch Exception and not Throwable since the other EJB interceptors // down the chain would have already wrapped the Throwable accordingly. However, if for some reason, // the failure happened even before those interceptors could come into play, then we just wrap the throwable // here and return it as an exception throw new Exception(t); } } }
public void handleExceptionInOurTx(InterceptorContext invocation, Throwable t, Transaction tx, final EJBComponent component) throws Exception { ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod()); if (ae != null) { if (ae.isRollback()) setRollbackOnly(tx); throw (Exception) t; } // if it's neither EJBException nor RemoteException if (!(t instanceof EJBException || t instanceof RemoteException)) { // errors and unchecked are wrapped into EJBException if (t instanceof Error) { //t = new EJBException(formatException("Unexpected Error", t)); Throwable cause = t; t = EjbMessages.MESSAGES.unexpectedError(); t.initCause(cause); } else if (t instanceof RuntimeException) { t = new EJBException((Exception) t); } else { // an application exception throw (Exception) t; } } setRollbackOnly(tx); throw (Exception) t; }
protected void handleInCallerTx(InterceptorContext invocation, Throwable t, Transaction tx, final EJBComponent component) throws Exception { ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod()); if (ae != null) { if (ae.isRollback()) setRollbackOnly(tx); // an app exception can never be an Error throw (Exception) t; } // if it's not EJBTransactionRolledbackException if (!(t instanceof EJBTransactionRolledbackException)) { if (t instanceof Error) { //t = new EJBTransactionRolledbackException(formatException("Unexpected Error", t)); Throwable cause = t; t = new EJBTransactionRolledbackException("Unexpected Error"); t.initCause(cause); } else if (t instanceof NoSuchEJBException) { // If this is an NoSuchEJBException, pass through to the caller } else if (t instanceof RuntimeException) { t = new EJBTransactionRolledbackException(t.getMessage(), (Exception) t); } else {// application exception throw (Exception) t; } } setRollbackOnly(tx); EjbLogger.ROOT_LOGGER.error(t); throw (Exception) t; }
final EJBComponent ejbComponent = component; if (ejbComponent.getApplicationException(ex.getClass(), context.getMethod()) != null) {
final EJBComponent ejbComponent = (EJBComponent)component; if (ejbComponent.getApplicationException(ex.getClass(), context.getMethod()) != null) {