You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by am...@apache.org on 2004/10/17 21:41:18 UTC
svn commit: rev 54972 - in geronimo/trunk/modules/jetty/src: java/org/apache/geronimo/jetty test/org/apache/geronimo/jetty
Author: ammulder
Date: Sun Oct 17 12:41:17 2004
New Revision: 54972
Modified:
geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyClassLoader.java
geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java
Log:
Whoops, didn't mean to mangle the slashes in the resource tests
Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyClassLoader.java
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyClassLoader.java (original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyClassLoader.java Sun Oct 17 12:41:17 2004
@@ -70,12 +70,12 @@
public URL getResource(String name) {
if (!contextPriorityClassLoader ||
- name.startsWith("java.") ||
- name.startsWith("javax.") ||
- name.startsWith("org.apache.geronimo.") ||
- name.startsWith("org.mortbay.") ||
- name.startsWith("org.xml.") ||
- name.startsWith("org.w3c.")) {
+ name.startsWith("java/") ||
+ name.startsWith("javax/") ||
+ name.startsWith("org/apache/geronimo/") ||
+ name.startsWith("org/mortbay/") ||
+ name.startsWith("org/xml/") ||
+ name.startsWith("org/w3c/")) {
return super.getResource(name);
}
Modified: geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java
==============================================================================
--- geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java (original)
+++ geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java Sun Oct 17 12:41:17 2004
@@ -21,6 +21,10 @@
import junit.framework.TestCase;
/**
+ * Tests loading various classes (as classes and URL resources) with different
+ * settings for contextPriorityClassLoader to make sure the restrictions on
+ * javax.* class loading are honored.
+ *
* @version $Rev: 54805 $ $Date: 2004-10-14 17:51:13 -0400 (Thu, 14 Oct 2004) $
*/
public class ClassLoaderTest extends TestCase {
@@ -33,6 +37,8 @@
urls = new URL[]{url};
}
+ //todo: try more restricted prefixed besides javax.*
+
/**
* Tries to load a javax.* class that's not available from the
* parent ClassLoader. This should work.
@@ -121,5 +127,91 @@
} catch(ClassNotFoundException e) {
fail("Problem with test; expecting to have mx4j.* on the ClassPath");
}
+ }
+
+ /**
+ * Tries to load a javax.* class that's not available from the
+ * parent ClassLoader. This should work.
+ */
+ public void testFalseNonexistantJavaxResource() {
+ cl = new JettyClassLoader(urls, getClass().getClassLoader(), false);
+ URL url = cl.getResource("javax/foo/Foo.class");
+ if(url == null) {
+ fail("Should be able to load a javax.* class that is not defined by my parent CL");
+ }
+ assertEquals(url.getProtocol(), "file");
+ }
+
+ /**
+ * Tries to load a javax.* class that's not available from the
+ * parent ClassLoader. This should work.
+ */
+ public void testTrueNonexistantJavaxResource() {
+ cl = new JettyClassLoader(urls, getClass().getClassLoader(), true);
+ URL url = cl.getResource("javax/foo/Foo.class");
+ if(url == null) {
+ fail("Should be able to load a javax.* class that is not defined by my parent CL");
+ }
+ assertEquals(url.getProtocol(), "file");
+ }
+
+ /**
+ * Tries to load a javax.* class that is avialable from the parent ClassLoader,
+ * when there's a different definition available from this ClassLoader too.
+ * This should always load the parent's copy.
+ */
+ public void testFalseExistantJavaxResource() {
+ cl = new JettyClassLoader(urls, getClass().getClassLoader(), false);
+ URL url = cl.getResource("javax/servlet/Servlet.class");
+ if(url == null) {
+ fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
+ }
+ assertEquals("Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet", url.getProtocol(), "jar");
+ }
+
+ /**
+ * Tries to load a javax.* class that is avialable from the parent ClassLoader,
+ * when there's a different definition available from this ClassLoader too.
+ * This should always load the parent's copy.
+ */
+ public void testTrueExistantJavaxResource() {
+ cl = new JettyClassLoader(urls, getClass().getClassLoader(), true);
+ URL url = cl.getResource("javax/servlet/Servlet.class");
+ if(url == null) {
+ fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
+ }
+ assertEquals("Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",url.getProtocol(),"jar");
+ }
+
+ /**
+ * Tries to load a non-javax.* class that is aailable form the parent
+ * ClassLoader, when there's a different definition available from this
+ * ClassLoader. This should load the parent's copy when
+ * contextPriorityClassLoader is set to false (as here) and the child's
+ * copy when the contextPriorityClassLoader is set to true.
+ */
+ public void testFalseExistantNonJavaxResource() {
+ cl = new JettyClassLoader(urls, getClass().getClassLoader(), false);
+ URL url = cl.getResource("mx4j/MBeanDescription.class");
+ if(url == null) {
+ fail("Problem with test; expecting to have mx4j.* on the ClassPath");
+ }
+ assertEquals("Should not have overriden parent CL definition of class mx4j.MBeanDescription", url.getProtocol(), "jar");
+ }
+
+ /**
+ * Tries to load a non-javax.* class that is aailable form the parent
+ * ClassLoader, when there's a different definition available from this
+ * ClassLoader. This should load the parent's copy when
+ * contextPriorityClassLoader is set to false and the child's copy when
+ * the contextPriorityClassLoader is set to true (as here).
+ */
+ public void testTrueExistantNonJavaxResource() {
+ cl = new JettyClassLoader(urls, getClass().getClassLoader(), true);
+ URL url = cl.getResource("mx4j/MBeanDescription.class");
+ if(url == null) {
+ fail("Problem with test; expecting to have mx4j.* on the ClassPath");
+ }
+ assertEquals("Should be able to override a class that is not in java.*, javax.*, etc.", url.getProtocol(), "file");
}
}