I'd like to embed Tomcat within my Java application, but where some Servlet 
requests would *directly* call into my running application's code (+data).   
The current "EmbededTomcat" support seems to be aimed at launching a 
stand-alone Tomcat that only supports file contexts, with no callback support 
for access to the launching application.

I'm thinking of Tomcat 3.3, 'though 4.0 could be used if required.

For example, suppose I have a calendar application that I'd like to add web 
support.  Inside my application I have all the data I need, and I'd like my 
servlets to directly access my the data structures.  Flattening the data out 
to an external database/filesystem is not an option.  All Servlet requests 
would funnel into my application so I can call my own (inner) Servlet.   I 
still want Tomcat to do the HTTP parsing, SSL, sessions, Servlet-API, etc.   
My application must load the internal Servlet instance.

Can I use an interceptor, or (if needed) pull apart "EmbededTomcat"?  Is 
there an example of how to do this?  I hope it's clear why this would be a 
very useful embedding scenario...

Pseudocode:

    public class MyApp implements Runnable {

       /** launcher */
       public static void main(String[] args) {
           // launch!
          (new MyApp()).run();
       }

       public void run() {
          // create my internal Servlet before Tomcat is launched
          //
          // this inner class is defined later in this method
          Servlet myServlet = new MyServlet();

          // launch Tomcat
          EmbeddedTomcat et = new EmbeddedTomcat();
          et.setArgs(new String[] {"start"});
          et.execute();

          //
          // hand-waving here!   Could be moved to before the "et.execute()".
          //
          insert myServlet into Tomcat to handle all "/*" requests

          // 
          //  I now want "myServlet" to be called with all "/*" requests
          // 

          // run forever in this example...
       }

       /**
        * sample internal data method.
        *
        * MyServlet will call this method
        */
       public String getInternalString() {
          return "foo";
       }

       /** 
        * My inner servlet -- has access back into "MyApp"  
        *  instance (non-static).
        */
       private class MyServlet extends HttpServlet {
          public void doGet(
              HttpServletRequest request, 
              HttpServletResponse response)
                   throws IOException, ServletException  {
           response.setContentType("text/html");
           PrintWriter out = response.getWriter();
           out.println("<html><body>Internal String is ");

           // access internal MyApp method/data!
           out.println(getInternalString());

           out.println("</body></html>");
       }
    }

Thanks!
   Todd

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to