[Winstone-devel] winstone/src/java/winstone/classLoader WebappClassLoader.java, 1.1, 1.2 LocalStrin
Status: Beta
Brought to you by:
rickknowles
From: Rick K. <ric...@us...> - 2007-12-28 06:34:21
|
Update of /cvsroot/winstone/winstone/src/java/winstone/classLoader In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv18611/src/java/winstone/classLoader Modified Files: WebappClassLoader.java LocalStrings.properties Log Message: Thanks to james berry for these changes to the webapp class loader. I've only given these a cursory test far (sorry about the inordinate delay), and the results are at least as good as the previous version. Please report any observed classloading weirdness as soon as possible. Thanks Index: LocalStrings.properties =================================================================== RCS file: /cvsroot/winstone/winstone/src/java/winstone/classLoader/LocalStrings.properties,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** LocalStrings.properties 30 Apr 2005 17:09:41 -0000 1.1 --- LocalStrings.properties 28 Dec 2007 06:34:17 -0000 1.2 *************** *** 5,6 **** --- 5,10 ---- ReloadingClassLoader.MaintenanceThreadError=Error in WinstoneClassLoader reloading monitor thread ReloadingClassLoader.MaintenanceThreadFinished=WinstoneClassLoader reloading monitor thread finished + + WebappClassLoader.LoadedByThisCL=Webapp classloader found class locally when loading #0 + WebappClassLoader.LoadedByParentCL=Webapp classloader deferred to parent for loading #0 + WebappClassLoader.LoadedBySystemCL=Webapp classloader deferred to system classloader for loading #0 \ No newline at end of file Index: WebappClassLoader.java =================================================================== RCS file: /cvsroot/winstone/winstone/src/java/winstone/classLoader/WebappClassLoader.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** WebappClassLoader.java 26 Jan 2007 10:35:02 -0000 1.1 --- WebappClassLoader.java 28 Dec 2007 06:34:17 -0000 1.2 *************** *** 11,19 **** import java.net.URLStreamHandlerFactory; /** * Implements the servlet spec model (v2.3 section 9.7.2) for classloading, which * is different to the standard JDK model in that it delegates *after* checking * local repositories. This has the effect of isolating copies of classes that exist ! * in 2 webapps from each other. * * @author <a href="mailto:ric...@ho...">Rick Knowles</a> --- 11,25 ---- import java.net.URLStreamHandlerFactory; + import winstone.Logger; + import winstone.WinstoneResourceBundle; + /** * Implements the servlet spec model (v2.3 section 9.7.2) for classloading, which * is different to the standard JDK model in that it delegates *after* checking * local repositories. This has the effect of isolating copies of classes that exist ! * in 2 webapps from each other. ! * ! * Thanks to James Berry for the changes to use the system classloader to prevent ! * loading servlet spec or system classpath classes again. * * @author <a href="mailto:ric...@ho...">Rick Knowles</a> *************** *** 21,24 **** --- 27,33 ---- */ public class WebappClassLoader extends URLClassLoader { + private static final WinstoneResourceBundle CL_RESOURCES = new WinstoneResourceBundle("winstone.classLoader.LocalStrings"); + + protected ClassLoader system = getSystemClassLoader(); public WebappClassLoader(URL[] urls) { *************** *** 38,58 **** Class c = findLoadedClass(name); // If an allowed class, load it locally first ! try { ! if (c == null) { // If still not found, then invoke findClass in order to find the class. c = findClass(name); } - } catch (ClassNotFoundException e) { - c = null; } if (c == null) { ClassLoader parent = getParent(); if (parent != null) { c = parent.loadClass(name); } else { ! c = getSystemClassLoader().loadClass(name); } } if (resolve && (c != null)) { resolveClass(c); --- 47,93 ---- Class c = findLoadedClass(name); + // Try the system loader first, to ensure that system classes are not + // overridden by webapps. Note that this includes any classes in winstone, + // including the javax.servlet classes + if (c == null) { + try { + c = system.loadClass(name); + if (c != null) { + Logger.log(Logger.MAX, CL_RESOURCES, "WebappClassLoader.LoadedBySystemCL", name); + } + } catch (ClassNotFoundException e) { + c = null; + } + } + // If an allowed class, load it locally first ! if (c == null) { ! try { // If still not found, then invoke findClass in order to find the class. c = findClass(name); + if (c != null) { + Logger.log(Logger.MAX, CL_RESOURCES, "WebappClassLoader.LoadedByThisCL", name); + } + } catch (ClassNotFoundException e) { + c = null; } } + + // otherwise, and only if we have a parent, delegate to our parent + // Note that within winstone, the only difference between this and the system + // class loader we've already tried is that our parent might include the common/shared lib. if (c == null) { ClassLoader parent = getParent(); if (parent != null) { c = parent.loadClass(name); + if (c != null) { + Logger.log(Logger.MAX, CL_RESOURCES, "WebappClassLoader.LoadedByParentCL", name); + } } else { ! // We have no other hope for loading the class, so throw the class not found exception ! throw new ClassNotFoundException(name); } } + if (resolve && (c != null)) { resolveClass(c); |