XPath evaluation - Error trying to bind to a schema

≡放荡痞女 提交于 2021-01-29 16:50:28

问题


I am using Java 14 with Maven and Spring Boot.

I was getting the following error:

org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "com.travellinck.client.approval.ApprovalRequest" as an element because it is missing an @XmlRootElement annotation]

To which I found the following solution: I would like to add @XmlRoot annotation on CXF codegen This requires binding to the schema.

So I added the following binding file to the pom:

                        <wsdlOption>
                            <wsdl>${project.basedir}/src/main/resources/wsdl/approval.wsdl</wsdl>
                            <bindingFiles>
                                <bindingFile>${basedir}/src/main/resources/wsdl/BindingFile.xjb</bindingFile>
                            </bindingFiles>
                            <extraargs><extraarg>-xjc-Xannotate</extraarg></extraargs>
                        </wsdlOption>

And the following binding file (BindingFile.xjb):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.0"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
               jaxb:extensionBindingPrefixes="annox xjc"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
               xmlns:xs="http://www.w3.org/2001/XMLSchema"
               xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
               xmlns:annox="http://annox.dev.java.net"
               xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance">

    <jaxb:bindings schemaLocation="approval.wsdl#types1" node="/xs:schema">
        <jaxb:bindings node="//xs:complexType[@name='ApprovalRequest']">
            <annox:annotate target="class">
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="approvalRequest"/>
            </annox:annotate>
        </jaxb:bindings>
        <jaxb:bindings node="//xs:complexType[@name='ApprovalResponse']">
            <annox:annotate target="class">
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="approvalResponse"/>
            </annox:annotate>
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

Error:

BindingFile.xjb [12,73]: XPath evaluation of "//xs:complexType[@name='ApprovalRequest']" results in empty target node
BindingFile.xjb [17,74]: XPath evaluation of "//xs:complexType[@name='ApprovalResponse']" results in empty target node

It looks like the issue is I am not matching the ApprovalRequest and ApprovalResponse objects correctly between the binding file and the schema.

More info:

