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