繁体   English   中英

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

[英]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文件路径错误。 纠正路径后,一切似乎都按预期工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM