Bug 40507 - XML validation fails when xmlValidation="true"
Summary: XML validation fails when xmlValidation="true"
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.5.20
Hardware: All Linux
: P2 minor (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-09-14 08:01 UTC by Roland Nygren
Modified: 2007-01-20 08:40 UTC (History)
0 users



Attachments
Patch to update host-manager webapp to use servlet 2.4 xsd (866 bytes, patch)
2006-12-28 09:38 UTC, Chris Halstead
Details | Diff
Patch to update servlets-examples webapp to use servlet 2.4 xsd (1.98 KB, patch)
2006-12-28 09:40 UTC, Chris Halstead
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Nygren 2006-09-14 08:01:23 UTC
I Downloaded and installed Tomcat 5.5.17.
The only change I made was  xmlValidation="true" in server.xml
Same result on both:
 - RedHat EL 3, Java 1.5.0_08-b03
 - Windows XP, Java 1.5.0_06-b05

catalina.out:

INFO: XML validation enabled
2006-sep-14 09:51:01 org.apache.tomcat.util.digester.Digester error
ALLVARLIG: Parse Error at line 5 column 19: cvc-elt.1: Cannot find the
declaration of element 'web-app'.
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element
'web-app'.
        at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)
        at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:172)
        at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
        at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
        at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1944)
        at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
        at
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:798)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:878)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$ContentDispatcher.scanRootElementHook(XMLDocumentScannerImpl.java:1157)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
        at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
        at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
        at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
        at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
        at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
        at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
        at
org.apache.catalina.startup.ContextConfig.processDefaultWebConfig(ContextConfig.java:676)
        at
org.apache.catalina.startup.ContextConfig.defaultWebConfig(ContextConfig.java:613)
        at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1033)
        at
org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:260)
        at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4119)
        at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
        at
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:608)
        at
org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
        at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
        at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
        at org.apache.catalina.core.StandardService.start(StandardService.java:450)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
Comment 1 Chris Halstead 2006-12-27 15:33:08 UTC
When you enable xmlValidation="true" you also need to enable
xmlNamespaceAware="true" as well.  If these are both set to true in your
server.xml you should be able to validate correctly.  Works for me anyway.
Comment 2 Roland Nygren 2006-12-28 05:14:24 UTC
(In reply to comment #1)
> When you enable xmlValidation="true" you also need to enable
> xmlNamespaceAware="true" as well.  If these are both set to true in your
> server.xml you should be able to validate correctly.  Works for me anyway.

I don't know what I do wrong.
The same occurs with Tomcat 5.5.20.
Setting both xmlValidation & xmlNamespaceAware true I still get:

INFO: XML validation enabled
2006-dec-28 14:04:45 org.apache.tomcat.util.digester.Digester error
ALLVARLIG: Parse Error at line 7 column 10: cvc-elt.1: Cannot find the 
declaration of element 'web-app'.
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of 
element 'web-app'.
	at 
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseExcep
tion(ErrorHandlerWrapper.java:236)

...

2006-dec-28 14:04:45 org.apache.catalina.startup.ContextConfig start
ALLVARLIG: Marking this application unavailable due to previous error(s)
2006-dec-28 14:04:45 org.apache.catalina.core.StandardContext start
ALLVARLIG: Error getConfigured
2006-dec-28 14:04:45 org.apache.catalina.core.StandardContext start
ALLVARLIG: Context [/host-manager] startup failed due to previous errors
Comment 3 Markus Schönhaber 2006-12-28 07:04:00 UTC
I've just tested this and could reproduce the error using Tomcat 5.5.17 and
5.5.20 with "xmlValidation" and "xmlNamespaceAware" set to "true".

To me, it seems that this problem occurs only for 2.3 webapps (i. e. validating
against the servlet 2.3 DTD fails), while everything is fine with 2.4 webapps
(i. e. validating against the 2.4 schema works).
Can you verify that it's the same for you? Check that of the stock webapps that
come with Tomcat "host-manager" and "servlets-examples" (which are 2.3 webapps)
are not started while "balancer", "jsp-examples", "manager", "tomcat-docs" and
"webdav" (which are 2.4 webapps) are running.

I've changed the severity of this bug to minor. Since although I think that this
is a bug, I don't think that verifying the correctness of web.xml is a matter of
deployment but it's a matter of development. I. e. when developing a webapp it
should be made sure that web.xml is correct, making another check during
deployment quite pointless.
Comment 4 Chris Halstead 2006-12-28 09:27:36 UTC
RE #3:

You are quite correct.  I came to the same conclusion this morning when looking
at this again.  Turns out my last test yesterday was mistakenly against an
instance that I had cleaned out (no webapps deployed).  That's what I get for
having too many test instances around ;-)

The two cuplrits are indeed the host-manager and servlets-examples webapps. 
They still reference 2.3 DTDs in their deployment descriptors.

Since TC5.5 is a Servlet 2.4 container, it seems to follow that all of the
webapps in the default install should use the 2.4 xsd reference.  I'm attaching
patches to the servlets-examples and host-manager deployment descriptors that
make that update.  The deployment descriptor for the servlets-examples webapp
also needed some changes to be 2.4 schema conformant (env-entry subelement
ordering).  With these changes I can now start 5.5.20 error-free with validation
enabled.

It will still throw errors if it encounters a webapp with a 2.3 DTD reference. 
I haven't tracked that down yet.
Comment 5 Chris Halstead 2006-12-28 09:38:46 UTC
Created attachment 19317 [details]
Patch to update host-manager webapp to use servlet 2.4 xsd
Comment 6 Chris Halstead 2006-12-28 09:40:23 UTC
Created attachment 19318 [details]
Patch to update servlets-examples webapp to use servlet 2.4 xsd
Comment 7 Mark Thomas 2007-01-20 08:40:18 UTC
Thanks for the patches. I have applied them to svn and they will be include din
5.5.21 onwards.

I have also been back through the mailing lists looks like the 2.3 validation
issues are caused by a bug in the xerces version used in the jvm. It is still
present in 1.5.0_10 and 1.6.0 but if you place the xerces jars included in the
5.5.x compat download in common/endorsed then they will be used instead and 2.3
webapps will validate successfully.