将MTOM与Apache CXF 2.5.2一起使用时架构验证失败



我正在使用Apache CXF 2.5.2创建web服务。我创建了一个端点,并使用启用了mtom和模式验证

<jaxws:properties>
    <entry key="mtom-enabled" value="true"/>
    <entry key="schema-validation-enabled" value="true"/>
</jaxws:properties>

如果我关闭了mtom-enabled属性,那么架构将正确验证。如果我关闭schema-validation-enabled属性,则mtom可以正常工作。

<result>
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:2fd0125c-bfb6-454b-8a98-9e3a16083dca-9@cxf.apache.org">
</xop:Include>
</result>

我的模式如下:

<xsd:complexType name="ResultList">
    <xsd:sequence>
        <xsd:element name="result" type="myns:ResultType"
            minOccurs="0" maxOccurs="unbounded" />
    </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ResultType">
    <xsd:simpleContent>
        <xsd:restriction base="xmime:base64Binary">
            <xsd:attribute ref="xmime:contentType" use="required" />
        </xsd:restriction>
    </xsd:simpleContent>
</xsd:complexType>

我的Base64Binary类看起来有点像这样:

public class Base64Binary
{
    @Lob @XmlValue
    protected byte[] value;
    @XmlAttribute(namespace = "http://www.w3.org/2005/05/xmlmime")
    protected String contentType;
}

启用模式验证后,我得到以下错误:

org.apache.cxf.interceptor.Fault: Marshalling Error: cvc-complex-type.2.2: Element 'result' must have no element [children], and the value must be valid.
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:261)
    at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
    at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:119)
    at org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213)
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154)
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:126)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: cvc-complex-type.2.2: Element 'result' must have no element [children], and the value must be valid.]
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(Unknown Source)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:550)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:236)
    ... 29 more
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.2: Element 'result' must have no element [children], and the value must be valid.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.endElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.endElement(Unknown Source)
    at org.xml.sax.helpers.XMLFilterImpl.endElement(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.output.SAXOutput.endTag(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.output.XmlOutputAbstractImpl.endTag(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.output.ForkXmlOutput.endTag(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.output.MTOMXmlOutput.endTag(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.output.NamespaceContextImpl$Element.endElement(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.endElement(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(Unknown Source)
    ... 33 more

关于如何绕过这个验证错误,有什么想法吗?

谢谢。

您可以将"result"元素设置为:吗

<xsd:element name="result" type="xsd:base64Binary"
        minOccurs="0" maxOccurs="unbounded" />

看看这是否有帮助。从根本上讲,JAXB模式验证和mtom并不是真正兼容的,因为mtom的东西是在验证之后处理的(这有点错误)。CXF确实尝试过让它一起工作,但我认为只有当元素类型直接是base64Binary类型时,它才能做到这一点。

相关内容

  • 没有找到相关文章

最新更新