You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@apache.org on 2002/05/04 01:19:38 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup HostConfig.java

craigmcc    02/05/03 16:19:37

  Modified:    catalina/src/share/org/apache/catalina/mbeans
                        StandardServerMBean.java
               catalina/src/share/org/apache/catalina/startup
                        HostConfig.java
  Log:
  Implement saving the server configuration back to "conf/server.xml", after
  saving the old version to "conf/server.xml.{timestamp}" as discussed on
  TOMCAT-DEV.
  
  Optimize the very common cases where the <Loader> and <Manager> elements
  contain all default values, and need not be written out (because the startup
  process will install them automatically).
  
  Ignore a spurious "application already installed" error when auto-deploying
  context configuration files (equivalent to the existing behavior when a
  WAR file or webapp directory is found in "webapps", and the corresponding
  context path is already in use.
  
  Revision  Changes    Path
  1.21      +103 -6    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java
  
  Index: StandardServerMBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- StandardServerMBean.java	3 May 2002 02:19:23 -0000	1.20
  +++ StandardServerMBean.java	3 May 2002 23:19:37 -0000	1.21
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.20 2002/05/03 02:19:23 craigmcc Exp $
  - * $Revision: 1.20 $
  - * $Date: 2002/05/03 02:19:23 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/mbeans/StandardServerMBean.java,v 1.21 2002/05/03 23:19:37 craigmcc Exp $
  + * $Revision: 1.21 $
  + * $Date: 2002/05/03 23:19:37 $
    *
    * ====================================================================
    *
  @@ -70,6 +70,7 @@
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.PrintWriter;
  +import java.sql.Timestamp;
   import java.util.Enumeration;
   import java.util.Hashtable;
   import java.util.Iterator;
  @@ -109,8 +110,10 @@
   import org.apache.catalina.deploy.ContextResourceLink;
   import org.apache.catalina.deploy.ContextEnvironment;
   import org.apache.catalina.deploy.ResourceParams;
  +import org.apache.catalina.loader.WebappLoader;
   import org.apache.catalina.net.ServerSocketFactory;
   import org.apache.catalina.session.PersistentManager;
  +import org.apache.catalina.session.StandardManager;
   import org.apache.commons.beanutils.PropertyUtils;
   import org.apache.commons.modeler.BaseModelMBean;
   
  @@ -120,7 +123,7 @@
    * <code>org.apache.catalina.core.StandardServer</code> component.</p>
    *
    * @author Amy Roh
  - * @version $Revision: 1.20 $ $Date: 2002/05/03 02:19:23 $
  + * @version $Revision: 1.21 $ $Date: 2002/05/03 23:19:37 $
    */
   
   public class StandardServerMBean extends BaseModelMBean {
  @@ -140,9 +143,14 @@
        * be persisted because they are automatically calculated.
        */
       private static String exceptions[][] = {
  +        { "org.apache.catalina.core.StandardContext", "available" },
           { "org.apache.catalina.core.StandardContext", "configured" },
  +        { "org.apache.catalina.core.StandardContext", "distributable" },
           { "org.apache.catalina.core.StandardContext", "name" },
  +        { "org.apache.catalina.core.StandardContext", "override" },
           { "org.apache.catalina.core.StandardContext", "publicId" },
  +        { "org.apache.catalina.core.StandardContext", "replaceWelcomeFiles" },
  +        { "org.apache.catalina.core.StandardContext", "sessionTimeout" },
           { "org.apache.catalina.core.StandardContext", "workDir" },
           { "org.apache.catalina.session.StandardManager", "distributable" },
           { "org.apache.catalina.session.StandardManager", "entropy" },
  @@ -241,6 +249,22 @@
               configNew = new File(System.getProperty("catalina.base"),
                                    configFile + ".new");
           }
  +        String ts = (new Timestamp(System.currentTimeMillis())).toString();
  +        //        yyyy-mm-dd hh:mm:ss
  +        //        0123456789012345678
  +        StringBuffer sb = new StringBuffer(".");
  +        sb.append(ts.substring(0, 10));
  +        sb.append('.');
  +        sb.append(ts.substring(11, 13));
  +        sb.append('-');
  +        sb.append(ts.substring(14, 16));
  +        sb.append('-');
  +        sb.append(ts.substring(17, 19));
  +        File configSave = new File(configFile + sb.toString());
  +        if (!configSave.isAbsolute()) {
  +            configSave = new File(System.getProperty("catalina.base"),
  +                                  configFile + sb.toString());
  +        }
   
           // Open an output writer for the new configuration file
           PrintWriter writer = null;
  @@ -273,7 +297,7 @@
               throw new MBeanException(e, "Writing conf/server.xml.new");
           }
   
  -        // Close the output file and rename to the original
  +        // Flush and close the output file
           try {
               writer.flush();
           } catch (Exception e) {
  @@ -284,7 +308,24 @@
           } catch (Exception e) {
               throw new MBeanException(e, "Closing conf/server.xml.new");
           }
  -        ; // FIXME - do not rename until 100% of server.xml is being written!
  +
  +        // Shuffle old->save and new->old
  +        if (configOld.renameTo(configSave)) {
  +            if (configNew.renameTo(configOld)) {
  +                return;
  +            } else {
  +                configSave.renameTo(configOld);
  +                throw new MBeanException
  +                    (new IOException("Cannot rename " +
  +                                     configNew.getAbsolutePath() + " to " +
  +                                     configOld.getAbsolutePath()));
  +            }
  +        } else {
  +            throw new MBeanException
  +                (new IOException("Cannot rename " +
  +                                 configOld.getAbsolutePath() + " to " +
  +                                 configSave.getAbsolutePath()));
  +        }
   
       }
   
  @@ -293,6 +334,55 @@
   
   
       /**
  +     * Is this an instance of the default <code>Loader</code> configuration,
  +     * with all-default properties?
  +     *
  +     * @param loader Loader to be tested
  +     */
  +    private boolean isDefaultLoader(Loader loader) {
  +
  +        if (!(loader instanceof WebappLoader)) {
  +            return (false);
  +        }
  +        WebappLoader wloader = (WebappLoader) loader;
  +        if ((wloader.getCheckInterval() != 15) ||
  +            (wloader.getDebug() != 0) ||
  +            (wloader.getDelegate() != false) ||
  +            !wloader.getLoaderClass().equals
  +             ("org.apache.catalina.loader.WebappClassLoader")) {
  +            return (false);
  +        }
  +        return (true);
  +
  +    }
  +
  +
  +    /**
  +     * Is this an instance of the default <code>Manager</code> configuration,
  +     * with all-default properties?
  +     *
  +     * @param manager Manager to be tested
  +     */
  +    private boolean isDefaultManager(Manager manager) {
  +
  +        if (!(manager instanceof StandardManager)) {
  +            return (false);
  +        }
  +        StandardManager smanager = (StandardManager) manager;
  +        if ((smanager.getDebug() != 0) ||
  +            !smanager.getPathname().equals("SESSIONS.ser") ||
  +            (smanager.getCheckInterval() != 60) ||
  +            !smanager.getRandomClass().equals("java.security.SecureRandom") ||
  +            (smanager.getMaxActiveSessions() != -1) ||
  +            !smanager.getAlgorithm().equals("MD5")) {
  +            return (false);
  +        }
  +        return (true);
  +
  +    }
  +
  +
  +    /**
        * Is the specified class name + property name combination an
        * exception that should not be persisted?
        *
  @@ -1036,6 +1126,9 @@
       private void storeLoader(PrintWriter writer, int indent,
                                Loader loader) throws Exception {
   
  +        if (isDefaultLoader(loader)) {
  +            return;
  +        }
           for (int i = 0; i < indent; i++) {
               writer.print(' ');
           }
  @@ -1079,6 +1172,10 @@
        */
       private void storeManager(PrintWriter writer, int indent,
                                 Manager manager) throws Exception {
  +
  +        if (isDefaultManager(manager)) {
  +            return;
  +        }
   
           // Store the beginning of this element
           for (int i = 0; i < indent; i++) {
  
  
  
  1.22      +14 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostConfig.java
  
  Index: HostConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostConfig.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- HostConfig.java	22 Apr 2002 00:01:21 -0000	1.21
  +++ HostConfig.java	3 May 2002 23:19:37 -0000	1.22
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostConfig.java,v 1.21 2002/04/22 00:01:21 glenn Exp $
  - * $Revision: 1.21 $
  - * $Date: 2002/04/22 00:01:21 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/HostConfig.java,v 1.22 2002/05/03 23:19:37 craigmcc Exp $
  + * $Revision: 1.22 $
  + * $Date: 2002/05/03 23:19:37 $
    *
    * ====================================================================
    *
  @@ -102,7 +102,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.21 $ $Date: 2002/04/22 00:01:21 $
  + * @version $Revision: 1.22 $ $Date: 2002/05/03 23:19:37 $
    */
   
   public class HostConfig
  @@ -433,6 +433,16 @@
               if (files[i].toLowerCase().endsWith(".xml")) {
   
                   deployed.add(files[i]);
  +
  +                // Calculate the context path and make sure it is unique
  +                String file = files[i].substring(0, files[i].length() - 4);
  +                String contextPath = "/" + file;
  +                if (file.equals("ROOT")) {
  +                    contextPath = "";
  +                }
  +                if (host.findChild(contextPath) != null) {
  +                    continue;
  +                }
   
                   // Assume this is a configuration descriptor and deploy it
                   log(sm.getString("hostConfig.deployDescriptor", files[i]));
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>