Hi All, Some people I work with noticed that Tomcat was spitting out a web.xml validation error for their app, but only the first time they started up. This gave them the impression that everything was ok the second time.
Well, I looked around a bit and found that WebXmlReader writes out a "validation mark" (webxmlval.txt) in the work directory. The timestamp of the validation mark is used as part of deciding whether to validate. The thing is, this mark is written out even if web.xml was not valid so next time through validation is skipped. I'm not sure if this was done on purpose and I can even imagine an argument about not nagging more than once. Still, in our case the disappearance of the validation errors brought about false confidence. In case this seems like a problem to anyone else, here's a patch that only writes out the validation mark if the XML parsed without errors. That way you keep seeing the validation errors until you a) disable validation or b) fix the offending xml. Interestingly, this patch takes advantage of an unused boolean field in the error handler. Makes me wonder if somebody already thought of this but decided not to deal with it. Perhaps there was a good reason. Regards, -David
--- WebXmlReader.java.orig Wed Oct 31 13:00:07 2001 +++ WebXmlReader.java Wed Oct 31 12:12:55 2001 @@ -99,7 +99,7 @@ static class WebXmlErrorHandler implements ErrorHandler{ Context ctx; XmlMapper xm; - boolean ok; + boolean ok = true; WebXmlErrorHandler( XmlMapper xm,Context ctx ) { this.ctx=ctx; this.xm=xm; @@ -113,16 +113,21 @@ public void error (SAXParseException exception) throws SAXException { + ok = false; ctx.log("web.xml: Error " + exception ); ctx.log(xm.positionToString()); } public void fatalError (SAXParseException exception) throws SAXException { + ok = false; ctx.log("web.xml: Fatal error " + exception ); ctx.log(xm.positionToString()); throw new SAXException( "Fatal error " + exception ); } + public boolean isOk() { + return ok; + } } void processWebXmlFile( Context ctx, String file) { @@ -134,13 +139,15 @@ } if( ctx.getDebug() > 0 ) ctx.log("Reading " + file ); XmlMapper xh=new XmlMapper(); + WebXmlErrorHandler xeh = null; File v=new File( ctx.getWorkDir(), "webxmlval.txt" ); if( validate ) { if( ! v.exists() || v.lastModified() < f.lastModified() ) { ctx.log("Validating web.xml"); xh.setValidating(true); - xh.setErrorHandler( new WebXmlErrorHandler( xh, ctx ) ); + xeh = new WebXmlErrorHandler( xh, ctx ); + xh.setErrorHandler( xeh ); } } @@ -230,7 +237,8 @@ Object ctx1=xh.readXml(f, ctx); - if( validate ) { + if( validate && xeh.isOk()) { + // don't create/update the validation mark if an error was detected try { FileOutputStream fos=new FileOutputStream( v ); fos.write( 1 );
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>