Skip to main content

SOAP anottation Schema Validation - atributes order problem

2 replies [Last post]
peterB007
Offline
Joined: 2012-02-16
Points: 0

Hello,

there is possibility in METRO turn on Schema Validation to enable server side validation.

Example:

import com.sun.xml.ws.developer.SchemaValidation;
...

@SchemaValidation
@WebService
public class HelloImpl {
}

We encountered problems that atributes of complex type in request should be ordered exactly like it is in XSD schema in other way we got following exception:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Body>

<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">

<faultcode>S:Client</faultcode>

<faultstring>org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'datumVyradeniaDo'. One of '{datumPovolenia}' is expected.</faultstring>

<detail>

<ns2:exception class="com.sun.istack.SAXParseException2" note="To disable this feature, set com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false" xmlns:ns2="http://jax-ws.dev.java.net/">

<message>org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'datumVyradeniaDo'. One of '{datumPovolenia}' is expected.</message>

<ns2:stackTrace>

<ns2:frame class="com.sun.xml.ws.util.xml.StAXSource$1" file="StAXSource.java" line="187" method="parse"/>

<ns2:frame class="com.sun.xml.ws.util.xml.StAXSource$1" file="StAXSource.java" line="172" method="parse"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl" line="unknown" method="validate"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl" line="unknown" method="validate"/>

<ns2:frame class="javax.xml.validation.Validator" line="unknown" method="validate"/>

<ns2:frame class="com.sun.xml.ws.util.pipe.AbstractSchemaValidationTube" file="AbstractSchemaValidationTube.java" line="283" method="doProcess"/>

<ns2:frame class="com.sun.xml.ws.server.ServerSchemaValidationTube" file="ServerSchemaValidationTube.java" line="276" method="processRequest"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="629" method="__doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="588" method="_doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="573" method="doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="470" method="runSync"/>

<ns2:frame class="com.sun.xml.ws.server.WSEndpointImpl$2" file="WSEndpointImpl.java" line="295" method="process"/>

<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit" file="HttpAdapter.java" line="515" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter" file="HttpAdapter.java" line="285" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.ServletAdapter" file="ServletAdapter.java" line="143" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServletDelegate" file="WSServletDelegate.java" line="155" method="doGet"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServletDelegate" file="WSServletDelegate.java" line="189" method="doPost"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServlet" file="WSServlet.java" line="76" method="doPost"/>

<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="641" method="service"/>

<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="722" method="service"/>

<ns2:frame class="org.apache.catalina.core.ApplicationFilterChain" file="ApplicationFilterChain.java" line="305" method="internalDoFilter"/>

<ns2:frame class="org.apache.catalina.core.ApplicationFilterChain" file="ApplicationFilterChain.java" line="210" method="doFilter"/>

<ns2:frame class="org.apache.catalina.core.StandardWrapperValve" file="StandardWrapperValve.java" line="224" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardContextValve" file="StandardContextValve.java" line="169" method="invoke"/>

<ns2:frame class="org.apache.catalina.authenticator.AuthenticatorBase" file="AuthenticatorBase.java" line="581" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardHostValve" file="StandardHostValve.java" line="168" method="invoke"/>

<ns2:frame class="org.apache.catalina.valves.ErrorReportValve" file="ErrorReportValve.java" line="98" method="invoke"/>

<ns2:frame class="org.apache.catalina.valves.AccessLogValve" file="AccessLogValve.java" line="928" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardEngineValve" file="StandardEngineValve.java" line="118" method="invoke"/>

<ns2:frame class="org.apache.catalina.connector.CoyoteAdapter" file="CoyoteAdapter.java" line="407" method="service"/>

<ns2:frame class="org.apache.coyote.http11.AbstractHttp11Processor" file="AbstractHttp11Processor.java" line="987" method="process"/>

<ns2:frame class="org.apache.coyote.AbstractProtocol$AbstractConnectionHandler" file="AbstractProtocol.java" line="539" method="process"/>

<ns2:frame class="org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor" file="JIoEndpoint.java" line="298" method="run"/>

<ns2:frame class="java.util.concurrent.ThreadPoolExecutor$Worker" line="unknown" method="runTask"/>

<ns2:frame class="java.util.concurrent.ThreadPoolExecutor$Worker" line="unknown" method="run"/>

<ns2:frame class="java.lang.Thread" line="unknown" method="run"/>

</ns2:stackTrace>

<ns2:cause class="com.sun.istack.XMLStreamException2" note="To disable this feature, set com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false">

<message>org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'datumVyradeniaDo'. One of '{datumPovolenia}' is expected.</message>

<ns2:stackTrace>

<ns2:frame class="com.sun.istack.XMLStreamReaderToContentHandler" file="XMLStreamReaderToContentHandler.java" line="270" method="handleStartElement"/>

<ns2:frame class="com.sun.istack.XMLStreamReaderToContentHandler" file="XMLStreamReaderToContentHandler.java" line="109" method="bridge"/>

