You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2001/03/21 06:05:44 UTC
cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources DirContextURLStreamHandler.java
remm 01/03/20 21:05:44
Modified: catalina/src/share/org/apache/naming/resources
DirContextURLStreamHandler.java
Log:
- Fix a problem where the following code would throw a NullPointerException
at line 163 of DirContextURLConnection when excuting the second
(new URL("jndi:/WEB-INF/web.xml")).openStream() :
InputStream is =
getServletContext().getResource
("/WEB-INF/web.xml").openStream();
is.close();
is = (new URL("jndi:/WEB-INF/web.xml")).openStream();
is.close();
URLClassLoader newcl =
new URLClassLoader(new URL[0],
Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(newcl);
is = getServletContext().getResource("/WEB-INF/web.xml")
.openStream();
is.close();
is = (new URL("jndi:/WEB-INF/web.xml")).openStream();
is.close();
- Now, the stream handler will also check the bindings with the parent of
the context class loader (up to the bootstrap class loader), so that case
should work.
- If the stream handler fails to retrieve the directory context, it will throw
an IllegalStateException indicating that the class loader configuration is
messed up. That should only happen if a servlet replaces the thread context
class loader with a totally separate loader. In that case, the web
application classloader will be unable to load most classes from /WEB-INF/lib
(because resolving a URL like "jar:jndi:/WEB-INF/lib/foo.jar!/foo/bar.class"
requires some magic), but this shouldn't be a problem since the new
classloader is totally independent, and will be used to load all classes.
- The ServletContext.getResource(String path) calls should always work,
regardless of how much hacking is done on the classloader (the stream
handler is specified when constructing the URL).
Revision Changes Path
1.3 +13 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandler.java
Index: DirContextURLStreamHandler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DirContextURLStreamHandler.java 2001/01/23 22:26:50 1.2
+++ DirContextURLStreamHandler.java 2001/03/21 05:05:44 1.3
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandler.java,v 1.2 2001/01/23 22:26:50 remm Exp $
- * $Revision: 1.2 $
- * $Date: 2001/01/23 22:26:50 $
+ * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/DirContextURLStreamHandler.java,v 1.3 2001/03/21 05:05:44 remm Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/03/21 05:05:44 $
*
* ====================================================================
*
@@ -75,7 +75,7 @@
* Stream handler to a JNDI directory context.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class DirContextURLStreamHandler
extends URLStreamHandler {
@@ -161,7 +161,15 @@
public static DirContext get() {
ClassLoader currentCL =
Thread.currentThread().getContextClassLoader();
- return (DirContext) clBindings.get(currentCL);
+ DirContext result = null;
+ while ((result == null) && (currentCL != null)) {
+ result = (DirContext) clBindings.get(currentCL);
+ if (result == null)
+ currentCL = currentCL.getParent();
+ }
+ if (result == null)
+ throw new IllegalStateException("Illegal class loader binding");
+ return result;
}