geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: rev 54968 - in geronimo/trunk/modules/jetty/src: java/org/apache/geronimo/jetty test-resources/deployables/cltest test-resources/deployables/cltest/javax test-resources/deployables/cltest/javax/foo test-resources/deployables/cltest/javax/servlet test-resources/deployables/cltest/mx4j test/org/apache/geronimo/jetty
Date Sun, 17 Oct 2004 17:36:21 GMT
Author: ammulder
Date: Sun Oct 17 10:36:20 2004
New Revision: 54968

Added:
   geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/
   geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/javax/
   geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/javax/foo/
   geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/javax/foo/Foo.class
  (contents, props changed)
   geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/javax/servlet/
   geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/javax/servlet/Servlet.class
  (contents, props changed)
   geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/mx4j/
   geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/mx4j/MBeanDescription.class
  (contents, props changed)
   geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java
Modified:
   geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyClassLoader.java
Log:
Update the Jetty CL to allow loading of javax.* classes that were
  not defined in the parent ClassLoader.
Add tests for various ClassLoading scenarios.


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 10:36:20 2004
@@ -39,7 +39,13 @@
     }
 
     public Class loadClass(String name) throws ClassNotFoundException {
-        if (!contextPriorityClassLoader) {
+        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.")) {
             return super.loadClass(name);
         }
 
@@ -63,7 +69,13 @@
     }
 
     public URL getResource(String name) {
-        if (!contextPriorityClassLoader) {
+        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.")) {
             return super.getResource(name);
         }
 
@@ -75,31 +87,5 @@
 
         // that didn't work... try the parent
         return parent.getResource(name);
-    }
-
-    protected Class findClass(String name) throws ClassNotFoundException {
-        if (name.startsWith("java.") ||
-                name.startsWith("javax.") ||
-                // todo we can't enable this because geronimo demo and tools are in this
package
-                // name.startsWith("org.apache.geronimo.") ||
-                name.startsWith("org.mortbay.") ||
-                name.startsWith("org.xml.") ||
-                name.startsWith("org.w3c.")) {
-            throw new ClassNotFoundException(name);
-        }
-        return super.findClass(name);
-    }
-
-    public URL findResource(String name) {
-        if (name.startsWith("java/") ||
-                name.startsWith("javax/") ||
-                // todo we can't enable this because geronimo demo and tools are in this
package
-                // name.startsWith("org/apache/geronimo/") ||
-                name.startsWith("org/mortbay/") ||
-                name.startsWith("org/xml/") ||
-                name.startsWith("org/w3c/")) {
-            return null;
-        }
-        return super.findResource(name);
     }
 }

Added: geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/javax/foo/Foo.class
==============================================================================
Binary file. No diff available.

Added: geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/javax/servlet/Servlet.class
==============================================================================
Binary file. No diff available.

Added: geronimo/trunk/modules/jetty/src/test-resources/deployables/cltest/mx4j/MBeanDescription.class
==============================================================================
Binary file. No diff available.

Added: geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ClassLoaderTest.java	Sun
Oct 17 10:36:20 2004
@@ -0,0 +1,125 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.jetty;
+
+import java.net.URL;
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev: 54805 $ $Date: 2004-10-14 17:51:13 -0400 (Thu, 14 Oct 2004) $
+ */
+public class ClassLoaderTest extends TestCase {
+    JettyClassLoader cl;
+    URL[] urls;
+
+    public void setUp() {
+        URL url = getClass().getClassLoader().getResource("deployables/cltest/");
+        System.err.println("URL: "+url);
+        urls = new URL[]{url};
+    }
+
+    /**
+     * Tries to load a javax.* class that's not available from the
+     * parent ClassLoader.  This should work.
+     */
+    public void testFalseNonexistantJavaxClass() {
+        cl = new JettyClassLoader(urls, getClass().getClassLoader(), false);
+        try {
+            cl.loadClass("javax.foo.Foo");
+        } catch(ClassNotFoundException e) {
+            fail("Should be able to load a javax.* class that is not defined by my parent
CL");
+        }
+    }
+
+    /**
+     * Tries to load a javax.* class that's not available from the
+     * parent ClassLoader.  This should work.
+     */
+    public void testTrueNonexistantJavaxClass() {
+        cl = new JettyClassLoader(urls, getClass().getClassLoader(), true);
+        try {
+            cl.loadClass("javax.foo.Foo");
+        } catch(ClassNotFoundException e) {
+            fail("Should be able to load a javax.* class that is not defined by my parent
CL");
+        }
+    }
+
+    /**
+     * 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 testFalseExistantJavaxClass() {
+        cl = new JettyClassLoader(urls, getClass().getClassLoader(), false);
+        try {
+            Class cls = cl.loadClass("javax.servlet.Servlet");
+            assertTrue("Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",cls.getDeclaredMethods().length
> 0);
+        } catch(ClassNotFoundException e) {
+            fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
+        }
+    }
+
+    /**
+     * 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 testTrueExistantJavaxClass() {
+        cl = new JettyClassLoader(urls, getClass().getClassLoader(), true);
+        try {
+            Class cls = cl.loadClass("javax.servlet.Servlet");
+            assertTrue("Loaded wrong class first; expected to find parent CL's copy of javax.servlet.Servlet",cls.getDeclaredMethods().length
> 0);
+        } catch(ClassNotFoundException e) {
+            fail("Problem with test; expecting to have javax.servlet.* on the ClassPath");
+        }
+    }
+
+    /**
+     * 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 testFalseExistantNonJavaxClass() {
+        cl = new JettyClassLoader(urls, getClass().getClassLoader(), false);
+        try {
+            Class cls = cl.loadClass("mx4j.MBeanDescription");
+            assertTrue("Should not have overriden parent CL definition of class mx4j.MBeanDescription",
cls.getDeclaredMethods().length > 0);
+        } catch(ClassNotFoundException e) {
+            fail("Problem with test; expecting to have mx4j.* on the ClassPath");
+        }
+    }
+
+    /**
+     * 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 testTrueExistantNonJavaxClass() {
+        cl = new JettyClassLoader(urls, getClass().getClassLoader(), true);
+        try {
+            Class cls = cl.loadClass("mx4j.MBeanDescription");
+            assertTrue("Should be able to override a class that is not in java.*, javax.*,
etc.", cls.getDeclaredMethods().length == 0);
+        } catch(ClassNotFoundException e) {
+            fail("Problem with test; expecting to have mx4j.* on the ClassPath");
+        }
+    }
+}

Mime
View raw message