Author: remy.maucherat(a)jboss.com
Date: 2009-06-22 10:28:45 -0400 (Mon, 22 Jun 2009)
New Revision: 1123
Modified:
trunk/java/org/apache/catalina/startup/Tomcat.java
Log:
- Sync utility embedded class.
Modified: trunk/java/org/apache/catalina/startup/Tomcat.java
===================================================================
--- trunk/java/org/apache/catalina/startup/Tomcat.java 2009-06-22 14:13:03 UTC (rev 1122)
+++ trunk/java/org/apache/catalina/startup/Tomcat.java 2009-06-22 14:28:45 UTC (rev 1123)
@@ -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;
@@ -78,7 +77,7 @@
* see setters for doc. It can be used for simple tests and
* demo.
*
- * @see TomcatStartupAPITest for examples on how to use this
+ * @see TestTomcat for examples on how to use this
* @author Costin Manolache
*/
public class Tomcat {
@@ -247,7 +246,6 @@
* Initialize and start the server.
*/
public void start() throws Exception {
- setSilent();
getServer();
getConnector();
server.initialize();
@@ -421,7 +419,7 @@
initSimpleAuth();
}
ctx.setRealm(defaultRealm);
- initWebappDefaults(ctx);
+ ctx.addLifecycleListener(new DefaultWebXmlListener());
ContextConfig ctxCfg = new ContextConfig();
ctx.addLifecycleListener( ctxCfg );
@@ -506,8 +504,14 @@
"org.apache.catalina.core.StandardEngine",
"org.apache.catalina.startup.ContextConfig",
"org.apache.catalina.core.ApplicationContext",
+ "org.apache.catalina.core.AprLifecycleListener"
};
+ /**
+ * Sets the log level to WARN for the loggers that log information on
+ * Tomcat start up. This prevents the usual startup information being
+ * logged to the console.
+ */
public void setSilent() {
for (String s : silences) {
Logger.getLogger(s).setLevel(Level.WARNING);
@@ -523,7 +527,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 +536,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");
+ servlet.setLoadOnStartup(3);
- // in default web.xml - but not here, only needed if you have
- // jsps.
- //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 +588,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 +724,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 +750,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 +773,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 +793,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",
+ "vsd", "application/x-visio",
"wav", "audio/x-wav",
- "svg", "image/svg+xml",
- "svgz", "image/svg+xml",
- "vsd", "application/x-visio",
"wbmp", "image/vnd.wap.wbmp",
"wml", "text/vnd.wap.wml",
"wmlc", "application/vnd.wap.wmlc",
@@ -787,9 +812,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"
};
}