Details
Description
SUMMARY:
When using a xsd:simpleType with pattern restriction, a non-valid reponse message (which generates a SAXParseException) results in CXF returning invalid XML (missing ">" etc...), instead of CXF returning a proper SOAP Fault. I think this is a major issue!
Any help on this problem really really appreciated!
EXPLANATION + REPRODUCTION DETAILS:
In here I will put all the information needed to reproduce the bug. We have a web service with external schema, xsd1.xsd
<include schemaLocation="xsd2.xsd"/>
<xsd:element name="Period">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="StartPeriod" type="uwvml:Datum"/>
<xsd:element name="EndPeriod" type="uwvml:Datum" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
/xsd:element>
This includes xsd2.xsd where Datum is defined as a pattern for year month day in yyyymmdd:
<simpleType name="Datum">
<restriction base="string">
<length value="8"/>
<pattern value="[1-2][0-9]
</restriction>
</simpleType>
We use CXF 2.1, with JAXB binding.
The service operation looks like:
public MyResponse doSomething(MyRequest, Holder<MyHeader header) {... }
In the MyResponse is a StartPeriod which does NOT comply with the XSD. It contains the value "21130" (without quotes).
In the Spring config we turned on validation:
<jaxws:endpoint ...
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
</jaxws:endpoint>
Now.... I would have expected CXF to return a SOAP-FAULT... but instead it returns:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns4:MyHeader xmlns:ns5=". . .. " xmlns:ns4=". . . " xmlns:ns3=". . ">
<!-- VALID XML -->
</ns4:MyHeader>
</soap:Header>
<soap:Body>
<ns3:MyResponse xmlns:ns2=". . . " xmlns:ns3=". . . " xmlns:ns4=". . . " xmlns:ns5=". . . ">
<!-- VALID XML until... -->
<ns3:SomeTagName<soap:Fault><faultcode>soap:Server</faultcode><faultstring>Marshalling Error: cvc-pattern-valid: Value '21130' is not facet-valid with respect to pattern '[1-2][0-9]{3}
(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])' for type 'Datum'.</faultstring></soap:Fault></soap:Body></soap:Envelope>
The stacktrace i got is:
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Marshalling Error: cvc-pattern-valid: Value '21130' is not facet-valid with respect to pattern '[1-2][0-9]
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:208)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:79)
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:86)
at org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:92)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:214)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:151)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:170)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFServlet.java:148)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-pattern-valid: Value '21130' is not facet-valid with respect to pattern '[1-2][0-9]{3}
(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])' for type 'Datum'.]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:331)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:257)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:436)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:189)
... 26 more
Caused by: org.xml.sax.SAXParseException: cvc-pattern-valid: Value '21130' is not facet-valid with respect to pattern '[1-2][0-9]
(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])' for type 'Datum'.
at com.sun.org.apache.xerces.internal.jaxp.validation.Util.toSAXParseException(Util.java:109)
at com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.error(ErrorHandlerAdaptor.java:104)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:382)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:429)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3185)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3113)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3025)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(XMLSchemaValidator.java:2178)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(XMLSchemaValidator.java:814)
at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(ValidatorHandlerImpl.java:345)
at org.xml.sax.helpers.XMLFilterImpl.endElement(XMLFilterImpl.java:546)
at com.sun.xml.bind.v2.runtime.output.SAXOutput.endTag(SAXOutput.java:128)
at com.sun.xml.bind.v2.runtime.output.XmlOutputAbstractImpl.endTag(XmlOutputAbstractImpl.java:120)
at com.sun.xml.bind.v2.runtime.output.ForkXmlOutput.endTag(ForkXmlOutput.java:87)
at com.sun.xml.bind.v2.runtime.XMLSerializer.leafElement(XMLSerializer.java:322)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.writeLeafElement(RuntimeBuiltinLeafInfoImpl.java:210)
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.writeLeafElement(RuntimeBuiltinLeafInfoImpl.java:209)
at com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransducedAccessorImpl.writeLeafElement(TransducedAccessor.java:250)
at com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody(SingleElementLeafProperty.java:98)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
at com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:65)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:168)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:150)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:322)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:681)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:151)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:185)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:305)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:312)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:71)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
... 30 more
To see what is wrong, i added in the service method, just before the return, the following code.
Class[] responseClasses =
{ MyResponse.class };
JAXBContext responseContext = JAXBContext.newInstance(responseClasses);
Marshaller responseMarshaller = responseContext.createMarshaller();
responseMarshaller.marshal(response,System.err);
This produces correct XML, but non-compliant with the XSD because there is a Datum tag with a "21130" value.
Cheers,
- Marcel Heemskerk
Attachments
Issue Links
- duplicates
-
CXF-1551 validation against XML schema - leads to invalid soap response
- Closed