5 Replies Latest reply on Aug 13, 2010 2:40 PM by Joseph Genchik

    Unable to get reference to EJB from POJO

    Joseph Genchik Newbie

      I am migrating from JBoss 6.0 M1 to JBoss 6.0 M4. It has .ear, .war and .jar.

      In a POJO that is located in a .war, I am trying to get a reference to EJB. In M1 the following code worked fine:

       

       

      Context ctx = null;
      try {
           ctx = new InitialContext();
           this.sessionFacade = (SessionFacadeLocal) ctx.lookup("ngp/SessionFacade/local");
      } catch (NamingException ne) {
           log.error("Unable to obtain initial context", ne);
      }
      
      

       

      When I migrated to M4 this stopped working.

      I tried the EE 6 format like this:

       

      this.sessionFacade = (SessionFacadeLocal) ctx.lookup("java:global/ngp/ngpEjb/SessionFacade!com.package.SessionFacadeLocal");
      

      but none of the combinations I tried worked.

       

      I would appreciate any suggestions.

       

      Thanks.

        • 1. Re: Unable to get reference to EJB from POJO
          jaikiran pai Master

          Joseph Genchik wrote:

           

          I am migrating from JBoss 6.0 M1 to JBoss 6.0 M4. It has .ear, .war and .jar.

          In a POJO that is located in a .war, I am trying to get a reference to EJB. In M1 the following code worked fine:

           

           

          Context ctx = null;
          try {
               ctx = new InitialContext();
               this.sessionFacade = (SessionFacadeLocal) ctx.lookup("ngp/SessionFacade/local");
          } catch (NamingException ne) {
               log.error("Unable to obtain initial context", ne);
          }
           
          

           

          Can you post the code from you SessionFacade bean implementation class? Also what kind of a bean is that? SLSB, SFSB or Singleton? Have you used the jmx-console to check the JNDIView for that bean?

          • 2. Re: Unable to get reference to EJB from POJO
            Joseph Genchik Newbie

            SessionFacade is a SLSB that has a remote and local interfaces. Following are code snippets:

             

            @Stateless
            @org.jboss.wsf.spi.annotation.WebContext(authMethod="BASIC")
            @RunAs(value="ngp")
            public class SessionFacade implements SessionFacadeLocal, SessionFacadeRemote {
                 @EJB
                 private AdminDaoLocal adminDao;
            ...  
            

             

            @Local
            public interface SessionFacadeLocal {
            ...
            }
            

             

             

            When jboss starts, I see the following in the log:

             

            2010-08-12 14:01:56,730 INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] (HDScanner) Binding the following Entries in Global JNDI:
            
                 ngp/ngpEjb.jar/SessionFacade!remote - EJB3.x Default Remote Business Interface
                 ngp/ngpEjb.jar/SessionFacade!com.audiocodes.ngp.ejb.SessionFacadeRemote - EJB3.x Remote Business Interface
                 ngp/ngpEjb.jar/SessionFacade!local - EJB3.x Default Local Business Interface
                 ngp/ngpEjb.jar/SessionFacade!com.audiocodes.ngp.ejb.SessionFacadeLocal - EJB3.x Local Business Interface
             
            

             

            In jmx-console I see this bean under "jboss.j2ee" and it looks like this:

            Name
            Domain
            jboss.j2ee
            service
            EJB3
            name
            SessionFacade
            ear
            ngp.ear
            jar
            ngpEjb.jar
            Java Class
            org.jboss.ejb3.stateless.StatelessDelegateWrapper
            Description
            Management Bean.
            
            
            Attribute Name
            Access
            Type
            Description
            Attribute Value
            CreateCount
            R
            int
            MBean Attribute.
            0    
            
            
            
            InvokeStats
            R
            org.jboss.ejb3.statistics.InvocationStatistics
            MBean Attribute.
            InvocationStatistics concurrentCalls='0'
                
            
            
            
            CurrentSize
            R
            int
            MBean Attribute.
            0    
            
            
            
            RemoveCount
            R
            int
            MBean Attribute.
            0    
            
            
            
            MaxSize
            R
            int
            MBean Attribute.
            0    
            
            
            
            AvailableCount
            R
            int
            MBean Attribute.
            0    
            
            
            
            
            
            
            
            
            
            Operation
            Return Type
            Description
            Parameters
            
            
            getTimerService
            javax.ejb.TimerService
            MBean Operation.
            
            
            
            
            p1
            java.lang.Object
            (no description)
            
            
            
            
            
            
            
            
            
            
            
            • 3. Re: Unable to get reference to EJB from POJO
              Wolfgang Knauf Master

              Hi,

               

              seems your JMX Console snippet lost all formatting. Did you take a look at the "JNDIView" MBean in your JMX console? Here you will find all JNDI names, and I assume that your JMX console snippet was not from the JNDIView.

               

              Best regards

               

              Wolfgang

              • 4. Re: Unable to get reference to EJB from POJO
                Joseph Genchik Newbie

                Wolfgang,

                 

                When I go to JNDIView and invoke "listXML" method, I get the following (this is not a complete list)

                 

                 

                SessionFacade!com.audiocodes.ngp.ejb.SessionFacadeLocal
                Proxy for: com.audiocodes.ngp.ejb.SessionFacadeLocal
                
                SessionFacade!com.audiocodes.ngp.ejb.SessionFacadeRemote
                Proxy for: com.audiocodes.ngp.ejb.SessionFacadeRemote
                
                SessionFacade!remote
                Proxy for: com.audiocodes.ngp.ejb.SessionFacadeRemote
                
                SessionFacade!local
                Proxy for: com.audiocodes.ngp.ejb.SessionFacadeLocal
                
                SessionFacade
                org.jnp.interfaces.NamingContext
                
                SessionFacade!remote
                $Proxy185
                
                
                
                
                
                

                Just to reiterate, the EJBs are in .jar being called from .war located in the same .ear.

                • 5. Re: Unable to get reference to EJB from POJO
                  Joseph Genchik Newbie

                  Additional note: Above was based on a "standard" domain. I switched to "default" and now I am able to get reference to an EJB "the old way"

                   

                  ngp/SessionFacade/local
                  

                  I am still unable to do it the EE 6 way

                   

                  java:global/ngp/ngpEjb/SessionFacade!com.abc.ngp.ejb.SessionFacadeLocal