2 Replies Latest reply on Aug 10, 2009 2:18 PM by mcheely

    Issues with @SchemaValidation and inheritance / @XmlSeeAlso

    mcheely

      I am developing a web service that uses inheritance to process multiple types of payments.

      The relevant code:

      @Stateless
      @WebService( name="PaymentService",
       serviceName = "PaymentService")
      @WebContext(contextRoot="/WebServices")
      @SchemaValidation
      @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
      public class PaymentService {
      
       private static final Log log = Logging.getLog(PaymentService.class);
      
       @WebMethod
       public PaymentResponse processPayment(Payment payment) {...
      


      And

      @XmlSeeAlso({CheckPayment.class, BankTransferPayment.class, CreditCardPayment.class})
      public abstract class Payment {...
      


      The relevant parts of the WSDL:
      <xs:schema targetNamespace='http://foo.com/' version='1.0' xmlns:tns='http://foo.com/' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
       <xs:element name='processPayment' nillable='true' type='tns:payment'/>
       <xs:element name='processPaymentResponse' nillable='true' type='tns:paymentResponse'/>
       <xs:complexType abstract='true' name='payment'>
       <xs:sequence>
       <xs:element minOccurs='0' name='accountNumber' type='xs:string'/>
       <xs:element name='amount' type='xs:decimal'/>
      
       <xs:element name='invoiceNumber' type='xs:string'/>
       <xs:element name='paymentDate' type='xs:dateTime'/>
       <xs:element name='receiptDate' type='xs:dateTime'/>
       <xs:element name='source' type='xs:string'/>
       <xs:element minOccurs='0' name='sourceTransactionId' type='xs:string'/>
       </xs:sequence>
       </xs:complexType>
       <xs:complexType name='checkPayment'>
       <xs:complexContent>
      
       <xs:extension base='tns:payment'>
       <xs:sequence>
       <xs:element minOccurs='0' name='accountId' type='xs:string'/>
       <xs:element minOccurs='0' name='bankId' type='xs:string'/>
       <xs:element minOccurs='0' name='checkNumber' type='xs:string'/>
       </xs:sequence>
       </xs:extension>
       </xs:complexContent>
       </xs:complexType>
      
       <xs:complexType name='bankTransferPayment'>
       <xs:complexContent>
       <xs:extension base='tns:payment'>
       <xs:sequence>
       <xs:element minOccurs='0' name='accountId' type='xs:string'/>
       <xs:element minOccurs='0' name='bankId' type='xs:string'/>
       <xs:element minOccurs='0' name='transactionId' type='xs:string'/>
       </xs:sequence>
       </xs:extension>
      
       </xs:complexContent>
       </xs:complexType>
       <xs:complexType name='creditCardPayment'>
       <xs:complexContent>
       <xs:extension base='tns:payment'>
       <xs:sequence>
       <xs:element minOccurs='0' name='creditCardType' type='xs:string'/>
       <xs:element minOccurs='0' name='reference' type='xs:string'/>
       <xs:element minOccurs='0' name='transactionId' type='xs:string'/>
      
       </xs:sequence>
       </xs:extension>
       </xs:complexContent>
       </xs:complexType>
      ...
      


      The issue I am having is that while the service works fine when schema validation is disabled, but when I enable it, and send this request:

      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://foo.com/" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
       <soapenv:Header/>
       <soapenv:Body>
       <req:processPayment xsi:type="creditCardPayment">
       <amount>1.00</amount>
       <invoiceNumber>10239659</invoiceNumber>
       <paymentDate>2009-07-24T00:00:00</paymentDate>
       <receiptDate>2009-07-27T10:52:55.1416037-04:00</receiptDate>
       <source>Magic</source>
       <sourceTransactionId>1000</sourceTransactionId>
       <creditCardType>Visa</creditCardType>
       <reference>12</reference>
       <transactionId>32</transactionId>
       </req:processPayment>
       </soapenv:Body>
      </soapenv:Envelope>
      


      I get the following error. Similar errors occur for the other payment types.

      org.jboss.ws.WSException: org.xml.sax.SAXException: cvc-elt.4.2: Cannot resolve 'creditCardPayment' to a type definition for element 'req:processPayment'.
      


      I can't see why that request XML shouldn't validate. Can anybody tell me if this is expected behavior, or if I should file a bug against it? Any ideas for a workaround?


        • 1. Re: Issues with @SchemaValidation and inheritance / @XmlSeeA
          soheil_has

          I have the same problem and I do not think that it is related to the @XmlSeeAlso. I have the issue without @XmlSeeAlso too!

          Studying the JBossWS source codes, I have got that @SchemaValidation needs the schemaLocation to be specified, but not as mentioned in http://www.jboss.org/community/wiki/JBossWS-Schemavalidationdemo! (It seems that org.jboss.ws.extensions.validation.SchemaExtractor is not called.)

          Fortunately I found a work around for this problem:

          The schemaLocation must points to the real xsd schema! I have put my JAXB generated XML schema in META-INF/test.xsd and annotate my SLSB like
          @SchemaValidation(enabled=true, schemaLocation="META-INF/test.xsd")

          Now it works!

          If you want the WSDL parameter schemas to be also be used you should merge the schemas under types element of your WSDL file.

          Bests,
          Soheil

          • 2. Re: Issues with @SchemaValidation and inheritance / @XmlSeeA
            mcheely

            Doh! Turns out this was a silly error on my part. I realized today that the value of the xsi:type attribute on the processPayment element wasn't properly namespaced.

            So,

            <req:processPayment xsi:type="creditCardPayment">
            

            Needs to be:
            <req:processPayment xsi:type="req:creditCardPayment">
            


            After making that change, everything works as expected.