User: simone  
  Date: 00/12/12 07:38:45

  Modified:    tomcat/src/main/org/jboss/tomcat EmbeddedTomcatService.java
  Log:
  Updated to use the new Log class
  
  Revision  Changes    Path
  1.8       +110 -110  
contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcatService.java
  
  Index: EmbeddedTomcatService.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/contrib/tomcat/src/main/org/jboss/tomcat/EmbeddedTomcatService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- EmbeddedTomcatService.java        2000/12/07 15:39:13     1.7
  +++ EmbeddedTomcatService.java        2000/12/12 15:38:45     1.8
  @@ -4,8 +4,8 @@
    * Distributable under GPL license.
    * See terms of license at gnu.org.
    */
  - 
   
  +
   package org.jboss.tomcat;
   
   //import java.io.IOException;
  @@ -54,232 +54,232 @@
   
   /**
    *   A service to launch tomcat from JMX.
  - *      
  - *   This uses the class org.apache.tomcat.startup.EmbededTomcat, which means 
  + *
  + *   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, Tomcat's server.xml file will NOT be processed, so 
  + *
  + *   If you use this service, Tomcat's server.xml file will NOT be processed, so
    *   you have to add all contexts through JMX.
  - *   
  + *
    *   @see <related>
    *   @author <a href="mailto:[EMAIL PROTECTED]">Sebastien Alborini</a>
    *   @author <a href="mailto:[EMAIL PROTECTED]">Kevin Lewis</a>
  - *   @version $Revision: 1.7 $
  + *   @version $Revision: 1.8 $
    */
   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 = new Log(NAME);
  -     
  +     final Log log = Log.createLog(NAME);
  +
        // Static --------------------------------------------------------
  -     
  +
        // Constructors --------------------------------------------------
  -   
  -     public EmbeddedTomcatService() 
  +
  +     public EmbeddedTomcatService()
        {
                this(null, 8080);
        }
  -     
  -     public EmbeddedTomcatService(String configFile, int port) 
  +
  +     public EmbeddedTomcatService(String configFile, int port)
      {
           this.configFile = configFile;
                this.port = port;
        }
  -             
  +
        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 new ObjectName(OBJECT_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 {      
  +                     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();
               System.out.println("Config file set to:"+configFile);
            }
  -                     
  +
                        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);
  -                     
  -                     // set the interceptors. 
  +
  +                     // set the interceptors.
                        addInterceptors(embededTomcat);
  -                     
  +
                        // add root context
                        deploy("/", "file:" + tomcatHome + "/webapps/ROOT");
  -         
  +
            // add contexts from file
   
            // Create an instance of the DocumentBuilderFactory
            
System.out.println(Class.forName("javax.xml.parsers.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));         
  +         // ROB: it�s not bulletproof maybe should validate against a dtd file
  +           Document doc = docBuilder.parse(new File(configFile));
   
  -         // get list with contexts          
  +         // get list with contexts
            NodeList contexts = doc.getElementsByTagName("Context");
  -         
  -         
  +
  +
            // 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");            
  +            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()) {
  -               deploy(path, "file:" + tomcatHome + "/" + docBase);        
  -               //System.out.println("file:" + tomcatHome + "/" + docBase);          
                                                      
  +               deploy(path, "file:" + tomcatHome + "/" + docBase);
  +               //System.out.println("file:" + tomcatHome + "/" + docBase);
               }
  -            
  +
               // otherwise if it�s c:/something do nothing
               else {
                  deploy(path, "file:" + docBase);
  -               //System.out.println("file:" + docBase);                           
  +               //System.out.println("file:" + docBase);
               }
            }
  -                 
  -      
  +
  +
                        // 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();
        }
  -     
  -     
  +
  +
        // 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. 
  +     // show inputs for URLs in HTML forms.
        public void deploy(String ctxPath, String warUrl) throws DeploymentException {
                Log.setLog(log);
  -             
  +
                try {
                        // add the context
                        ServletContext servletCtx = embededTomcat.addContext(ctxPath, 
new URL(warUrl));
  -                     
  +
                        // init the context
                        embededTomcat.initContext(servletCtx);
  -                     
  +
                        // keep track of deployed contexts for undeployment
                        deployedURLs.put(warUrl, servletCtx);
  -             
  +
                } catch (Error e)
         {
           e.printStackTrace();
  -        throw e; 
  +        throw e;
         } catch (Exception e) {
                        e.printStackTrace();
                        throw new DeploymentException(e.getMessage());
  @@ -287,67 +287,67 @@
                        Log.unsetLog();
                }
        }
  -     
  -     
  +
  +
        public void undeploy(String warUrl) throws DeploymentException {
                Log.setLog(log);
  -             
  +
                try {
                        // find the javax.servlet.ServletContext in the repository
                        ServletContext servletCtx = 
(ServletContext)deployedURLs.get(warUrl);
  -                     
  -                     if (servletCtx == null) 
  +
  +                     if (servletCtx == null)
                                throw new DeploymentException("URL " + warUrl + " is 
not deployed");
  -                     
  +
                        // remove the context
                        embededTomcat.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 specif 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 );
  -             
  +
           tomcat.addContextInterceptor( new 
org.jboss.tomcat.naming.JbossWebXmlReader() );
  -             
  +
                ContextClassLoaderInterceptor ccli = new 
ContextClassLoaderInterceptor();
                tomcat.addContextInterceptor(ccli);
  -             
  +
                DefaultCMSetter defaultCMI=new DefaultCMSetter();
                tomcat.addContextInterceptor( defaultCMI );
  -             
  +
                WorkDirInterceptor wdI=new WorkDirInterceptor();
                tomcat.addContextInterceptor( wdI );
  -             
  +
                LoadOnStartupInterceptor loadOnSI=new LoadOnStartupInterceptor();
                tomcat.addContextInterceptor( loadOnSI );
       }
  -    
  +
       protected void addSecurityRequestInterceptors(EmbededTomcat tomcat) {
       }
   
  @@ -355,7 +355,7 @@
                // Debug
                //      LogEvents logEventsI=new LogEvents();
                //      addRequestInterceptor( logEventsI );
  -             
  +
                // this one is custom
                // set context class loader
           // New interceptor.
  @@ -363,34 +363,34 @@
   
                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);
  -        
  +
                Jdk12Interceptor jdk12I=new Jdk12Interceptor();
  -             tomcat.addRequestInterceptor( jdk12I );        
  +             tomcat.addRequestInterceptor( jdk12I );
   
           addSecurityRequestInterceptors(tomcat);
       }
   
        // Private -------------------------------------------------------
  -    
  +
        private void addInterceptors(EmbededTomcat tomcat) {
   
           try {
  
  
  

Reply via email to