From 16be43597f08145b72040c7e6f3267ec6f6e0319 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 9 Jul 2010 11:42:19 +0000 Subject: [PATCH] 319370 WebAppClassLoaderContext git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2088 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../webapp/OSGiWebappClassLoader.java | 2 +- .../jetty/server/handler/ContextHandler.java | 15 +++-- .../jetty/webapp/WebAppClassLoader.java | 65 +++++++++++++++++-- .../eclipse/jetty/webapp/WebAppContext.java | 10 +-- 5 files changed, 79 insertions(+), 14 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index cc855256cf1..210088f2673 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,5 +1,6 @@ jetty-7.2-SNAPSHOT + 319334 Concurrent, sharable ResourceCache + + 319370 WebAppClassLoader.Context jetty-7.1.5.v20100705 + Update ecj to 3.6 Helios release drop diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java index 13c097e85ea..4a7dcf96e90 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/internal/webapp/OSGiWebappClassLoader.java @@ -193,7 +193,7 @@ public class OSGiWebappClassLoader extends WebAppClassLoader implements BundleRe } else { - __logger.info("Did not add " + path + " to the classloader of the webapp " + getContext().getContextPath()); + __logger.info("Did not add " + path + " to the classloader of the webapp " + getContext()); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index faf7a73fa3f..c69732ebf96 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -1154,6 +1154,8 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. */ public MimeTypes getMimeTypes() { + if (_mimeTypes==null) + _mimeTypes=new MimeTypes(); return _mimeTypes; } @@ -1334,13 +1336,16 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. } /* ------------------------------------------------------------ */ - /** Convert URL to Resource - * wrapper for {@link Resource#newResource(String)} enables extensions to - * provide alternate resource implementations. + /** Convert a URL or path to a Resource. + * The default implementation + * is a wrapper for {@link Resource#newResource(String)}. + * @param urlOrPath The URL or path to convert + * @return The Resource for the URL/path + * @throws IOException The Resource could not be created. */ - public Resource newResource(String url) throws IOException + public Resource newResource(String urlOrPath) throws IOException { - return Resource.newResource(url); + return Resource.newResource(urlOrPath); } /* ------------------------------------------------------------ */ diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index ca37ab4f42a..03dfc1e92f8 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -56,14 +56,71 @@ import org.eclipse.jetty.util.resource.ResourceCollection; public class WebAppClassLoader extends URLClassLoader { private String _name; - private WebAppContext _context; + private Context _context; private ClassLoader _parent; private HashSet _extensions; + + /* ------------------------------------------------------------ */ + /** The Context in which the classloader operates. + */ + public interface Context + { + /* ------------------------------------------------------------ */ + /** Convert a URL or path to a Resource. + * The default implementation + * is a wrapper for {@link Resource#newResource(String)}. + * @param urlOrPath The URL or path to convert + * @return The Resource for the URL/path + * @throws IOException The Resource could not be created. + */ + Resource newResource(String urlOrPath) throws IOException; + + /* ------------------------------------------------------------ */ + /** + * @return Returns the permissions. + */ + PermissionCollection getPermissions(); + + /* ------------------------------------------------------------ */ + /** Is the class a System Class. + * A System class is a class that is visible to a webapplication, + * but that cannot be overridden by the contents of WEB-INF/lib or + * WEB-INF/classes + * @param clazz The fully qualified name of the class. + * @return True if the class is a system class. + */ + boolean isSystemClass(String clazz); + + /* ------------------------------------------------------------ */ + /** Is the class a Server Class. + * A Server class is a class that is part of the implementation of + * the server and is NIT visible to a webapplication. The web + * application may provide it's own implementation of the class, + * to be loaded from WEB-INF/lib or WEB-INF/classes + * @param clazz The fully qualified name of the class. + * @return True if the class is a server class. + */ + boolean isServerClass(String clazz); + + /* ------------------------------------------------------------ */ + /** + * @return True if the classloader should delegate first to the parent + * classloader (standard java behaviour) or false if the classloader + * should first try to load from WEB-INF/lib or WEB-INF/classes (servlet + * spec recommendation). + */ + boolean isParentLoaderPriority(); + + /* ------------------------------------------------------------ */ + String getExtraClasspath(); + + } + /* ------------------------------------------------------------ */ /** Constructor. */ - public WebAppClassLoader(WebAppContext context) + public WebAppClassLoader(Context context) throws IOException { this(null,context); @@ -72,7 +129,7 @@ public class WebAppClassLoader extends URLClassLoader /* ------------------------------------------------------------ */ /** Constructor. */ - public WebAppClassLoader(ClassLoader parent, WebAppContext context) + public WebAppClassLoader(ClassLoader parent, Context context) throws IOException { super(new URL[]{},parent!=null?parent @@ -120,7 +177,7 @@ public class WebAppClassLoader extends URLClassLoader /* ------------------------------------------------------------ */ - public ContextHandler getContext() + public Context getContext() { return _context; } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index e3abd2df9a7..cea44168f26 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -57,10 +57,8 @@ import org.eclipse.jetty.util.resource.ResourceCollection; * * @org.apache.xbean.XBean description="Creates a servlet web application at a given context from a resource base" * - * - * */ -public class WebAppContext extends ServletContextHandler +public class WebAppContext extends ServletContextHandler implements WebAppClassLoader.Context { public static final String TEMPDIR = "javax.servlet.context.tempdir"; public static final String BASETEMPDIR = "org.eclipse.jetty.webapp.basetempdir"; @@ -522,6 +520,7 @@ public class WebAppContext extends ServletContextHandler return _systemClasses.getPatterns(); } + /* ------------------------------------------------------------ */ public void addSystemClass(String classname) { if (_systemClasses == null) @@ -640,7 +639,10 @@ public class WebAppContext extends ServletContextHandler /* ------------------------------------------------------------ */ /** - * @return Returns the java2compliant. + * @return True if the classloader should delegate first to the parent + * classloader (standard java behaviour) or false if the classloader + * should first try to load from WEB-INF/lib or WEB-INF/classes (servlet + * spec recommendation). */ public boolean isParentLoaderPriority() {