8 Replies Latest reply on Jun 3, 2003 10:49 AM by frito

    JNDI for ejbs, remote vs. local

    gtian

      Hi There,

      I am using JBoss3.2.1 with Tomcat bundle. I did not deploy my app in ear file, but in a web war and ejb jar file. This comes my first question: do the web war and ejb jar run in one JVM? I am using remote ejb lookup from war, no complaints. However, I guess they run in one JVM.

      If I use the standard ejb-jar.xml only and use the ejb-name from that file for all of the JNDI lookup, everthing works. When I try to use jboss.xml and jboss-web.xml for JBoss JNDI names, it failed.

      Anbody went through this on JBoss 3.2.1?

      Thanks!

        • 1. Re: JNDI for ejbs, remote vs. local
          haraldgliebe

          Yes, the jar and the war are running in the same JVM.
          If you don't have a jboss.xml for your EJBs the ejb-name will be taken as default for the jndi-name, therefore you lookup succeeds.
          Could you post the relevant sections of you jboss.xml and jboss-web.xml?

          Regards,
          Harald

          • 2. Re: JNDI for ejbs, remote vs. local
            gtian

            Thank you so much Harald!

            Before I post the files, here is another question: because it runs in one JVM, I can make all of the ejbs local access to the web war sevlets and java classes. But how do I run the ejbs in another JVM, which means I intend to make them remote to the war file?


            Here is the ejb-jar.xml file:

            <ejb-jar>
            <display-name>MyEJBs</display-name>
            <enterprise-beans>

            <display-name>MySessionBean</display-name>
            <ejb-name>MySessionJNDIName</ejb-name>
            com.xxx.MySessionHome
            com.xxx.MySession
            <ejb-class>com.xxx.MysessionBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Bean</transaction-type>
            <security-identity>

            <use-caller-identity></use-caller-identity>
            </security-identity>

            <resource-ref>
            <res-ref-name>MSSQLDS</res-ref-name>
            <res-type>javax.sql.DataSource</res-type>
            <res-auth>Container</res-auth>
            <res-sharing-scope>Shareable</res-sharing-scope>
            </resource-ref>

            </enterprise-beans>
            </ejb-jar>

            If I just use this file, everything should work if you intialContext.lookup("MySessionJNDIName"). By the way, the web.xml does not have any ejb-ref defined there. If I put ejb-ref in web.xml, the deployment will throw exceptions.

            If you want to map it to another JNDI name by using jboss.xml shown below, it will through exceptions during deployment:

            jboss.xml:


            <enterprise-beans>

            <ejb-name>MySessionJNDIName</ejb-name>
            <jndi-name>ejb/MySessionJNDIName</jndi-name>


            <resource-ref>
            <res-ref-name>MSSQLDS</res-ref-name>
            <jndi-name>java:/MSSQLDS</jndi-name>
            </resource-ref>


            </enterprise-beans>



            If I have the jboss.xml, I tried to use or not use the jboss-web.xml, but either way it does not help. Here is the jboss-web.xml:

            <jboss-web>

            <ejb-ref>
            <ejb-ref-name>ejb/MySessionJNDIName</ejb-ref-name>
            <jndi-name>newJBoss/MysessionRemote</jndi-name>
            </ejb-ref>

            </jboss-web>

            and here is the section of web.xml for ejb-ref:

            <ejb-ref>
            <ejb-ref-name>newJBoss/MysessionRemote</ejb-ref-name>
            <ejb-ref-type>Session</ejb-ref-type>
            com.xxx.MySessionHome
            com.xxx.MySession
            <ejb-link>MySession</ejb-link>
            </ejb-ref>

            Please note the ejb-link has to be used in the web.xml file, otherwise, the JBoss refues to deploy (throw some exceptions).

            Please let me know if this info is enough. I bet somebody has done something like this before in JBoss 3.2.1. I have been using WebLogic and WebSphere a lot in the past using deployment tools. I feel a little frustrated about the JBoss doc support.

            - Gordon

            • 3. Re: JNDI for ejbs, remote vs. local
              haraldgliebe

              You can either use <ejb-link> in the web.xml which must the match the ejb-name of your session bean:

              <ejb-ref>
              ....
              <ejb-link>MySessionJNDIName</ejb-link>
              </ejb-ref>

              or define the jndi name which should be used for the ejb-ref in jboss-web.xml :

              <jboss-web>

              <ejb-ref>
              <ejb-ref-name>newJBoss/MysessionRemote</ejb-ref-name>
              <jndi-name>ejb/MySessionJNDIName</jndi-name>
              </ejb-ref>

              </jboss-web>

              The ejb-ref-name must match the ejb-ref-name in web.xml and the jndi-name must match the jndi-name in jboss.xml.

              The lookup inside the web-application should no be possible as

              ctx.lookup("java:comp/env/newJBoss/MysessionRemote");

              Regards,
              Harald

              • 4. Re: JNDI for ejbs, remote vs. local
                frito

                If they have to run in another vm, you will need two instances of JBoss, or Tomcat standalone)...

                If you want to isolate the war and the ejb jar, use the loader-repository tag (jboss-web.xml and jboss.xml) to have them loaded by differen classloaders. Since JBoss is optimizing every call (JBoss 3.2 does call by reference as default if both are in the same vm) and if you want to have JBoss do real remote calls with marshalling, use the ByValueInvokerInterceptor instead of the InvokerInterceptor for your bean configuration.

                Greetings,
                Frito

                • 5. Re: JNDI for ejbs, remote vs. local
                  gtian

                  Thanks a lot for the answers.

                  If I run my application in one instance of JBoss-Tomcat, all of the EJB will be local to the servlet and other plain java classes since they run in the same JVM. My understanding of JBoss3.2.1's optiomization is the EJB call will be "local" even if the JNDI lookup is on the "remote" EJB. Is this correct?

                  - Gordon

                  • 6. Re: JNDI for ejbs, remote vs. local
                    haraldgliebe

                    Yes, the standard configurations use local (by-reference) calls if the caller of an EJB is in the same VM.

                    Regards,
                    Harald

                    • 7. Re: JNDI for ejbs, remote vs. local
                      j_agra

                      Is that optimization used in jboss 3.2.x only, or does jboss 3.0.x has it also ?

                      • 8. Re: JNDI for ejbs, remote vs. local
                        frito

                        AFAIK, 3.x .

                        Greetings,
                        Frito