javax.ejb.ApplicationException Java Examples

The following examples show how to use javax.ejb.ApplicationException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnnotationDeployerTest.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Test
/**
 *  For http://issues.apache.org/jira/browse/OPENEJB-980
 */
public void applicationExceptionInheritanceTest() throws Exception {
    EjbModule ejbModule = testModule();
    final AnnotationDeployer.DiscoverAnnotatedBeans discvrAnnBeans = new AnnotationDeployer.DiscoverAnnotatedBeans();
    ejbModule = discvrAnnBeans.deploy(ejbModule);

    final AssemblyDescriptor assemblyDescriptor = ejbModule.getEjbJar().getAssemblyDescriptor();
    org.apache.openejb.jee.ApplicationException appEx =
        assemblyDescriptor.getApplicationException(BusinessException.class);
    assertThat(appEx, notNullValue());
    assertThat(appEx.getExceptionClass(), is(BusinessException.class.getName()));
    assertThat(appEx.isRollback(), is(true));

    //inheritance is now handled at runtime, only explicitly mentioned exceptions are in the assembly descriptor
    appEx = assemblyDescriptor.getApplicationException(ValueRequiredException.class);
    assertThat(appEx, nullValue());
}
 
Example #2
Source File: DeployedSessionBean.java    From development with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isApplicationException(Exception e) {
    for (Class<?> declaredEx : interfaceMethod.getExceptionTypes()) {
        if (declaredEx.isInstance(e)) {
            return true;
        }
    }
    if (e.getClass().getAnnotation(ApplicationException.class) != null) {
        return true;
    }
    return false;
}
 
Example #3
Source File: TransactionUtils.java    From testfun with Apache License 2.0 5 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    boolean newTransaction = beginTransaction();

    try {
        return method.invoke(delegate, args);

    } catch (Throwable throwable) {

        if (throwable instanceof InvocationTargetException) {
            InvocationTargetException invocationTargetException = (InvocationTargetException) throwable;

            ApplicationException applicationException = invocationTargetException.getTargetException().getClass().getAnnotation(ApplicationException.class);

            if (applicationException == null || applicationException.rollback()) {
                rollbackTransaction();
            }

        } else {
            rollbackTransaction();
        }

        throw throwable.getCause();

    } finally {
        endTransaction(newTransaction);
    }
}
 
Example #4
Source File: BeanContext.java    From tomee with Apache License 2.0 5 votes vote down vote up
public ExceptionType getExceptionType(final Throwable e) {
    // Errors are always system exceptions
    if (!(e instanceof Exception)) {
        return ExceptionType.SYSTEM;
    }

    // check the registered app exceptions
    Class<?> exceptionClass = e.getClass();
    boolean inherited = false;
    while (exceptionClass != Object.class) {
        final ExceptionType type = exceptions.get(exceptionClass);
        if (type == ExceptionType.APPLICATION || type == ExceptionType.APPLICATION_ROLLBACK) {
            return type;
        }
        if (type != null) {
            if (inherited) {
                return ExceptionType.SYSTEM;
            }
            if (type == ExceptionType.APPLICATION_NOT_INHERITED) {
                return ExceptionType.APPLICATION;
            }
            return ExceptionType.APPLICATION_ROLLBACK;
        }
        exceptionClass = exceptionClass.getSuperclass();
        inherited = true;
    }

    // Unregistered - runtime exceptions are system exception and the rest are application exceptions
    final Class<? extends Throwable> eClass = e.getClass();
    final ApplicationException applicationException = eClass.getAnnotation(ApplicationException.class);
    if (applicationException != null) {
        addApplicationException(eClass, applicationException.rollback(), applicationException.inherited());
        return getExceptionType(e);
    }

    if (e instanceof RuntimeException) {
        return ExceptionType.SYSTEM;
    }
    return ExceptionType.APPLICATION;
}
 
Example #5
Source File: Ejb3TransactionAnnotationParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean rollbackOn(Throwable ex) {
	ApplicationException ann = ex.getClass().getAnnotation(ApplicationException.class);
	return (ann != null ? ann.rollback() : super.rollbackOn(ex));
}
 
Example #6
Source File: Ejb3TransactionAnnotationParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean rollbackOn(Throwable ex) {
	ApplicationException ann = ex.getClass().getAnnotation(ApplicationException.class);
	return (ann != null ? ann.rollback() : super.rollbackOn(ex));
}
 
Example #7
Source File: Ejb3TransactionAnnotationParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean rollbackOn(Throwable ex) {
	ApplicationException ann = ex.getClass().getAnnotation(ApplicationException.class);
	return (ann != null ? ann.rollback() : super.rollbackOn(ex));
}
 
Example #8
Source File: Ejb3TransactionAnnotationParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public boolean rollbackOn(Throwable ex) {
	ApplicationException ann = ex.getClass().getAnnotation(ApplicationException.class);
	return (ann != null ? ann.rollback() : super.rollbackOn(ex));
}
 
Example #9
Source File: TransactionInvocationHandlers.java    From development with Apache License 2.0 4 votes vote down vote up
private static boolean hasRollbackAnnotation(Exception ex) {
    ApplicationException annotation = ex.getClass().getAnnotation(
            ApplicationException.class);
    return annotation != null && annotation.rollback();
}