Ошибка проверки схемы при использовании MTOM с Apache CXF 2.5.2 - PullRequest
2 голосов
/ 14 марта 2012

Я использую Apache CXF 2.5.2 для создания веб-службы.Я создал конечную точку и включил проверку 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

Есть мысли, как обойти эту ошибку проверки?

Спасибо.

1 Ответ

0 голосов
/ 14 марта 2012

Можете ли вы установить для элемента "result" просто:

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

и посмотреть, поможет ли это.По сути, валидация схемы JAXB и mtom на самом деле не совместимы, так как вещи mtom обрабатываются после валидации (что немного неправильно IMO).CXF делает некоторые попытки заставить его работать вместе, но я думаю, что он может сделать это только в том случае, если типом элемента является тип base64Binary напрямую.

...