Bugs item #664400, was opened at 2003-01-08 14:19 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=376685&aid=664400&group_id=22866
Category: JBossServer Group: v3.2 Status: Open Resolution: None Priority: 5 Submitted By: Rod Burgett (rodburgett) Assigned to: Nobody/Anonymous (nobody) Summary: JNDIView.listXML() produces ill-formed XML Initial Comment: The 'String listXML()' method in the org.jboss.naming.JNDIView class produces XML file that is not well-formed if an error is encountered during recursive examination of Context instances. Error handling in the private listXML(Context, StringBuffer) method results in a <context> tag with a matching </context> tag. Reproducing the bug symptoms requires an error to be encountered during Context.list(). In my vanilla installation of JBoss, the java:TimedCacheFactory context produced this error, producing the following XML: <context> <name>timedCacheFactory</name> <attribute>javax.nameing.Context</attribute> <error> <message>Failed to lookup: timedCacheFActory, errmsg=org.jboss.util.TimedCachePolicy</message> </error> Subsequent XML output goes on to list other JNDI entries, but the lack of </context> tag following the </error> tag produces an XML validation error. The listXML(Context,StringBuffer) method is called recursively to handle nested contexts. The problem is cause by grouping in a single try-catch block the code to append <context> tag, call self, and append </context> tag. When listXML throws an exception, the closing </context> tag is never appended to the buffer. The fix strategy is to restructure the error handling to minimize the amount of code contained in try block. Here's a diff for a fix: diff -r1.19 JNDIView.java 220a221,223 > > Collection containers = null; > 223,257c226 < Collection containers = (Collection) server.getAttribute(app, "Containers"); < for (Iterator iter = containers.iterator(); iter.hasNext();) < { < Container con = (Container)iter.next(); < /* Set the thread class loader to that of the container as < the class loader is used by the java: context object < factory to partition the container namespaces. < */ < Thread.currentThread ().setContextClassLoader(con.getClassLoader()); < String bean = con.getBeanMetaData ().getEjbName(); < buffer.append( "<context>" ); < buffer.append( '\n' ); < buffer.append ( "<name>java:comp</name>" ); < buffer.append( '\n' ); < buffer.append( "<attribute name=\bean\>" + bean + "</attribute>" ); < buffer.append( '\n' ); < try < { < context = new InitialContext(); < context = (Context)context.lookup ("java:comp"); < } < catch(NamingException e) < { < buffer.append( "<error>" ); < buffer.append( '\n' ); < buffer.append( "<message>" + "Failed on lookup, " + e.toString( true ) + "</message>" ); < buffer.append( '\n' ); < buffer.append( "</error>" ); < buffer.append( '\n' ); < continue; < } < listXML( context, buffer ); < buffer.append( "</context>" ); < buffer.append( '\n' ); < } --- > containers = (Collection)server.getAttribute (app, "Containers"); 261c230 < log.error("getConainers failed", e); --- > log.error("getContainers failed", e); 266a236,286 > > for (Iterator iter = containers.iterator(); iter.hasNext();) > { > Container con = (Container)iter.next(); > /* Set the thread class loader to that of the container as > the class loader is used by the java: context object > factory to partition the container namespaces. > */ > Thread.currentThread().setContextClassLoader (con.getClassLoader()); > String bean = con.getBeanMetaData ().getEjbName(); > buffer.append( "<context>" ); > buffer.append( '\n' ); > buffer.append( "<name>java:comp</name>" ); > buffer.append( '\n' ); > buffer.append( "<attribute name=\bean\>" + bean + "</attribute>" ); > buffer.append( '\n' ); > try > { > context = new InitialContext(); > context = (Context)context.lookup ("java:comp"); > } > catch(NamingException e) > { > buffer.append( "<error>" ); > buffer.append( '\n' ); > buffer.append( "<message>" + "Failed on lookup, " + e.toString( true ) + "</message>" ); > buffer.append( '\n' ); > buffer.append( "</error>" ); > buffer.append( '\n' ); > continue; > } > > try > { > listXML( context, buffer ); > } > catch(Throwable t) > { > buffer.append( "<error>" ); > buffer.append( '\n' ); > buffer.append( "<message>" + "Failed on list contents, " + t.toString() + "</message>" ); > buffer.append( '\n' ); > buffer.append( "</error>" ); > buffer.append( '\n' ); > continue; > } > > buffer.append( "</context>" ); > buffer.append( '\n' ); > } > 494a515,516 > LinkRef link = null; > 497,507c519 < LinkRef link = (LinkRef) ctx.lookupLink (name); < buffer.append( "<link-ref>" ); < buffer.append( '\n' ); < buffer.append( "<name>" + pair.getName () + "</name>" ); < buffer.append( '\n' ); < buffer.append( "<link>" + link.getLinkName() + "</link>" ); < buffer.append( '\n' ); < buffer.append( "<attribute name=\class\>" + pair.getClassName() + "</attribute>" ); < buffer.append( '\n' ); < buffer.append( "</link-ref>" ); < buffer.append( '\n' ); --- > link = (LinkRef) ctx.lookupLink(name); 519a532,542 > > buffer.append( "<link-ref>" ); > buffer.append( '\n' ); > buffer.append( "<name>" + pair.getName() + "</name>" ); > buffer.append( '\n' ); > buffer.append( "<link>" + link.getLinkName () + "</link>" ); > buffer.append( '\n' ); > buffer.append( "<attribute name=\class\>" + pair.getClassName() + "</attribute>" ); > buffer.append( '\n' ); > buffer.append( "</link-ref>" ); > buffer.append( '\n' ); 522a546,547 > Object value = null; > 524,532c549,569 < Object value = ctx.lookup(name); < if( value instanceof Context ) { < Context subctx = (Context) value; < buffer.append( "<context>" ); < buffer.append( '\n' ); < buffer.append( "<name>" + pair.getName() + "</name>" ); < buffer.append( '\n' ); < buffer.append( "<attribute name=\class\>" + pair.getClassName() + "</attribute>" ); < buffer.append( '\n' ); --- > value = ctx.lookup(name); > } > catch(Throwable t) { > buffer.append( "<error>" ); > buffer.append( '\n' ); > buffer.append( "<message>" + "Failed to lookup: "+name+", errmsg="+t.getMessage() + "</message>" ); > buffer.append( '\n' ); > buffer.append( "</error>" ); > buffer.append( '\n' ); > } > > if( value instanceof Context ) { > Context subctx = (Context) value; > buffer.append( "<context>" ); > buffer.append( '\n' ); > buffer.append( "<name>" + pair.getName() + "</name>" ); > buffer.append( '\n' ); > buffer.append( "<attribute name=\class\>" + pair.getClassName() + "</attribute>" ); > buffer.append( '\n' ); > > try { 534,535d570 < buffer.append( "</context>" ); < buffer.append( '\n' ); 537,540c572,573 < else { < buffer.append( "<non-context>" ); < buffer.append( '\n' ); < buffer.append( "<name>" + pair.getName() + "</name>" ); --- > catch(Throwable t) { > buffer.append( "<error>" ); 542c575 < buffer.append( "<attribute name=\value\>" + value + "</attribute>" ); --- > buffer.append( "<message>" + "Failed to list contents of: "+name+", errmsg="+t.getMessage() + "</message>" ); 544c577 < buffer.append( "</non-context>" ); --- > buffer.append( "</error>" ); 546a580,582 > > buffer.append( "</context>" ); > buffer.append( '\n' ); 548,549c584,585 < catch(Throwable t) { < buffer.append( "<error>" ); --- > else { > buffer.append( "<non-context>" ); 551c587 < buffer.append( "<message>" + "Failed to lookup: "+name+", errmsg="+t.getMessage() + "</message>" ); --- > buffer.append( "<name>" + pair.getName() + "</name>" ); 553c589,591 < buffer.append( "</error>" ); --- > buffer.append( "<attribute name=\value\>" + value + "</attribute>" ); > buffer.append( '\n' ); > buffer.append( "</non-context>" ); ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=376685&aid=664400&group_id=22866 ------------------------------------------------------- This SF.NET email is sponsored by: SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See! http://www.vasoftware.com _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development