geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: rev 53935 - in geronimo/trunk/modules/jetty/src: java/org/apache/geronimo/jetty java/org/apache/geronimo/jetty/deployment test/org/apache/geronimo/jetty
Date Thu, 07 Oct 2004 05:32:35 GMT
Author: dain
Date: Wed Oct  6 22:32:34 2004
New Revision: 53935

Added:
   geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyClassLoader.java
Modified:
   geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
   geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppJACCContext.java
   geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
   geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java
   geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java
Log:
Added back support for child first class loading


Added: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyClassLoader.java
==============================================================================
--- (empty file)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyClassLoader.java
Wed Oct  6 22:32:34 2004
@@ -0,0 +1,105 @@
+/**
+ *
+ * Copyright 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 java.net.URLClassLoader;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JettyClassLoader extends URLClassLoader {
+    private final boolean contextPriorityClassLoader;
+    private final ClassLoader parent;
+
+    public JettyClassLoader(URL[] urls, ClassLoader parent, boolean contextPriorityClassLoader)
{
+        super(urls, parent);
+
+        if (parent == null) {
+            throw new IllegalArgumentException("Parent class loader is null");
+        }
+
+        // hold on to the parent so we don't have to go throught the security check each
time
+        this.parent = parent;
+        this.contextPriorityClassLoader = contextPriorityClassLoader;
+    }
+
+    public Class loadClass(String name) throws ClassNotFoundException {
+        if (!contextPriorityClassLoader) {
+            return super.loadClass(name);
+        }
+
+        // first check if this class has already been loaded
+        Class clazz = findLoadedClass(name);
+        if (clazz != null) {
+            return clazz;
+        }
+
+        // try to load the class from this class loader
+        try {
+            clazz = findClass(name);
+        } catch (ClassNotFoundException ignored) {
+        }
+        if (clazz != null) {
+            return clazz;
+        }
+
+        // that didn't work... try the parent
+        return parent.loadClass(name);
+    }
+
+    public URL getResource(String name) {
+        if (!contextPriorityClassLoader) {
+            return super.getResource(name);
+        }
+
+        // try to load the resource from this class loader
+        URL url = findResource(name);
+        if (url != null) {
+            return url;
+        }
+
+        // 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);
+    }
+}

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppContext.java
Wed Oct  6 22:32:34 2004
@@ -21,7 +21,6 @@
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URL;
-import java.net.URLClassLoader;
 import java.util.Set;
 import javax.resource.ResourceException;
 
@@ -61,7 +60,6 @@
     private final TrackedConnectionAssociator trackedConnectionAssociator;
     private final JettyContainer jettyContainer;
 
-    private boolean contextPriorityClassLoader = false;
     private final URI webAppRoot;
 
     /**
@@ -84,6 +82,7 @@
             UserTransactionImpl userTransaction,
             ClassLoader classLoader,
             URI[] webClassPath,
+            boolean contextPriorityClassLoader,
             URL configurationBaseUrl,
             Set unshareableResources,
             Set applicationManagedSecurityResources,
@@ -121,43 +120,8 @@
             classPathEntry = webAppRoot.resolve(classPathEntry);
             urls[i] = classPathEntry.toURL();
         }
-        this.classLoader = new URLClassLoader(urls, classLoader);
-    }
-
-    /**
-     * getContextPriorityClassLoader.
-     *
-     * @return True if this context should give web application class in preference over
the containers
-     *         classes, as per the servlet specification recommendations.
-     */
-    public boolean getContextPriorityClassLoader() {
-        return contextPriorityClassLoader;
-    }
-
-    /**
-     * setContextPriorityClassLoader.
-     *
-     * @param b True if this context should give web application class in preference over
the containers
-     * classes, as per the servlet specification recommendations.
-     */
-    public void setContextPriorityClassLoader(boolean b) {
-        contextPriorityClassLoader = b;
-    }
-
-    /**
-     * init the classloader. Uses the value of contextPriorityClassLoader to
-     * determine if the context needs to create its own classloader.
-     */
-    protected void initClassLoader(boolean forceContextLoader) throws MalformedURLException,
IOException {
-        setClassLoader(classLoader);
-
-        // todo this has no effect since our classloader is not a Jetty context loader
-        setClassLoaderJava2Compliant(!contextPriorityClassLoader);
-        super.initClassLoader(forceContextLoader);
-
-        if (log.isDebugEnabled()) {
-            log.debug("classloader for " + getContextPath() + ": " + getClassLoader());
-        }
+        this.classLoader = new JettyClassLoader(urls, classLoader, contextPriorityClassLoader);
+        setClassLoader(this.classLoader);
     }
 
     public void handle(String pathInContext,
@@ -218,6 +182,9 @@
     }
 
     public void doStart() throws WaitingException, Exception {
+        // reset the classsloader... jetty likes to set it to null when stopping
+        setClassLoader(classLoader);
+
         // merge Geronimo and Jetty Lifecycles
         if (!isStarting()) {
             super.start();
@@ -376,12 +343,12 @@
         infoFactory.addAttribute("userTransaction", UserTransactionImpl.class, true);
         infoFactory.addAttribute("classLoader", ClassLoader.class, false);
         infoFactory.addAttribute("webClassPath", URI[].class, true);
+        infoFactory.addAttribute("contextPriorityClassLoader", boolean.class, true);
         infoFactory.addAttribute("configurationBaseUrl", URL.class, true);
         infoFactory.addAttribute("unshareableResources", Set.class, true);
         infoFactory.addAttribute("applicationManagedSecurityResources", Set.class, true);
 
         infoFactory.addAttribute("contextPath", String.class, true);
-        infoFactory.addAttribute("contextPriorityClassLoader", Boolean.TYPE, true);
 
         infoFactory.addReference("TransactionContextManager", TransactionContextManager.class);
         infoFactory.addReference("TrackedConnectionAssociator", TrackedConnectionAssociator.class);
@@ -393,6 +360,7 @@
             "userTransaction",
             "classLoader",
             "webClassPath",
+            "contextPriorityClassLoader",
             "configurationBaseUrl",
             "unshareableResources",
             "applicationManagedSecurityResources",

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppJACCContext.java
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppJACCContext.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebAppJACCContext.java
Wed Oct  6 22:32:34 2004
@@ -101,6 +101,7 @@
             UserTransactionImpl userTransaction,
             ClassLoader classLoader,
             URI[] webClassPath,
+            boolean contextPriorityClassLoader,
             URL configurationBaseUrl,
             Set unshareableResources,
             Set applicationManagedSecurityResources,
@@ -115,6 +116,7 @@
                 userTransaction,
                 classLoader,
                 webClassPath,
+                contextPriorityClassLoader,
                 configurationBaseUrl,
                 unshareableResources,
                 applicationManagedSecurityResources,
@@ -503,6 +505,7 @@
             "userTransaction",
             "classLoader",
             "webClassPath",
+            "contextPriorityClassLoader",
             "configurationBaseUrl",
             "unshareableResources",
             "applicationManagedSecurityResources",

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
Wed Oct  6 22:32:34 2004
@@ -18,20 +18,19 @@
 package org.apache.geronimo.jetty.deployment;
 
 import java.io.File;
-import java.io.IOException;
 import java.io.FileFilter;
+import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.net.MalformedURLException;
-import java.net.URLClassLoader;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.LinkedList;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 import javax.management.AttributeNotFoundException;
@@ -50,6 +49,7 @@
 import org.apache.geronimo.j2ee.deployment.Module;
 import org.apache.geronimo.j2ee.deployment.ModuleBuilder;
 import org.apache.geronimo.j2ee.deployment.WebModule;
+import org.apache.geronimo.jetty.JettyClassLoader;
 import org.apache.geronimo.jetty.JettyWebAppContext;
 import org.apache.geronimo.jetty.JettyWebAppJACCContext;
 import org.apache.geronimo.naming.deployment.ENCConfigBuilder;
@@ -254,6 +254,9 @@
     public String addGBeans(EARContext earContext, Module module, ClassLoader cl) throws
DeploymentException {
         WebModule webModule = (WebModule) module;
 
+        WebAppType webApp = (WebAppType) webModule.getSpecDD();
+        JettyWebAppType jettyWebApp = (JettyWebAppType) webModule.getVendorDD();
+
         // construct the webClassLoader
         URI[] webClassPath = getWebClassPath(earContext, webModule);
         URI baseUri = earContext.getTargetFile(URI.create(webModule.getTargetPath() + "/")).toURI();
@@ -266,11 +269,12 @@
                 throw new DeploymentException("Invalid web class path element: path=" + path
+ ", baseUri=" + baseUri);
             }
         }
-        ClassLoader webClassLoader = new URLClassLoader(webClassPathURLs, cl);
 
-
-        WebAppType webApp = (WebAppType) webModule.getSpecDD();
-        JettyWebAppType jettyWebApp = (JettyWebAppType) webModule.getVendorDD();
+        boolean contextPriorityClassLoader = false;
+        if (jettyWebApp != null) {
+            contextPriorityClassLoader = Boolean.valueOf(jettyWebApp.getContextPriorityClassloader()).booleanValue();
+        }
+        ClassLoader webClassLoader = new JettyClassLoader(webClassPathURLs, cl, contextPriorityClassLoader);
 
         if (jettyWebApp != null) {
             JettyGbeanType[] gbeans = jettyWebApp.getGbeanArray();
@@ -321,7 +325,7 @@
             setResourceEnvironment(gbean, webApp.getResourceRefArray(), jettyWebApp.getResourceRefArray());
 
             gbean.setAttribute("contextPath", webModule.getContextRoot());
-            gbean.setAttribute("contextPriorityClassLoader", Boolean.valueOf(jettyWebApp.getContextPriorityClassloader()));
+            gbean.setAttribute("contextPriorityClassLoader", Boolean.valueOf(contextPriorityClassLoader));
 
             gbean.setReferencePattern("TransactionContextManager", earContext.getTransactionContextManagerObjectName());
             gbean.setReferencePattern("TrackedConnectionAssociator", earContext.getConnectionTrackerObjectName());

Modified: geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java
==============================================================================
--- geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java	(original)
+++ geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/ApplicationTest.java	Wed
Oct  6 22:32:34 2004
@@ -66,6 +66,7 @@
         UserTransactionImpl userTransaction = new UserTransactionImpl();
         app.setAttribute("userTransaction", userTransaction);
         app.setAttribute("webClassPath", new URI[0]);
+        app.setAttribute("contextPriorityClassLoader", Boolean.FALSE);
         app.setAttribute("configurationBaseUrl", Thread.currentThread().getContextClassLoader().getResource("deployables/"));
         app.setReferencePattern("TransactionContextManager", tcmName);
         app.setReferencePattern("TrackedConnectionAssociator", tcaName);

Modified: geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java
==============================================================================
--- geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java	(original)
+++ geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/SecurityTest.java	Wed
Oct  6 22:32:34 2004
@@ -110,6 +110,7 @@
         UserTransactionImpl userTransaction = new UserTransactionImpl();
         app.setAttribute("userTransaction", userTransaction);
         app.setAttribute("webClassPath", new URI[0]);
+        app.setAttribute("contextPriorityClassLoader", Boolean.FALSE);
         app.setAttribute("configurationBaseUrl", Thread.currentThread().getContextClassLoader().getResource("deployables/"));
         app.setAttribute("securityConfig", securityConfig);
         app.setAttribute("policyContextID", "TEST");

Mime
View raw message