The assumption that contexts will always be file system based or that resources will...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 9 Nov 2009 20:43:47 +0000 (20:43 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 9 Nov 2009 20:43:47 +0000 (20:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@834220 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/ApplicationContext.java
java/org/apache/catalina/core/StandardContext.java
java/org/apache/catalina/ha/context/ReplicatedContext.java
java/org/apache/catalina/startup/DefaultJarScanner.java

index 45499d6..0f939f3 100644 (file)
@@ -19,7 +19,6 @@
 package org.apache.catalina.core;
 
 
-import java.io.File;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -90,10 +89,9 @@ public class ApplicationContext
      *
      * @param context The associated Context instance
      */
-    public ApplicationContext(String basePath, StandardContext context) {
+    public ApplicationContext(StandardContext context) {
         super();
         this.context = context;
-        this.basePath = basePath;
         
         // Populate session tracking modes
         populateSessionTrackingModes();
@@ -158,12 +156,6 @@ public class ApplicationContext
 
 
     /**
-     * Base path.
-     */
-    private String basePath = null;
-
-
-    /**
      * Thread local data used during request dispatch.
      */
     private ThreadLocal<DispatchData> dispatchData =
@@ -492,37 +484,21 @@ public class ApplicationContext
             throw new MalformedURLException(sm.getString("applicationContext.requestDispatcher.iae", path));
 
         
-        path = RequestUtil.normalize(path);
-        if (path == null)
+        String normPath = RequestUtil.normalize(path);
+        if (normPath == null)
             return (null);
 
-        String libPath = "/WEB-INF/lib/";
-        if ((path.startsWith(libPath)) && (path.endsWith(".jar"))) {
-            File jarFile = null;
-            if (context.isFilesystemBased()) {
-                jarFile = new File(basePath, path);
-            } else {
-                jarFile = new File(context.getWorkPath(), path);
-            }
-            if (jarFile.exists()) {
-                return jarFile.toURI().toURL();
-            } else {
-                return null;
-            }
-        } else {
-
-            DirContext resources = context.getResources();
-            if (resources != null) {
-                String fullPath = context.getName() + path;
-                String hostName = context.getParent().getName();
-                try {
-                    resources.lookup(path);
-                    return new URL
-                        ("jndi", "", 0, getJNDIUri(hostName, fullPath),
-                         new DirContextURLStreamHandler(resources));
-                } catch (Exception e) {
-                    // Ignore
-                }
+        DirContext resources = context.getResources();
+        if (resources != null) {
+            String fullPath = context.getName() + normPath;
+            String hostName = context.getParent().getName();
+            try {
+                resources.lookup(path);
+                return new URL
+                    ("jndi", "", 0, getJNDIUri(hostName, fullPath),
+                     new DirContextURLStreamHandler(resources));
+            } catch (Exception e) {
+                // Ignore
             }
         }
 
index da9569f..7a1e27e 100644 (file)
@@ -1758,7 +1758,7 @@ public class StandardContext
     public ServletContext getServletContext() {
 
         if (context == null) {
-            context = new ApplicationContext(getBasePath(), this);
+            context = new ApplicationContext(this);
             if (altDDName != null)
                 context.setAttribute(Globals.ALT_DD_ATTR,altDDName);
         }
index 424afef..73f6ae7 100644 (file)
@@ -54,7 +54,7 @@ public class ReplicatedContext extends StandardContext implements LifecycleListe
         super.addLifecycleListener(this);            
         try {
             CatalinaCluster catclust = (CatalinaCluster)this.getCluster();
-            if (this.context == null) this.context = new ReplApplContext(this.getBasePath(), this);
+            if (this.context == null) this.context = new ReplApplContext(this);
             if ( catclust != null ) {
                 ReplicatedMap map = new ReplicatedMap(this,catclust.getChannel(),DEFAULT_REPL_TIMEOUT,
                                                       getName(),getClassLoaders());
@@ -116,7 +116,7 @@ public class ReplicatedContext extends StandardContext implements LifecycleListe
     @Override
     public ServletContext getServletContext() {
         if (context == null) {
-            context = new ReplApplContext(getBasePath(), this);
+            context = new ReplApplContext(this);
             if (getAltDDName() != null)
                 context.setAttribute(Globals.ALT_DD_ATTR,getAltDDName());
         }
@@ -130,8 +130,8 @@ public class ReplicatedContext extends StandardContext implements LifecycleListe
         protected ConcurrentHashMap<String, Object> tomcatAttributes =
             new ConcurrentHashMap<String, Object>();
         
-        public ReplApplContext(String basePath, ReplicatedContext context) {
-            super(basePath,context);
+        public ReplApplContext(ReplicatedContext context) {
+            super(context);
         }
         
         protected ReplicatedContext getParent() {
index 0bbf571..62783af 100644 (file)
@@ -163,7 +163,7 @@ public class DefaultJarScanner implements JarScanner {
             callback.scan((JarURLConnection) conn);
         } else {
             String urlStr = url.toString();
-            if (urlStr.startsWith("file:")) {
+            if (urlStr.startsWith("file:") || urlStr.startsWith("jndi:")) {
                 if (urlStr.endsWith(JAR_EXT)) {
                     URL jarURL = new URL("jar:" + urlStr + "!/");
                     callback.scan((JarURLConnection) jarURL.openConnection());