gpt4 book ai didi

jaxb - 通过 wsimport 使用 JAXB 剧集文件

转载 作者:行者123 更新时间:2023-12-01 06:28:40 24 4
gpt4 key购买 nike

有两个 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>
BusinessException.xsd是常见的方案之一。

我正在尝试通过这些带有 wsimport 的 WSDL 生成 Java 代码。 .将通用模式与 WSDLd 分开编译,然后在编译 WSDL 时重用从这些模式派生的类是合理的。为此,我生成了一个 JAXB 插曲文件以及通用 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>
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

此调用出现以下错误:
[ERROR] Schema descriptor {java:org.my.exception}BusinessException in message part "BusinessException" is not defined and could not be bound to Java. ...

顺便说一句,如果绑定(bind) BusinessException.xsd在一个普通的外部 JAXB 绑定(bind)文件(不是在剧集文件中)中进行了描述,一切正常。看起来像 wsimport在处理情节文件时存在一些问题,这些情节文件描述了直接在 WSDL 中导入的方案的绑定(bind)。

有没有办法通过 wsimport 使用剧集文件?对于直接在 WSDL 中导入的方案(如 BusinessException.xsd 在我的情况下)?

最佳答案

https://github.com/javaee/jaxb-v2/issues/514说不可能使用 JAXB 情节为 WSDL 生成源。

Sun/Oracle 工程师 11 年(2008-2019)无法实现必要的增强。最近甲骨文向 Eclipse 项目(2018 年 10 月)抛出了源代码。

我生成没有情节的 WSDL 绑定(bind),作为最后一步,我从公共(public)模式中删除包。对于 Gradle,它看起来像:

wsimport {
wsdl = file("${project.rootDir}/wsdl/PingService.wsdl")
bindings = files(...)
}
task('afterWsimport', type: Delete) {
delete new File(file(wsimport.javaDir), "com/bla/schema")
delete new File(file(wsimport.javaDir), "com/foo")
}
wsimport.finalizedBy(afterWsimport)

关于jaxb - 通过 wsimport 使用 JAXB 剧集文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25282870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com