5 Replies Latest reply on Mar 5, 2003 7:25 PM by Kenny Choi

    Naming Exception when I try to search the context

    Kenny Choi Newbie

      All,

      I am not sure how to deploy Ejb on my jBoss 3.0x and define the JNDI name for the Ejb. The follows are what I defined and the error return from the server

      The files created for the session ejb

      com/enixtech/ejb/DemoSessionHome <--- Home Interface
      com/enixtech/ejb/DemoSession <--- Remote Interface
      com/enixtech/ejb/DemoSessionBean <--- Session Bean

      In jboss-web.xml, I defined

      <ejb-ref>
      <ejb-ref-name>ejb/test/DemoSession</ejb-ref-name>
      <jndi-name>java:comp/env/ejb/DemoSession</jndi-name>
      </ejb-ref>


      In web-client, I defined

      <ejb-ref>
      <ejb-ref-name>ejb/test/DemoSession</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      DemoSessionHome
      DemoSession
      </ejb-ref>

      In index.jsp, I wrote

      <%
      try {
      Context lContext = new InitialContext();
      DemoSessionHome lHome = (DemoSessionHome) lContext.lookup(
      "java:comp/env/ejb/DemoSession"
      );
      DemoSession lSession = lHome.create();
      out.println( "" + lSession.getCompanyName());
      }
      catch( Exception e ) {
      out.println( "Caugth exception: " + e.getMessage() );
      e.printStackTrace();
      }
      %>

      Error I got

      Caugth exception: DemoSession not bound

      All the stuff are referring from jBoss Template and could all the expert tell what I did wrongly and how to rectify it?

      Many thanks,
      kenny

        • 1. Re: Naming Exception when I try to search the context
          Adrian Brock Master

          <ejb-ref>
          <ejb-ref-name>ejb/test/DemoSession</ejb-ref-name>

          defines
          java:comp/env/ejb/test/DemoSession

          <jndi-name> should be the global jndi name of the bean,
          you don't provide your deployment descriptors so I can't
          tell you what it is.

          Regards,
          Adrian

          • 2. Re: Naming Exception when I try to search the context
            Kenny Choi Newbie

            Adrian,

            Thank you for your reply. First of all, I don't know what is global JNDI, so could you tell me more about this?

            In addition, the the descriptor values changed as you suggestioned, I got the error "Caugth exception: ejb not bound"

            Any idea for me? Many Many thanks !!

            Kenny

            • 3. Re: Naming Exception when I try to search the context
              Adrian Brock Master

              You still haven't posted your deployment descriptors.

              By default jboss binds the ejb into global jndi
              at <ejb-name> unless you specify <jndi-name> in jboss.xml

              Assuming your ejb has just
              <ejb-name>DemoSession</ejb-name>

              You woud write
              <ejb-ref>
              <ejb-ref-name>ejb/test/DemoSession</ejb-ref-name>
              <jndi-name>DemoSession</jndi-name>
              </ejb-ref>

              The lookup
              java:comp/env/ejb/test/DemoSession

              For more info look at
              docs/dtd/jboss_3_0.dtd
              docs/dtd/jboss-web_3_0.dtd

              Regards,
              Adrian

              • 4. Re: Naming Exception when I try to search the context
                Jacky Newbie

                The &lt;ejb-ref&gt; element defines a reference from one bean to another. So in the xml you wrote your telling jboss the your session bean needs a reference to another session bean.
                To fix the problem, I suggest you remove the whole &lt;ejb-ref&gt; thing. Your webclient doesn't need it also. Remove all the &lt;ejb-ref&gt;s from your xmls.
                The lookup call you should use in your client should be the &lt;ejb-name&gt; of your bean. For example, if you typed your ejb-name like this:

                &lt;ejb-name&gt;DemoSession&lt;/ejb-name&gt;

                then you should have a lookup call like this:

                (DemoSessionHome)PortableRemoteObject.narrow(IContext.lookup("DemoSessionHome"), DemoSessionHome.class)

                The Home object is an RMI-IIOP objects and so the must be cast into RMI-IIOP objects using a special RMI-OOP cast. In short, usign PortableRemoteObject.narrow(...) is the proper way of casting a remote object.

                • 5. Re: Naming Exception when I try to search the context
                  Kenny Choi Newbie

                  Adrian/Jacky,

                  Thank you very much for your support. Now I could deploy ejb to my jBoss. However, I tried session bean only and believe will hit more problem on ejb deployment on the coming futher. This forum must be the way for me to find the answer.

                  Thanks,
                  Kenny
                  :)