WSDL cxf自定义绑定

时间:2017-10-04 13:05:47

标签: cxf-codegen-plugin

我正在尝试从内联WSDL更改cxf生成的源的类名。我使用xpath指定的绑定不断被忽略。

以下是我的绑定文件:

<jaxws:bindings
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns="http://java.sun.com/xml/ns/jaxws"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
    targetNamespace="http://www.example.org/Small/"
    version="1.0">

    <jaxb:bindings node="//xsd:element[@name='NewOperationRequest']">
      <jaxb:class name="xyz"/>
    </jaxb:bindings>
</jaxws:bindings>

以下是我的wsdl文件:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/Small/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Small" targetNamespace="http://www.example.org/Small/">
  <wsdl:types>
    <xsd:schema targetNamespace="http://www.example.org/Small/">
      <xsd:element name="NewOperationX">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="in" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="NewOperationResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="out" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="NewOperationRequest">
    <wsdl:part element="tns:NewOperationX" name="parameters"/>
  </wsdl:message>
  <wsdl:message name="NewOperationResponse">
    <wsdl:part element="tns:NewOperationResponse" name="parameters"/>
  </wsdl:message>
  <wsdl:portType name="Small">
    <wsdl:operation name="NewOperation">
      <wsdl:input message="tns:NewOperationRequest"/>
      <wsdl:output message="tns:NewOperationResponse"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="SmallSOAP" type="tns:Small">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="NewOperation">
      <soap:operation soapAction="http://www.example.org/Small/NewOperation"/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="Small">
    <wsdl:port binding="tns:SmallSOAP" name="SmallSOAP">
      <soap:address location="http://www.example.org/"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

以下是我的cxf pom插件:

     <plugin>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-codegen-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
            <execution>
                <configuration>
                    <sourceRoot>
                        target/generated-sources
                    </sourceRoot>
                    <wsdlOptions>
                        <wsdlOption>
                            <wsdl>${basedir}/src/main/webapp/WEB-INF/wsdl/small.wsdl</wsdl>
                            <bindingFiles>
                               <bindingFile>${basedir}/src/main/webapp/WEB-INF/wsdl/small.xjb</bindingFile>
                             </bindingFiles>
                        </wsdlOption>
                    </wsdlOptions>
                </configuration>
                <goals>
                    <goal>wsdl2java</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

我无法使用CXF找到内联WSDL的自定义绑定示例。任何帮助表示赞赏。谢谢,

1 个答案:

答案 0 :(得分:0)

我认为您在这里遇到名称空间问题。您的内部绑定必须是 jaxws 绑定,而不是 jaxb 绑定。

尝试使用以下内容作为您最里面的绑定,而不是您的<jaxb:bindings>元素(我也修改了您的xpath):

<jaxws:bindings node="wsdl:definitions/wsdl:message[@name='NewOperationRequest']">
        <class name="xyz"/>
</jaxws:bindings>       

还有一个类似的示例,它在 JAXWS Customization 部分下的Apache CXF site上重命名端口类型。

有关更多选项,这里是GitHub上指向JAX-WS sample binding file的链接,展示了您可以自定义的wsdl的各个部分。