Apache CXF 插件 - 导致目标节点为空

Apache CXF Plugin - results in empty target node

我正在尝试从我拥有的 wsdl 文件生成存根网络服务代码 当我最初 运行 mvn install 命令时 - 它引用的 wsdl 有重复名称的问题。我上网看了看,意识到我需要使用绑定文件

我有这个设置,但遗憾的是我无法获得要编译的代码

这里是相关的细节

Pom 文件插件入口

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <!-- <version>2.5.2</version> -->
    <version>3.1.4</version>
    <executions>
        <execution>
            <id>cxf-codegen</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
            <configuration>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/resources/wsdl/MyService.wsdl</wsdl>                                  
                        <packagenames>
                            <packagename>com.services.api.myservice.generated</packagename>
                        </packagenames>
                        <bindingFiles>
                            <bindingFile>${basedir}/src/main/resources/wsdl/MyBinding.xml</bindingFile>
                        </bindingFiles>     
                    </wsdlOption>                       
                </wsdlOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

绑定文件 - MyBinding.xml

<jxb:bindings version="1.0"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:s="http://www.w3.org/2001/XMLSchema"
    wsdlLocation="MyService.wsdl">

    <jxb:bindings> 
        <jxb:bindings node="./s:element[@name='MyAdvancedSearchResult']/s:complexType/s:sequence/s:any[@minOccurs='1']">
            <jxb:property name="ValueAttribute2" />
        </jxb:bindings>     

        <jxb:bindings node=".//s:element[@name='ResponseTable']/s:complexType/s:sequence/s:any[@minOccurs='0']">
            <jxb:property name="responseTable2" />
        </jxb:bindings>     
    </jxb:bindings>
</jxb:bindings>

Wsdl 文件 - MyService.wsdl

