【问题标题】:How to map wsdl using maven-jaxb2-plugin with name collision如何使用名称冲突的 maven-jaxb2-plugin 映射 wsdl
【发布时间】:2016-09-03 00:29:05
【问题描述】:

我在将 Web 服务映射到 Java POJO 时遇到问题,因为它包含两个元素:

  • label1
  • label_1

当插件将其转换为 java POJO 时,名称中的下划线被剥离,导致生成的类中出现重复字段。

[ERROR] 生成代码时出错。位置 [ 文件:/C:/PrivateWS/test-project/sources/target/wsdl/test.wsdl{12,94}]。 com.sun.istack.SAXParseException2;系统标识: 文件:/C:/PrivateWS/test-project/sources/target/wsdl/test.wsdl; 行号:12;列号:94;两个声明导致冲突 在 ObjectFactory 类中。

我尝试使用外部绑定文件将其中一个元素重命名为不同的名称,但失败了。 我查看了很多不同的论坛,但我找不到任何似乎有效的解决方案。据我所知,该属性未被识别,这会导致以下错误。

[错误] 解析架构时出错。位置 [ 文件:/C:/PrivateWS/test-project/sources/target/classes/bindings.xjb{9,46}]。 com.sun.istack.SAXParseException2;系统标识: 文件:/C:/PrivateWS/test-project/sources/target/classes/bindings.xjb; 行号:9;列号:46;编译器无法兑现这一点 属性定制。它附着在错误的地方,或者它的 与其他绑定不一致。

我做错了什么使字段的重命名起作用?

更改 wsdl 不是一种选择,因为它是第三方 wsdl。

pom.xml

<?xml version="1.0"?><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
     xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>

<groupId>com.testproject</groupId>
<artifactId>testproject</artifactId>
<version>0.0.0-SNAPSHOT</version>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-binding-file</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.basedir}/src/main/resources</directory>
                                <includes>
                                    <include>bindings.xjb</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
                <execution>
                    <id>copy-wsdl-file</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/wsdl</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.basedir}/src/main/resources/wsdl</directory>
                                <includes>
                                    <include>test.wsdl</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.13.1</version>
            <executions>
                <execution>
                    <id>TestProject</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <generatePackage>com.testproject</generatePackage>
                        <schemaIncludes>
                            <schemaInclude>wsdl/test.wsdl</schemaInclude>
                        </schemaIncludes>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <bindingDirectory>${project.build.outputDirectory}</bindingDirectory>
                <bindingIncludes>
                    <include>bindings.xjb</include>
                </bindingIncludes>
                <forceRegenerate>true</forceRegenerate>
                <schemaDirectory>${project.build.directory}</schemaDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>

test.wsdl

<definitions name="HelloService"
         targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl"
         xmlns="http://schemas.xmlsoap.org/wsdl/"
         xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
         xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:schema xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl" elementFormDefault="unqualified" targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl" version="1.0">
    <xsd:element name="requestType" type="tns:requestType"/>

    <xsd:complexType final="extension restriction" name="requestType">
        <xsd:sequence>
            <xsd:element form="qualified" minOccurs="0" name="label1" type="xsd:string"/>
            <xsd:element form="qualified" minOccurs="0" name="label_1" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

<message name="SayHelloRequest">
    <part element="tns:requestType" name="parameters"/>
</message>

<message name="SayHelloResponse">
    <part name="greeting" type="xsd:string"/>
</message>

<portType name="Hello_PortType">
    <operation name="sayHello">
        <input message="tns:SayHelloRequest"/>
        <output message="tns:SayHelloResponse"/>
    </operation>
</portType>

<binding name="Hello_Binding" type="tns:Hello_PortType">
    <soap:binding style="rpc"
                  transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="sayHello">
        <soap:operation soapAction="sayHello"/>
        <input>
            <soap:body
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    namespace="urn:examples:helloservice"
                    use="encoded"/>
        </input>

        <output>
            <soap:body
                    encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                    namespace="urn:examples:helloservice"
                    use="encoded"/>
        </output>
    </operation>
</binding>

<service name="Hello_Service">
    <documentation>WSDL File for HelloService</documentation>
    <port binding="tns:Hello_Binding" name="Hello_Port">
        <soap:address
                location="http://www.examples.com/SayHello/"/>
    </port>
</service>

绑定.xjb

<jxb:bindings
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    version="2.1">

<jxb:bindings schemaLocation="*">
    <jxb:bindings node="//xs:complexType[@name='requestType']" required="false">
        <jxb:bindings node=".//xs:element[@name='label_1']" required="false">
            <jxb:property name="label2"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

【问题讨论】:

    标签: java binding maven-jaxb2-plugin


    【解决方案1】:

    你设置underscoreBinding并尝试了吗?

    <jxb:bindings schemaLocation="*">
        <jxb:globalBindings underscoreBinding="asCharInWord" />
    </jxb:bindings>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多