定制Java包JAXB wsimport [英] Customizing Java packages JAXB wsimport

查看:69
本文介绍了定制Java包JAXB wsimport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一个wsdl文件中生成一个带有maven和jaxb的客户端,该文件内部有2个模式,而一些元素具有来自不同模式的相同名称

I'm trying to generate a client with maven and jaxb from a wsdl file with 2 schemas inside and some elements with the same name from different schemas

当我尝试执行编译时,出现下一个错误:

When I try to execute the compilation I'm getting the next error:

Two declarations cause a collision in the ObjectFactory class.

WSDL模式:

<wsdl:types>
    <schema targetNamespace="http://ws.services" xmlns="http://www.w3.org/2001/XMLSchema">...</schema>
    <schema targetNamespace="http://ws.models" xmlns="http://www.w3.org/2001/XMLSchema">...</schema>
</wsdl:types>

我尝试重命名产生错误的元素,但是然后,我的spring客户端会收到正确的SOAP消息,但是它没有正确填充响应对象(其所有属性均为null).我想问题可能出在重命名响应类,所以这就是为什么我试图生成保留所有类原始名称的不同包的原因.

I tried renaming the elements that produce the error, but then my spring client receive the correct SOAP message, but it doesn't populate the response object properly (all its attributes are null). I guess the problem might come from renaming the response classes, so that's why I'm trying to generate different packages keeping the original name of all the classes.

为此,我编写了下一个绑定文件,但是我不知道我在做什么错了,因为它不起作用.

In order to do that, I wrote the next bindings file but I don't know what I'm doing wrong that it is not working.

bindings.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>  
<jaxb:bindings version="2.1"  
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"  
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"  
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"  
    xmlns:xs="http://www.w3.org/2001/XMLSchema" >  

<jaxb:bindings schemaLocation="mywsdl.wsdl#types?schema1"
    node="/xs:schema[@targetNamespace='http://ws.services']">  
        <jaxb:schemaBindings>  
            <jaxb:package name="package1" />  
        </jaxb:schemaBindings>  
</jaxb:bindings>  

<jaxb:bindings schemaLocation="mywsdl.wsdl#types?schema2"
    node="/xs:schema[@targetNamespace='http://ws.models']">  
        <jaxb:schemaBindings>  
            <jaxb:package name="package2" />  
        </jaxb:schemaBindings>  
</jaxb:bindings> 

</jaxb:bindings>  

下一个是我在maven文件中的配置部分,以防万一它有用:

My configuration part in the maven file is the next, just in case it is useful:

<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
    <execution>
        <goals>
            <goal>wsimport</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <wsdlLocation>wsdl/mywsdl.wsdl</wsdlLocation>
    <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
    <wsdlFiles>
        <wsdlFile>mywsdl.wsdl</wsdlFile>
    </wsdlFiles>
    <bindingDirectory>src/main/resources/wsdl</bindingDirectory>
    <bindingFiles>
        <bindingFile>bindings.xml</bindingFile>
    </bindingFiles>
    <packageName>original.package</packageName>
    <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
</configuration>

当我使用此绑定文件进行编译时,会出现相同的错误.所以我认为这可能是不对的.

When I compile with this bindings files, the same error appears. So I think that maybe it isn't right.

您发现任何错误吗?

谢谢.

推荐答案

根据我的经验,最好创建2个绑定文件(每个WSDL文件一个). 相应地更新pom.xml并确保绑定文件的根元素是jaxws:bindings(而不是jaxb:bindings!)

From my experience it is best to create 2 binding files (one for each WSDL file). Update your pom.xml accordingly and make sure that the root element of the binding files is jaxws:bindings (and not jaxb:bindings!)

一些提示:

  1. 确保正确设置"wsdlLocation"属性!它必须使用相对路径指向WSDL文件!
  2. jaxws:package确定将用于生成的服务类的软件包. (用@WebService注释的内容)
  3. 根据需要启用或禁用wrapperStyle和asyncMapping. ;-)

"package1"的绑定文件示例:

Example binding file for "package1":

<?xml version="1.0" encoding="UTF-8"?>

    <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
                    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
                    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
                    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                    xmlns:xs="http://www.w3.org/2001/XMLSchema"
                    wsdlLocation="mywsdl.wsdl"
                    version="2.0">

        <jaxws:package name="package1"/>
        <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
        <jaxws:enableAsyncMapping>true</jaxws:enableAsyncMapping>

        <jaxws:bindings node="//wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://ws.services']">
            <jaxb:schemaBindings>
                <jaxb:package name="package1"/>
            </jaxb:schemaBindings>
        </jaxws:bindings>

    </jaxws:bindings>

这篇关于定制Java包JAXB wsimport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