--- Tomcat.java +++ Tomcat-fixed.java @@ -75,28 +75,35 @@ /** * Minimal tomcat starter for embedding/unit tests. * + *

* Tomcat supports multiple styles of configuration and * startup - the most common and stable is server.xml-based, * implemented in org.apache.catalina.startup.Bootstrap. * + *

* This class is for use in apps that embed tomcat. + * + *

* Requirements: + *

* - * - no config file is required. This class provides methods to - * use if you have a webapp with a web.xml file, but it is - * optional - you can use your own servlets. - * + *

* There are a variety of 'add' methods to configure servlets and webapps. These * methods, by default, create a simple in-memory security realm and apply it. * If you need more complex security processing, you can define a subclass of * this class. * + *

* This class provides a set of convenience methods for configuring webapp * contexts, all overloads of the method addWebapp. These methods * create a webapp context, configure it, and then add it to a {@link Host}. @@ -104,6 +111,7 @@ * listener that adds the standard DefaultServlet, JSP processing, and welcome * files. * + *

* In complex cases, you may prefer to use the ordinary Tomcat API to create * webapp contexts; for example, you might need to install a custom Loader * before the call to {@link Host#addChild(Container)}. To replicate the basic @@ -111,14 +119,17 @@ * methods of this class: {@link #noDefaultWebXmlPath()} and * {@link #getDefaultWebXmlListener()}. * + *

* {@link #getDefaultWebXmlListener()} returns a {@link LifecycleListener} that * adds the standard DefaultServlet, JSP processing, and welcome files. If you * add this listener, you must prevent Tomcat from applying any standard global * web.xml with ... * + *

* {@link #noDefaultWebXmlPath()} returns a dummy pathname to configure to * prevent {@link ContextConfig} from trying to apply a global web.xml file. * + *

* This class provides a main() and few simple CLI arguments, * see setters for doc. It can be used for simple tests and * demo. @@ -153,11 +164,15 @@ * Tomcat needs a directory for temp files. This should be the * first method called. * + *

* By default, if this method is not called, we use: - * - system properties - catalina.base, catalina.home - * - $PWD/tomcat.$PORT + *

* (/tmp doesn't seem a good choice for security). * + *

* TODO: disable work dir if not needed ( no jsp, etc ). * * @param basedir The Tomcat base folder on which all others @@ -215,24 +230,30 @@ * programmatically, there will still be no scanning for * {@link javax.servlet.annotation.HandlesTypes} matches. * + *

* API calls equivalent with web.xml: * - * context-param + *

{@code
+     *  // context-param
      *  ctx.addParameter("name", "value");
      *
      *
-     * error-page
-     *    ErrorPage ep = new ErrorPage();
-     *    ep.setErrorCode(500);
-     *    ep.setLocation("/error.html");
-     *    ctx.addErrorPage(ep);
+     *  // error-page
+     *  ErrorPage ep = new ErrorPage();
+     *  ep.setErrorCode(500);
+     *  ep.setLocation("/error.html");
+     *  ctx.addErrorPage(ep);
      *
-     * ctx.addMimeMapping("ext", "type");
+     *  ctx.addMimeMapping("ext", "type");
+     * }
+ * * + *

* Note: If you reload the Context, all your configuration will be lost. If * you need reload support, consider using a LifecycleListener to provide * your configuration. * + *

* TODO: add the rest * * @param contextPath The context mapping to use, "" for root context. @@ -247,14 +268,16 @@ /** * Equivalent to <servlet><servlet-name><servlet-class>. * + *

* In general it is better/faster to use the method that takes a * Servlet as param - this one can be used if the servlet is not * commonly used, and want to avoid loading all deps. * ( for example: jsp servlet ) * * You can customize the returned servlet, ex: - * + *

      *    wrapper.addInitParameter("name", "value");
+     *  
* * @param contextPath Context to add Servlet to * @param servletName Servlet name (used in mappings) @@ -399,6 +422,7 @@ * Get the default http connector. You can set more * parameters - the port is already initialized. * + *

* Alternatively, you can construct a Connector and set any params, * then call addConnector(Connector) * @@ -933,6 +957,7 @@ /** * Fix startup sequence - required if you don't use web.xml. * + *

* The start() method in context will set 'configured' to false - and * expects a listener to set it back to true. */