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;
initSimpleAuth();
}
ctx.setRealm(defaultRealm);
- initWebappDefaults(ctx);
+ ctx.addLifecycleListener(new DefaultWebXmlListener());
ContextConfig ctxCfg = new ContextConfig();
ctx.addLifecycleListener( ctxCfg );
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
*/
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
}
}
+
+ /**
+ * 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.
"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",
"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",
"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",
"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",
"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"
};
}