You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2001/01/12 07:50:06 UTC

cvs commit: jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core ApplicationContext.java ContainerBase.java StandardContext.java

remm        01/01/11 22:50:06

  Modified:    catalina/src/share/org/apache/catalina/core
                        ApplicationContext.java ContainerBase.java
                        StandardContext.java
  Log:
  - Updated the ServletContext facade to use the DirContext.
  - Will produce URLs using the new DirContextURLHandler.
  - ServletContext.getResourcePaths() is commeted out for now.
  - The standard context will put the associated DirContext in two places :
    - in the naming environment, it is bound to java:/comp/Resources
    - in the ServletContext, it is bound as org.apache.catalina.resources
  
  Revision  Changes    Path
  1.10      +35 -22    jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ApplicationContext.java
  
  Index: ApplicationContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ApplicationContext.java	2001/01/03 00:17:06	1.9
  +++ ApplicationContext.java	2001/01/12 06:50:06	1.10
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.9 2001/01/03 00:17:06 craigmcc Exp $
  - * $Revision: 1.9 $
  - * $Date: 2001/01/03 00:17:06 $
  + * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v 1.10 2001/01/12 06:50:06 remm Exp $
  + * $Revision: 1.10 $
  + * $Date: 2001/01/12 06:50:06 $
    *
    * ====================================================================
    *
  @@ -74,18 +74,21 @@
   import java.util.HashMap;
   import java.util.HashSet;
   import java.util.Set;
  +import javax.naming.directory.DirContext;
   import javax.servlet.RequestDispatcher;
   import javax.servlet.Servlet;
   import javax.servlet.ServletContext;
   import javax.servlet.ServletContextAttributeEvent;
   import javax.servlet.ServletContextAttributesListener;
   import javax.servlet.http.HttpServletRequest;
  +import org.apache.naming.resources.Resource;
  +import org.apache.naming.resources.DirContextURLStreamHandler;
  +import org.apache.naming.resources.DirContextURLConnection;
   import org.apache.catalina.Container;
   import org.apache.catalina.Context;
   import org.apache.catalina.Globals;
   import org.apache.catalina.Host;
   import org.apache.catalina.Logger;
  -import org.apache.catalina.Resources;
   import org.apache.catalina.Wrapper;
   import org.apache.catalina.connector.HttpRequestBase;
   import org.apache.catalina.deploy.ApplicationParameter;
  @@ -100,7 +103,8 @@
    * associated with each instance of <code>StandardContext</code>.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.9 $ $Date: 2001/01/03 00:17:06 $
  + * @author Remy Maucherat
  + * @version $Revision: 1.10 $ $Date: 2001/01/12 06:50:06 $
    */
   
   public final class ApplicationContext
  @@ -167,7 +171,7 @@
        * The path must begin with a "/" and is interpreted as relative to the
        * current context root.
        */
  -    public Resources getResources() {
  +    public DirContext getResources() {
   
   	return context.getResources();
   
  @@ -303,11 +307,15 @@
        */
       public String getMimeType(String file) {
   
  -	Resources resources = context.getResources();
  -	if (resources == null)
  +	if (file == null)
   	    return (null);
  -	else
  -	    return (resources.getMimeType(file));
  +	int period = file.lastIndexOf(".");
  +	if (period < 0)
  +	    return (null);
  +	String extension = file.substring(period + 1);
  +	if (extension.length() < 1)
  +	    return (null);
  +	return (context.findMimeMapping(extension));
   
       }
   
  @@ -343,11 +351,7 @@
        */
       public String getRealPath(String path) {
   
  -	Resources resources = context.getResources();
  -	if (resources == null)
  -	    return (null);
  -	else
  -	    return (resources.getRealPath(path));
  +        return (null);
   
       }
   
  @@ -415,11 +419,12 @@
        */
       public URL getResource(String path) throws MalformedURLException {
   
  -	Resources resources = context.getResources();
  +	DirContext resources = context.getResources();
   	if (resources == null)
   	    return (null);
   	else
  -	    return (resources.getResource(path));
  +	    return new URL("jndi", null, 0, path, 
  +                           new DirContextURLStreamHandler(resources));
   
       }
   
  @@ -434,11 +439,16 @@
        */
       public InputStream getResourceAsStream(String path) {
   
  -	Resources resources = context.getResources();
  -	if (resources == null)
  -	    return (null);
  -	else
  -	    return (resources.getResourceAsStream(path));
  +        DirContext resources = context.getResources();
  +        if (resources != null) {
  +            try {
  +                Object resource = resources.lookup(path);
  +                if (resource instanceof Resource)
  +                    return (((Resource) resource).streamContent());
  +            } catch (Exception e) {
  +            }
  +        }
  +        return (null);
   
       }
   
  @@ -451,6 +461,8 @@
       public Set getResourcePaths() {
   
           ResourceSet set = new ResourceSet();
  +        // FIXME !
  +        /*
           Resources resources = context.getResources();
           if (resources == null) {
               set.setLocked(true);
  @@ -461,6 +473,7 @@
               paths = new String[0];
           for (int i = 0; i < paths.length; i++)
               set.add(paths[i]);
  +        */
           set.setLocked(true);
           return (set);
   
  
  
  
  1.7       +21 -40    jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ContainerBase.java
  
  Index: ContainerBase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ContainerBase.java	2001/01/04 20:05:36	1.6
  +++ ContainerBase.java	2001/01/12 06:50:06	1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v 1.6 2001/01/04 20:05:36 craigmcc Exp $
  - * $Revision: 1.6 $
  - * $Date: 2001/01/04 20:05:36 $
  + * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v 1.7 2001/01/12 06:50:06 remm Exp $
  + * $Revision: 1.7 $
  + * $Date: 2001/01/12 06:50:06 $
    *
    * ====================================================================
    *
  @@ -70,8 +70,11 @@
   import java.io.IOException;
   import java.util.ArrayList;
   import java.util.HashMap;
  +import java.util.Hashtable;
   import java.util.Iterator;
  +import javax.naming.directory.DirContext;
   import javax.servlet.ServletException;
  +import org.apache.naming.resources.ProxyDirContext;
   import org.apache.catalina.Container;
   import org.apache.catalina.ContainerEvent;
   import org.apache.catalina.ContainerListener;
  @@ -86,7 +89,6 @@
   import org.apache.catalina.Pipeline;
   import org.apache.catalina.Realm;
   import org.apache.catalina.Request;
  -import org.apache.catalina.Resources;
   import org.apache.catalina.Response;
   import org.apache.catalina.Valve;
   import org.apache.catalina.util.LifecycleSupport;
  @@ -150,7 +152,8 @@
    * class comments of the implementation class.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.6 $ $Date: 2001/01/04 20:05:36 $
  + * @author Remy Maucherat
  + * @version $Revision: 1.7 $ $Date: 2001/01/12 06:50:06 $
    */
   
   public abstract class ContainerBase
  @@ -257,9 +260,9 @@
   
   
       /**
  -     * The Resources object with which this Container is associated.
  +     * The resources DirContext object with which this Container is associated.
        */
  -    protected Resources resources = null;
  +    protected DirContext resources = null;
   
   
       /**
  @@ -725,11 +728,12 @@
   
   
       /**
  -     * Return the Resources with which this Container is associated.  If there
  -     * is no associated Resources object, return the Resources associated with
  -     * our parent Container (if any); otherwise return <code>null</code>.
  +     * Return the resources DirContext object with which this Container is 
  +     * associated.  If there is no associated resources object, return the 
  +     * resources associated with our parent Container (if any); otherwise 
  +     * return <code>null</code>.
        */
  -    public Resources getResources() {
  +    public DirContext getResources() {
   
   	if (resources != null)
   	    return (resources);
  @@ -741,41 +745,18 @@
   
   
       /**
  -     * Set the Resources object with which this Container is associated.
  +     * Set the resources DirContext object with which this Container is 
  +     * associated.
        *
  -     * @param resources The newly associated Resources
  +     * @param resources The newly associated DirContext
        */
  -    public synchronized void setResources(Resources resources) {
  +    public synchronized void setResources(DirContext resources) {
   
   	// Change components if necessary
  -	Resources oldResources = this.resources;
  +	DirContext oldResources = this.resources;
   	if (oldResources == resources)
   	    return;
  -	this.resources = resources;
  -
  -	// Stop the old component if necessary
  -	if (started && (oldResources != null) &&
  -	    (oldResources instanceof Lifecycle)) {
  -	    try {
  -		((Lifecycle) oldResources).stop();
  -	    } catch (LifecycleException e) {
  -		log("ContainerBase.setResources: stop: ", e);
  -	    }
  -	}
  -	if (oldResources != null)
  -	    oldResources.setContainer(null);
  -
  -	// Start the new component if necessary
  -	if (resources != null)
  -	    resources.setContainer(this);
  -	if (started && (resources != null) &&
  -	    (resources instanceof Lifecycle)) {
  -	    try {
  -		((Lifecycle) resources).start();
  -	    } catch (LifecycleException e) {
  -		log("ContainerBase.setResources: start: ", e);
  -	    }
  -	}
  +	this.resources = new ProxyDirContext(new Hashtable(), resources);
   
   	// Report this property change to interested listeners
   	support.firePropertyChange("resources", oldResources, this.resources);
  
  
  
  1.34      +64 -6     jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/StandardContext.java
  
  Index: StandardContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- StandardContext.java	2000/12/23 19:00:32	1.33
  +++ StandardContext.java	2001/01/12 06:50:06	1.34
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.33 2000/12/23 19:00:32 craigmcc Exp $
  - * $Revision: 1.33 $
  - * $Date: 2000/12/23 19:00:32 $
  + * $Header: /home/cvs/jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.34 2001/01/12 06:50:06 remm Exp $
  + * $Revision: 1.34 $
  + * $Date: 2001/01/12 06:50:06 $
    *
    * ====================================================================
    *
  @@ -88,6 +88,7 @@
   import javax.naming.NamingEnumeration;
   import javax.naming.Binding;
   import javax.naming.StringRefAddr;
  +import javax.naming.directory.DirContext;
   import org.apache.naming.NamingContext;
   import org.apache.naming.ContextBindings;
   import org.apache.naming.ContextAccessController;
  @@ -95,9 +96,12 @@
   import org.apache.naming.ResourceRef;
   import org.apache.naming.ResourceEnvRef;
   import org.apache.naming.TransactionRef;
  +import org.apache.naming.resources.FileDirContext;
  +import org.apache.naming.resources.BaseDirContext;
   import org.apache.catalina.Container;
   import org.apache.catalina.ContainerListener;
   import org.apache.catalina.Context;
  +import org.apache.catalina.Host;
   import org.apache.catalina.Globals;
   import org.apache.catalina.HttpRequest;
   import org.apache.catalina.InstanceListener;
  @@ -120,7 +124,6 @@
   import org.apache.catalina.deploy.SecurityCollection;
   import org.apache.catalina.deploy.SecurityConstraint;
   import org.apache.catalina.loader.StandardLoader;
  -import org.apache.catalina.resources.FileResources;
   import org.apache.catalina.session.StandardManager;
   import org.apache.catalina.util.CharsetMapper;
   import org.apache.catalina.util.RequestUtil;
  @@ -133,7 +136,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.33 $ $Date: 2000/12/23 19:00:32 $
  + * @version $Revision: 1.34 $ $Date: 2001/01/12 06:50:06 $
    */
   
   public class StandardContext
  @@ -900,6 +903,41 @@
       }
   
   
  +    /**
  +     * Set the resources DirContext object with which this Container is 
  +     * associated.
  +     *
  +     * @param resources The newly associated DirContext
  +     */
  +    public synchronized void setResources(DirContext resources) {
  +
  +        if (resources instanceof BaseDirContext) {
  +            String docBase = null;
  +            Container container = this;
  +            while (container != null) {
  +                if (container instanceof Host)
  +                    break;
  +                container = container.getParent();
  +            }
  +            if (container == null) {
  +                docBase = (new File(engineBase(), getDocBase())).getPath();
  +            } else {
  +                // Use the "appBase" property of this container
  +                String appBase = ((Host) container).getAppBase();
  +                File file = new File(appBase);
  +                if (!file.isAbsolute())
  +                    file = new File(engineBase(), appBase);
  +                docBase = (new File(file, getDocBase())).getPath();
  +            }
  +            ((BaseDirContext) resources).setDocBase(docBase);
  +        }
  +        super.setResources(resources);
  +        // We put the resources into the servlet context
  +        getServletContext().setAttribute(Globals.RESOURCES_ATTR, resources);
  +
  +    }
  +
  +
       // ------------------------------------------------------ Public Properties
   
   
  @@ -2887,7 +2925,7 @@
           if (getResources() == null) {   // (1) Required by Loader
               if (debug >= 1)
                   log("Configuring default Resources");
  -            setResources(new FileResources());
  +            setResources(new FileDirContext());
           }
           if (getLoader() == null) {      // (2) Required by Manager
               if (debug >= 1)
  @@ -3100,6 +3138,17 @@
       }
   
   
  +    /**
  +     * Return a File object representing the base directory for the
  +     * entire servlet container (i.e. the Engine container if present).
  +     */
  +    protected File engineBase() {
  +
  +	return (new File(System.getProperty("catalina.home")));
  +
  +    }
  +
  +
       // -------------------------------------------------------- Private Methods
   
   
  @@ -3236,9 +3285,18 @@
           try {
               Reference ref = new TransactionRef();
               compCtx.bind("UserTransaction", ref);
  +            addAdditionalParameters(ref, "UserTransaction");
           } catch (NamingException e) {
               log(sm.getString("standardContext.bindFailed", e));
           }
  +
  +        // Binding the resources directory context
  +        try {
  +            compCtx.bind("Resources", resources);
  +        } catch (NamingException e) {
  +            log(sm.getString("standardContext.bindFailed", e));
  +        }
  +
   
           // Setting the context in read only mode
           ContextAccessController.setReadOnly(getName());