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/04/06 21:32:03 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources DirContextURLConnection.java ProxyDirContext.java

remm        01/04/06 12:32:03

  Modified:    catalina/src/share/org/apache/naming/resources
                        DirContextURLConnection.java ProxyDirContext.java
  Log:
  - Fix for bug 1219. It makes the URLs generated more unique, to avoid confusing
    the JDK's JAR URL cache.
  
  Revision  Changes    Path
  1.6       +25 -7     jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLConnection.java
  
  Index: DirContextURLConnection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLConnection.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DirContextURLConnection.java	2001/03/31 14:06:31	1.5
  +++ DirContextURLConnection.java	2001/04/06 19:31:59	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLConnection.java,v 1.5 2001/03/31 14:06:31 glenn Exp $
  - * $Revision: 1.5 $
  - * $Date: 2001/03/31 14:06:31 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLConnection.java,v 1.6 2001/04/06 19:31:59 remm Exp $
  + * $Revision: 1.6 $
  + * $Date: 2001/04/06 19:31:59 $
    *
    * ====================================================================
    *
  @@ -91,7 +91,7 @@
    * content is directly returned.
    * 
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class DirContextURLConnection 
       extends URLConnection {
  @@ -105,7 +105,7 @@
           if (context == null)
               throw new IllegalArgumentException
                   ("Directory context can't be null");
  -        this.permission = new FilePermission(url.toString(),"read");
  +        this.permission = new FilePermission(url.toString(), "read");
           this.context = context;
       }
       
  @@ -172,8 +172,26 @@
               
               try {
                   date = System.currentTimeMillis();
  -                object = context.lookup(getURL().getFile());
  -                attributes = context.getAttributes(getURL().getFile());
  +                String path = getURL().getFile();
  +                if (context instanceof ProxyDirContext) {
  +                    ProxyDirContext proxyDirContext = 
  +                        (ProxyDirContext) context;
  +                    String hostName = proxyDirContext.getHostName();
  +                    String contextName = proxyDirContext.getContextName();
  +                    if (hostName != null) {
  +                        if (!url.getHost().equalsIgnoreCase(hostName))
  +                            return;
  +                    }
  +                    if (contextName != null) {
  +                        if (!path.startsWith(contextName)) {
  +                            return;
  +                        } else {
  +                            path = path.substring(contextName.length());
  +                        }
  +                    }
  +                }
  +                object = context.lookup(path);
  +                attributes = context.getAttributes(path);
                   if (object instanceof Resource)
                       resource = (Resource) object;
                   if (object instanceof DirContext)
  
  
  
  1.3       +49 -4     jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/ProxyDirContext.java
  
  Index: ProxyDirContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/ProxyDirContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProxyDirContext.java	2001/02/05 05:10:00	1.2
  +++ ProxyDirContext.java	2001/04/06 19:32:00	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/ProxyDirContext.java,v 1.2 2001/02/05 05:10:00 remm Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/02/05 05:10:00 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/ProxyDirContext.java,v 1.3 2001/04/06 19:32:00 remm Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/04/06 19:32:00 $
    *
    * ====================================================================
    *
  @@ -84,7 +84,7 @@
    * Proxy Directory Context implementation.
    *
    * @author Remy Maucherat
  - * @version $Revision: 1.2 $ $Date: 2001/02/05 05:10:00 $
  + * @version $Revision: 1.3 $ $Date: 2001/04/06 19:32:00 $
    */
   
   public class ProxyDirContext implements DirContext {
  @@ -93,6 +93,10 @@
       // -------------------------------------------------------------- Constants
   
   
  +    public static final String CONTEXT = "context";
  +    public static final String HOST = "host";
  +
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -110,6 +114,8 @@
                   cacheTTL = ((BaseDirContext) dirContext).getCacheTTL();
               }
           }
  +        hostName = (String) env.get(HOST);
  +        contextName = (String) env.get(CONTEXT);
       }
   
   
  @@ -135,6 +141,18 @@
   
   
       /**
  +     * Host name.
  +     */
  +    protected String hostName;
  +
  +
  +    /**
  +     * Context name.
  +     */
  +    protected String contextName;
  +
  +
  +    /**
        * Cache.
        * Path -> Cache entry.
        */
  @@ -148,6 +166,33 @@
   
   
       // --------------------------------------------------------- Public Methods
  +
  +
  +    /**
  +     * Return the document root for this component.
  +     */
  +    public String getDocBase() {
  +        if (dirContext instanceof BaseDirContext)
  +            return ((BaseDirContext) dirContext).getDocBase();
  +        else
  +            return "";
  +    }
  +
  +
  +    /**
  +     * Return the host name.
  +     */
  +    public String getHostName() {
  +        return this.hostName;
  +    }
  +
  +
  +    /**
  +     * Return the context name.
  +     */
  +    public String getContextName() {
  +        return this.contextName;
  +    }
   
   
       // -------------------------------------------------------- Context Methods