dewayne, are you going to document the server.xml setup required to get all
the right ContextInterceptors running?  I fudged it from the old code, but
it would be nice to see it online somewhere.

This is what I have, I cant remember how much of it is changed from the
original server.xml

      <!-- ==================== Interceptors ==================== -->

        <!-- 
         ContextInterceptor className="org.apache.tomcat.context.LogEvents" 
         -->
        
        <ContextInterceptor className="org.apache.tomcat.context.AutoSetup"
/>

        <ContextInterceptor 
            className="org.apache.tomcat.context.WebXmlReader" />

        <!-- Uncomment out if you have JDK1.2 and want to use policy 
        -->
        <ContextInterceptor 
            className="org.apache.tomcat.context.PolicyInterceptor" />

        <ContextInterceptor 
            className="org.apache.tomcat.context.LoaderInterceptor" />
        <ContextInterceptor 
            className="org.jboss.tomcat.ContextClassLoaderInterceptor" />
        <ContextInterceptor 
            className="org.apache.tomcat.context.DefaultCMSetter" />
        <ContextInterceptor 
            className="org.apache.tomcat.context.WorkDirInterceptor" />
        <ContextInterceptor 
            className="org.jboss.tomcat.naming.JbossWebXmlReader" />

        <!-- Request processing -->
        <RequestInterceptor 
            className="org.apache.tomcat.request.Jdk12Interceptor" />
        <!-- Session interceptor will extract the session id from cookies