<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
      <s:element name="MyAdvancedSearch">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="keyword" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="corpId" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="MyAdvancedSearchResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="MyAdvancedSearchResult">
              <s:complexType>
                <s:sequence>
                  <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax" />
                  <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax" />
                </s:sequence>
              </s:complexType>
            </s:element>
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="getToDoListbyStatus">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Corpid" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="getToDoListbyStatusResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="getToDoListbyStatusResult" type="tns:ArrayOfActivityToDoListbyStatus" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfActivityToDoListbyStatus">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="ActivityToDoListbyStatus" nillable="true" type="tns:ActivityToDoListbyStatus" />
        </s:sequence>
      </s:complexType>
      <s:complexType name="ActivityToDoListbyStatus">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="ActivityId" type="s:int" />
          <s:element minOccurs="0" maxOccurs="1" name="ActivityName" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="ActivityDesc" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="ActivityLabel" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="Code" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="StartDate" />
          <s:element minOccurs="0" maxOccurs="1" name="EndDate" />
          <s:element minOccurs="1" maxOccurs="1" name="Requiredind" type="s:int" />
          <s:element minOccurs="1" maxOccurs="1" name="ExactDueDate" type="s:dateTime" />
          <s:element minOccurs="1" maxOccurs="1" name="Assignedind" type="s:int" />
          <s:element minOccurs="1" maxOccurs="1" name="RegStatus" type="s:int" />
          <s:element minOccurs="1" maxOccurs="1" name="Duration" type="s:float" />
          <s:element minOccurs="0" maxOccurs="1" name="Catagory" type="s:string" />
        </s:sequence>
      </s:complexType>
      <s:element name="reqActAuthHeader" type="tns:reqActAuthHeader" />
      <s:complexType name="reqActAuthHeader">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
        </s:sequence>
        <s:anyAttribute />
      </s:complexType>
      <s:element name="getToDoListbyStatus_LG">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Corpid" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="getToDoListbyStatus_LGResponse">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="getToDoListbyStatus_LGResult" type="tns:ArrayOfActivityToDoListbyStatus" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ResponseTable" nillable="true">
        <s:complexType>
          <s:sequence>
            <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax" />
            <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="ArrayOfActivityToDoListbyStatus" nillable="true" type="tns:ArrayOfActivityToDoListbyStatus" />
    </s:schema>
  </wsdl:types>
  <wsdl:message name="MyAdvancedSearchSoapIn">
    <wsdl:part name="parameters" element="tns:MyAdvancedSearch" />
  </wsdl:message>
  <wsdl:message name="MyAdvancedSearchSoapOut">
    <wsdl:part name="parameters" element="tns:MyAdvancedSearchResponse" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatusSoapIn">
    <wsdl:part name="parameters" element="tns:getToDoListbyStatus" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatusSoapOut">
    <wsdl:part name="parameters" element="tns:getToDoListbyStatusResponse" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatusreqActAuthHeader">
    <wsdl:part name="reqActAuthHeader" element="tns:reqActAuthHeader" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatus_LGSoapIn">
    <wsdl:part name="parameters" element="tns:getToDoListbyStatus_LG" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatus_LGSoapOut">
    <wsdl:part name="parameters" element="tns:getToDoListbyStatus_LGResponse" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatus_LGreqActAuthHeader">
    <wsdl:part name="reqActAuthHeader" element="tns:reqActAuthHeader" />
  </wsdl:message>
  <wsdl:message name="MyAdvancedSearchHttpGetIn">
    <wsdl:part name="keyword" type="s:string" />
    <wsdl:part name="corpId" type="s:string" />
  </wsdl:message>
  <wsdl:message name="MyAdvancedSearchHttpGetOut">
    <wsdl:part name="Body" element="tns:ResponseTable" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatusHttpGetIn">
    <wsdl:part name="Corpid" type="s:string" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatusHttpGetOut">
    <wsdl:part name="Body" element="tns:ArrayOfActivityToDoListbyStatus" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatus_LGHttpGetIn">
    <wsdl:part name="Corpid" type="s:string" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatus_LGHttpGetOut">
    <wsdl:part name="Body" element="tns:ArrayOfActivityToDoListbyStatus" />
  </wsdl:message>
  <wsdl:message name="MyAdvancedSearchHttpPostIn">
    <wsdl:part name="keyword" type="s:string" />
    <wsdl:part name="corpId" type="s:string" />
  </wsdl:message>
  <wsdl:message name="MyAdvancedSearchHttpPostOut">
    <wsdl:part name="Body" element="tns:ResponseTable" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatusHttpPostIn">
    <wsdl:part name="Corpid" type="s:string" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatusHttpPostOut">
    <wsdl:part name="Body" element="tns:ArrayOfActivityToDoListbyStatus" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatus_LGHttpPostIn">
    <wsdl:part name="Corpid" type="s:string" />
  </wsdl:message>
  <wsdl:message name="getToDoListbyStatus_LGHttpPostOut">
    <wsdl:part name="Body" element="tns:ArrayOfActivityToDoListbyStatus" />
  </wsdl:message>
  <wsdl:portType name="MyServiceSoap">
    <wsdl:operation name="MyAdvancedSearch">
      <wsdl:input message="tns:MyAdvancedSearchSoapIn" />
      <wsdl:output message="tns:MyAdvancedSearchSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus">
      <wsdl:input message="tns:getToDoListbyStatusSoapIn" />
      <wsdl:output message="tns:getToDoListbyStatusSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus_LG">
      <wsdl:input message="tns:getToDoListbyStatus_LGSoapIn" />
      <wsdl:output message="tns:getToDoListbyStatus_LGSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="MyServiceHttpGet">
    <wsdl:operation name="MyAdvancedSearch">
      <wsdl:input message="tns:MyAdvancedSearchHttpGetIn" />
      <wsdl:output message="tns:MyAdvancedSearchHttpGetOut" />
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus">
      <wsdl:input message="tns:getToDoListbyStatusHttpGetIn" />
      <wsdl:output message="tns:getToDoListbyStatusHttpGetOut" />
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus_LG">
      <wsdl:input message="tns:getToDoListbyStatus_LGHttpGetIn" />
      <wsdl:output message="tns:getToDoListbyStatus_LGHttpGetOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="MyServiceHttpPost">
    <wsdl:operation name="MyAdvancedSearch">
      <wsdl:input message="tns:MyAdvancedSearchHttpPostIn" />
      <wsdl:output message="tns:MyAdvancedSearchHttpPostOut" />
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus">
      <wsdl:input message="tns:getToDoListbyStatusHttpPostIn" />
      <wsdl:output message="tns:getToDoListbyStatusHttpPostOut" />
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus_LG">
      <wsdl:input message="tns:getToDoListbyStatus_LGHttpPostIn" />
      <wsdl:output message="tns:getToDoListbyStatus_LGHttpPostOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="MyServiceSoap" type="tns:MyServiceSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="MyAdvancedSearch">
      <soap:operation soapAction="http://tempuri.org/MyAdvancedSearch" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus">
      <soap:operation soapAction="http://tempuri.org/getToDoListbyStatus" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
        <soap:header message="tns:getToDoListbyStatusreqActAuthHeader" part="reqActAuthHeader" use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus_LG">
      <soap:operation soapAction="http://tempuri.org/getToDoListbyStatus_LG" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
        <soap:header message="tns:getToDoListbyStatus_LGreqActAuthHeader" part="reqActAuthHeader" use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="MyServiceSoap12" type="tns:MyServiceSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="MyAdvancedSearch">
      <soap12:operation soapAction="http://tempuri.org/MyAdvancedSearch" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus">
      <soap12:operation soapAction="http://tempuri.org/getToDoListbyStatus" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
        <soap12:header message="tns:getToDoListbyStatusreqActAuthHeader" part="reqActAuthHeader" use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus_LG">
      <soap12:operation soapAction="http://tempuri.org/getToDoListbyStatus_LG" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
        <soap12:header message="tns:getToDoListbyStatus_LGreqActAuthHeader" part="reqActAuthHeader" use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="MyServiceHttpGet" type="tns:MyServiceHttpGet">
    <http:binding verb="GET" />
    <wsdl:operation name="MyAdvancedSearch">
      <http:operation location="/MyAdvancedSearch" />
      <wsdl:input>
        <http:urlEncoded />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus">
      <http:operation location="/getToDoListbyStatus" />
      <wsdl:input>
        <http:urlEncoded />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus_LG">
      <http:operation location="/getToDoListbyStatus_LG" />
      <wsdl:input>
        <http:urlEncoded />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="MyServiceHttpPost" type="tns:MyServiceHttpPost">
    <http:binding verb="POST" />
    <wsdl:operation name="MyAdvancedSearch">
      <http:operation location="/MyAdvancedSearch" />
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded" />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus">
      <http:operation location="/getToDoListbyStatus" />
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded" />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getToDoListbyStatus_LG">
      <http:operation location="/getToDoListbyStatus_LG" />
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded" />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="MyService">
    <wsdl:port name="MyServiceSoap" binding="tns:MyServiceSoap">
      <soap:address location="http://test.com/Myservice.asmx" />
    </wsdl:port>
    <wsdl:port name="MyServiceSoap12" binding="tns:MyServiceSoap12">
      <soap12:address location="http://test.com/Myservice.asmx" />
    </wsdl:port>
    <wsdl:port name="MyServiceHttpGet" binding="tns:MyServiceHttpGet">
      <http:address location="http://test.com/Myservice.asmx" />
    </wsdl:port>
    <wsdl:port name="MyServiceHttpPost" binding="tns:MyServiceHttpPost">
      <http:address location="http://test.com/Myservice.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

