Faulty SOAPFaults and Java5

There may not be many good reasons for wanting to perform XML schema validation on a SOAP Fault. I had cause to as part of a unit test for a piece of fault generation code. I used SAAJ to create the fault and Spring's XMLValidator to validate.

The unit test passed on JDK 1.6 but failed with the exceptions below when run under JDK 1.5.

   org.xml.sax.SAXParseException: UndeclaredPrefix: Cannot resolve 'SOAP-ENV:Server' as a QName: the prefix 'SOAP-ENV' is not declared.
   org.xml.sax.SAXParseException: cvc-type.3.1.3: The value 'SOAP-ENV:Server' of element 'faultcode' is not valid.

The XML in question was the qualified name in the faultcode that had been created by default.


The fix was to remove the SOAP-ENV namespace prefix by calling setFaultCode("Server") on the SOAPFault. The test then passed on both JDKs.

Here's the reason. Under the hood, XMLValidator uses the Xerces JAXP validator bundled in the JRE's rt.jar. From 1.5 to 1.6 the validator implementation was changed from using a SAX parser to DOM. It appears that the former is unable to resolve the prefix correctly when it features in the text content.

posted by James Gemmell on Mon, 17 May 2010 at 15:33 | permalink | tags: , ,