Search in sources :

Example 1 with ApplicationServerInternalException

use of javax.resource.spi.ApplicationServerInternalException in project wildfly by wildfly.

the class MessageEndpointInvocationHandler method beforeDelivery.

@Override
public void beforeDelivery(Method method) throws NoSuchMethodException, ResourceException {
    // JCA 1.6 FR 13.5.6
    // The application server must set the thread context class loader to the endpoint
    // application class loader during the beforeDelivery call.
    previousClassLoader = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(getApplicationClassLoader());
    try {
        final TransactionManager tm = getTransactionManager();
        // TODO: in violation of JCA 1.6 FR 13.5.9?
        previousTx = tm.suspend();
        boolean isTransacted = service.isDeliveryTransacted(method);
        if (isTransacted) {
            tm.begin();
            currentTx = tm.getTransaction();
            if (xaRes != null)
                currentTx.enlistResource(xaRes);
        }
    } catch (Throwable t) {
        throw new ApplicationServerInternalException(t);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(previousClassLoader);
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) ApplicationServerInternalException(javax.resource.spi.ApplicationServerInternalException)

Example 2 with ApplicationServerInternalException

use of javax.resource.spi.ApplicationServerInternalException 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

ApplicationServerInternalException (javax.resource.spi.ApplicationServerInternalException)2 EJBException (javax.ejb.EJBException)1 UnavailableException (javax.resource.spi.UnavailableException)1 TransactionManager (javax.transaction.TransactionManager)1 ApplicationException (org.apache.openejb.ApplicationException)1 SystemException (org.apache.openejb.SystemException)1