Author: markt
Date: Mon Jun 15 15:13:22 2009
New Revision: 784804

URL: http://svn.apache.org/viewvc?rev=784804&view=rev
Log:
Align programmatic web.xml defaults with conf/web.xml
Don't set anything that is already set by default
Switch to a context listener for the defaults so they get applied on re-load

Modified:
    tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java

Modified: tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=784804&r1=784803&r2=784804&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Mon Jun 15 
15:13:22 2009
@@ -42,7 +42,6 @@
 import org.apache.catalina.core.StandardServer;
 import org.apache.catalina.core.StandardService;
 import org.apache.catalina.core.StandardWrapper;
-import org.apache.catalina.deploy.LoginConfig;
 import org.apache.catalina.realm.GenericPrincipal;
 import org.apache.catalina.realm.RealmBase;
 import org.apache.catalina.session.StandardManager;
@@ -421,7 +420,7 @@
             initSimpleAuth();
         }
         ctx.setRealm(defaultRealm);
-        initWebappDefaults(ctx);
+        ctx.addLifecycleListener(new DefaultWebXmlListener());
         
         ContextConfig ctxCfg = new ContextConfig();
         ctx.addLifecycleListener( ctxCfg );
@@ -523,7 +522,8 @@
         Logger.getLogger(base).setLevel(Level.WARNING);
     }
     
-    /** Init default servlets for the context. This should be the programmatic
+    /**
+     * Provide default configuration for a context. This is the programmatic
      * equivalent of the default web.xml. 
      * 
      *  TODO: in normal tomcat, if default-web.xml is not found, use this 
@@ -531,44 +531,35 @@
      */
     public static void initWebappDefaults(StandardContext ctx) {
         // Default servlet 
-        StandardWrapper servlet = 
-            addServlet(ctx, "default", 
-                    //new DefaultServlet());
-        // Or:
-                    "org.apache.catalina.servlets.DefaultServlet");
-        servlet.addInitParameter("listings", "false");
+        StandardWrapper servlet = addServlet(
+                ctx, "default", "org.apache.catalina.servlets.DefaultServlet");
         servlet.setLoadOnStartup(1);
 
-        // class name - to avoid loading all deps
-        servlet = addServlet(ctx, "jsp", 
-            "org.apache.jasper.servlet.JspServlet");
+        // JSP servlet (by class name - to avoid loading all deps)
+        servlet = addServlet(
+                ctx, "jsp", "org.apache.jasper.servlet.JspServlet");
         servlet.addInitParameter("fork", "false");
-        servlet.addInitParameter("xpoweredBy", "false");
-        
-        // in default web.xml - but not here, only needed if you have
-        // jsps.
-        //servlet.setLoadOnStartup(3);
+        servlet.setLoadOnStartup(3);
         
+        // Servlet mappings 
         ctx.addServletMapping("/", "default");
         ctx.addServletMapping("*.jsp", "jsp");
         ctx.addServletMapping("*.jspx", "jsp");
+
         // Sessions
         ctx.setManager( new StandardManager());
         ctx.setSessionTimeout(30);
         
-        // TODO: read mime from /etc/mime.types on linux, or some
-        // resource
+        // MIME mappings
         for (int i = 0; i < DEFAULT_MIME_MAPPINGS.length; ) {
             ctx.addMimeMapping(DEFAULT_MIME_MAPPINGS[i++],
                     DEFAULT_MIME_MAPPINGS[i++]);
         }
+        
+        // Welcome files
         ctx.addWelcomeFile("index.html");
         ctx.addWelcomeFile("index.htm");
         ctx.addWelcomeFile("index.jsp");
-        
-        ctx.setLoginConfig( new LoginConfig("NONE", null, null, null));
-        
-        // TODO: set a default realm, add simple API to add users
     }
 
     
@@ -592,6 +583,24 @@
         
     }
 
