Search in sources :

Example 16 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class StatelessInterceptorTest method test.

public void test() throws Exception {
    final Target target = (Target) ctx.lookup("TargetBeanLocal");
    target.echo(new ArrayList());
    assertCalls(Call.values());
    calls.clear();
    int i = target.echo(123);
    assertEquals(123, i);
    assertCalls(Call.Default_Invoke_BEFORE, Call.Method_ann_Invoke_BEFORE, Call.Method_dd_Invoke_BEFORE, Call.Bean_Invoke_BEFORE, Call.Bean_Invoke, Call.Bean_Invoke_AFTER, Call.Method_dd_Invoke_AFTER, Call.Method_ann_Invoke_AFTER, Call.Default_Invoke_AFTER);
    calls.clear();
    boolean b = target.echo(true);
    assertTrue(b);
    assertCalls(Call.Method_ann_Invoke_BEFORE, Call.Method_dd_Invoke_BEFORE, Call.Bean_Invoke_BEFORE, Call.Bean_Invoke, Call.Bean_Invoke_AFTER, Call.Method_dd_Invoke_AFTER, Call.Method_ann_Invoke_AFTER);
    calls.clear();
    try {
        target.throwAppException();
        fail("Should have thrown app exception");
    } catch (final AppException e) {
    // pass
    }
    try {
        target.throwSysException();
        fail("Should have thrown a sys exception");
    } catch (final EJBException e) {
        // so far so good
        final Throwable cause = e.getCause();
        if (!(cause instanceof SysException)) {
            fail("Inner Exception should be a SysException");
        }
    }
    calls.clear();
    final Target target2 = (Target) ctx.lookup("Target2BeanLocal");
    i = target2.echo(123);
    assertEquals(123, i);
    calls.clear();
    i = target2.echo(123);
    assertEquals(123, i);
    assertCalls(Call.Method_ann_Invoke_BEFORE, Call.Bean_Invoke_BEFORE, Call.Bean_Invoke, Call.Bean_Invoke_AFTER, Call.Method_ann_Invoke_AFTER);
    calls.clear();
    b = target2.echo(true);
    assertTrue(b);
    assertCalls(Call.Method_ann_Invoke_BEFORE, Call.Bean_Invoke_BEFORE, Call.Bean_Invoke, Call.Bean_Invoke_AFTER, Call.Method_ann_Invoke_AFTER);
    calls.clear();
}
Also used : ArrayList(java.util.ArrayList) EJBException(javax.ejb.EJBException)

Example 17 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class CmpContainer method ejbStore.

private void ejbStore(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }
    final ThreadContext callContext = createThreadContext(entityBean);
    callContext.setCurrentOperation(Operation.STORE);
    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.ejbStore();
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 18 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class CmpContainer method setEntityContext.

private void setEntityContext(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }
    // activating entity doen't have a primary key
    final BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
    final ThreadContext callContext = new ThreadContext(beanContext, null);
    callContext.setCurrentOperation(Operation.SET_CONTEXT);
    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.setEntityContext(new EntityContext(securityService));
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) ThreadContext(org.apache.openejb.core.ThreadContext) EntityContext(org.apache.openejb.core.entity.EntityContext) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 19 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class StorageBean method setBytes.

public void setBytes(final byte[] bytes) {
    try {
        final DataSource ds = (DataSource) new InitialContext().lookup("java:comp/env/jdbc/DefaultDatabase");
        final Connection c = ds.getConnection();
        final PreparedStatement ps = c.prepareStatement("UPDATE storage SET blob_column = ? WHERE id = ?");
        ps.setBinaryStream(1, new ByteArrayInputStream(bytes), bytes.length);
        ps.setInt(2, ((Integer) ctx.getPrimaryKey()).intValue());
        ps.executeUpdate();
        ps.close();
        c.close();
    } catch (final Exception e) {
        throw new EJBException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) EJBException(javax.ejb.EJBException) InitialContext(javax.naming.InitialContext) EJBException(javax.ejb.EJBException) CreateException(javax.ejb.CreateException) DataSource(javax.sql.DataSource)

Example 20 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class EjbTimerServiceImpl method createTimer.

@Override
public Timer createTimer(final Object primaryKey, final Method timeoutMethod, final long initialDuration, final long intervalDuration, final TimerConfig timerConfig) throws IllegalArgumentException, IllegalStateException, EJBException {
    if (initialDuration < 0) {
        throw new IllegalArgumentException("initialDuration is negative: " + initialDuration);
    }
    if (intervalDuration < 0) {
        throw new IllegalArgumentException("intervalDuration is negative: " + intervalDuration);
    }
    checkState();
    final Date initialExpiration = new Date(System.currentTimeMillis() + initialDuration);
    try {
        final TimerData timerData = timerStore.createIntervalTimer(this, (String) deployment.getDeploymentID(), primaryKey, timeoutMethod, initialExpiration, intervalDuration, timerConfig);
        initializeNewTimer(timerData);
        return timerData.getTimer();
    } catch (final TimerStoreException e) {
        throw new EJBException(e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException) Date(java.util.Date)

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