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