基于WSDL使用CXF生成客户端的jaxb绑定文件集成

Integration of jaxb binding file using CXF to generate client based on WSDL

我试图在使用 CXF XJC 插件调用 wsdl2java 时合并 JAXB 绑定文件。所以我实际上正在生成 wsdl 并使用

-createxsdimports

创建外部模式文件,这样我就可以在该特定文件上执行 JAXB 绑定,而不必使用 JAXWS 绑定。我正在寻找有关我遇到的错误的帮助或替代解决方案,例如使用 JAXWS 绑定文件而不进行外部化等。

这是我的 WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="TestImplService" targetNamespace="http://service.logging.a/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://service.logging.a/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
  <import namespace="http://service.logging.a/" schemaLocation="TestImpl_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="method">
    <wsdl:part name="parameters" element="tns:method">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="methodResponse">
    <wsdl:part name="parameters" element="tns:methodResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="Test">
    <wsdl:operation name="method">
      <wsdl:input name="method" message="tns:method">
    </wsdl:input>
      <wsdl:output name="methodResponse" message="tns:methodResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="TestImplServiceSoapBinding" type="tns:Test">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="method">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="method">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="methodResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="TestImplService">
    <wsdl:port name="TestImplPort" binding="tns:TestImplServiceSoapBinding">
      <soap:address location="http://localhost:9090/TestImplPort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

这里是TestImpl_schema1.xsd:

<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://service.logging.a/" elementFormDefault="unqualified" targetNamespace="http://service.logging.a/" version="1.0">
<xs:element name="method" type="tns:method"/>
<xs:element name="methodResponse" type="tns:methodResponse"/>
<xs:complexType name="method">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="tns:foo"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="foo">
    <xs:sequence>
      <xs:element name="map">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" minOccurs="0" name="entry">
              <xs:complexType>
                <xs:sequence>
                  <xs:element minOccurs="0" name="key" type="xs:string"/>
                  <xs:element minOccurs="0" name="value" type="xs:anyType"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="methodResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="tns:foo"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

这是我的 binding.xml 文件:

<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1">
  <jaxb:bindings schemaLocation="wsdl/TestImpl_schema1.xsd">
    <jaxb:bindings node="//xs:complexType[@name='foo']//xs:element[@name='map']">
      <jaxb:property>
        <jaxb:baseType name="java.util.HashMap;" />
      </jaxb:property>
    </jaxb:bindings>
  </jaxb:bindings>
 </jaxb:bindings>

这是我的 Maven 依赖项:

<plugin>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-codegen-plugin</artifactId>
    <version>${cxf.version}</version>
    <executions>
        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <configuration>

                <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                <wsdlOptions>
                    <wsdlOption>
                        <wsdl>${basedir}/src/main/resources/META-INF/wsdl/TestImpl.wsdl</wsdl>
                        <bindingFiles>
                            <bindingFile>${basedir}/src/main/resources/META-INF/wsdl/binding.xml</bindingFile>
                        </bindingFiles>
                    </wsdlOption>
                </wsdlOptions>
            </configuration>
            <goals>
                <goal>wsdl2java</goal>
            </goals>
        </execution>
    </executions>
</plugin>

这是我在尝试 运行 插件时遇到的错误:

[ERROR] Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.7.13:wsdl2java (generate-sources) on project Test-Client: Execution generate-sources of goal org.apache.cxf:cxf-codegen-plugin:2.7.13:wsdl2java failed. IllegalArgumentException: Illegal character in opaque part at index 2: C:\..\Tester-Client/src/main/resources/META-INF/wsdl/binding.xml -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

实际上没有什么需要改变的。在 CXF 插件中,我的 binding.xml 文件路径错误。更正路径后,一切似乎都按预期工作。