5 Replies Latest reply on Jun 6, 2007 4:34 AM by mcgerman1

    Problem looking up EJB session bean (Name not bound)

      Hello all,

      Can someone help me with a simple context lookup?

      I have a session bean deployed within JBoss 4.0.4 GA AS, JDK 5. My EJB code is as followed:

      @Stateless
      @Local(AuthenticatorLocal.class)
      @Remote(AuthenticatorRemote.class)
      public class AuthenticatorBean implements Authenticator {


      The server started and deployed this session bean without any problem. Here is a snippet of the log:
      10:28:10,609 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=test.ear,jar=test.jar,name=AuthenticatorBean,service=EJB3 with dependencies:
      10:28:10,609 INFO [JmxKernelAbstraction] persistence.units:ear=test.ear,jar=test.jar,unitName=test
      10:28:10,625 INFO [EJBContainer] STARTED EJB: com.judots.test.AuthenticatorBean ejbName: AuthenticatorBean


      From an external client, my client is calling:
      Properties p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      p.put(Context.PROVIDER_URL, "jnp://localhost:1099");
      _intialCtx = new InitialContext(p);
      
      Object authenRef = _intialCtx.lookup("AuthenticatorBean");



      This code failed with the following exception:
      javax.naming.NameNotFoundException: AuthenticatorBean not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)


      I tried using various name like "Authenticator", "Authenticator/remote", "AuthenticatorBean/remote" as well as using the physical address for the InitialContext but ended up with the same "'name' not found error. Can some one please help?

      Thanks
      -tony

        • 1. Re: Problem looking up EJB session bean (Name not bound)
          roist

          not sure about ejb3, but shouldn't this be more like

          "java:comp/env/Authenticator" ?

          in ejb2 this would be the proper prefix...

          • 2. Re: Problem looking up EJB session bean (Name not bound)

            I think the problem I am having is relating to the way I packaged my ear file.

            When I unpacked the ear and deployed only the jar file, I had no problem looking up the remote interfaces.

            I would greatly appreciate if someone can help clarifying what I need in my ear file. O'Reilly's Enterprise JavaBeans 3.0 does not seem to address this at all.

            Here is the structure of my ear file:

            test.ear
             test-ds.xml
             test.jar
             META-INF
             application.xml
             MANIFEST.MF


            My application.xml contains the following:
            <?xml version="1.0" encoding="UTF-8"?>
            <application>
             <display-name>test</display-name>
             <description>Test Project</description>
             <!-- The EJB-JAR -->
             <!-- TODO: JBoss needs 'ejb' element but the spec requires 'persistence' -->
             <module>
             <!--
             <ejb>test.jar</ejb>
             -->
             <persistence>test.jar</persistence>
             </module>
            </application>


            And my test-ds.xml is as followed:
            <?xml version="1.0" encoding="UTF-8"?>
            <datasources>
             <local-tx-datasource>
             <jndi-name>testDS</jndi-name>
             <connection-url>jdbc:sqlserver://localhost:1814;databaseName=test;selectMethod=cursor;</connection-url>
             <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
             <user-name>***</user-name>
             <password>***</password>
             <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
             <min-pool-size>25</min-pool-size>
             <max-pool-size>100</max-pool-size>
             <blocking-timeout-millis>5000</blocking-timeout-millis>
             <idle-timeout-minutes>15</idle-timeout-minutes>
             <prepared-statement-cache-size>75</prepared-statement-cache-size>
             </local-tx-datasource>
            </datasources>


            I think my test-ds.xml is OK because it worked with plain jar deployment. What else missing in my application.xml file?

            Thanks for your help.
            -tony

            • 3. Re: Problem looking up EJB session bean (Name not bound)

              Have you give JNDI name to your EJB ?
              During the déployment, you should see something like this :

              [EjbModule] Deploying XXX
              [ProxyFactory] Bound EJB Home 'XXX' to jndi 'X_X'
              [EJBDeployer] Deployed: file:/C:/jboss-portal-2.4.1/server/default/deploy/XXX.jar


              NO ?

              • 4. Re: Problem looking up EJB session bean (Name not bound)

                No.

                I thought with EJB3, the JNDI name should be defaulted the unqualified classname.

                Do I need an explicit JNDI name if I were to deploy with EAR file? Deployment with JAR did not seem to require the JNDI names at all.

                • 5. Re: Problem looking up EJB session bean (Name not bound)
                  mcgerman1

                  Hi the correct Lookup when deploying in an ear file must be:

                  Object authenRef = _intialCtx.lookup("<ear-file-without-extension>/AuthenticatorBean/remote");

                  in your case:
                  Object authenRef = _intialCtx.lookup("test/AuthenticatorBean/remote");

                  I had the same problem like you before ;-))


                  Greedings McGerman