use of javax.ejb.NoSuchEJBException in project tomee by apache.
the class SingletonInstanceManager method createInstance.
private Instance createInstance(final ThreadContext callContext, final BeanContext beanContext) throws ApplicationException {
try {
initializeDependencies(beanContext);
final InstanceContext context = beanContext.newInstance();
if (context.getBean() instanceof SessionBean) {
final Operation originalOperation = callContext.getCurrentOperation();
try {
callContext.setCurrentOperation(Operation.CREATE);
final Method create = beanContext.getCreateMethod();
final InterceptorStack ejbCreate = new InterceptorStack(context.getBean(), create, Operation.CREATE, new ArrayList<>(), new HashMap());
ejbCreate.invoke();
} finally {
callContext.setCurrentOperation(originalOperation);
}
}
final ReadWriteLock lock;
if (beanContext.isBeanManagedConcurrency()) {
// Bean-Managed Concurrency
lock = new BeanManagedLock();
} else {
// Container-Managed Concurrency
lock = new ReentrantReadWriteLock();
}
return new Instance(context.getBean(), context.getInterceptors(), context.getCreationalContext(), lock);
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
final String t = "The bean instance " + beanContext.getDeploymentID() + " threw a system exception:" + e;
logger.error(t, e);
throw new ApplicationException(new NoSuchEJBException("Singleton failed to initialize").initCause(e));
}
}
use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.
the class InterDeploymentDependenciesEarTestCase method testWithRestart.
@Test
public void testWithRestart() throws NamingException, IOException, DeploymentException, MgmtOperationException {
try {
deployer.deploy(DEPENDENT);
fail("Application deployment must fail if the dependencies are not satisfied.");
} catch (Exception e) {
LOGGER.debug("Expected fail", e);
}
deployer.deploy(DEPENDEE);
deployer.deploy(DEPENDENT);
LogAccess helloApp1 = lookupEJB(DEP_APP1);
LogAccess helloApp2 = lookupEJB(DEP_APP2);
assertEquals(SleeperContextListener.class.getSimpleName() + LogAccessBean.class.getSimpleName(), helloApp1.getLog());
assertEquals(LogAccessBean.class.getSimpleName(), helloApp2.getLog());
ModelNode redeploy = Util.createEmptyOperation("redeploy", PathAddress.pathAddress("deployment", DEPENDEE.getName()));
ManagementOperations.executeOperation(managementClient.getControllerClient(), redeploy);
helloApp1 = lookupEJB(DEP_APP1);
helloApp2 = lookupEJB(DEP_APP2);
assertEquals(SleeperContextListener.class.getSimpleName() + LogAccessBean.class.getSimpleName(), helloApp1.getLog());
assertEquals(LogAccessBean.class.getSimpleName(), helloApp2.getLog());
forceDependeeUndeploy();
try {
helloApp2.getLog();
fail("Calling EJB from dependent application should fail");
} catch (IllegalStateException | NoSuchEJBException e) {
// OK
}
// cleanUp will undeploy DEP_APP2
}
use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.
the class EjbRemoteSuspendTestCase method testSuspendedCallRejected.
@Test
@InSequence(1)
public void testSuspendedCallRejected() throws Exception {
final Echo localEcho = (Echo) context.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME + "/" + EchoBean.class.getSimpleName() + "!" + Echo.class.getName() + "?stateful");
final String message = "Silence!";
String echo = localEcho.echo(message);
Assert.assertEquals(message, echo);
ModelNode op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("suspend");
managementClient.getControllerClient().execute(op);
try {
long fin = System.currentTimeMillis() + TimeoutUtil.adjust(5000);
while (true) {
echo = localEcho.echo(message);
if (System.currentTimeMillis() > fin)
Assert.fail("call should have been rejected");
Thread.sleep(300);
}
} catch (NoSuchEJBException expected) {
} catch (Exception e) {
Assert.fail(e.getMessage() + " thrown but NoSuchEJBException was expected");
} finally {
op = new ModelNode();
op.get(ModelDescriptionConstants.OP).set("resume");
managementClient.getControllerClient().execute(op);
// we need to make sure the module availbility message has been recieved
// (this is why we have InSequence, so avoid two sleep() calls)
// otherwise the test might fail intermittently if the message has not been recieved when the
// next test is started
// this is a somewhat weird construct, basically we just wait up to 5 seconds for the connection
// to become usable again
long fin = System.currentTimeMillis() + 5000;
while (true) {
try {
localEcho.echo(message);
break;
} catch (Exception e) {
if (System.currentTimeMillis() > fin) {
throw e;
}
}
Thread.sleep(300);
}
}
}
use of javax.ejb.NoSuchEJBException in project wildfly by wildfly.
the class BeforeCompletionExceptionDestroysBeanTestCase method testExceptionInBeforeCompletionDestroysBean.
@Test
public void testExceptionInBeforeCompletionDestroysBean() throws NamingException, SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException {
final UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
final BeforeCompletionSFSB bean = (BeforeCompletionSFSB) new InitialContext().lookup("java:module/" + BeforeCompletionSFSB.class.getSimpleName());
// begin a transaction
userTransaction.begin();
bean.enlist();
// commit, this should destroy the bean, as it's @BeforeCompletion method will throw an exception
try {
userTransaction.commit();
} catch (RollbackException expected) {
}
try {
userTransaction.begin();
bean.enlist();
throw new RuntimeException("Expected SFSB to be destroyed");
} catch (NoSuchEJBException expected) {
} finally {
userTransaction.rollback();
}
}
Aggregations