Search in sources :

Example 31 with ApplicationException

use of org.apache.openejb.ApplicationException in project tomee by apache.

the class EndpointHandler method deliverMessage.

public Object deliverMessage(final Method method, final Object[] args) throws Throwable {
    boolean callBeforeAfter = false;
    // verify current state
    switch(state) {
        case NONE:
            try {
                beforeDelivery(method);
            } catch (final ApplicationServerInternalException e) {
                throw (EJBException) new EJBException().initCause(e.getCause());
            }
            callBeforeAfter = true;
            state = State.METHOD_CALLED;
            break;
        case BEFORE_CALLED:
            state = State.METHOD_CALLED;
            break;
        case RELEASED:
            throw new IllegalStateException("Message endpoint factory has been released");
        case METHOD_CALLED:
        case SYSTEM_EXCEPTION:
            throw new IllegalStateException("The last message delivery must be completed with an afterDeliver before another message can be delivered");
    }
    Throwable throwable = null;
    Object value = null;
    try {
        // deliver the message
        value = container.invoke(instance, method, null, wrapMessageForAmq5(args));
    } catch (final SystemException se) {
        throwable = se.getRootCause() != null ? se.getRootCause() : se;
        state = State.SYSTEM_EXCEPTION;
    } catch (final ApplicationException ae) {
        throwable = ae.getRootCause() != null ? ae.getRootCause() : ae;
    } finally {
        // if the adapter is not using before/after, we must call afterDelivery to clean up
        if (callBeforeAfter) {
            try {
                afterDelivery();
            } catch (final ApplicationServerInternalException e) {
                throwable = throwable == null ? e.getCause() : throwable;
            } catch (final UnavailableException e) {
                throwable = throwable == null ? e : throwable;
            }
        }
    }
    if (throwable != null) {
        throwable.printStackTrace();
        if (isValidException(method, throwable)) {
            throw throwable;
        } else {
            throw new EJBException().initCause(throwable);
        }
    }
    return value;
}
Also used : ApplicationException(org.apache.openejb.ApplicationException) SystemException(org.apache.openejb.SystemException) UnavailableException(javax.resource.spi.UnavailableException) ApplicationServerInternalException(javax.resource.spi.ApplicationServerInternalException) EJBException(javax.ejb.EJBException)

Aggregations

ApplicationException (org.apache.openejb.ApplicationException)31 OpenEJBException (org.apache.openejb.OpenEJBException)16 SystemException (org.apache.openejb.SystemException)15 BeanContext (org.apache.openejb.BeanContext)12 ThreadContext (org.apache.openejb.core.ThreadContext)10 EjbTransactionUtil.handleApplicationException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException)10 RemoteException (java.rmi.RemoteException)8 EjbTransactionUtil.handleSystemException (org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException)8 Method (java.lang.reflect.Method)7 EJBAccessException (javax.ejb.EJBAccessException)7 InvalidateReferenceException (org.apache.openejb.InvalidateReferenceException)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Operation (org.apache.openejb.core.Operation)6 SystemInstance (org.apache.openejb.loader.SystemInstance)6 EJBException (javax.ejb.EJBException)5 NamingException (javax.naming.NamingException)5 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)5 EJBHome (javax.ejb.EJBHome)4 EJBLocalHome (javax.ejb.EJBLocalHome)4 RemoveException (javax.ejb.RemoveException)4