8 Replies Latest reply on Jan 13, 2009 5:27 PM by cpopetz

    Problem in EJB lookp with Jboss Embedded

    pedrosena

      Hi guys,


      I'm trying to make a simple ejb lookup w/o success.


      Lookup code:



           public void testLookup() throws Exception {
                new ComponentTest() {
                     @Override
                     protected void testComponents() throws Exception {
                          Context context = new InitialContext();
                          INetSarHostingProvider hostingProvider = (INetSarHostingProvider) context.lookup("hosting/local");
                          assert hostingProvider != null;
                     }
                }.run();
           }



      My EJB:



      @Stateful(name="hosting")
      @Local(INetSarHostingProvider.class)
      
      public class HostingFacade implements INetSarHostingProvider {
      ...



      My jndi.properties:


      java.naming.factory.initial=org.jboss.naming.JBossRemotingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces



      and a snippet of my components.xml



      <core:init jndi-pattern="#{ejbName}/local" debug="true" precedence="100"/>



      I already tried to make a lookup at just hosting, java:comp/hosting and java:comp/hosting/local.


      I'm getting the following error:



      javax.naming.NameNotFoundException: hosting not bound



      Am I missing something ?


      Thanks in advance,


      Pedro Sena

        • 1. Re: Problem in EJB lookp with Jboss Embedded
          matt.nirgue

          Try to change your logging configuration so you can see what happens when JBoss Embedded starts but also when your Seam components are initialized... you should find something like:


          INFO  [Component] Component: yourComponent, scope: STATELESS, type: STATELESS_SESSION_BEAN, class: com.yourproject.util, JNDI: yourJNDI


          This should help you figuring out why you can't get your component

          • 2. Re: Problem in EJB lookp with Jboss Embedded
            pedrosena

            Hi Matt,


            Thanks for your reply.


            I did what you told me, now I'm more surprised:


            INFO  [org.jboss.ejb3.MCKernelAbstraction] installing bean: jboss.j2ee:ear=travelnetwork-business.ear,jar=ejb-0.0.1.jar,name=hosting,service=EJB3 with dependencies:
            INFO  [org.jboss.ejb3.MCKernelAbstraction]   and supplies:
            INFO  [org.jboss.ejb3.MCKernelAbstraction]      Class:br.com.netsar.tnw.core.model.service.INetSarHostingProvider
            INFO  [org.jboss.ejb3.EJBContainer] STARTED EJB: br.com.netsar.tnw.business.model.facade.HostingFacade ejbName: hosting



            My EJB is correctly installed, but when I try to lookup it, the lookup fails.


            Actually my component is not a Seam-managed EJB, just a default EJB.


            Any tips?


            Thnaks again,


            Pedro Sena

            • 3. Re: Problem in EJB lookp with Jboss Embedded
              dthibau1

              Don't you have a file named component.properties in your classpath which overrides the snippet of your components.xml ?


              With JBoss Embeded, I use a component .properties like that :



              #
              #Thu Dec 27 14:22:39 CET 2007
              jndiPattern=\#{ejbName}/local
              embeddedEjb=true



              • 4. Re: Problem in EJB lookp with Jboss Embedded
                coenos

                Hi,


                I'm facing the same problem. I see the EJB is created, but at runtime I get the not bound exception.


                Also this statement:


                
                INFO [Component] Component: yourComponent, scope: STATELESS, type: STATELESS_SESSION_BEAN, class: com.yourproject.util, JNDI: yourJNDI
                
                



                Is a JBOSS log statement. In embedded JBoss I don't see the JNDI name statement in the console.


                I have tried to set the @JndiName explicitly but this doesn't work either.


                Note that I can access the Entity Beans (plus Home and List classes) correctly, so these Seam components are started up correctly.


                I think the problem lies in the fact that the JNDI name from components.properties is not set at startup time in the embedded jboss server.


                Regards,
                Coen



                • 5. Re: Problem in EJB lookp with Jboss Embedded
                  coenos

                  Ok I solved the issue by indeed changing the components.xml from


                  
                  <core:init debug="true" jndi-pattern="application-name/#{ejbName}/local" />
                  
                  



                  to


                  
                  <core:init debug="true" jndi-pattern="#{ejbName}/local" />
                  
                  



                  But the upper tag works only on JBoss. And the lower tag only on Tomcat Embedded JBoss.


                  Cheers,
                  Coen

                  • 6. Re: Problem in EJB lookp with Jboss Embedded
                    cpopetz

                    Yup, but as mentioned above, you can create a components.properties for each type of deployment (tomcat vs jboss), with a line in each that says:


                    jndiPattern=<the correct jndi pattern here>



                    and then use:


                    <core:init debug="true" jndi-pattern="@jndiPattern@"/>



                    in your components.xml, and have your build script copy the correct components.properties into WEB-INF/classes for the deployment in question.





                    • 7. Re: Problem in EJB lookp with Jboss Embedded
                      coenos

                      actually,


                      the components.properties doesn't get picked up by Seam at startup...


                      This is why I have to change the components.xml :(


                      • 8. Re: Problem in EJB lookp with Jboss Embedded
                        cpopetz

                        Well, that's either a bug or misconfiguration.  Seam will look for the first components.properties in the servletContext using ServletContext.getResourceAsStream, and then it will search classpaths using classloader.getResourceAsStream().  My guess is that if you are placing your components.properties in your classpath and it isn't being used, then there's probably a blank components.properties higher up in the classpath.