User: starksm Date: 01/06/23 20:47:11 Modified: src/main/org/jboss/test/web/util Util.java Added: src/main/org/jboss/test/web/util ClassInClasses.java weblog4j.properties Log: Add tests of accessing WEB-INF elements from a JSP page Revision Changes Path 1.3 +123 -1 jbosstest/src/main/org/jboss/test/web/util/Util.java Index: Util.java =================================================================== RCS file: /cvsroot/jboss/jbosstest/src/main/org/jboss/test/web/util/Util.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Util.java 2001/06/01 14:08:49 1.2 +++ Util.java 2001/06/24 03:47:11 1.3 @@ -1,14 +1,24 @@ package org.jboss.test.web.util; +import java.io.PrintWriter; +import java.io.StringWriter; import java.net.URL; +import java.net.URLClassLoader; import java.util.Date; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.LinkRef; +import javax.naming.NamingEnumeration; +import javax.naming.NamingException; +import javax.naming.NameClassPair; +import javax.naming.NameParser; /** A trivial utility class that is placed into the lib/util.jar directory of the war archive and used by servlets in the war to test access to the lib jars. @author [EMAIL PROTECTED] -@version $Revision: 1.2 $ +@version $Revision: 1.3 $ */ public class Util { @@ -32,5 +42,117 @@ System.out.println("getResource('web2log4j.properties') via CL = "+web2PropsURL2); System.out.println("getResource('/log4j.properties') via CL = "+propsURL2); return propsURL; + } + + public static void showTree(String indent, Context ctx, PrintWriter out) + throws NamingException + { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); + NamingEnumeration enum = ctx.list(""); + while( enum.hasMoreElements() ) + { + NameClassPair ncp = (NameClassPair)enum.next(); + String name = ncp.getName(); + out.print(indent + " +- " + name); + boolean recursive = false; + boolean isLinkRef = false; + try + { + Class c = loader.loadClass(ncp.getClassName()); + if( Context.class.isAssignableFrom(c) ) + recursive = true; + if( LinkRef.class.isAssignableFrom(c) ) + isLinkRef = true; + } + catch(ClassNotFoundException cnfe) + { + } + + if( isLinkRef ) + { + try + { + LinkRef link = (LinkRef) ctx.lookupLink(name); + out.print("[link -> "); + out.print(link.getLinkName()); + out.print(']'); + } + catch(Throwable e) + { + e.printStackTrace(); + out.print("[invalid]"); + } + } + out.println(); + + if( recursive ) + { + try + { + Object value = ctx.lookup(name); + if( value instanceof Context ) + { + Context subctx = (Context) value; + showTree(indent + " | ", subctx, out); + } + else + { + out.println(indent + " | NonContext: "+value); + } + } + catch(Throwable t) + { + out.println("Failed to lookup: "+name+", errmsg="+t.getMessage()); + } + } + + } + } + + public static void dumpClassLoader(ClassLoader cl, PrintWriter out) + { + int level = 0; + while( cl != null ) + { + String msg = "Servlet ClassLoader["+level+"]: "+cl.getClass().getName()+':'+cl.hashCode(); + out.println(msg); + if( cl instanceof URLClassLoader ) + { + URLClassLoader ucl = (URLClassLoader) cl; + URL[] urls = ucl.getURLs(); + msg = " URLs:"; + out.println(msg); + for(int u = 0; u < urls.length; u ++) + { + msg = " ["+u+"] = "+urls[u]; + out.println(msg); + } + } + cl = cl.getParent(); + level ++; + } + } + + public static void dumpENC(PrintWriter out) throws NamingException + { + InitialContext iniCtx = new InitialContext(); + Context enc = (Context) iniCtx.lookup("java:comp/env"); + showTree("", enc, out); + } + + public String displayClassLoaders(ClassLoader cl) throws NamingException + { + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw); + dumpClassLoader(cl, out); + return sw.toString(); + } + + public String displayENC() throws NamingException + { + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw); + dumpENC(out); + return sw.toString(); } } 1.1 jbosstest/src/main/org/jboss/test/web/util/ClassInClasses.java Index: ClassInClasses.java =================================================================== package org.jboss.test.web.util; /** A class that is placed into the WEB-INF/classes directory to test the access of classes in that directory. @author [EMAIL PROTECTED] @version */ public class ClassInClasses { public ClassInClasses() { } } 1.1 jbosstest/src/main/org/jboss/test/web/util/weblog4j.properties Index: weblog4j.properties =================================================================== # A war local log4j.properties file _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-development