9 Replies Latest reply on May 12, 2009 6:00 AM by Nick Mpallas

    Embedded EJB3 and JNDI lookups

    Jason Holmes Newbie

      I'm migrating from a Hibernate setup to an EJB3 setup. We got our web application to work with the regular EJB3 patch for JBoss, but we'd like to be able to run tests outside of the AS. So I'm trying to setup the Embedded container for our JUnit tests.

      I've got it to the point where it loads the server, finds the datasource, puts the datasource into JNDI, and then finds and loads the EJB3 Session beans.

      The problem is I can't locate the GeoFeatureManagerBean (an EJB3 Stateless session bean) in JNDI. I've tried looking up GeoFeatureManagerBean, GeoFeatureManagerBean/remote, motionbased/GeoFeatureManagerBean/remote, motionbased/GeoFeatureManagerBean. Everything says it cannot be found (btw, motionbased is the name of our ear during the AS deploy. I knew it wouldn't be in there, but I'm desperate now).

      I know something's working, because I can find the GeoDataSource at "java:/com.free2be.datasource.GeoDataSource". I get a ClassCastException coming back from it - which is fine with me. But I can't for the life of me determine what the JNDI lookup name for a EJB3 Stateless Session Bean in an embedded context is.

      I'm not all that familiar with JNDI, but is there a way to print out everything it has? I know I can use the jmx-console under the AS, but that's not really an option here.


      0 [main] DEBUG KernelFactory - Starting JBoss Kernel construction...
      125 [main] DEBUG KernelFactory - Completed JBoss Kernel construction. Duration: 125 milliseconds
      890 [main] DEBUG BeanXMLDeployer - Parsing file:/C:/dev/mb/main/components/server/test/resources/embedded-jboss-beans.xml took 718 milliseconds
      1109 [main] DEBUG UserTransactionImpl - new UserTx: org.jboss.ejb3.embedded.UserTransactionImpl@1242b11
      1187 [main] INFO LocalTxDataSource - Bound datasource to JNDI name 'java:/com.free2be.datasource.GeoDataSource'
      1187 [main] DEBUG BeanXMLDeployer - Deploying file:/C:/dev/mb/main/components/server/test/resources/embedded-jboss-beans.xml took 1015 milliseconds
      1719 [main] DEBUG JaccHelper - Initialising JACC Context for deployment: UserProfile
      1922 [main] DEBUG EjbJarDDObjectFactory - found ejb-jar.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/UserProfile.jar!/META-INF/ejb-jar.xml
      2469 [main] DEBUG JBossDDObjectFactory - found jboss.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/UserProfile.jar!/META-INF/jboss.xml
      2531 [main] INFO Ejb3Deployment - EJB3 deployment time took: 812
      2531 [main] DEBUG JaccHelper - Initialising JACC Context for deployment: GpsTrack
      2531 [main] DEBUG EjbJarDDObjectFactory - found ejb-jar.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/GpsTrack.jar!/META-INF/ejb-jar.xml
      2781 [main] DEBUG JBossDDObjectFactory - found jboss.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/GpsTrack.jar!/META-INF/jboss.xml
      2812 [main] INFO Ejb3Deployment - EJB3 deployment time took: 281
      2812 [main] DEBUG JaccHelper - Initialising JACC Context for deployment: Activity
      2812 [main] DEBUG EjbJarDDObjectFactory - found ejb-jar.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/Activity.jar!/META-INF/ejb-jar.xml
      3109 [main] DEBUG JBossDDObjectFactory - found jboss.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/Activity.jar!/META-INF/jboss.xml
      3156 [main] INFO Ejb3Deployment - EJB3 deployment time took: 344
      3156 [main] DEBUG JaccHelper - Initialising JACC Context for deployment: Climate
      3156 [main] DEBUG EjbJarDDObjectFactory - found ejb-jar.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/Climate.jar!/META-INF/ejb-jar.xml
      3312 [main] DEBUG JBossDDObjectFactory - found jboss.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/Climate.jar!/META-INF/jboss.xml
      3328 [main] INFO Ejb3Deployment - EJB3 deployment time took: 172
      3328 [main] DEBUG JaccHelper - Initialising JACC Context for deployment: Equipment
      3328 [main] DEBUG EjbJarDDObjectFactory - found ejb-jar.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/Equipment.jar!/META-INF/ejb-jar.xml
      3500 [main] DEBUG JBossDDObjectFactory - found jboss.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/Equipment.jar!/META-INF/jboss.xml
      3531 [main] INFO Ejb3Deployment - EJB3 deployment time took: 203
      3531 [main] DEBUG JaccHelper - Initialising JACC Context for deployment: NoaaWeatherServer
      3531 [main] DEBUG EjbJarDDObjectFactory - found ejb-jar.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/NoaaWeatherServer.jar!/META-INF/ejb-jar.xml
      3687 [main] DEBUG JBossDDObjectFactory - found jboss.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/NoaaWeatherServer.jar!/META-INF/jboss.xml
      3703 [main] INFO Ejb3Deployment - EJB3 deployment time took: 172
      3703 [main] DEBUG JaccHelper - Initialising JACC Context for deployment: GeoFeatureBeans
      3828 [main] DEBUG Ejb3AnnotationHandler - found EJB3: ejbName=GenericDaoBean, class=com.garmin.mb.dao.GenericDaoBean, type=STATELESS
      3844 [main] DEBUG ProxyDeployer - no declared remote bindings for : GenericDaoBean
      3859 [main] DEBUG Ejb3AnnotationHandler - found EJB3: ejbName=GeoFeatureDaoBean, class=com.garmin.mb.dao.gis.feature.GeoFeatureDaoBean, type=STATELESS
      3859 [main] DEBUG ProxyDeployer - no declared remote bindings for : GeoFeatureDaoBean
      3890 [main] DEBUG Ejb3AnnotationHandler - found EJB3: ejbName=GeoFeatureManagerBean, class=com.garmin.mb.framework.gis.feature.GeoFeatureManagerBean, type=STATELESS
      3890 [main] DEBUG ProxyDeployer - no declared remote bindings for : GeoFeatureManagerBean
      3890 [main] DEBUG ProxyDeployer - there is remote interfaces for GeoFeatureManagerBean
      3890 [main] DEBUG ProxyDeployer - default remote binding has jndiName of GeoFeatureManagerBean/remote
      3953 [main] DEBUG DTDEntityResolver - trying to resolve system-id [http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd]
      3953 [main] DEBUG EJB3DTDEntityResolver - recognized EJB3 ORM namespace; attempting to resolve on classpath under org/hibernate/ejb
      3953 [main] DEBUG EJB3DTDEntityResolver - located [http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd] in classpath
      3969 [main] INFO Ejb3Deployment - EJB3 deployment time took: 266
      3969 [main] DEBUG JaccHelper - Initialising JACC Context for deployment: PrimaryKey
      3984 [main] DEBUG EjbJarDDObjectFactory - found ejb-jar.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/PrimaryKey.jar!/META-INF/ejb-jar.xml
      4031 [main] DEBUG JBossDDObjectFactory - found jboss.xml jar:file:/C:/dev/mb/main/build/deploy/ejb/PrimaryKey.jar!/META-INF/jboss.xml
      4062 [main] INFO Ejb3Deployment - EJB3 deployment time took: 93
      lookup
       UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
      lookup
       UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
      lookup
       UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
      lookup
       UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
      lookup
       UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
      lookup
       UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
      4062 [main] INFO MCKernelAbstraction - installing bean: persistence.units:jar=GeoFeatureBeans.jar,unitName=GeoFeatureDataSource with dependencies:
      4062 [main] INFO MCKernelAbstraction - AbstractDemandMetaData@8b058b{demand=com.free2be.datasource.GeoDataSource whenRequiredDescribed}
      4109 [main] DEBUG EJBContainer - Initialising interceptors for GenericDaoBean...
      4109 [main] DEBUG EJBContainer - Default interceptors: null
      4109 [main] DEBUG EJBContainer - Class interceptors: []
      4109 [main] DEBUG EJBContainer - All applicable interceptor classes: []
      4109 [main] DEBUG EJBContainer - Initialising interceptors for GeoFeatureDaoBean...
      4109 [main] DEBUG EJBContainer - Default interceptors: null
      4109 [main] DEBUG EJBContainer - Class interceptors: []
      4109 [main] DEBUG EJBContainer - All applicable interceptor classes: []
      4219 [main] DEBUG EJBContainer - Initialising interceptors for GeoFeatureManagerBean...
      4219 [main] DEBUG EJBContainer - Default interceptors: null
      4219 [main] DEBUG EJBContainer - Class interceptors: []
      4219 [main] DEBUG EJBContainer - All applicable interceptor classes: []
      4219 [main] INFO MCKernelAbstraction - installing bean: jboss.j2ee:jar=GeoFeatureBeans,name=GenericDaoBean,service=EJB3 with dependencies:
      4219 [main] INFO MCKernelAbstraction - AbstractDemandMetaData@df2d38{demand=persistence.units:jar=GeoFeatureBeans.jar,unitName=GeoFeatureDataSource whenRequiredDescribed}
      4219 [main] DEBUG Ejb3Deployment - Bound ejb3 container jboss.j2ee:service=EJB3,jar=GeoFeatureBeans,name=GenericDaoBean
      4219 [main] INFO MCKernelAbstraction - installing bean: jboss.j2ee:jar=GeoFeatureBeans,name=GeoFeatureDaoBean,service=EJB3 with dependencies:
      4219 [main] INFO MCKernelAbstraction - AbstractDemandMetaData@873723{demand=persistence.units:jar=GeoFeatureBeans.jar,unitName=GeoFeatureDataSource whenRequiredDescribed}
      4234 [main] DEBUG Ejb3Deployment - Bound ejb3 container jboss.j2ee:service=EJB3,jar=GeoFeatureBeans,name=GeoFeatureDaoBean
      4234 [main] INFO MCKernelAbstraction - installing bean: jboss.j2ee:jar=GeoFeatureBeans,name=GeoFeatureManagerBean,service=EJB3 with dependencies:
      4234 [main] INFO MCKernelAbstraction - AbstractDemandMetaData@1f38fc6{demand=jboss.j2ee:jar=GeoFeatureBeans,name=GeoFeatureDaoBean,service=EJB3 whenRequiredDescribed}
      4234 [main] DEBUG Ejb3Deployment - Bound ejb3 container jboss.j2ee:service=EJB3,jar=GeoFeatureBeans,name=GeoFeatureManagerBean
      lookup
       UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
      lookup
       UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
      


      Here's the test-code ...
      package com.garmin.mb.dao.gis.feature.pc;
      
      import static org.junit.Assert.assertEquals;
      import static org.junit.Assert.assertTrue;
      import static org.junit.Assert.fail;
      
      import java.util.NoSuchElementException;
      
      import org.junit.AfterClass;
      import org.junit.Before;
      import org.junit.BeforeClass;
      import org.junit.Test;
      
      import com.garmin.mb.dao.EJB3TestContainer;
      import com.garmin.mb.framework.gis.feature.pc.PopulatedPlaceClassification;
      
      public class PopulatedPlaceClassifcationDAOUnitTest {
      
       private static EJB3TestContainer container;
      
       private PopulatedPlaceClassificationDao dao;
      
       @BeforeClass
       public static void beforeClass() throws Exception {
       container = new EJB3TestContainer();
       container.startup();
       }
      
       @AfterClass
       public static void afterClass() throws Exception {
       container.shutdown();
       }
      
       @Before
       public void setUp() {
       Object daoToCast = EJB3TestContainer.lookup("GeoFeatureManagerBean/remote");
       this.dao = (PopulatedPlaceClassificationDao) daoToCast;
       }
      
       @Test
       public void testFindById() {
       long id = 2;
       PopulatedPlaceClassification value = dao.findById(id, false);
      
       assert value != null;
       long pkValue = value.getPopulatedPlaceClassificationPk();
      
       assertEquals(pkValue, id);
       assertEquals("Medium-High", value.getDatabaseDescription());
       }
      
       @Test
       public void testFindValue() {
       int key = 3;
       PopulatedPlaceClassification value = dao.findByCode(key);
       assertEquals("Medium", value.getDatabaseDescription());
       }
      
       @Test
       public void testFindValueNotPresent() {
       int key = 991;
      
       try {
       dao.findByCode(key);
       fail();
       } catch (NoSuchElementException e) {
       assertTrue(true);
       }
       }
      }
      


      jndi.properties ...
      java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces