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/12 20:57:30 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core ApplicationContext.java StandardContext.java StandardHost.java RootContext.java

craigmcc    00/08/12 11:57:30

  Modified:    catalina/src/conf server.xml
               catalina/src/share/org/apache/catalina Context.java
                        Host.java
               catalina/src/share/org/apache/catalina/core
                        ApplicationContext.java StandardContext.java
                        StandardHost.java
  Removed:     catalina/src/share/org/apache/catalina/core RootContext.java
  Log:
  Clean up the former special handling of getContext("/") calls.  Now,
  requests for this are treated like anything else (and will return the root
  context).
  
  Add a new Context property (crossContext) that allows the administrator
  to turn on and off, on a per-app basis, the ability for getContext() to
  cross application boundaries.  Defaults to "true" to keep Watchdog happy.
  
  The Tomcat 4.0 version of Catalina passes all the Watchdog servlet tests
  except for the getContext() one, but that is only because the ROOT context
  is not currently configured in $CATALINA_HOME/webapps.  That will be fixed
  soon.
  
  Revision  Changes    Path
  1.3       +1 -1      jakarta-tomcat-4.0/catalina/src/conf/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/conf/server.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- server.xml	2000/08/11 23:53:50	1.2
  +++ server.xml	2000/08/12 18:57:28	1.3
  @@ -75,7 +75,7 @@
         userRoleTable="user_roles" roleNameCol="role_name" />
   -->
   
  -    <Host name="localhost" debug="0" root="true" appBase="webapps">
  +    <Host name="localhost" debug="0" appBase="webapps">
   
         <!-- Access log processes all requests for this virtual host -->
         <Valve className="org.apache.catalina.valves.AccessLogValve"
  
  
  
  1.2       +18 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Context.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Context.java	2000/08/11 05:24:05	1.1
  +++ Context.java	2000/08/12 18:57:28	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Context.java,v 1.1 2000/08/11 05:24:05 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 05:24:05 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Context.java,v 1.2 2000/08/12 18:57:28 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/08/12 18:57:28 $
    *
    * ====================================================================
    *
  @@ -91,7 +91,7 @@
    * <p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 05:24:05 $
  + * @version $Revision: 1.2 $ $Date: 2000/08/12 18:57:28 $
    */
   
   public interface Context extends Container {
  @@ -112,6 +112,20 @@
        * @param cookies The new flag
        */
       public void setCookies(boolean cookies);
  +
  +
  +    /**
  +     * Return the "allow crossing servlet contexts" flag.
  +     */
  +    public boolean getCrossContext();
  +
  +
  +    /**
  +     * Set the "allow crossing servlet contexts" flag.
  +     *
  +     * @param crossContext The new cross contexts flag
  +     */
  +    public void setCrossContext(boolean crossContext);
   
   
       /**
  
  
  
  1.2       +4 -14     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Host.java
  
  Index: Host.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Host.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Host.java	2000/08/11 05:24:06	1.1
  +++ Host.java	2000/08/12 18:57:28	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Host.java,v 1.1 2000/08/11 05:24:06 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 05:24:06 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Host.java,v 1.2 2000/08/12 18:57:28 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/08/12 18:57:28 $
    *
    * ====================================================================
    *
  @@ -90,7 +90,7 @@
    * an individual servlet context), depending upon the Engine implementation.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 05:24:06 $
  + * @version $Revision: 1.2 $ $Date: 2000/08/12 18:57:28 $
    */
   
   public interface Host extends Container {
  @@ -148,16 +148,6 @@
        * @exception IllegalArgumentException if name is null
        */
       public void setName(String name);
  -
  -
  -    /**
  -     * Return a specialized ServletContext instance that wraps the
  -     * resources of the underlying virtual host; or <code>null</code>
  -     * if access to these resources is not supported or not allowed.
  -     * In general, this method will be used when a servlet calls
  -     * <code>ServletContext.getContext("/")</code>.
  -     */
  -    public ServletContext getRootContext();
   
   
       // --------------------------------------------------------- Public Methods
  
  
  
  1.2       +23 -24    jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java
  
  Index: ApplicationContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApplicationContext.java	2000/08/11 23:40:44	1.1
  +++ ApplicationContext.java	2000/08/12 18:57:29	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.1 2000/08/11 23:40:44 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 23:40:44 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.2 2000/08/12 18:57:29 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/08/12 18:57:29 $
    *
    * ====================================================================
    *
  @@ -93,7 +93,7 @@
    * associated with each instance of <code>StandardContext</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 23:40:44 $
  + * @version $Revision: 1.2 $ $Date: 2000/08/12 18:57:29 $
    */
   
   public final class ApplicationContext
  @@ -107,7 +107,7 @@
        * Construct a new instance of this class, associated with the specified
        * Context instance.
        *
  -     * @param context The associated Host instance
  +     * @param context The associated Context instance
        */
       public ApplicationContext(StandardContext context) {
   
  @@ -198,36 +198,35 @@
        * access to the context for various parts of the server, and as needed
        * obtain <code>RequestDispatcher</code> objects or resources from the
        * context.  The given path must be absolute (beginning with a "/"),
  -     * and is interpreted based on the server's document root.
  -     * <p>
  -     * <b>IMPLEMENTATION NOTE</b>:  This implementation is dependent upon
  -     * our associated Context having a parent that is a StandardHost.  :-(
  +     * and is interpreted based on our virtual host's document root.
        *
        * @param uri Absolute URI of a resource on the server
        */
       public ServletContext getContext(String uri) {
   
  -	// Identify the parent Host of our Context, if any
  -	StandardHost host = null;
  -	try {
  -	    host = (StandardHost) context.getParent();
  -	} catch (Throwable t) {
  -	    host = null;
  -	}
  -	if (host == null)
  +	// Validate the format of the specified argument
  +	if ((uri == null) || (!uri.startsWith("/")))
   	    return (null);
  -	if (!host.getRoot())
  -	    return (null);
  +
  +	// Return the current context if requested
  +	String contextPath = context.getPath();
  +	if ((contextPath.length() > 0) &&
  +	    (uri.startsWith(contextPath))) {
  +	    return (this);
  +	}
   
  -	// Return the appropriate Context for the specified URI
  -	if (uri.equals("/"))
  -	    return (host.getRootContext());
  -	else {
  -	    Context child = (Context) host.map(uri);
  +	// Return other contexts only if allowed
  +	if (!context.getCrossContext())
  +	    return (null);
  +	try {
  +	    Host host = (Host) context.getParent();
  +	    Context child = host.map(uri);
   	    if (child != null)
   		return (child.getServletContext());
   	    else
   		return (null);
  +	} catch (Throwable t) {
  +	    return (null);
   	}
   
       }
  
  
  
  1.2       +37 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java
  
  Index: StandardContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardContext.java	2000/08/11 23:40:45	1.1
  +++ StandardContext.java	2000/08/12 18:57:29	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.1 2000/08/11 23:40:45 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 23:40:45 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.2 2000/08/12 18:57:29 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/08/12 18:57:29 $
    *
    * ====================================================================
    *
  @@ -100,7 +100,7 @@
    * requests directed to a particular servlet.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 23:40:45 $
  + * @version $Revision: 1.2 $ $Date: 2000/08/12 18:57:29 $
    */
   
   public final class StandardContext
  @@ -144,6 +144,13 @@
   
   
       /**
  +     * Should we allow the <code>ServletContext.getContext()</code> method
  +     * to access the context of other web applications in this server?
  +     */
  +    private boolean crossContext = true;
  +
  +
  +    /**
        * The distributable flag for this web application.
        */
       private boolean distributable = false;
  @@ -329,6 +336,32 @@
   	support.firePropertyChange("cookies",
   				   new Boolean(oldCookies),
   				   new Boolean(this.cookies));
  +
  +    }
  +
  +
  +    /**
  +     * Return the "allow crossing servlet contexts" flag.
  +     */
  +    public boolean getCrossContext() {
  +
  +	return (this.crossContext);
  +
  +    }
  +
  +
  +    /**
  +     * Set the "allow crossing servlet contexts" flag.
  +     *
  +     * @param crossContext The new cross contexts flag
  +     */
  +    public void setCrossContext(boolean crossContext) {
  +
  +	boolean oldCrossContext = this.crossContext;
  +	this.crossContext = crossContext;
  +	support.firePropertyChange("crossContext",
  +				   new Boolean(oldCrossContext),
  +				   new Boolean(this.crossContext));
   
       }
   
  
  
  
  1.2       +4 -61     jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java
  
  Index: StandardHost.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardHost.java	2000/08/11 23:40:45	1.1
  +++ StandardHost.java	2000/08/12 18:57:29	1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v 1.1 2000/08/11 23:40:45 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2000/08/11 23:40:45 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v 1.2 2000/08/12 18:57:29 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2000/08/12 18:57:29 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,7 @@
    * requests directed to a particular web application.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2000/08/11 23:40:45 $
  + * @version $Revision: 1.2 $ $Date: 2000/08/12 18:57:29 $
    */
   
   public final class StandardHost
  @@ -135,18 +135,6 @@
   	"org.apache.catalina.core.StandardHostMapper";
   
   
  -    /**
  -     * Should we return a root context?
  -     */
  -    private boolean root = false;
  -
  -
  -    /**
  -     * The root context for this virtual host.
  -     */
  -    private ServletContext rootContext = null;
  -
  -
       // ------------------------------------------------------------- Properties
   
   
  @@ -206,51 +194,6 @@
   	String oldName = this.name;
   	this.name = name;
   	support.firePropertyChange("name", oldName, this.name);
  -
  -    }
  -
  -
  -    /**
  -     * Return the root context flag.
  -     */
  -    public boolean getRoot() {
  -
  -	return (this.root);
  -
  -    }
  -
  -
  -    /**
  -     * Set the root context flag.
  -     *
  -     * @param root The new root context flag
  -     */
  -    public void setRoot(boolean root) {
  -
  -	boolean oldRoot = this.root;
  -	this.root = root;
  -	support.firePropertyChange("root", new Boolean(oldRoot),
  -				   new Boolean(this.root));
  -
  -    }
  -
  -
  -    /**
  -     * Return a specialized ServletContext instance that wraps the
  -     * resources of the underlying virtual host; or <code>null</code>
  -     * if access to these resources is not supported or not allowed.
  -     * In general, this method will be used when a servlet calls
  -     * <code>ServletContext.getContext("/")</code>.
  -     */
  -    public ServletContext getRootContext() {
  -
  -	if (!root)
  -	    return (null);
  -
  -	// Construct a root context object if necessary
  -	rootContext = null;	// XXX - create root context object
  -
  -	return (rootContext);
   
       }