<ns2:frame class="com.sun.xml.ws.util.xml.StAXSource$1" file="StAXSource.java" line="184" method="parse"/>

<ns2:frame class="com.sun.xml.ws.util.xml.StAXSource$1" file="StAXSource.java" line="172" method="parse"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl" line="unknown" method="validate"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl" line="unknown" method="validate"/>

<ns2:frame class="javax.xml.validation.Validator" line="unknown" method="validate"/>

<ns2:frame class="com.sun.xml.ws.util.pipe.AbstractSchemaValidationTube" file="AbstractSchemaValidationTube.java" line="283" method="doProcess"/>

<ns2:frame class="com.sun.xml.ws.server.ServerSchemaValidationTube" file="ServerSchemaValidationTube.java" line="276" method="processRequest"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="629" method="__doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="588" method="_doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="573" method="doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="470" method="runSync"/>

<ns2:frame class="com.sun.xml.ws.server.WSEndpointImpl$2" file="WSEndpointImpl.java" line="295" method="process"/>

<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit" file="HttpAdapter.java" line="515" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter" file="HttpAdapter.java" line="285" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.ServletAdapter" file="ServletAdapter.java" line="143" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServletDelegate" file="WSServletDelegate.java" line="155" method="doGet"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServletDelegate" file="WSServletDelegate.java" line="189" method="doPost"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServlet" file="WSServlet.java" line="76" method="doPost"/>

<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="641" method="service"/>

<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="722" method="service"/>

<ns2:frame class="org.apache.catalina.core.ApplicationFilterChain" file="ApplicationFilterChain.java" line="305" method="internalDoFilter"/>

<ns2:frame class="org.apache.catalina.core.ApplicationFilterChain" file="ApplicationFilterChain.java" line="210" method="doFilter"/>

<ns2:frame class="org.apache.catalina.core.StandardWrapperValve" file="StandardWrapperValve.java" line="224" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardContextValve" file="StandardContextValve.java" line="169" method="invoke"/>

<ns2:frame class="org.apache.catalina.authenticator.AuthenticatorBase" file="AuthenticatorBase.java" line="581" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardHostValve" file="StandardHostValve.java" line="168" method="invoke"/>

<ns2:frame class="org.apache.catalina.valves.ErrorReportValve" file="ErrorReportValve.java" line="98" method="invoke"/>

<ns2:frame class="org.apache.catalina.valves.AccessLogValve" file="AccessLogValve.java" line="928" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardEngineValve" file="StandardEngineValve.java" line="118" method="invoke"/>

<ns2:frame class="org.apache.catalina.connector.CoyoteAdapter" file="CoyoteAdapter.java" line="407" method="service"/>

<ns2:frame class="org.apache.coyote.http11.AbstractHttp11Processor" file="AbstractHttp11Processor.java" line="987" method="process"/>

<ns2:frame class="org.apache.coyote.AbstractProtocol$AbstractConnectionHandler" file="AbstractProtocol.java" line="539" method="process"/>

<ns2:frame class="org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor" file="JIoEndpoint.java" line="298" method="run"/>

<ns2:frame class="java.util.concurrent.ThreadPoolExecutor$Worker" line="unknown" method="runTask"/>

<ns2:frame class="java.util.concurrent.ThreadPoolExecutor$Worker" line="unknown" method="run"/>

<ns2:frame class="java.lang.Thread" line="unknown" method="run"/>

</ns2:stackTrace>

<ns2:cause class="org.xml.sax.SAXParseException" note="To disable this feature, set com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false">

<message>cvc-complex-type.2.4.a: Invalid content was found starting with element 'datumVyradeniaDo'. One of '{datumPovolenia}' is expected.</message>

<ns2:stackTrace>

<ns2:frame class="com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper" line="unknown" method="createSAXParseException"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper" line="unknown" method="error"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.impl.XMLErrorReporter" line="unknown" method="reportError"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.impl.XMLErrorReporter" line="unknown" method="reportError"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter" line="unknown" method="reportError"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator" line="unknown" method="reportSchemaError"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator" line="unknown" method="handleStartElement"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator" line="unknown" method="startElement"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl" line="unknown" method="startElement"/>

<ns2:frame class="org.xml.sax.helpers.XMLFilterImpl" line="unknown" method="startElement"/>

<ns2:frame class="com.sun.istack.XMLStreamReaderToContentHandler" file="XMLStreamReaderToContentHandler.java" line="264" method="handleStartElement"/>

<ns2:frame class="com.sun.istack.XMLStreamReaderToContentHandler" file="XMLStreamReaderToContentHandler.java" line="109" method="bridge"/>

<ns2:frame class="com.sun.xml.ws.util.xml.StAXSource$1" file="StAXSource.java" line="184" method="parse"/>

<ns2:frame class="com.sun.xml.ws.util.xml.StAXSource$1" file="StAXSource.java" line="172" method="parse"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl" line="unknown" method="validate"/>