and 
             deal with URL rewriting ( by fixing the URL ).  If you wish to
             suppress the use of cookies for session identifiers, change the
             "noCookies" attribute to "true"
          -->
        <RequestInterceptor 
            className="org.apache.tomcat.request.SessionInterceptor"
            noCookies="false" />

        <!-- Find the container ( context and prefix/extension map ) 
             for a request.
          -->
        <RequestInterceptor 
            className="org.apache.tomcat.request.SimpleMapper1" 
            debug="0" />

        <!-- Non-standard invoker, for backward compat. ( /servlet/* )
             You can modify the prefix that is matched by adjusting the
             "prefix" parameter below.  Be sure your modified pattern
             starts and ends with a slash.

             NOTE:  This prefix applies to *all* web applications that
             are running in this instance of Tomcat.
          -->
        <RequestInterceptor 
            className="org.apache.tomcat.request.InvokerInterceptor" 
            debug="0" prefix="/servlet/" />

        <!-- "default" handler - static files and dirs.  Set the
             "suppress" property to "true" to suppress directory listings
             when no welcome file is present.

             NOTE:  This setting applies to *all* web applications that
             are running in this instance of Tomcat.
          -->
        <RequestInterceptor 
            className="org.apache.tomcat.request.StaticInterceptor" 
            debug="0" suppress="false" />

        <!-- Plug a session manager. You can plug in more advanced session
             modules.
          -->
        <RequestInterceptor 
            className="org.apache.tomcat.session.StandardSessionInterceptor"
/>

        <!-- Check if the request requires an authenticated role.
          -->
        <RequestInterceptor 
            className="org.apache.tomcat.request.AccessInterceptor" 
            debug="0" />

        <!-- Check permissions using the simple xml file. You can 
             plug more advanced authentication modules.
          -->
        <RequestInterceptor 
            className="org.apache.tomcat.request.SimpleRealm" 
            debug="0" />

       <!-- UnComment the following and comment out the
            above to get a JDBC realm.
            Other options for driverName: 
              driverName="oracle.jdbc.driver.OracleDriver"
              connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
              connectionName="scott"
              connectionPassword="tiger"

              driverName="org.gjt.mm.mysql.Driver"
              connectionURL="jdbc:mysql://localhost/authority"
              connectionName="test"
              connectionPassword="test"

            "connectionName" and "connectionPassword" are optional.
        -->
        <!--
        <RequestInterceptor 
            className="org.apache.tomcat.request.JDBCRealm" 
            debug="99" 
            driverName="sun.jdbc.odbc.JdbcOdbcDriver" 
            connectionURL="jdbc:odbc:TOMCAT" 
            userTable="users" 
            userNameCol="user_name" 
            userCredCol="user_pass" 
            userRoleTable="user_roles" 
            roleNameCol="role_name" />
        -->

        <!-- Loaded last since JSP's that load-on-startup use request
handling -->
        <ContextInterceptor 
            className="org.apache.tomcat.context.LoadOnStartupInterceptor"
/>


-----Original Message-----
From: jBoss CVS Development [mailto:[EMAIL PROTECTED]]
Sent: Saturday, February 10, 2001 12:00 AM
To: [EMAIL PROTECTED]
Subject: [jBoss-Dev] CVS update:
contrib/tomcat/src/main/org/jboss/tomcat EmbeddedTomcatService.java
EmbeddedTomcatServiceMBean.java


  User: dewayne 
  Date: 01/02/09 22:00:18

  Modified:    tomcat/src/main/org/jboss/tomcat EmbeddedTomcatService.java
                        EmbeddedTomcatServiceMBean.java
  Log:
  Removed port and configfile accessors because they are no longer needed.
  Tomcat's server.xml is now parsed, so the information is obtained there.
  
  Revision  Changes    Path
  1.10      +65 -320
contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcatService.java
  
  Index: EmbeddedTomcatService.java
  ===================================================================
  RCS file:
/products/cvs/ejboss/contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcat
Service.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- EmbeddedTomcatService.java        2000/12/21 16:29:48     1.9
  +++ EmbeddedTomcatService.java        2001/02/10 06:00:17     1.10
  @@ -4,11 +4,14 @@
    * Distributable under LGPL license.
    * See terms of license at gnu.org.
    */
  +
   package org.jboss.tomcat;
   
  -//import java.io.IOException;
  +import java.io.DataInputStream;
  +import java.io.IOException;
   import java.io.File;
   import java.net.URL;
  +import java.net.URL;
   import java.net.MalformedURLException;
   import java.net.InetAddress;
   import java.lang.reflect.Method;
  @@ -20,264 +23,91 @@
   import javax.management.*;
   import javax.servlet.ServletContext;
   
  -import org.jboss.logging.Log;
   import org.jboss.logging.Logger;
  +import org.jboss.logging.Log;
   import org.jboss.util.ServiceMBeanSupport;
   import org.jboss.ejb.DeploymentException;
   
  -import org.apache.tomcat.startup.EmbededTomcat;
  -import org.apache.tomcat.context.WebXmlReader;
  -import org.apache.tomcat.context.PolicyInterceptor;
  -import org.apache.tomcat.context.LoaderInterceptor;
  -import org.apache.tomcat.context.DefaultCMSetter;
  -import org.apache.tomcat.context.WorkDirInterceptor;
  -import org.apache.tomcat.context.LoadOnStartupInterceptor;
  -import org.apache.tomcat.request.SessionInterceptor;
  -import org.apache.tomcat.request.SimpleMapper1;
  -import org.apache.tomcat.request.InvokerInterceptor;
  -import org.apache.tomcat.request.StaticInterceptor;
  -import org.apache.tomcat.request.AccessInterceptor;
  -import org.apache.tomcat.request.Jdk12Interceptor;
  -import org.apache.tomcat.session.StandardSessionInterceptor;
  -
  -import org.w3c.dom.Document;
  -import org.w3c.dom.Element;
  -import org.w3c.dom.NodeList;
  -
  -import javax.xml.parsers.DocumentBuilderFactory;
  -import javax.xml.parsers.DocumentBuilder;
  -
   /**
  - *   A service to launch tomcat from JMX.
  - *
  - *   This uses the class org.apache.tomcat.startup.EmbededTomcat, which
means
  - *   that we can add and remove tomcat "contexts" on the fly.
  - *
  - *   If you use this service, the contexts defined in Tomcat's server.xml
file 
  - *   will be used, but all other info in that file will be ignored.
  + *   <description>
    *
  - *   @author <a href="mailto:[EMAIL PROTECTED]">Rickard Öberg</a>
  - *   @author <a href="mailto:[EMAIL PROTECTED]">Sebastien
Alborini</a>
  - *   @author <a href="mailto:[EMAIL PROTECTED]">Kevin Lewis</a>
  - *   @version $Revision: 1.9 $
  + *   @see <related>
  + *   @author Rickard Öberg ([EMAIL PROTECTED])
  + *   @author Dewayne McNair ([EMAIL PROTECTED])
  + *   @version $Revision: 1.10 $
    */
  -public class EmbeddedTomcatService extends ServiceMBeanSupport
  -     implements EmbeddedTomcatServiceMBean, MBeanRegistration 
  -{
  -
  -   // Constants -----------------------------------------------------
  -   public static final String NAME = "EmbeddedTomcat";
  -
  -   // Attributes ----------------------------------------------------
  -
  -   // the tomcat launcher
  -   private EmbededTomcat embededTomcat;
  -
  -   // the path to tomcat. We need it to set the root context
  -   String tomcatHome;
  -
  -   // the port tomcat must listen to
  -   int port;
  -
  -   // the config file to be used
  -   String configFile;
  -
  -   // repository for deployed URLs and the associated servletContexts
  -   Hashtable deployedURLs = new Hashtable();
  -
  -   final Log log = Log.createLog(NAME);
  -
  -   // Constructors --------------------------------------------------
  -   public EmbeddedTomcatService()
  -   {
  -      this(null, 8080);
  -   }
  -
  -   public EmbeddedTomcatService(String configFile, int port)
  -   {
  -      this.configFile = configFile;
  -      this.port = port;
  -   }
  -
  -   // Public --------------------------------------------------------
  -   public void setPort(int port)
  -   {
  -      this.port = port;
  -   }
  -
  -   public int getPort()
  -   {
  -      return port;
  -   }
  -
  -   public void setConfigFile(String configFile)
  -   {
  -      this.configFile = configFile;
  -   }
  -
  -   public String getConfigFile()
  -   {
  -      return configFile;
  -   }
  -
  -   // Public --------------------------------------------------------
  -   public ObjectName getObjectName(MBeanServer server, ObjectName name)
  -   throws javax.management.MalformedObjectNameException
  -   {
  -
  -      return name == null ? new ObjectName(OBJECT_NAME) : name;
  -   }
  -
  -   public String getName()
  -   {
  -      return NAME;
  -   }
  -
  -
  -   public void startService() throws Exception
  -   {
  -      Log.setLog(log);
  -
  -      Logger.log("Testing if Tomcat is present....");
  -
  -      // tomcat (jdk12Interceptor) seems sets the contextclassloader but
doesn't restore the original one
  -      ClassLoader oldCcl =
Thread.currentThread().getContextClassLoader();
  -
  -      try
  -      {
  -         // We need the tomcat home to set tomcat's working dir / ROOT
context
  -         Class tomcatClass;
  -         try {
  -            tomcatClass =
Class.forName("org.apache.tomcat.startup.EmbededTomcat");
  -
  -         } catch(Exception e)
  -         {
  -
  -            Logger.log("failed");
  -            Logger.log("Tomcat not found.  You need tomcat 3.2b4+");
  -            throw new Exception("start failed");
  -         }
  -
  -         URL tomcatUrl =
tomcatClass.getProtectionDomain().getCodeSource().getLocation();
  -         tomcatHome = new File(new
File(tomcatUrl.getFile()).getParent()).getParent();
  -
  -         // Locate server.xml
  -         if(configFile == null)
  -         {
  -            configFile = new File(tomcatHome,
"conf/server.xml").toString();
  -         }
  -
  -         try
  -         {
  -
  -            // Using EmbededTomcat instead of
org.apache.tomcat.startup.Tomcat
  -            // allows us to add/remove contexts on the fly
  -            embededTomcat = new EmbededTomcat();
  -            Logger.log("OK");
  -
  -         } catch(NoClassDefFoundError e)
  -         {
  -            Logger.log("failed");
  -            Logger.log("org.apache.tomcat.startup.EmbededTomcat wasn't
found. Be sure to have your CLASSPATH correctly set");
  -            Logger.log("You need tomcat 3.2b4+ to use this service");
  -
  -            throw e;
  -         }
  -
  -         // Initialize the EmbededTomcat object.
  -         // See javadoc in org.apache.tomcat.startup.EmbededTomcat
   
  -         // set debug  (Warning: setting debug to anything higher gave me
lot of exceptions)
  -         embededTomcat.setDebug(0);
  -
  -         embededTomcat.setWorkDir(tomcatHome+"/work");
  -
  -         // set the interceptors.
  -         addInterceptors(embededTomcat);
  -
  -         // add root context
  -         deploy("/", "file:" + tomcatHome + "/webapps/ROOT");
  -
  -         // add contexts from file
  -
  -         // Create an instance of the DocumentBuilderFactory
  -         com.sun.xml.parser.DocumentBuilderFactoryImpl docBuilderFactory
= new com.sun.xml.parser.DocumentBuilderFactoryImpl();
  -
  -         //Get the DocumentBuilder from the factory that we just got
above.
  -         com.sun.xml.parser.DocumentBuilderImpl docBuilder =
(com.sun.xml.parser.DocumentBuilderImpl)docBuilderFactory.newDocumentBuilder
();
  -
  -         // parse the config file
  -         // ROB: it´s not bulletproof maybe should validate against a dtd
file
  -         Document doc = docBuilder.parse(new File(configFile));
  +public class EmbeddedTomcatService
  +extends ServiceMBeanSupport
  +implements EmbeddedTomcatServiceMBean, MBeanRegistration
  +{
  +    // Constants -----------------------------------------------------
  +    public static final String NAME = "EmbeddedTomcat";
   
  -         // get list with contexts
  -         NodeList contexts = doc.getElementsByTagName("Context");
  +    Thread runner;
  +    TomcatEntry tomcat = null;
   
  +    // repository for deployed URLs and the associated servletContexts
  +    Hashtable deployedURLs = new Hashtable();
   
  -         // add them
  -         for(int i=0; i<contexts.getLength(); i++)
  -         {
  -            Element context = (Element)contexts.item(i);
  -            String path = context.getAttribute("path");
  -            String docBase = context.getAttribute("docBase");
  -            File f = new File(docBase);
  -            // check if docbase is of type /something in which case add
tomcat home
  -            if(!f.exists())
  +    public ObjectName getObjectName (MBeanServer server, ObjectName name)
  +    throws javax.management.MalformedObjectNameException
  +    {
  +        return new ObjectName(OBJECT_NAME);
  +    }
  +
  +    public String getName()
  +    {
  +        return NAME;
  +    }
  +
  +    public void startService()
  +    throws Exception
  +    {
  +        final Log log = this.log;
  +
  +        log.log ("Starting " + NAME + "....");
  +        tomcat = new TomcatEntry();
  +        log.log ("OK");
  +    }
  +
  +    public void stopService()
  +    {
  +        if (tomcat != null)
  +        {
  +            try
               {
  -               deploy(path, "file:" + tomcatHome + "/" + docBase);
  -               //System.out.println("file:" + tomcatHome + "/" +
docBase);
  +                tomcat.stopTomcat();
               }
  -
  -            // otherwise if it´s c:/something do nothing
  -            else
  +            catch (Exception e)
               {
  -               deploy(path, "file:" + docBase);
  -               //System.out.println("file:" + docBase);
  +                // nothing -- we're shutting down
               }
  -         }
  -
  -
  -         // add endpoint (web service)
  -         embededTomcat.addEndpoint(port, null, null);
  -
  -         // start
  -         embededTomcat.start();
  -
  -      } finally
  -      {
  +        }
   
  -         // restore the original value of the ccl.
  -         Thread.currentThread().setContextClassLoader(oldCcl);
  -
  -         // unset log for the main thread.
  -         // tomcat's child threads have a copy of it anyway.
  -         Log.unsetLog();
  -      }
  -   }
  -
  -
  -   public void stopService()
  -   {
  -      // NYI in tomcat for now (3.2b6)
  -      embededTomcat.stop();
  -   }
  +        if (runner != null)
  +        {
  +            runner.stop();
  +            runner = null;
  +        }
  +    }
   
  -
  -   // warURL could be given as a java.net.URL, but the JMX RI's html
adaptor can't
  +   // warURL could be given as a java.net.URL,
  +   // but the JMX RI's html adaptor can't
      // show inputs for URLs in HTML forms.
  -   public void deploy(String ctxPath, String warUrl) throws
DeploymentException
  +   public void deploy(String ctxPath, String warUrl)
  +   throws DeploymentException
      {
  -      Log.setLog(log);
  +        final Log log = this.log;
   
         ClassLoader oldCcl =
Thread.currentThread().getContextClassLoader();
         try
         {
  -
            // add the context
  -         ServletContext servletCtx = embededTomcat.addContext(ctxPath,
new URL(warUrl));
  +         ServletContext servletCtx = tomcat.addContext(ctxPath, new
URL(warUrl));
   
            // init the context
  -         embededTomcat.initContext(servletCtx);
  +         tomcat.initContext(servletCtx);
   
            // keep track of deployed contexts for undeployment
            deployedURLs.put(warUrl, servletCtx);
  @@ -292,15 +122,13 @@
            throw new DeploymentException(e.getMessage());
         } finally
         {
  -         Log.unsetLog();
            Thread.currentThread().setContextClassLoader(oldCcl);
         }
      }
   
  -
      public void undeploy(String warUrl) throws DeploymentException
      {
  -      Log.setLog(log);
  +        final Log log = this.log;
   
         try
         {
  @@ -311,103 +139,20 @@
               throw new DeploymentException("URL " + warUrl + " is not
deployed");
   
            // remove the context
  -         embededTomcat.removeContext(servletCtx);
  +         tomcat.removeContext(servletCtx);
   
         } catch(Exception e)
         {
            throw new DeploymentException(e.getMessage());
         } finally
         {
  -         Log.unsetLog();
         }
  -
      }
   
  -
      public boolean isDeployed(String warUrl)
      {
         return deployedURLs.containsKey(warUrl);
      }
   
  -
  -   // Protected -----------------------------------------------------
  -
  -   protected void addContextInterceptors(EmbededTomcat tomcat)
  -   {
  -      // Since we add one non-default interceptor, we have to specify
them all
  -      // the list comes from org.apache.tomcat.startup.EmbededTomcat
  -
  -      WebXmlReader webXmlI=new WebXmlReader();
  -      webXmlI.setValidate(false);
  -      tomcat.addContextInterceptor(webXmlI);
  -
  -      PolicyInterceptor polI=new PolicyInterceptor();
  -      tomcat.addContextInterceptor(polI);
  -      polI.setDebug(0);
  -
  -      LoaderInterceptor loadI=new LoaderInterceptor();
  -      tomcat.addContextInterceptor(loadI);
  -
  -      ContextClassLoaderInterceptor ccli = new
ContextClassLoaderInterceptor();
  -      tomcat.addContextInterceptor(ccli);
  -
  -      DefaultCMSetter defaultCMI=new DefaultCMSetter();
  -      tomcat.addContextInterceptor(defaultCMI);
  -
  -      WorkDirInterceptor wdI=new WorkDirInterceptor();
  -      tomcat.addContextInterceptor(wdI);
  -
  -      tomcat.addContextInterceptor(new
org.jboss.tomcat.naming.JbossWebXmlReader());
  -
  -      LoadOnStartupInterceptor loadOnSI=new LoadOnStartupInterceptor();
  -      tomcat.addContextInterceptor(loadOnSI);
  -   }
  -
  -   protected void addSecurityRequestInterceptors(EmbededTomcat tomcat)
  -   {
  -   }
  -
  -   protected void addRequestInterceptors(EmbededTomcat tomcat)
  -   {
  -
  -      Jdk12Interceptor jdk12I=new Jdk12Interceptor();
  -      tomcat.addRequestInterceptor(jdk12I);
  -
  -      // Debug
  -      //     LogEvents logEventsI=new LogEvents();
  -      //     addRequestInterceptor( logEventsI );
  -
  -      SessionInterceptor sessI=new SessionInterceptor();
  -      tomcat.addRequestInterceptor(sessI);
  -
  -      SimpleMapper1 mapI=new SimpleMapper1();
  -      tomcat.addRequestInterceptor(mapI);
  -      mapI.setDebug(0);
  -
  -      InvokerInterceptor invI=new InvokerInterceptor();
  -      tomcat.addRequestInterceptor(invI);
  -      invI.setDebug(0);
  -
  -      StaticInterceptor staticI=new StaticInterceptor();
  -      tomcat.addRequestInterceptor(staticI);
  -      mapI.setDebug(0);
  -
  -      tomcat.addRequestInterceptor(new StandardSessionInterceptor());
  -
  -      // access control ( find if a resource have constraints )
  -      AccessInterceptor accessI=new AccessInterceptor();
  -      tomcat.addRequestInterceptor(accessI);
  -      accessI.setDebug(0);
  -
  -      addSecurityRequestInterceptors(tomcat);
  -   }
  -
  -   // Private -------------------------------------------------------
  -
  -   private void addInterceptors(EmbededTomcat tomcat)
  -   {
  -      addContextInterceptors(tomcat);
  -      addRequestInterceptors(tomcat);
  -   }
   }
   
  
  
  
  1.5       +1 -8
contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcatServiceMBean.java
  
  Index: EmbeddedTomcatServiceMBean.java
  ===================================================================
  RCS file:
/products/cvs/ejboss/contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcat
ServiceMBean.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- EmbeddedTomcatServiceMBean.java   2000/12/21 16:29:48     1.4
  +++ EmbeddedTomcatServiceMBean.java   2001/02/10 06:00:17     1.5
  @@ -14,7 +14,7 @@
    *      
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]">Sebastien
Alborini</a>
  - *   @version $Revision: 1.4 $
  + *   @version $Revision: 1.5 $
    */
   public interface EmbeddedTomcatServiceMBean 
      extends org.jboss.util.ServiceMBean 
  @@ -23,13 +23,6 @@
        // Constants -----------------------------------------------------
        public static final String OBJECT_NAME = ":service=EmbeddedTomcat";
        
  -     // Public --------------------------------------------------------
  -   public void setPort(int port);
  -   public int getPort();
  -
  -   public void setConfigFile(String configFile);
  -   public String getConfigFile();
  -   
        public void deploy(String ctxPath, String warUrl) 
         throws DeploymentException;
        
  
  
  

Reply via email to