use of javax.ejb.SessionContext in project tomee by apache.
the class ContextLookupSingletonBean method lookupSessionContext.
public void lookupSessionContext() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
// lookup in enc
final SessionContext sctx = (SessionContext) ctx.lookup("java:comp/env/sessioncontext");
Assert.assertNotNull("The SessionContext got from java:comp/env/sessioncontext is null", sctx);
// lookup using global name
final EJBContext ejbCtx = (EJBContext) ctx.lookup("java:comp/EJBContext");
Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx);
// verify context was set via legacy set method
Assert.assertNotNull("The SessionContext is null from setter method", ejbContext);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
use of javax.ejb.SessionContext in project tomee by apache.
the class EncSingletonBean method lookupSessionContext.
public void lookupSessionContext() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
// lookup in enc
final SessionContext sctx = (SessionContext) ctx.lookup("java:comp/env/sessioncontext");
Assert.assertNotNull("The SessionContext got from java:comp/env/sessioncontext is null", sctx);
// lookup using global name
final EJBContext ejbCtx = (EJBContext) ctx.lookup("java:comp/EJBContext");
Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx);
// verify context was set via legacy set method
Assert.assertNotNull("The SessionContext is null from setter method", ejbContext);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
use of javax.ejb.SessionContext in project tomee by apache.
the class StatefulContainer method deploy.
@Override
public synchronized void deploy(final BeanContext beanContext) throws OpenEJBException {
final Map<Method, MethodType> methods = getLifecycleMethodsOfInterface(beanContext);
deploymentsById.put(beanContext.getDeploymentID(), beanContext);
beanContext.setContainer(this);
final Data data = new Data(new Index<Method, MethodType>(methods));
beanContext.setContainerData(data);
// Create stats interceptor
if (StatsInterceptor.isStatsActivated()) {
final StatsInterceptor stats = new StatsInterceptor(beanContext.getBeanClass());
beanContext.addFirstSystemInterceptor(stats);
final MBeanServer server = LocalMBeanServer.get();
final ObjectNameBuilder jmxName = new ObjectNameBuilder("openejb.management");
jmxName.set("J2EEServer", "openejb");
jmxName.set("J2EEApplication", null);
jmxName.set("EJBModule", beanContext.getModuleID());
jmxName.set("StatefulSessionBean", beanContext.getEjbName());
jmxName.set("j2eeType", "");
jmxName.set("name", beanContext.getEjbName());
// register the invocation stats interceptor
try {
final ObjectName objectName = jmxName.set("j2eeType", "Invocations").build();
if (server.isRegistered(objectName)) {
server.unregisterMBean(objectName);
}
server.registerMBean(new ManagedMBean(stats), objectName);
data.jmxNames.add(objectName);
} catch (final Exception e) {
logger.error("Unable to register MBean ", e);
}
}
try {
final Context context = beanContext.getJndiEnc();
context.bind("comp/EJBContext", sessionContext);
} catch (final NamingException e) {
throw new OpenEJBException("Failed to bind EJBContext", e);
}
beanContext.set(EJBContext.class, this.sessionContext);
}
use of javax.ejb.SessionContext in project tomee by apache.
the class ContextLookupStatelessBean method lookupSessionContext.
public void lookupSessionContext() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
// lookup in enc
final SessionContext sctx = (SessionContext) ctx.lookup("java:comp/env/sessioncontext");
Assert.assertNotNull("The SessionContext got from java:comp/env/sessioncontext is null", sctx);
// lookup using global name
final EJBContext ejbCtx = (EJBContext) ctx.lookup("java:comp/EJBContext");
Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx);
// verify context was set via legacy set method
Assert.assertNotNull("The SessionContext is null from setter method", ejbContext);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
use of javax.ejb.SessionContext in project tomee by apache.
the class EncStatelessBean method lookupSessionContext.
public void lookupSessionContext() throws TestFailureException {
try {
try {
final InitialContext ctx = new InitialContext();
Assert.assertNotNull("The InitialContext is null", ctx);
// lookup in enc
final SessionContext sctx = (SessionContext) ctx.lookup("java:comp/env/sessioncontext");
Assert.assertNotNull("The SessionContext got from java:comp/env/sessioncontext is null", sctx);
// lookup using global name
final EJBContext ejbCtx = (EJBContext) ctx.lookup("java:comp/EJBContext");
Assert.assertNotNull("The SessionContext got from java:comp/EJBContext is null ", ejbCtx);
// verify context was set via legacy set method
Assert.assertNotNull("The SessionContext is null from setter method", ejbContext);
} catch (final Exception e) {
Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
}
} catch (final AssertionFailedError afe) {
throw new TestFailureException(afe);
}
}
Aggregations