<ns2:frame class="com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl" line="unknown" method="validate"/>

<ns2:frame class="javax.xml.validation.Validator" line="unknown" method="validate"/>

<ns2:frame class="com.sun.xml.ws.util.pipe.AbstractSchemaValidationTube" file="AbstractSchemaValidationTube.java" line="283" method="doProcess"/>

<ns2:frame class="com.sun.xml.ws.server.ServerSchemaValidationTube" file="ServerSchemaValidationTube.java" line="276" method="processRequest"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="629" method="__doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="588" method="_doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="573" method="doRun"/>

<ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="470" method="runSync"/>

<ns2:frame class="com.sun.xml.ws.server.WSEndpointImpl$2" file="WSEndpointImpl.java" line="295" method="process"/>

<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit" file="HttpAdapter.java" line="515" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter" file="HttpAdapter.java" line="285" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.ServletAdapter" file="ServletAdapter.java" line="143" method="handle"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServletDelegate" file="WSServletDelegate.java" line="155" method="doGet"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServletDelegate" file="WSServletDelegate.java" line="189" method="doPost"/>

<ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServlet" file="WSServlet.java" line="76" method="doPost"/>

<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="641" method="service"/>

<ns2:frame class="javax.servlet.http.HttpServlet" file="HttpServlet.java" line="722" method="service"/>

<ns2:frame class="org.apache.catalina.core.ApplicationFilterChain" file="ApplicationFilterChain.java" line="305" method="internalDoFilter"/>

<ns2:frame class="org.apache.catalina.core.ApplicationFilterChain" file="ApplicationFilterChain.java" line="210" method="doFilter"/>

<ns2:frame class="org.apache.catalina.core.StandardWrapperValve" file="StandardWrapperValve.java" line="224" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardContextValve" file="StandardContextValve.java" line="169" method="invoke"/>

<ns2:frame class="org.apache.catalina.authenticator.AuthenticatorBase" file="AuthenticatorBase.java" line="581" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardHostValve" file="StandardHostValve.java" line="168" method="invoke"/>

<ns2:frame class="org.apache.catalina.valves.ErrorReportValve" file="ErrorReportValve.java" line="98" method="invoke"/>

<ns2:frame class="org.apache.catalina.valves.AccessLogValve" file="AccessLogValve.java" line="928" method="invoke"/>

<ns2:frame class="org.apache.catalina.core.StandardEngineValve" file="StandardEngineValve.java" line="118" method="invoke"/>

<ns2:frame class="org.apache.catalina.connector.CoyoteAdapter" file="CoyoteAdapter.java" line="407" method="service"/>

<ns2:frame class="org.apache.coyote.http11.AbstractHttp11Processor" file="AbstractHttp11Processor.java" line="987" method="process"/>

<ns2:frame class="org.apache.coyote.AbstractProtocol$AbstractConnectionHandler" file="AbstractProtocol.java" line="539" method="process"/>

<ns2:frame class="org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor" file="JIoEndpoint.java" line="298" method="run"/>

<ns2:frame class="java.util.concurrent.ThreadPoolExecutor$Worker" line="unknown" method="runTask"/>

<ns2:frame class="java.util.concurrent.ThreadPoolExecutor$Worker" line="unknown" method="run"/>

<ns2:frame class="java.lang.Thread" line="unknown" method="run"/>

</ns2:stackTrace>

</ns2:cause>

</ns2:cause>

</ns2:exception>

</detail>

</S:Fault>

</S:Body>

</S:Envelope>

We just exchanged order of atributes "datumPovolenia" and "datumVyradeniaDo", and obtained this exception (so both atributes were in request).

The problem is clients which use our web services are external clients and companies and we are not able to guarantee their requests will be in exact order.

I hope i described problem clearly, if not ask for any other info.

Thank you

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
snajper
Offline
Joined: 2004-10-01
Points: 0

Pasting Glen's reply to the forum, since the forum sync is still broken (IT working on it already).

---

I think you mean "elements" and not "attributes", right? Attributes can be in any order. For elements, (1) you'll need to shut off schema validation, or (2) change the XSD's to allow the elements to occur in any order (XML Schema supports that to some extent, by changing xsd:sequence to xsd:all: http://www.w3.org/TR/xmlschema-0/#groups), or (3) require your clients to send the elements in the order required by the schema. For (3) it's not your job to guarantee that your external clients send the elements in the proper order, it is your external clients', who need to follow that as part of the WSDL contract. Further, requiring clients to send elements in the order specified within xsd:sequences is hardly too much to ask, that's very basic coding easily supported by most web service frameworks.

Glen

---

peterB007
Offline
Joined: 2012-02-16
Points: 0

Thanks for reply.

Yes you are right i thought elements not atributes.

Idea with exchange xsd:sequence to xsd:all is nice but it has one problem. Xsd:all specifies that child elements can appear in any order, and that each child element must occur only once. Problem if you need elements which don't fill this limitation.

Anyway thank your answer.