Search in sources :

Example 1 with EJBException

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

the class EJB2xMDB method ejbCreate.

public void ejbCreate() {
    InitialContext iniCtx = null;
    try {
        iniCtx = new InitialContext();
        cf = (ConnectionFactory) iniCtx.lookup("java:/ConnectionFactory");
    } catch (NamingException e) {
        throw new EJBException(e);
    }
}
Also used : NamingException(javax.naming.NamingException) EJBException(javax.ejb.EJBException) InitialContext(javax.naming.InitialContext)

Example 2 with EJBException

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

the class EJB2xMDB method onMessage.

@Override
public void onMessage(Message message) {
    logger.trace("Received message " + message + " in MDB " + this.getClass().getName());
    try {
        if (message.getStringProperty("MessageFormat") != null)
            logger.trace("MessageFormat property = " + message.getStringProperty("MessageFormat"));
        Destination replyTo = message.getJMSReplyTo();
        if (replyTo == null) {
            try {
                logger.trace("mdbContext = " + mdbContext);
                replyTo = (Destination) mdbContext.lookup("jms/replyQueue");
            } catch (Throwable e) {
                logger.warn(e);
            }
        } else {
            logger.trace("Using replyTo from message JMSReplyTo: " + replyTo);
        }
        if (replyTo == null) {
            throw new EJBException("no replyTo Destination");
        }
        final TextMessage tm = (TextMessage) message;
        final String reply = tm.getText() + "processed by: " + hashCode();
        try (JMSContext context = cf.createContext()) {
            context.createProducer().setJMSCorrelationID(message.getJMSMessageID()).send(replyTo, reply);
        }
    } catch (Exception e) {
        logger.error(e);
        throw new EJBException(e);
    }
}
Also used : Destination(javax.jms.Destination) EJBException(javax.ejb.EJBException) TextMessage(javax.jms.TextMessage) JMSContext(javax.jms.JMSContext) EJBException(javax.ejb.EJBException) NamingException(javax.naming.NamingException)

Example 3 with EJBException

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

the class MDBLifecycleCallback method ejbRemove.

@Override
public void ejbRemove() throws EJBException {
    try {
        ITestResultsSingleton results = this.getSingleton();
        log.trace(MDBLifecycleCallback.class.getSimpleName() + " @PreDestroy called");
        Principal princ = null;
        try {
            princ = msgContext.getCallerPrincipal();
        } catch (IllegalStateException e) {
            results.setMdb("predestroy", "OKstop");
            return;
        }
        results.setMdb("predestroy", "Method getCallerPrincipal was called from @PreDestroy with result: " + princ);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Principal(java.security.Principal) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) EJBException(javax.ejb.EJBException)

Example 4 with EJBException

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

the class AnnotationHomeTestCase method testGetEjbLocalObject.

@Test
public void testGetEjbLocalObject() throws Exception {
    final String message = "Bean Message";
    final SimpleStatefulHome home = (SimpleStatefulHome) iniCtx.lookup("java:module/SimpleStatefulBean!" + SimpleStatefulHome.class.getName());
    SimpleInterface ejbInstance = home.createSimple(message);
    try {
        Assert.assertEquals(message, ejbInstance.otherMethod());
    } catch (EJBException e) {
        Assert.assertEquals(IllegalStateException.class, e.getCause().getClass());
    }
}
Also used : EJBException(javax.ejb.EJBException) SimpleInterface(org.jboss.as.test.integration.ejb.home.remotehome.SimpleInterface) SimpleStatefulHome(org.jboss.as.test.integration.ejb.home.remotehome.SimpleStatefulHome) Test(org.junit.Test)

Example 5 with EJBException

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

the class PoolOverrideTestCase method testSimulatenousInvocationOnEJBsWithSingleInstanceInPool.

/**
     * Submits 2 {@link Callable}s to a {@link java.util.concurrent.Executor} to invoke on the {@link AbstractSlowBean bean}
     * simulatenously. The bean is backed by a pool with <code>maxPoolSize</code> of 1 and the bean method "sleeps"
     * for 1 second. So the second invocation waits for the first to complete. The pool for these beans is configured
     * such that the instance acquisition timeout on the pool is (very) low compared to the time the bean method processing/sleep
     * time. As a result, the second invocation is expected to fail. This method just validates that the correct pool is being used
     * by the bean and not the default pool whose instance acquisition timeout is greater and these custom pools.
     *
     * @param bean The bean to invoke on
     * @throws Exception
     */
private void testSimulatenousInvocationOnEJBsWithSingleInstanceInPool(final AbstractSlowBean bean) throws Exception {
    final ExecutorService executorService = Executors.newFixedThreadPool(2);
    Future<Void> firstBeanInvocationResult = null;
    Future<Void> secondBeanInvocationResult = null;
    try {
        final PooledBeanInvoker firstBeanInvoker = new PooledBeanInvoker(bean, 1000);
        firstBeanInvocationResult = executorService.submit(firstBeanInvoker);
        final PooledBeanInvoker secondBeanInvoker = new PooledBeanInvoker(bean, 1000);
        secondBeanInvocationResult = executorService.submit(secondBeanInvoker);
    } finally {
        executorService.shutdown();
    }
    boolean firstInvocationFailed = false;
    boolean secondInvocationFailed = false;
    try {
        firstBeanInvocationResult.get(5, TimeUnit.SECONDS);
    } catch (ExecutionException ee) {
        if (ee.getCause() instanceof EJBException) {
            logger.trace("Got EJBException for first invocation ", ee.getCause());
            firstInvocationFailed = true;
        } else {
            throw ee;
        }
    }
    try {
        secondBeanInvocationResult.get(5, TimeUnit.SECONDS);
    } catch (ExecutionException ee) {
        if (ee.getCause() instanceof EJBException) {
            logger.trace("Got EJBException for second invocation ", ee.getCause());
            secondInvocationFailed = true;
        } else {
            throw ee;
        }
    }
    // if both failed, then it's an error
    if (firstInvocationFailed && secondInvocationFailed) {
        Assert.fail("Both first and second invocations to EJB failed. Only one was expected to fail");
    }
    // if none failed, then it's an error too
    if (!firstInvocationFailed && !secondInvocationFailed) {
        Assert.fail("Both first and second invocations to EJB passed. Only one was expected to pass");
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) EJBException(javax.ejb.EJBException)

Aggregations

EJBException (javax.ejb.EJBException)86 InitialContext (javax.naming.InitialContext)40 OpenEJBException (org.apache.openejb.OpenEJBException)24 Test (org.junit.Test)16 RemoteException (java.rmi.RemoteException)13 CreateException (javax.ejb.CreateException)12 NamingException (javax.naming.NamingException)11 Connection (java.sql.Connection)10 PreparedStatement (java.sql.PreparedStatement)10 DataSource (javax.sql.DataSource)10 Properties (java.util.Properties)9 ThreadContext (org.apache.openejb.core.ThreadContext)9 FinderException (javax.ejb.FinderException)7 HashMap (java.util.HashMap)6 RemoveException (javax.ejb.RemoveException)6 BeanContext (org.apache.openejb.BeanContext)6 File (java.io.File)5 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)5 JMSException (javax.jms.JMSException)5 Assembler (org.apache.openejb.assembler.classic.Assembler)5