Search in sources :

Example 21 with NoSuchEJBException

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));
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) HashMap(java.util.HashMap) SystemInstance(org.apache.openejb.loader.SystemInstance) Operation(org.apache.openejb.core.Operation) Method(java.lang.reflect.Method) SessionBean(javax.ejb.SessionBean) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) InvocationTargetException(java.lang.reflect.InvocationTargetException) ApplicationException(org.apache.openejb.ApplicationException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) InstanceContext(org.apache.openejb.core.InstanceContext) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack)

Example 22 with NoSuchEJBException

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
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) ModelNode(org.jboss.dmr.ModelNode) NoSuchEJBException(javax.ejb.NoSuchEJBException) NamingException(javax.naming.NamingException) MgmtOperationException(org.jboss.as.test.integration.management.util.MgmtOperationException) IOException(java.io.IOException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) Test(org.junit.Test)

Example 23 with NoSuchEJBException

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);
        }
    }
}
Also used : NoSuchEJBException(javax.ejb.NoSuchEJBException) ModelNode(org.jboss.dmr.ModelNode) NoSuchEJBException(javax.ejb.NoSuchEJBException) NamingException(javax.naming.NamingException) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 24 with NoSuchEJBException

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();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) NoSuchEJBException(javax.ejb.NoSuchEJBException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

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