[SWS-932] Not enough namespace context during XSD validation when using AxiomSoapMessageFactory Created: 08/Jan/16  Updated: 09/Feb/16  Resolved: 09/Feb/16

Status: Closed
Project: Spring Web Services
Component/s: Core
Affects Version/s: 2.2.4
Fix Version/s: 2.3.0

Type: Bug Priority: Minor
Reporter: Dennis Walter Assignee: Greg Turnquist
Resolution: Complete Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File 0001-Fixed-namespace-context-bug.patch     GZip Archive springws-extension.tar.gz    
Pull Request URL: https://github.com/spring-projects/spring-ws/pull/59

 Description   

XSD request validation using AxiomSoapMessageFactory and PayloadValidatingInterceptor fails with an UndeclaredPrefix validation error, because Axiom does not have full access to the namespace declarations made on the SOAP Envelope level.

As suggested in http://stackoverflow.com/questions/34633662/xsd-validation-fails-with-undeclaredprefix-when-using-axiomsoapmessagefactory-in, a possible fix is to use OMContainer#getXMLStreamReader(boolean, OMXMLStreamReaderConfiguration) and set the preserveNamespaceContext property to true in the OMXMLStreamReaderConfiguration object (in CachingPayload#getStreamReader(OMElement)).

I tested this, and it fixes the problem. Patch is attached, as well as a small sample project exposing the erroneous behaviour.

Request that fails:

<soapenv:Envelope xmlns:sch="http://example.com/springws/extension/schema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
   <soapenv:Header/>
   <soapenv:Body>
      <sch:formatRequest >
         <sch:value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="sch:dateType">
           <sch:day>1</sch:day>
           <sch:month>1</sch:month>
           <sch:year>2000</sch:year>
         </sch:value>
      </sch:formatRequest>
   </soapenv:Body>
</soapenv:Envelope>

Response is a SOAP fault with detail

<detail>
    <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">UndeclaredPrefix: Cannot resolve 'sch:dateType' as a QName: the prefix 'sch' is not declared.</spring-ws:ValidationError>
    <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-elt.4.1: The value 'sch:dateType' of attribute 'http://www.w3.org/2001/XMLSchema-instance,type' of element 'sch:value' is not a valid QName.</spring-ws:ValidationError>
    <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-type.2: The type definition cannot be abstract for element sch:value.</spring-ws:ValidationError>
    <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">UndeclaredPrefix: Cannot resolve 'sch:dateType' as a QName: the prefix 'sch' is not declared.</spring-ws:ValidationError>
    <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-attribute.3: The value 'sch:dateType' of attribute 'xsi:type' on element 'sch:value' is not valid with respect to its type, 'QName'.</spring-ws:ValidationError>
    <spring-ws:ValidationError xmlns:spring-ws="http://springframework.org/spring-ws">cvc-complex-type.2.1: Element 'sch:value' must have no character or element information item [children], because the type's content type is empty.</spring-ws:ValidationError>
</detail>

Request that works, with namespace decl in payload:
localhost:8084/format/format.wsdl

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
   <soapenv:Header/>
   <soapenv:Body>
      <sch:formatRequest xmlns:sch="http://example.com/springws/extension/schema" >
         <sch:value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="sch:dateType">
           <sch:day>1</sch:day>
           <sch:month>1</sch:month>
           <sch:year>2000</sch:year>
         </sch:value>
      </sch:formatRequest>
   </soapenv:Body>
</soapenv:Envelope>



 Comments   
Comment by Greg Turnquist [ 19/Jan/16 ]

Evaluating if this fits in the scope of our 2.3 release.

Generated at Mon Dec 18 05:19:33 UTC 2017 using JIRA 6.4.14#64029-sha1:ae256fe0fbb912241490ff1cecfb323ea0905ca5.