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

    Embedded EJB3 and JNDI lookups

    holmes.j

      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




        • 1. Re: Embedded EJB3 and JNDI lookups
          holmes.j

          Somebody ... anybody, throw me a bone.

          -Jason

          • 2. Re: Embedded EJB3 and JNDI lookups
            holmes.j

            So I'm not so sure the beans are getting published into JNDI.

            Anybody know how to see what's in the JNDI tables?

            -Jason

            • 3. Re: Embedded EJB3 and JNDI lookups
              jaikiran

               

              Anybody know how to see what's in the JNDI tables?


              Follow these steps:

              1) Hit http://localhost:8080/jmx-console
              2) On the page that comes up, search for service=JNDIView
              3) Click on it
              4) On the page that comes up, click on the Invoke button beside the list method.
              5) This will show the JNDI contents.

              • 4. Re: Embedded EJB3 and JNDI lookups
                holmes.j

                I know to use that when testing in the JBoss Container, but I'm trying to use the embedded/stand-alone version.

                There are no web-services, or jmx-console in the embedded EJB3 version.

                But thanks for the effort,
                -Jason

                • 5. Re: Embedded EJB3 and JNDI lookups
                  holmes.j

                  So I'm quite confident in the fact that the Beans aren't making it into JNDI. During lookups, the NamingServer class prints out what's in it's contents. So when I run the samples provided, I see UserTransaction and CustomerBean. If I stick a really simplified version of my bean in with the Customer, it appears in the lookup.

                  So I'm doing something wrong somewhere. I just don't know where.If anybody has any ideas - that'd be awesome!

                  -Jason

                  • 6. Re: Embedded EJB3 and JNDI lookups
                    mmarcom

                    hello,
                    i am testig ejb3 with microcontainer.. (rc9)

                    you can lookup JNDI with YourBeanName/local if it is local or ../remote if it is remote

                    but you might get a ClassCastException, because rather than having back your EJBLocal home you could have back a proxy..
                    that depends on the CallByValue parameter of your naming service...
                    that might explain why you can successfully lookup DataSource but you cant EJBs..
                    try to put a try/catch around your JNDI lookup for the EJB.. i m sure you will see a ClassCastException while looking up bean...
                    i got that error with JBossContainer and was able to get over it by setting true in ejb3-deployer.xml
                    i m not sure what you'd need to do with microcontainer, you might want to post your question in microcontainer forum

                    i had similar problems, resorte to test EEJB using EntityManager directly...

                    hth
                    marco

                    • 7. Re: Embedded EJB3 and JNDI lookups
                      holmes.j

                      I found that it's not JNDI I'm having problems with, it's the @PersistenceContext on the Dao EntityManager.

                      I've posted a new thread http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3975197#3975197

                      -Jason

                      • 8. Re: Embedded EJB3 and JNDI lookups

                        dir holme,
                        since i had alot of trouble can you please provide a bit more insight about the setup of you project in order to use the Embedded JBoss.I had no luck until now....and from an official answer i got...that the project is very much "dead"...

                        • 9. Re: Embedded EJB3 and JNDI lookups

                          I found out after debugging that there are different projects like EJB 3.0 and Embedded.The embedded is pretty match dead.I have configured the ejb 3.0 embedded and works like a charm.I have also a fix in the EJB3StandaloneBootstrap.java to be more flexible in the way you define configuration files.Hope they will resurrect sometime soon the embedded jboss project.!!