9 Replies Latest reply on Mar 22, 2006 4:22 PM by Borys Marcelo Borches Herrera

    Calling JBoss 3.2.3 from standalone Tomcat

    damonrand Newbie

      Hi guys,

      I have made some progress on connecting to an EJB from Tomcat 4.1.29 running on a standalone server. Unfortunately the system seems to be demanding JBoss server-side libraries for some reason.. Here is what I have done so far.

      1. I have this in web.xml

      <ejb-ref>
      Test EJB connection.....
      <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type> org.service.helloworld.server.facade.interfaces.HelloWorldRemoteHome
      org.service.helloworld.server.facade.interfaces.HelloWorldRemote
      <ejb-link>jnp://server:1099/remote/org.service.helloworld.server.facade.ejb.HelloWorld</ejb-link>
      </ejb-ref>

      2. And in /WEB-INF/classes/jndi.properties

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

      3. And copy all the jars from JBoss 3.2.3 client folder into %JRE_HOME%/lib/ext

      4. Copied my helloworld-service.jar (containing the EJB interfaces) into web-inf/lib

      Now I am now running into this error..
      class java.lang.NoClassDefFoundError: javax.ejb.EJBObject

      And if I solve that one but making j2ee.jar available to Tomcat I get too..
      class java.lang.NoClassDefFoundError: org/jboss/tm/TransactionPropagationContextFactory

      So looks like I am going to run into a sequence of NoClassDefFoundError that lead me to put the whole of JBoss into my Tomcat webapp -- not a preferable option. ;-)

      Am I doing anything obviously wrong or will this config just not work?

      Regards,
      Damon.

        • 1. Re: Calling JBoss 3.2.3 from standalone Tomcat
          Juha Lindfors Master

          Are you sure your web-app is seeing the JBoss client/ libs? If it's not finding the J2EE interfaces then it is probably not finding much anything else either.

          • 2. Re: Calling JBoss 3.2.3 from standalone Tomcat
            Raja Master

            Can you try removing the ejb-link? Anyway you are not in-VM to use the ejb-link feature!

            • 3. Re: Calling JBoss 3.2.3 from standalone Tomcat
              Ricardo Arguello Newbie

              You don't have to copy ALL the jars!

              You just need jboss-3.2.3/client/jbossall-client.jar, but copy it in WEB-INF/lib, not in %JRE_HOME%/lib/ext

              Ricardo Arguello

              • 4. Re: Calling JBoss 3.2.3 from standalone Tomcat
                damonrand Newbie

                Thanks for the replies everyone,

                I returned my JDK/Tomcat to a default environment and copied jbossall-client.jar into the WEB-INF lib along with my helloworld-service.jar. I removed the <ejb-link/> tag so I have..

                <ejb-ref>
                Test EJB connection
                <ejb-ref-name>ejb/HelloWorld</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                org.service.helloworld.server.facade.interfaces.HelloWorldRemoteHome
                org.service.helloworld.server.facade.interfaces.HelloWorldRemote
                </ejb-ref>

                And modified jndi.properties to be

                java.naming.factory.url.pkgs=org.apache.naming:org.jnp.interfaces
                java.naming.provider.url=jnp://server:1099


                Now I am getting a different error:

                class javax.naming.NameNotFoundException: org.service.helloworld.server.facade.ejb.HelloWorld not bound

                I have connected to the EJB server with jndiexplorer and confirmed the JNDI path. An ethereal packet traces show that no connection is made to the EJB server though.

                Am I missing anything else?

                Regards,
                Damon.

                • 5. Re: Calling JBoss 3.2.3 from standalone Tomcat
                  damonrand Newbie

                  Oops, was using the apache naming factory, not the jboss one.. Now I have this in jndi.properties.

                  java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
                  java.naming.provider.url=jnp://server:1099

                  And am getting this error message..

                  class javax.naming.NamingException: Cannot create resource instance

                  Regards,
                  Damon.

                  • 6. Re: Calling JBoss 3.2.3 from standalone Tomcat
                    gorano Newbie

                    If you used the default settings when you installed Tomcat it added a space in the path to Tomcat.

                    Get rid of this space if you have it, otherwise it won't work.

                    /Goran

                    • 7. Re: Calling JBoss 3.2.3 from standalone Tomcat
                      Ricardo Arguello Newbie

                      You are probably using Tomcat's embedded JNDI server without knowing it!

                      Read this:
                      http://www.amitysolutions.com.au/documents/JBossTomcatJNDI-technote.pdf

                      You might start Tomcat with the "-nonaming" option to disable their JNDI server.

                      Or you could programatically create an InitialContext with properties pointing to your EJB server... this is hardcoded and sucks.

                      Ricardo Arguello

                      • 8. Re: Calling JBoss 3.2.3 from standalone Tomcat
                        damonrand Newbie

                        Thanks,
                        I don't want to mess around with -nonaming, sounds too brutal a solution to me..

                        The amity article looks to be exactly what I need. I'll give that a try tomorrow.. I found org.apache.naming.factory.EjbFactory in the Tomcat source but looking at the code it seems to use a hardcoded reference to a specific (non-jboss) factory class.. Pity there is no org.apache.naming.factory.GenericEjbFactory with Tomcat yet.

                        Once again, thanks for your help.

                        Regards,
                        Damon.

                        • 9. TOMCAT + JBOSS - CALLING EJB IN A JBOSS FROM A EXTERNAL TOMC
                          Borys Marcelo Borches Herrera Newbie

                          Hello guy´s.

                          For a cups of days I´ve been trying to lookup an ejb in a Jboss Server from a Tomcat 5.x. I tried a lot of solutions, that with the inside a contex too, and I realized that nothing work at all.

                          So, I did the obvious...

                          I unistalled the tomcat from my computer. Instaled Again in a directory called D:\Tomcat

                          Put my application inside the webapps.

                          And called EJB in the normal classic way!... And works for me. The trick is that in a Windows OS, the tomcat instalation home had a blank spaces in the name of the path. i.e - c:\Program Files\Apache Software Foundation\Tomcat 5.5\....

                          so, this blank spaces do not let the initial context to initialized de properties wrigth.


                          BoryS


                          My CODE:



                          package br.gov.tresp.servlets;
                          
                          import java.io.IOException;
                          import java.io.PrintWriter;
                          import java.util.Properties;
                          
                          import javax.naming.InitialContext;
                          import javax.rmi.PortableRemoteObject;
                          import javax.servlet.ServletException;
                          import javax.servlet.http.HttpServlet;
                          import javax.servlet.http.HttpServletRequest;
                          import javax.servlet.http.HttpServletResponse;
                          
                          import com.fiap.hello.ejb.Hello;
                          import com.fiap.hello.ejb.HelloHome;
                          import com.fiap.hello.ejb.Pessoa;
                          
                          public class Cliente extends HttpServlet {
                          
                           /**
                           *
                           */
                           private static final long serialVersionUID = -2896402595743969746L;
                          
                           protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
                           // TODO Auto-generated method stub
                           this.doPost(arg0, arg1);
                           }
                          
                           protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                           // TODO Auto-generated method stub
                          
                           Properties props = new Properties();
                          
                           props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
                           props.setProperty("java.naming.provider.url", "localhost:1099");
                           props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
                          
                           try {
                           InitialContext context = new InitialContext(props);
                           Object objref = context.lookup("ejb/HelloHome");
                           //Object objref = new InitialContext().lookup("java:comp/env/bean/Locator");
                          
                           HelloHome home = (HelloHome)PortableRemoteObject.narrow(objref, HelloHome.class);
                           System.out.println(home);
                           Hello hello = home.create();
                           Pessoa p = new Pessoa();
                           p.setNome("Borys Marcelo");
                           p.setIdade(24);
                           hello.meMostra(p);
                           } catch (Exception e){
                           e.printStackTrace();
                           PrintWriter out = response.getWriter();
                           StackTraceElement[] elements = e.getStackTrace();
                           e.printStackTrace(out);
                           out.print(e.getMessage());
                          
                           }
                          
                           }
                          
                          
                          
                          
                          
                          
                          
                          }
                          



                          Don´t need nothing more in the WEB.xml neither in a Context.xml