From 605594ab15bc13e075d47df3691f47e08a251af4 Mon Sep 17 00:00:00 2001 From: markt Date: Mon, 9 Nov 2009 20:43:47 +0000 Subject: [PATCH] The assumption that contexts will always be file system based or that resources will always be extracted to the work does not hold true, particularly for custom DirContext implementations. Don't make the assumption and clean-up up the redundant field that is no longer required. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@834220 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/catalina/core/ApplicationContext.java | 52 ++++++---------------- java/org/apache/catalina/core/StandardContext.java | 2 +- .../catalina/ha/context/ReplicatedContext.java | 8 ++-- .../apache/catalina/startup/DefaultJarScanner.java | 2 +- 4 files changed, 20 insertions(+), 44 deletions(-) diff --git a/java/org/apache/catalina/core/ApplicationContext.java b/java/org/apache/catalina/core/ApplicationContext.java index 45499d670..0f939f360 100644 --- a/java/org/apache/catalina/core/ApplicationContext.java +++ b/java/org/apache/catalina/core/ApplicationContext.java @@ -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 = @@ -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 } } diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index da9569f1e..7a1e27e45 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -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); } diff --git a/java/org/apache/catalina/ha/context/ReplicatedContext.java b/java/org/apache/catalina/ha/context/ReplicatedContext.java index 424afefd6..73f6ae708 100644 --- a/java/org/apache/catalina/ha/context/ReplicatedContext.java +++ b/java/org/apache/catalina/ha/context/ReplicatedContext.java @@ -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 tomcatAttributes = new ConcurrentHashMap(); - public ReplApplContext(String basePath, ReplicatedContext context) { - super(basePath,context); + public ReplApplContext(ReplicatedContext context) { + super(context); } protected ReplicatedContext getParent() { diff --git a/java/org/apache/catalina/startup/DefaultJarScanner.java b/java/org/apache/catalina/startup/DefaultJarScanner.java index 0bbf571b7..62783af07 100644 --- a/java/org/apache/catalina/startup/DefaultJarScanner.java +++ b/java/org/apache/catalina/startup/DefaultJarScanner.java @@ -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()); -- 2.11.0