You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by "Heemskerk, Marcel (M.)" <Ma...@uwv.nl> on 2008/05/27 18:10:27 UTC
Bug in CXF Validation, produces invalid XML
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! We have a quick fix
by programmatically checking the response properties on XSD compliance
and throwing an Exception ourselves.. But this is not he way to go.
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]{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])"/>
</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><faultstri
ng>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]{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])' for type
'Datum'.
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(BareOutInter
ceptor.java:68)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:221)
at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outgoi
ngChainInterceptor.java:74)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:221)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati
onObserver.java:78)
at
org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestin
ation.java:92)
at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser
vletController.java:214)
at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl
ler.java:151)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFSe
rvlet.java:170)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doPost(AbstractCXFSe
rvlet.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(Applica
tionFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.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:2
63)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:84
4)
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:2
57)
at
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshaller
Impl.java:75)
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.ja
va: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]{3}(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.toSAXParseExcept
ion(Util.java:109)
at
com.sun.org.apache.xerces.internal.jaxp.validation.ErrorHandlerAdaptor.e
rror(ErrorHandlerAdaptor.java:104)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XML
ErrorReporter.java:382)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XML
ErrorReporter.java:316)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorRe
porter.reportError(XMLSchemaValidator.java:429)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSche
maError(XMLSchemaValidator.java:3185)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLoc
allyValidType(XMLSchemaValidator.java:3113)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processEle
mentContent(XMLSchemaValidator.java:3025)
at
com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndE
lement(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(XmlOutpu
tAbstractImpl.java:120)
at
com.sun.xml.bind.v2.runtime.output.ForkXmlOutput.endTag(ForkXmlOutput.ja
va:87)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.leafElement(XMLSerializer.java
:322)
at
com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.writeLeafEle
ment(RuntimeBuiltinLeafInfoImpl.java:210)
at
com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl$1.writeLeafEle
ment(RuntimeBuiltinLeafInfoImpl.java:209)
at
com.sun.xml.bind.v2.runtime.reflect.TransducedAccessor$CompositeTransduc
edAccessorImpl.writeLeafElement(TransducedAccessor.java:250)
at
com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.serialize
Body(SingleElementLeafProperty.java:98)
at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInf
oImpl.java:322)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
ava:681)
at
com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeI
tem(ArrayElementNodeProperty.java:65)
at
com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListB
ody(ArrayElementProperty.java:168)
at
com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(Array
ERProperty.java:152)
at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInf
oImpl.java:322)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
ava:681)
at
com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serialize
Body(SingleElementNodeProperty.java:150)
at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInf
oImpl.java:322)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
ava:681)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementB
eanInfoImpl.java:151)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementB
eanInfoImpl.java:185)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBea
nInfoImpl.java:305)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBea
nInfoImpl.java:312)
at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBea
nInfoImpl.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