You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/08/05 02:50:06 UTC

cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup Embedded.java

craigmcc    00/08/04 17:50:05

  Modified:    proposals/catalina/src/share/org/apache/tomcat/startup
                        Embedded.java
  Log:
  Split the act of constructing a new Host or Context from the act of adding
  it to the parent container, so that you have a chance to customize properties
  and/or add listeners *before* the new component is started.
  
  Revision  Changes    Path
  1.3       +51 -33    jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Embedded.java
  
  Index: Embedded.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Embedded.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Embedded.java	2000/07/28 18:58:18	1.2
  +++ Embedded.java	2000/08/05 00:50:04	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Embedded.java,v 1.2 2000/07/28 18:58:18 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/07/28 18:58:18 $
  + * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/startup/Embedded.java,v 1.3 2000/08/05 00:50:04 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/08/05 00:50:04 $
    *
    * ====================================================================
    *
  @@ -105,11 +105,14 @@
    *     call its property setters as desired.</li>
    * <li>Call <code>createHost()</code> to create at least one virtual Host
    *     associated with the newly created Engine, and then call its property
  - *     setters as desired.</li>
  + *     setters as desired.  After you customize this Host, add it to the
  + *     corresponding Engine with <code>engine.addChild(host)</code>.</li>
    * <li>Call <code>createContext()</code> to create at least one Context
    *     associated with each newly created Host, and then call its property
    *     setters as desired.  You <strong>MUST</strong> create a Context with
  - *     a pathname equal to a zero-length string.</li>
  + *     a pathname equal to a zero-length string.  After you customize
  + *     this Context, add it to the corresponding Host with
  + *     <code>host.addChild(context)</code>.</li>
    * <li>Call <code>addEngine()</code> to attach this Engine to the set of
    *     defined Engines for this object.</li>
    * <li>Call <code>createConnector()</code> to create at least one TCP/IP
  @@ -141,7 +144,7 @@
    * </pre>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2000/07/28 18:58:18 $
  + * @version $Revision: 1.3 $ $Date: 2000/08/05 00:50:04 $
    */
   
   public class Embedded implements Lifecycle {
  @@ -488,10 +491,18 @@
       /**
        * Create, configure, and return a Context that will process all
        * HTTP requests received from one of the associated Connectors,
  -     * and directed to the specified context path on the specified virtual
  -     * host.
  +     * and directed to the specified context path on the virtual host
  +     * to which this Context is connected.
  +     * <p>
  +     * After you have customized the properties, listeners, and Valves
  +     * for this Context, you must attach it to the corresponding Host
  +     * by calling:
  +     * <pre>
  +     *   host.addChild(context);
  +     * </pre>
  +     * which will also cause the Context to be started if the Host has
  +     * already been started.
        *
  -     * @param host Host with which this Context will be associated
        * @param path Context path of this application ("" for the default
        *  application for this host, must start with a slash otherwise)
        * @param docBase Absolute pathname to the document base directory
  @@ -500,11 +511,11 @@
        * @exception IllegalArgumentException if an invalid parameter
        *  is specified
        */
  -    public Context createContext(Host host, String path, String docBase) {
  +    public Context createContext(String path, String docBase) {
   
   	if (debug >= 1)
  -	    logger.log("Creating context for host='" + host.getName() +
  -		       "' path='" + path + "' docBase='" + docBase + "'");
  +	    logger.log("Creating context '" + path + "' with docBase '" +
  +		       docBase + "'");
   
   	StandardContext context = new StandardContext();
   
  @@ -516,7 +527,6 @@
   	config.setDebug(debug);
   	((Lifecycle) context).addLifecycleListener(config);
   
  -	host.addChild(context);
   	return (context);
   
       }
  @@ -547,11 +557,22 @@
       /**
        * Create, configure, and return a Host that will process all
        * HTTP requests received from one of the associated Connectors,
  -     * and directed to the specified virtual host.  The very first
  -     * Host associated with a particular Engine will become the
  -     * default virtual host for that Engine.
  +     * and directed to the specified virtual host.
  +     * <p>
  +     * After you have customized the properties, listeners, and Valves
  +     * for this Host, you must attach it to the corresponding Engine
  +     * by calling:
  +     * <pre>
  +     *   engine.addChild(host);
  +     * </pre>
  +     * which will also cause the Host to be started if the Engine has
  +     * already been started.  If this is the default (or only) Host you
  +     * will be defining, you may also tell the Engine to pass all requests
  +     * not assigned to another virtual host to this one:
  +     * <pre>
  +     *   engine.setDefaultHost(host.getName());
  +     * </pre>
        *
  -     * @param engine Engine with which this Host will be associated
        * @param name Canonical name of this virtual host
        * @param appBase Absolute pathname to the application base directory
        *  for this virtual host
  @@ -559,11 +580,11 @@
        * @exception IllegalArgumentException if an invalid parameter
        *  is specified
        */
  -    public Host createHost(Engine engine, String name, String appBase) {
  +    public Host createHost(String name, String appBase) {
   
   	if (debug >= 1)
  -	    logger.log("Creating host for engine='" + engine.getName() +
  -		       "' name='" + name + "' appBase='" + appBase + "'");
  +	    logger.log("Creating host '" + name + "' with appBase '" +
  +		       appBase + "'");
   
   	StandardHost host = new StandardHost();
   
  @@ -571,14 +592,6 @@
   	host.setDebug(debug);
   	host.setName(name);
   
  -	Container hosts[] = engine.findChildren();
  -	if (hosts.length < 1) {
  -	    if (debug >= 1)
  -		logger.log("Setting default host to '" + name + "'");
  -	    ((StandardEngine) engine).setDefaultHost(name);
  -	}
  -
  -	engine.addChild(host);
   	return (host);
   
       }
  @@ -941,13 +954,18 @@
   	// that simulates a portion of the one configured in server.xml
   	// by default
   	Engine engine = embedded.createEngine();
  -	Host host = embedded.createHost(engine, "localhost",
  -					home + "/webapps");
  -	Context root = embedded.createContext(host, "",
  -					      home + "/webapps/ROOT");
  -	Context examples = embedded.createContext(host, "/examples",
  +
  +	Host host = embedded.createHost("localhost", home + "/webapps");
  +	engine.addChild(host);
  +
  +	Context root = embedded.createContext("", home + "/webapps/ROOT");
  +	host.addChild(root);
  +
  +	Context examples = embedded.createContext("/examples",
   						  home + "/webapps/examples");
   	customize(examples);	// Special customization for this web-app
  +	host.addChild(examples);
  +
   	embedded.addEngine(engine);
   
   	// Assemble and install a non-secure connector for port 8080