Search in sources :

Example 1 with SessionContext

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

the class ManagedContainer 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("StatelessSessionBean", 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);
}
Also used : SessionContext(javax.ejb.SessionContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) EJBContext(javax.ejb.EJBContext) InstanceContext(org.apache.openejb.core.InstanceContext) ThreadContext(org.apache.openejb.core.ThreadContext) OpenEJBException(org.apache.openejb.OpenEJBException) StatsInterceptor(org.apache.openejb.monitoring.StatsInterceptor) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) Method(java.lang.reflect.Method) NamingException(javax.naming.NamingException) InvalidateReferenceException(org.apache.openejb.InvalidateReferenceException) EJBAccessException(javax.ejb.EJBAccessException) RemoveException(javax.ejb.RemoveException) OpenEJBException(org.apache.openejb.OpenEJBException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) SystemException(org.apache.openejb.SystemException) NoSuchObjectException(java.rmi.NoSuchObjectException) EntityManagerAlreadyRegisteredException(org.apache.openejb.persistence.EntityManagerAlreadyRegisteredException) ApplicationException(org.apache.openejb.ApplicationException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) ObjectName(javax.management.ObjectName) ObjectNameBuilder(org.apache.openejb.monitoring.ObjectNameBuilder) NamingException(javax.naming.NamingException) ManagedMBean(org.apache.openejb.monitoring.ManagedMBean) MBeanServer(javax.management.MBeanServer) LocalMBeanServer(org.apache.openejb.monitoring.LocalMBeanServer)

Example 2 with SessionContext

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

the class ContextLookupStatefulPojoBean 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);
    }
}
Also used : EJBContext(javax.ejb.EJBContext) SessionContext(javax.ejb.SessionContext) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) InitialContext(javax.naming.InitialContext) JMSException(javax.jms.JMSException) TestFailureException(org.apache.openejb.test.TestFailureException)

Example 3 with SessionContext

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

the class ContextLookupStatefulBean 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);
    }
}
Also used : EJBContext(javax.ejb.EJBContext) SessionContext(javax.ejb.SessionContext) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) InitialContext(javax.naming.InitialContext) JMSException(javax.jms.JMSException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) TestFailureException(org.apache.openejb.test.TestFailureException) CreateException(javax.ejb.CreateException)

Example 4 with SessionContext

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

the class ContextLookupStatelessPojoBean 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);
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
Also used : EJBContext(javax.ejb.EJBContext) SessionContext(javax.ejb.SessionContext) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) TestFailureException(org.apache.openejb.test.TestFailureException)

Example 5 with SessionContext

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

the class ContextLookupSingletonPojoBean 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);
        } catch (final Exception e) {
            Assert.fail("Received Exception " + e.getClass() + " : " + e.getMessage());
        }
    } catch (final AssertionFailedError afe) {
        throw new TestFailureException(afe);
    }
}
Also used : EJBContext(javax.ejb.EJBContext) SessionContext(javax.ejb.SessionContext) TestFailureException(org.apache.openejb.test.TestFailureException) AssertionFailedError(junit.framework.AssertionFailedError) InitialContext(javax.naming.InitialContext) NamingException(javax.naming.NamingException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) TestFailureException(org.apache.openejb.test.TestFailureException)

Aggregations

EJBContext (javax.ejb.EJBContext)11 SessionContext (javax.ejb.SessionContext)11 RemoteException (java.rmi.RemoteException)10 EJBException (javax.ejb.EJBException)10 InitialContext (javax.naming.InitialContext)9 AssertionFailedError (junit.framework.AssertionFailedError)9 TestFailureException (org.apache.openejb.test.TestFailureException)9 JMSException (javax.jms.JMSException)7 NamingException (javax.naming.NamingException)4 Method (java.lang.reflect.Method)2 NoSuchObjectException (java.rmi.NoSuchObjectException)2 CreateException (javax.ejb.CreateException)2 EJBAccessException (javax.ejb.EJBAccessException)2 RemoveException (javax.ejb.RemoveException)2 MBeanServer (javax.management.MBeanServer)2 ObjectName (javax.management.ObjectName)2 Context (javax.naming.Context)2 ApplicationException (org.apache.openejb.ApplicationException)2 BeanContext (org.apache.openejb.BeanContext)2 InvalidateReferenceException (org.apache.openejb.InvalidateReferenceException)2