使用JAX-WS + xjc +绑定向我的WSDL存​​根添加可序列化和默认的UID

时间:2014-03-25 14:22:29

标签: maven jax-ws xjc

我正在尝试使用globalBindings元素向我的WSDL存​​根类添加可序列化的+一个默认的UID,这样我就可以摆脱Eclipse中一堆恼人的警告。

我正在尝试遵循this answer中的建议,但没有运气。仍然可以在Eclipse中获得所有警告。

我可能错过了pom文件中的内容吗?

我可以升级到更新版本的jaxws插件,如果需要,甚至可以转移到其他插件。

这是我的绑定文件:

<bindings xmlns="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
    <globalBindings>
        <xjc:serializable uid="1" />
    </globalBindings>
    <bindings
        schemaLocation="../resources/com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl#types?schema3"
        version="1.0">

        <schemaBindings>
            <package name="com.satorisoftware.ws.infuseiac-intladdresscorrection" />
        </schemaBindings>
        <!-- Tell JAXB to generate Java class specifically named CorrectRequestElement 
            for this element, to avoid the name clash that automatic naming causes. -->
        <bindings node="//xsd:element[@name='CorrectRequest']">
            <class name="CorrectRequestElement" />
        </bindings>
    </bindings>
</bindings>

这是我的pom.xml文件的相关部分:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>1.12</version>
            <executions>
                <execution>
                    <id>import-iac-wsdl</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <inherited>false</inherited>
                    <configuration>
                        <packageName>com.satorisoftware.ws.infuseiac.intladdresscorrection</packageName>
                        <wsdlLocation>com/satorisoftware/ws/infuseiac/intladdresscorrection/intladdresscorrection.wsdl</wsdlLocation>
                        <staleFile>${project.build.directory}/jaxws/stale/wsdl.intladdresscorrection.done</staleFile>
                        <sourceDestDir>${project.build.directory}/generated/jaxws-infuseiac-intladdresscorrection</sourceDestDir>
                        <wsdlDirectory>src/main/resources/com/satorisoftware/ws/infuseiac/intladdresscorrection</wsdlDirectory>
                        <bindingFiles>
                            <!-- See http://www.jroller.com/gmazza/entry/enhancing_jaxb_artifacts#BindingFile 
                            for an end-to-end-example of doing bindings files for WSDL files. -->
                            <bindingFile>${basedir}/src/main/bindings/bindings-intladdresscorrection.xjb</bindingFile>
                        </bindingFiles>
                        <!-- <wsdlUrls> <value>https://infuseiac.satorisoftware.com/wsdl/IntlAddressCorrection.2012.12.wsdl</value> 
                            </wsdlUrls> -->

                        <!-- Generate JAX-WS 2.0 compatible stubs -->
                        <target>2.0</target>
                    </configuration>
                </execution>
            </executions>
        </plugin>

这是一个没有UID的生成类的示例

package com.satorisoftware.ws.infuseiac.intladdresscorrection;

import javax.xml.ws.WebFault;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.1.7-b01-
 * Generated source version: 2.0
 * 
 */
@WebFault(name = "DuplicateFieldFaultContract", targetNamespace = "infuse.satorisoftware.com/2012/08")
public class IntlAddressCorrectionCorrectDuplicateFieldFaultContractOfInfuseSingleFieldFaultFaultMessage
    extends Exception
{

    /**
     * Java type that goes as soapenv:Fault detail element.
     * 
     */
    private DuplicateFieldFaultContract faultInfo;

    /**
     * 
     * @param message
     * @param faultInfo
     */
    public IntlAddressCorrectionCorrectDuplicateFieldFaultContractOfInfuseSingleFieldFaultFaultMessage(String message, DuplicateFieldFaultContract faultInfo) {
        super(message);
        this.faultInfo = faultInfo;
    }

    /**
     * 
     * @param message
     * @param faultInfo
     * @param cause
     */
    public IntlAddressCorrectionCorrectDuplicateFieldFaultContractOfInfuseSingleFieldFaultFaultMessage(String message, DuplicateFieldFaultContract faultInfo, Throwable cause) {
        super(message, cause);
        this.faultInfo = faultInfo;
    }

    /**
     * 
     * @return
     *     returns fault bean: com.satorisoftware.ws.infuseiac.intladdresscorrection.DuplicateFieldFaultContract
     */
    public DuplicateFieldFaultContract getFaultInfo() {
        return faultInfo;
    }

}

根据要求提供了一些WSDL:

        <xsd:complexType name="DuplicateFieldFaultContract">
            <xsd:annotation>
                <xsd:appinfo>
                    <GenericType xmlns="http://schemas.microsoft.com/2003/10/Serialization/"
                        Name="DuplicateFieldFaultContract" Namespace="infuse.satorisoftware.com/2012/08">
                        <GenericParameter Name="InfuseField"
                            Namespace="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single" />
                    </GenericType>
                </xsd:appinfo>
            </xsd:annotation>
            <xsd:complexContent mixed="false">
                <xsd:extension base="tns:InfuseFaultContract">
                    <xsd:sequence>
                        <xsd:element
                            xmlns:q4="http://schemas.datacontract.org/2004/07/Satori.Infuse.Single"
                            name="DuplicateFields" nillable="true" type="q4:ArrayOfInfuseField" />
                    </xsd:sequence>
                </xsd:extension>
            </xsd:complexContent>
        </xsd:complexType>
        <xsd:element name="DuplicateFieldFaultContract" nillable="true"
            type="tns:DuplicateFieldFaultContract" />

2 个答案:

答案 0 :(得分:3)

的Anders

这是我从WSimport的帖子中了解到的

  1. 默认情况下,JAXB生成的代码不可序列化
  2. 我们需要添加一种机制来生成适用于POjos的UID
  3. 它不会为异常类创建serialVersionUID
  4. wsdl2java,默认情况下生成的异常类将具有serialVersionUID

    请尝试wsdl2java,希望这会解决您的问题

答案 1 :(得分:1)

安德烈

你没看到这个

private static final long serialVersionUID =&#34; 1L&#34; ?

生成的每个类都是可序列化的并且具有指定的uid:此过程的限制是每个生成的类将具有相同的uid。