Uploaded image for project: 'Spring Web Services'
  1. Spring Web Services
  2. SWS-932

Not enough namespace context during XSD validation when using AxiomSoapMessageFactory

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 2.2.4
    • Fix Version/s: 2.3.0
    • Component/s: Core
    • Labels:
      None

      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>
      

      1. 0001-Fixed-namespace-context-bug.patch
        2 kB
        Dennis Walter
      2. springws-extension.tar.gz
        3 kB
        Dennis Walter

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            gregturn Greg Turnquist
            Reporter:
            dnswlt Dennis Walter
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: