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;
}
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;
}
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());
}
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;
}
}
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");
}
Aggregations