vec*_*ect 5 xsd wsdl jax-ws jaxb wsimport
有两个 WSDL 共享一些用于定义数据类型的模式。以下是其中一个 WSDL 的示例:
<wsdl:definitions
name="FooService"
targetNamespace="http://xmlns.my.org/services/FooService/v001"
xmlns:srv="http://xmlns.my.org/services/FooService/v001"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:fault="java:org.my.exception"
...
>
<wsdl:types>
<xsd:schema>
<xsd:import namespace="java:org.my.exception" schemaLocation="../xsd/common/BusinessException.xsd"/>
<xsd:import namespace="http://xmlns.my.org/services/FooServiceMessages/v001" schemaLocation="../xsd/fooservice/FooServiceMessages_v001.xsd"/>
</xsd:schema>
</wsdl:types>
...
<wsdl:message name="BusinessException">
<wsdl:part element="fault:BusinessException" name="BusinessException"/>
</wsdl:message>
...
<wsdl:portType name="IFooService">
<wsdl:operation name="getItems">
...
<wsdl:fault message="srv:BusinessException" name="BusinessException"/>
</wsdl:operation>
...
</wsdl:portType>
...
</wsdl:definitions>
Run Code Online (Sandbox Code Playgroud)
BusinessException.xsd是常见的方案之一。
我正在尝试通过这些 WSDL 生成 Java 代码wsimport。将公共模式与 WSDLd 分开编译,然后在编译 WSDL 时重用从这些模式派生的类是合理的。为此,我生成了一个 JAXB Episode 文件以及常见的 Java 代码:
<bindings version="2.1" xmlns="http://java.sun.com/xml/ns/jaxb">
<bindings scd="x-schema::tns" xmlns:tns="java:org.my.exception">
<schemaBindings map="false">
<package name="org.my.integration.dto.common"/>
</schemaBindings>
<bindings scd="~tns:BusinessException">
<class ref="org.my.integration.dto.common.BusinessException"/>
</bindings>
</bindings>
<bindings scd="x-schema::tns" xmlns:tns="http://xmlns.my.org/BaseIdentifiers/v001">
<schemaBindings map="false">
<package name="org.my.integration.dto.common"/>
</schemaBindings>
<bindings scd="~tns:EntityIdentifierListType">
<class ref="org.my.integration.dto.common.EntityIdentifierListType"/>
</bindings>
<bindings scd="~tns:...">
<class ref="..."/>
</bindings>
...
</bindings>
</bindings>
Run Code Online (Sandbox Code Playgroud)
http://xmlns.my.org/BaseIdentifiers/v001命名空间填充了另一个导入的通用模式FooServiceMessages_v001.xsd(实际上是在一个导入的模式中,该模式是...导入的FooServiceMessages_v001.xsd)。
下面是我用来生成 Java 代码的 wsimport 调用:
wsimport -B-XautoNameResolution -Xnocompile -s ./../java/ -verbose -b ./bindings/fooservice/jaxws-bindings.xml -b ./bindings/fooservice/jaxb-bindings.xml -b ./bindings/common/common.episode -keep ./wsdl/FooService_v001.wsdl
Run Code Online (Sandbox Code Playgroud)
此调用发生以下错误:
[ERROR] Schema descriptor {java:org.my.exception}BusinessException in message part "BusinessException" is not defined and could not be bound to Java. ...
Run Code Online (Sandbox Code Playgroud)
顺便说一句,如果BusinessException.xsd在普通的外部 JAXB 绑定文件(而不是情节文件)中描述了绑定,则一切正常。看起来wsimport在处理情节文件时存在一些问题,这些文件描述了直接在 WSDL 中导入的方案的绑定。
有没有办法将情节文件与wsimport直接导入到 WSDL 中的方案一起使用(就像BusinessException.xsd我的情况一样)?