Search in sources :

Example 1 with NoSuchEJBException

use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.

the class CMTTxInterceptor method handleInCallerTx.

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;
    }
    Exception toThrow;
    if (!(t instanceof EJBTransactionRolledbackException)) {
        if (t instanceof Error) {
            toThrow = new EJBTransactionRolledbackException(EjbLogger.ROOT_LOGGER.convertUnexpectedError());
            toThrow.initCause(t);
        } else if (t instanceof NoSuchEJBException || t instanceof NoSuchEntityException) {
            // If this is an NoSuchEJBException, pass through to the caller
            toThrow = (Exception) t;
        } else if (t instanceof RuntimeException) {
            toThrow = new EJBTransactionRolledbackException(t.getMessage(), (Exception) t);
        } else {
            // application exception
            throw (Exception) t;
        }
    } else {
        toThrow = (Exception) t;
    }
    setRollbackOnly(tx);
    throw toThrow;
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBTransactionRolledbackException(javax.ejb.EJBTransactionRolledbackException) NoSuchEntityException(javax.ejb.NoSuchEntityException) NoSuchEJBException(javax.ejb.NoSuchEJBException) RollbackException(javax.transaction.RollbackException) NoSuchEntityException(javax.ejb.NoSuchEntityException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) EJBTransactionRolledbackException(javax.ejb.EJBTransactionRolledbackException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Example 2 with NoSuchEJBException

use of javax.ejb.NoSuchEJBException in project Payara by payara.

the class SafeProperties method mapLocal3xException.

private Throwable mapLocal3xException(Throwable t) {
    Throwable mappedException = null;
    if (t instanceof TransactionRolledbackLocalException) {
        mappedException = new EJBTransactionRolledbackException();
        mappedException.initCause(t);
    } else if (t instanceof TransactionRequiredLocalException) {
        mappedException = new EJBTransactionRequiredException();
        mappedException.initCause(t);
    } else if (t instanceof NoSuchObjectLocalException) {
        mappedException = new NoSuchEJBException();
        mappedException.initCause(t);
    } else if (t instanceof AccessLocalException) {
        mappedException = new EJBAccessException();
        mappedException.initCause(t);
    }
    return (mappedException != null) ? mappedException : t;
}
Also used : NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException) NoSuchEJBException(javax.ejb.NoSuchEJBException) TransactionRolledbackLocalException(javax.ejb.TransactionRolledbackLocalException) AccessLocalException(javax.ejb.AccessLocalException) EJBTransactionRolledbackException(javax.ejb.EJBTransactionRolledbackException) TransactionRequiredLocalException(javax.ejb.TransactionRequiredLocalException) EJBTransactionRequiredException(javax.ejb.EJBTransactionRequiredException) EJBAccessException(javax.ejb.EJBAccessException)

Example 3 with NoSuchEJBException

use of javax.ejb.NoSuchEJBException in project core by weld.

the class StatefulSessionBeanRecreatedAfterDestroyTest method testWithSpi.

@Test
public void testWithSpi() {
    assertEquals("pong", bean.ping());
    // cause SFSB to be removed
    try {
        bean.throwException();
        Assert.fail();
    } catch (EJBException expected) {
    }
    // verify that every access causes NoSuchEJBException
    try {
        bean.ping();
        Assert.fail();
    } catch (NoSuchEJBException expected) {
    }
    // try to destroy the bean
    Bean<?> contextual = manager.resolve(manager.getBeans(StatefulBean.class));
    AlterableContext context = (AlterableContext) manager.getContext(ApplicationScoped.class);
    context.destroy(contextual);
    assertEquals("pong", bean.ping());
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException) ApplicationScoped(javax.enterprise.context.ApplicationScoped) AlterableContext(javax.enterprise.context.spi.AlterableContext) Test(org.junit.Test)

Example 4 with NoSuchEJBException

use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.

the class CMTTxInterceptor method invokeInCallerTx.

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;
    }
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) EJBTransactionRolledbackException(javax.ejb.EJBTransactionRolledbackException) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException) NoSuchEJBException(javax.ejb.NoSuchEJBException) RollbackException(javax.transaction.RollbackException) NoSuchEntityException(javax.ejb.NoSuchEntityException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) EJBTransactionRolledbackException(javax.ejb.EJBTransactionRolledbackException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Example 5 with NoSuchEJBException

use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.

the class StatefulServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String module = getRequiredParameter(req, MODULE);
    String bean = getRequiredParameter(req, BEAN);
    HttpSession session = req.getSession(true);
    Incrementor incrementor = (Incrementor) session.getAttribute(BEAN);
    if (incrementor == null) {
        try (LocalEJBDirectory directory = new LocalEJBDirectory(module)) {
            incrementor = directory.lookupStateful(bean, Incrementor.class);
        } catch (NamingException e) {
            throw new ServletException(e);
        }
    }
    try {
        resp.setHeader(COUNT, String.valueOf(incrementor.increment()));
        session.setAttribute(BEAN, incrementor);
    } catch (NoSuchEJBException e) {
        resp.setHeader(COUNT, String.valueOf(0));
        session.removeAttribute(BEAN);
    }
    resp.getWriter().write("Success");
}
Also used : ServletException(javax.servlet.ServletException) NoSuchEJBException(javax.ejb.NoSuchEJBException) HttpSession(javax.servlet.http.HttpSession) Incrementor(org.jboss.as.test.clustering.cluster.ejb.stateful.bean.Incrementor) NamingException(javax.naming.NamingException) LocalEJBDirectory(org.jboss.as.test.clustering.ejb.LocalEJBDirectory)

Aggregations

NoSuchEJBException (javax.ejb.NoSuchEJBException)24 Test (org.junit.Test)9 InitialContext (javax.naming.InitialContext)8 EJBException (javax.ejb.EJBException)5 NamingException (javax.naming.NamingException)5 Incrementor (org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor)4 EJBTransactionRolledbackException (javax.ejb.EJBTransactionRolledbackException)3 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)3 RollbackException (javax.transaction.RollbackException)3 UserTransaction (javax.transaction.UserTransaction)3 RemoteEJBDirectory (org.jboss.as.test.clustering.ejb.RemoteEJBDirectory)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 RemoteException (java.rmi.RemoteException)2 Future (java.util.concurrent.Future)2 NoSuchEntityException (javax.ejb.NoSuchEntityException)2 Context (javax.naming.Context)2 ServletException (javax.servlet.ServletException)2 HttpSession (javax.servlet.http.HttpSession)2 HeuristicMixedException (javax.transaction.HeuristicMixedException)2 SystemException (javax.transaction.SystemException)2