3 Replies Latest reply on Apr 7, 2004 7:53 PM by James Clover

    How to get the Catalina Container from an EJB

    James Clover Newbie

      I'm trying to "wrap" a web application in a web service call. I've already done this using a proxy that communicates over HTTP, but I now want to make that call in-JVM rather than across HTTP.

      It appears that I can do this if I can get ahold of the org.apache.catalina.Container object for my webapp. From the Tomcat 4 source, it seems like this would be the path to get the Container:

      * Use org.apache.catalina.ServerFactory.getServer() to get the main Catalina org.apache.catalina.Server
      * Use server.findService("probably your context name, such as 'h2g'") to get the org.apache.catalina.Service for your webapp.
      * Use service.getContainer() to get the org.apache.catalina.Container for your webapp
      * Use container.invoke(Request, Response) to run the servlet.

      However, calling ServerFactory.getServer() just returns null. Is there some other way, perhaps via the appropriate MBean, to get what I need?

        • 1. Re: How to get the Catalina Container from an EJB
          Scott Stark Master

          I've thought about a JMX invoker into the web container but have not had a chance to look into it. I would be starting with the Tomcat 5 source however since its the more MBean friendly architecture.

          • 2. Re: How to get the Catalina Container from an EJB
            James Clover Newbie

            I think I found in under TC5 - I'll post the details here when I have it verified.

            • 3. Re: How to get the Catalina Container from an EJB
              James Clover Newbie

              Ok, I've found how to get the Container object for a web application using 3.2.4 or 4.0 and TC5. Here's a snippet:

              InitialContext ic = new InitialContext();
              RMIAdaptor rmiServer = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor");
              ObjectName name = new
               ObjectName("jboss.web:j2eeType=WebModule,name=//localhost/<web app name here>,
              org.apache.catalina.Manager manager = (org.apache.catalina.Manager)
               rmiServer.getAttribute(name, "manager");
              org.apache.catalina.core.StandardContext container =
               (org.apache.catalina.core.StandardContext) manager.getContainer();

              That will give you the Container object that has the prized invoke(request, response) method in it. However, I'm having a very hard time building my request; there doesn't seem to be a easy way to build it so that TC5 will recognize it and call the JSP/Servlet. In TC4, there was a base class for the Request objects, TC5 is full of wrappers on wrappers.

              So, this is a question for any TC5 gurus out there: how can I correctly build my request object (and response for that matter) so that I can call Container.invoke(req, resp)?