Schema (http://localhost:8088/approval?xsd=5)

<!--  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.5-b05 .  -->
<!--  Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.5-b05 .  -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.travellinck.com/client/approval/service" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.travellinck.com/client/approval/service" name="ApprovalService">
<types>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/service" schemaLocation="http://localhost:8088/approval?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/evaluation/strategy" schemaLocation="http://localhost:8088/approval?xsd=2"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/evaluation" schemaLocation="http://localhost:8088/approval?xsd=3"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/contact" schemaLocation="http://localhost:8088/approval?xsd=4"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval" schemaLocation="http://localhost:8088/approval?xsd=5"/>
</xsd:schema>
</types>
<message name="submitRequestForApproval">
<part xmlns:ns1="http://www.travellinck.com/client/approval" name="approvalRequest" element="ns1:approvalRequest"/>
</message>
<message name="submitRequestForApprovalResponse">
<part xmlns:ns2="http://www.travellinck.com/client/approval" name="approvalResponse" element="ns2:approvalResponse"/>
</message>
<message name="UnsupportedBusinessRequest">
<part name="fault" element="tns:unsupportedBusinessRequest"/>
</message>
<message name="UnsupportedSupportingDocument">
<part name="fault" element="tns:unsupportedSupportingDocument"/>
</message>
<message name="getApprovalState">
<part xmlns:ns3="http://www.travellinck.com/client/approval" name="getApprovalStateRequest" element="ns3:getApprovalStateRequest"/>
</message>
<message name="getApprovalStateResponse">
<part xmlns:ns4="http://www.travellinck.com/client/approval" name="getApprovalStateResponse" element="ns4:getApprovalStateResponse"/>
</message>
<message name="UnknownApprovalRequest">
<part name="fault" element="tns:unknownApprovalRequest"/>
</message>
<message name="withdrawRequestForApproval">
<part xmlns:ns5="http://www.travellinck.com/client/approval" name="withdrawApprovalRequest" element="ns5:withdrawApprovalRequest"/>
</message>
<message name="withdrawRequestForApprovalResponse">
<part xmlns:ns6="http://www.travellinck.com/client/approval" name="withdrawApprovalResponse" element="ns6:withdrawApprovalResponse"/>
</message>
<message name="InvalidRequest">
<part name="fault" element="tns:invalidRequest"/>
</message>
<message name="RequestNoLongerInProgress">
<part name="fault" element="tns:requestNoLongerInProgress"/>
</message>
<portType name="Approval">
<operation name="submitRequestForApproval">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApprovalRequest" message="tns:submitRequestForApproval"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApprovalResponse" message="tns:submitRequestForApprovalResponse"/>
<fault message="tns:UnsupportedBusinessRequest" name="UnsupportedBusinessRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApproval/Fault/UnsupportedBusinessRequest"/>
<fault message="tns:UnsupportedSupportingDocument" name="UnsupportedSupportingDocument" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApproval/Fault/UnsupportedSupportingDocument"/>
</operation>
<operation name="getApprovalState">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalStateRequest" message="tns:getApprovalState"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalStateResponse" message="tns:getApprovalStateResponse"/>
<fault message="tns:UnknownApprovalRequest" name="UnknownApprovalRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalState/Fault/UnknownApprovalRequest"/>
</operation>
<operation name="withdrawRequestForApproval">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApprovalRequest" message="tns:withdrawRequestForApproval"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApprovalResponse" message="tns:withdrawRequestForApprovalResponse"/>
<fault message="tns:InvalidRequest" name="InvalidRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/InvalidRequest"/>
<fault message="tns:RequestNoLongerInProgress" name="RequestNoLongerInProgress" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/RequestNoLongerInProgress"/>
<fault message="tns:UnknownApprovalRequest" name="UnknownApprovalRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/UnknownApprovalRequest"/>
</operation>
</portType>
<binding name="ApprovalPortBinding" type="tns:Approval">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="submitRequestForApproval">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UnsupportedBusinessRequest">
<soap:fault name="UnsupportedBusinessRequest" use="literal"/>
</fault>
<fault name="UnsupportedSupportingDocument">
<soap:fault name="UnsupportedSupportingDocument" use="literal"/>
</fault>
</operation>
<operation name="getApprovalState">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UnknownApprovalRequest">
<soap:fault name="UnknownApprovalRequest" use="literal"/>
</fault>
</operation>
<operation name="withdrawRequestForApproval">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="InvalidRequest">
<soap:fault name="InvalidRequest" use="literal"/>
</fault>
<fault name="RequestNoLongerInProgress">
<soap:fault name="RequestNoLongerInProgress" use="literal"/>
</fault>
<fault name="UnknownApprovalRequest">
<soap:fault name="UnknownApprovalRequest" use="literal"/>
</fault>
</operation>
</binding>
<service name="ApprovalService">
<port name="ApprovalPort" binding="tns:ApprovalPortBinding">
<soap:address location="http://localhost:8088/approval"/>
</port>
</service>
</definitions>

WSDL (http://localhost:8088/approval?wsdl)

<!--  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.5-b05 .  -->
<!--  Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2.5-b05 .  -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.travellinck.com/client/approval/service" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://www.travellinck.com/client/approval/service" name="ApprovalService">
<types>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/service" schemaLocation="http://localhost:8088/approval?xsd=1"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/evaluation/strategy" schemaLocation="http://localhost:8088/approval?xsd=2"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/evaluation" schemaLocation="http://localhost:8088/approval?xsd=3"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval/contact" schemaLocation="http://localhost:8088/approval?xsd=4"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://www.travellinck.com/client/approval" schemaLocation="http://localhost:8088/approval?xsd=5"/>
</xsd:schema>
</types>
<message name="submitRequestForApproval">
<part xmlns:ns1="http://www.travellinck.com/client/approval" name="approvalRequest" element="ns1:approvalRequest"/>
</message>
<message name="submitRequestForApprovalResponse">
<part xmlns:ns2="http://www.travellinck.com/client/approval" name="approvalResponse" element="ns2:approvalResponse"/>
</message>
<message name="UnsupportedBusinessRequest">
<part name="fault" element="tns:unsupportedBusinessRequest"/>
</message>
<message name="UnsupportedSupportingDocument">
<part name="fault" element="tns:unsupportedSupportingDocument"/>
</message>
<message name="getApprovalState">
<part xmlns:ns3="http://www.travellinck.com/client/approval" name="getApprovalStateRequest" element="ns3:getApprovalStateRequest"/>
</message>
<message name="getApprovalStateResponse">
<part xmlns:ns4="http://www.travellinck.com/client/approval" name="getApprovalStateResponse" element="ns4:getApprovalStateResponse"/>
</message>
<message name="UnknownApprovalRequest">
<part name="fault" element="tns:unknownApprovalRequest"/>
</message>
<message name="withdrawRequestForApproval">
<part xmlns:ns5="http://www.travellinck.com/client/approval" name="withdrawApprovalRequest" element="ns5:withdrawApprovalRequest"/>
</message>
<message name="withdrawRequestForApprovalResponse">
<part xmlns:ns6="http://www.travellinck.com/client/approval" name="withdrawApprovalResponse" element="ns6:withdrawApprovalResponse"/>
</message>
<message name="InvalidRequest">
<part name="fault" element="tns:invalidRequest"/>
</message>
<message name="RequestNoLongerInProgress">
<part name="fault" element="tns:requestNoLongerInProgress"/>
</message>
<portType name="Approval">
<operation name="submitRequestForApproval">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApprovalRequest" message="tns:submitRequestForApproval"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApprovalResponse" message="tns:submitRequestForApprovalResponse"/>
<fault message="tns:UnsupportedBusinessRequest" name="UnsupportedBusinessRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApproval/Fault/UnsupportedBusinessRequest"/>
<fault message="tns:UnsupportedSupportingDocument" name="UnsupportedSupportingDocument" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/submitRequestForApproval/Fault/UnsupportedSupportingDocument"/>
</operation>
<operation name="getApprovalState">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalStateRequest" message="tns:getApprovalState"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalStateResponse" message="tns:getApprovalStateResponse"/>
<fault message="tns:UnknownApprovalRequest" name="UnknownApprovalRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/getApprovalState/Fault/UnknownApprovalRequest"/>
</operation>
<operation name="withdrawRequestForApproval">
<input wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApprovalRequest" message="tns:withdrawRequestForApproval"/>
<output wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApprovalResponse" message="tns:withdrawRequestForApprovalResponse"/>
<fault message="tns:InvalidRequest" name="InvalidRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/InvalidRequest"/>
<fault message="tns:RequestNoLongerInProgress" name="RequestNoLongerInProgress" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/RequestNoLongerInProgress"/>
<fault message="tns:UnknownApprovalRequest" name="UnknownApprovalRequest" wsam:Action="http://www.travellinck.com/client/approval/service/Approval/withdrawRequestForApproval/Fault/UnknownApprovalRequest"/>
</operation>
</portType>
<binding name="ApprovalPortBinding" type="tns:Approval">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="submitRequestForApproval">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UnsupportedBusinessRequest">
<soap:fault name="UnsupportedBusinessRequest" use="literal"/>
</fault>
<fault name="UnsupportedSupportingDocument">
<soap:fault name="UnsupportedSupportingDocument" use="literal"/>
</fault>
</operation>
<operation name="getApprovalState">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UnknownApprovalRequest">
<soap:fault name="UnknownApprovalRequest" use="literal"/>
</fault>
</operation>
<operation name="withdrawRequestForApproval">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="InvalidRequest">
<soap:fault name="InvalidRequest" use="literal"/>
</fault>
<fault name="RequestNoLongerInProgress">
<soap:fault name="RequestNoLongerInProgress" use="literal"/>
</fault>
<fault name="UnknownApprovalRequest">
<soap:fault name="UnknownApprovalRequest" use="literal"/>
</fault>
</operation>
</binding>
<service name="ApprovalService">
<port name="ApprovalPort" binding="tns:ApprovalPortBinding">
<soap:address location="http://localhost:8088/approval"/>
</port>
</service>
</definitions>

来源:https://stackoverflow.com/questions/62641071/xpath-evaluation-error-trying-to-bind-to-a-schema

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!