You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/01/22 21:44:18 UTC
svn commit: r1654050 - in /tomcat/trunk: java/org/apache/catalina/
java/org/apache/catalina/webresources/ test/org/apache/catalina/webresources/
Author: markt
Date: Thu Jan 22 20:44:18 2015
New Revision: 1654050
URL: http://svn.apache.org/r1654050
Log:
Resource JARs should only be used for static resources. Block class loader resources.
Modified:
tomcat/trunk/java/org/apache/catalina/WebResourceSet.java
tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java
tomcat/trunk/java/org/apache/catalina/webresources/EmptyResourceSet.java
tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
tomcat/trunk/test/org/apache/catalina/webresources/TestResourceJars.java
Modified: tomcat/trunk/java/org/apache/catalina/WebResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/WebResourceSet.java?rev=1654050&r1=1654049&r2=1654050&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/WebResourceSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/WebResourceSet.java Thu Jan 22 20:44:18 2015
@@ -92,18 +92,33 @@ public interface WebResourceSet extends
void setRoot(WebResourceRoot root);
/**
- * Are resources provided by this resource set only intended for use by
- * calls to {@link WebResourceRoot#getClassLoaderResource(String)}.
+ * Should resources returned by this resource set only be included in any
+ * results when the lookup is explicitly looking for class loader resources.
+ * i.e. should these resources be excluded from look ups that are explicitly
+ * looking for static (non-class loader) resources.
*
* @return <code>true</code> if these resources should only be used for
- * calls to {@link WebResourceRoot#getClassLoaderResource(String)},
- * otherwise <code>false</code>
+ * class loader resource lookups, otherwise <code>false</code>
*/
boolean getClassLoaderOnly();
void setClassLoaderOnly(boolean classLoaderOnly);
/**
+ * Should resources returned by this resource set only be included in any
+ * results when the lookup is explicitly looking for static (non-class
+ * loader) resources. i.e. should these resources be excluded from look ups
+ * that are explicitly looking for class loader resources.
+ *
+ * @return <code>true</code> if these resources should only be used for
+ * static (non-class loader) resource lookups, otherwise
+ * <code>false</code>
+ */
+ boolean getStaticOnly();
+
+ void setStaticOnly(boolean staticOnly);
+
+ /**
* Obtain the base URL for this set of resources. One of the uses of this is
* to grant read permissions to the resources when running under a security
* manager.
Modified: tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java?rev=1654050&r1=1654049&r2=1654050&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/AbstractResourceSet.java Thu Jan 22 20:44:18 2015
@@ -31,6 +31,7 @@ public abstract class AbstractResourceSe
private String internalPath = "";
private String webAppMount;
private boolean classLoaderOnly;
+ private boolean staticOnly;
protected static final StringManager sm =
@@ -100,6 +101,16 @@ public abstract class AbstractResourceSe
this.classLoaderOnly = classLoaderOnly;
}
+ @Override
+ public boolean getStaticOnly() {
+ return staticOnly;
+ }
+
+ @Override
+ public void setStaticOnly(boolean staticOnly) {
+ this.staticOnly = staticOnly;
+ }
+
//-------------------------------------------------------- Lifecycle methods
@Override
protected final void startInternal() throws LifecycleException {
Modified: tomcat/trunk/java/org/apache/catalina/webresources/EmptyResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/EmptyResourceSet.java?rev=1654050&r1=1654049&r2=1654050&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/EmptyResourceSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/EmptyResourceSet.java Thu Jan 22 20:44:18 2015
@@ -40,6 +40,7 @@ public class EmptyResourceSet extends Li
private WebResourceRoot root;
private boolean classLoaderOnly;
+ private boolean staticOnly;
public EmptyResourceSet(WebResourceRoot root) {
this.root = root;
@@ -110,6 +111,16 @@ public class EmptyResourceSet extends Li
this.classLoaderOnly = classLoaderOnly;
}
+ @Override
+ public boolean getStaticOnly() {
+ return staticOnly;
+ }
+
+ @Override
+ public void setStaticOnly(boolean staticOnly) {
+ this.staticOnly = staticOnly;
+ }
+
/**
* {@inheritDoc}
* <p>
Modified: tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java?rev=1654050&r1=1654049&r2=1654050&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java (original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/StandardRoot.java Thu Jan 22 20:44:18 2015
@@ -276,7 +276,8 @@ public class StandardRoot extends Lifecy
WebResource mainEmpty = null;
for (List<WebResourceSet> list : allResources) {
for (WebResourceSet webResourceSet : list) {
- if (useClassLoaderResources || !webResourceSet.getClassLoaderOnly()) {
+ if (!useClassLoaderResources && !webResourceSet.getClassLoaderOnly() ||
+ useClassLoaderResources && !webResourceSet.getStaticOnly()) {
result = webResourceSet.getResource(path);
if (result.exists()) {
return result;
@@ -421,6 +422,8 @@ public class StandardRoot extends Lifecy
if (type.equals(ResourceSetType.CLASSES_JAR)) {
resourceSet.setClassLoaderOnly(true);
+ } else if (type.equals(ResourceSetType.RESOURCE_JAR)) {
+ resourceSet.setStaticOnly(true);
}
resourceList.add(resourceSet);
Modified: tomcat/trunk/test/org/apache/catalina/webresources/TestResourceJars.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/webresources/TestResourceJars.java?rev=1654050&r1=1654049&r2=1654050&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/webresources/TestResourceJars.java (original)
+++ tomcat/trunk/test/org/apache/catalina/webresources/TestResourceJars.java Thu Jan 22 20:44:18 2015
@@ -19,7 +19,6 @@ package org.apache.catalina.webresources
import java.io.File;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
import org.apache.catalina.WebResource;
@@ -27,7 +26,6 @@ import org.apache.catalina.WebResourceSe
public class TestResourceJars {
- @Ignore // This test currenty fails. A fix is in hand...
@Test
public void testNonStaticResources() {
File empty = new File("test/webresources/dir3");
@@ -43,6 +41,7 @@ public class TestResourceJars {
// would be added
JarResourceSet test =
new JarResourceSet(root, "/", jar.getAbsolutePath(), "/META-INF/resources");
+ test.setStaticOnly(true);
root.addJarResources(test);
WebResource resource = root.getClassLoaderResource("/org/apache/tomcat/unittest/foo.txt");
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org