+
+    /**
+     * Fix reload - required if reloading and using programmatic configuration.
+     * When a context is reloaded, any programmatic configuration is lost. This
+     * listener sets the equivalent of conf/web.xml when the context starts. 
The
+     * context needs to be an instance of StandardContext for this listener to
+     * have any effect.
+     */
+    public static class DefaultWebXmlListener implements LifecycleListener {
+        public void lifecycleEvent(LifecycleEvent event) {
+            if (Lifecycle.BEFORE_START_EVENT.equals(event.getType()) &&
+                    event.getLifecycle() instanceof StandardContext) {
+                initWebappDefaults((StandardContext) event.getLifecycle());
+            }
+        }
+    }
+
+
     /** Helper class for wrapping existing servlets. This disables servlet 
      * lifecycle and normal reloading, but also reduces overhead and provide
      * more direct control over the servlet.  
@@ -710,12 +719,21 @@
         "odp", "application/vnd.oasis.opendocument.presentation", 
         "ods", "application/vnd.oasis.opendocument.spreadsheet", 
         "odt", "application/vnd.oasis.opendocument.text", 
-        "ogg", "application/ogg", 
-        "otg ", "application/vnd.oasis.opendocument.graphics-template", 
+        "otg", "application/vnd.oasis.opendocument.graphics-template", 
         "oth", "application/vnd.oasis.opendocument.text-web", 
         "otp", "application/vnd.oasis.opendocument.presentation-template", 
         "ots", "application/vnd.oasis.opendocument.spreadsheet-template ", 
-        "ott", "application/vnd.oasis.opendocument.text-template", 
+        "ott", "application/vnd.oasis.opendocument.text-template",
+        "ogx", "application/ogg",
+        "ogv", "video/ogg",
+        "oga", "audio/ogg",
+        "ogg", "audio/ogg",
+        "spx", "audio/ogg",
+        "faca", "audio/flac",
+        "anx", "application/annodex",
+        "axa", "audio/annodex",
+        "axv", "video/annodex",
+        "xspf", "application/xspf+xml",
         "pbm", "image/x-portable-bitmap", 
         "pct", "image/pict", 
         "pdf", "application/pdf", 
@@ -727,7 +745,8 @@
         "pnm", "image/x-portable-anymap", 
         "pnt", "image/x-macpaint", 
         "ppm", "image/x-portable-pixmap", 
-        "ppt", "application/powerpoint", 
+        "ppt", "application/vnd.ms-powerpoint",
+        "pps", "application/vnd.ms-powerpoint",
         "ps", "application/postscript", 
         "psd", "image/x-photoshop", 
         "qt", "video/quicktime", 
@@ -749,6 +768,8 @@
         "src", "application/x-wais-source", 
         "sv4cpio", "application/x-sv4cpio", 
         "sv4crc", "application/x-sv4crc", 
+        "svg", "image/svg+xml", 
+        "svgz", "image/svg+xml", 
         "swf", "application/x-shockwave-flash", 
         "t", "application/x-troff", 
         "tar", "application/x-tar", 
@@ -767,16 +788,15 @@
         "xbm", "image/x-xbitmap", 
         "xht", "application/xhtml+xml", 
         "xhtml", "application/xhtml+xml", 
+        "xls", "application/vnd.ms-excel", 
         "xml", "application/xml", 
         "xpm", "image/x-xpixmap", 
         "xsl", "application/xml", 
         "xslt", "application/xslt+xml", 
         "xul", "application/vnd.mozilla.xul+xml", 
         "xwd", "image/x-xwindowdump", 
-        "wav", "audio/x-wav", 
-        "svg", "image/svg+xml", 
-        "svgz", "image/svg+xml", 
         "vsd", "application/x-visio", 
+        "wav", "audio/x-wav", 
         "wbmp", "image/vnd.wap.wbmp", 
         "wml", "text/vnd.wap.wml", 
         "wmlc", "application/vnd.wap.wmlc", 
@@ -787,9 +807,6 @@
         "wspolicy", "application/wspolicy+xml", 
         "Z", "application/x-compress", 
         "z", "application/x-compress", 
-        "zip", "application/zip", 
-        "xls", "application/vnd.ms-excel", 
-        "doc", "application/vnd.ms-word", 
-        "ppt", "application/vnd.ms-powerpoint"
+        "zip", "application/zip" 
     };
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to