Save This Page
Home » apache-tomcat-6.0.26-src » org.apache » catalina » startup » [javadoc | source]
org.apache.catalina.startup
public class: Tomcat [javadoc | source]
java.lang.Object
   org.apache.catalina.startup.Tomcat
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: - all tomcat classes and possibly servlets are in the classpath. ( for example all is in one big jar, or in eclipse CP, or in any other combination ) - we need one temporary directory for work files - 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. This class provides a main() and few simple CLI arguments, see setters for doc. It can be used for simple tests and demo.
Nested Class Summary:
public static class  Tomcat.FixContextListener  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. 
public static class  Tomcat.ExistingStandardWrapper  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. 
Field Summary
protected  StandardServer server     
protected  StandardService service     
protected  StandardEngine engine     
protected  Connector connector     
protected  StandardHost host     
protected  int port     
protected  String hostname     
protected  String basedir     
protected  Realm defaultRealm     
static  String[] silences     
public static final  String[] DEFAULT_MIME_MAPPINGS    TODO: would a properties resource be better ? Or just parsing /etc/mime.types ? This is needed because we don't use the default web.xml, where this is encoded. 
Constructor:
 public Tomcat() 
Method from org.apache.catalina.startup.Tomcat Summary:
addContext,   addContext,   addRole,   addServlet,   addServlet,   addServlet,   addUser,   addWebapp,   addWebapp,   getConnector,   getEngine,   getHost,   getServer,   getService,   initBaseDir,   initSimpleAuth,   initWebappDefaults,   setBaseDir,   setConnector,   setDefaultRealm,   setHost,   setHostname,   setPort,   setSilent,   start,   stop
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.catalina.startup.Tomcat Detail:
 public StandardContext addContext(String contextPath,
    String baseDir) 
    Add a context - programmatic mode, no web.xml used. API calls equivalent with web.xml: context-param ctx.addParameter("name", "value"); error-page ErrorPage ep = new ErrorPage(); ep.setErrorCode(500); ep.setLocation("/error.html"); ctx.addErrorPage(ep); ctx.addMimeMapping("ext", "type"); TODO: add the rest
 public StandardContext addContext(StandardHost host,
    String contextPath,
    String dir) 
 public  void addRole(String user,
    String role) 
 public StandardWrapper addServlet(String contextPath,
    String servletName,
    String servletClass) 
 public StandardWrapper addServlet(StandardContext ctx,
    String servletName,
    String servletClass) 
    Equivalent with . 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");
 public StandardWrapper addServlet(StandardContext ctx,
    String servletName,
    Servlet servlet) 
    Use an existing servlet, no class.forName or initialization will be performed
 public  void addUser(String user,
    String pass) 
    Add a user for the in-memory realm. All created apps use this by default, can be replaced using setRealm().
 public StandardContext addWebapp(String contextPath,
    String baseDir) throws ServletException 
    Add a webapp using normal WEB-INF/web.xml if found.
 public StandardContext addWebapp(StandardHost host,
    String url,
    String path) throws ServletException 
 public Connector getConnector() throws Exception 
    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)
 public StandardEngine getEngine() 
    Access to the engine, for further customization.
 public StandardHost getHost() 
 public StandardServer getServer() 
    Get the server object. You can add listeners and few more customizations.
 public StandardService getService() 
    Get the service object. Can be used to add more connectors and few other global settings.
 protected  void initBaseDir() 
 protected  void initSimpleAuth() 
    Initialize an in-memory realm. You can replace it for contexts with a real one.
 protected  void initWebappDefaults(StandardContext ctx) 
    Init default servlets for the context. This should be the programmatic equivalent of the default web.xml. TODO: in normal tomcat, if default-web.xml is not found, use this method
 public  void setBaseDir(String basedir) 
    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 - $HOME/tomcat.$PORT ( /tmp doesn't seem a good choice for security ). TODO: better default ? Maybe current dir ? TODO: disable work dir if not needed ( no jsp, etc ).
 public  void setConnector(Connector connector) 
 public  void setDefaultRealm(Realm realm) 
    Set a custom realm for auth. If not called, a simple default will be used, using an internal map. Must be called before adding a context.
 public  void setHost(StandardHost host) 
    Sets the current host - all future webapps will be added to this host. When tomcat starts, the host will be the default host.
 public  void setHostname(String s) 
    The the hostname of the default host, default is 'localhost'.
 public  void setPort(int port) 
    Set the port for the default connector. Must be called before start().
 public  void setSilent() 
 public  void start() throws Exception 
    Initialize and start the server.
 public  void stop() throws Exception 
    Stop the server.