Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 83015 invoked from network); 17 Oct 2004 19:41:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 17 Oct 2004 19:41:21 -0000 Received: (qmail 13292 invoked by uid 500); 17 Oct 2004 19:41:20 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 13272 invoked by uid 500); 17 Oct 2004 19:41:19 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@geronimo.apache.org Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 13259 invoked by uid 99); 17 Oct 2004 19:41:19 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 17 Oct 2004 12:41:19 -0700 Received: (qmail 82996 invoked by uid 65534); 17 Oct 2004 19:41:18 -0000 Date: 17 Oct 2004 19:41:18 -0000 Message-ID: <20041017194118.82993.qmail@minotaur.apache.org> From: ammulder@apache.org To: scm@geronimo.apache.org Subject: svn commit: rev 54972 - in geronimo/trunk/modules/jetty/src: java/org/apache/geronimo/jetty test/org/apache/geronimo/jetty X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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"); } }