当我 运行 mvn install - 我得到以下错误 - 知道我需要做什么来解决这个问题吗?

XPath evaluation of "./s:element[@name='MyAdvancedSearchResult']/s:complexType/s:sequence/s:any[@minOccurs='1']" results in empty target node
XPath evaluation of ".//s:element[@name='ResponseTable']/s:complexType/s:sequence/s:any[@minOccurs='0']" results in empty target node

我可以建议您MyBinding.xml的以下版本,以解决您目前遇到的错误。 我刚刚更换:

  • .///
  • .////.

因此,您需要在文件中的任何位置。希望这就是你想要的。

<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:s="http://www.w3.org/2001/XMLSchema"
wsdlLocation="MyService.wsdl">

<jxb:bindings> 
   <jxb:bindings node="//s:element[@name='MyAdvancedSearchResult']/s:complexType/s:sequence/s:any[@minOccurs='1']">
        <jxb:property name="ValueAttribute2" />
    </jxb:bindings>     

     <jxb:bindings node="//s:element[@name='ResponseTable']/s:complexType/s:sequence/s:any[@minOccurs='0']">
        <jxb:property name="responseTable2" />
    </jxb:bindings>     
</jxb:bindings>

我之前的回答更多是修复XP​​ath问题,确实修复了XPath问题,但是还是无法生成代码。

我喜欢这个问题,我想再试一次。 我用你的文件创建了一个简单的项目,鉴于 wsdl 由 3rd 方服务提供商提供,并且无法更改,我只修改了 MyBinding.xml 文件并且 我设法生成了代码成功。 这是我想出的 MyBinding.xml 文件的版本:

<jxb:bindings schemaLocation="MyService.wsdl#types1">
    <jxb:bindings xmlns:s="http://www.w3.org/2001/XMLSchema"
        node="//s:element[@name='MyAdvancedSearchResponse']/s:complexType/s:sequence/s:element[@name='MyAdvancedSearchResult']/s:complexType/s:sequence/s:any[@minOccurs='1']">
        <jxb:property name="ValueAttribute2" />
    </jxb:bindings>
    <jxb:bindings xmlns:s="http://www.w3.org/2001/XMLSchema"
        node="//s:element[@name='ResponseTable']/s:complexType/s:sequence/s:any[@minOccurs='1']">
        <jxb:property name="responseTable2" />
    </jxb:bindings>
</jxb:bindings>

This是一道SO题,我参考了