Mic*_*ael 4 java wsdl web-services jaxb
背景: 我们正在开发一个与多个第三方Web服务通信的应用程序。可悲的是,其中之一使用不良的命名约定定义了WSDL文件。相同的名称经常用于响应元素及其使用的complexType。下面摘录的代码举例说明了这种情况:
<s:element name="Reset_PasswordResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Reset_PasswordResult" type="tns:ResetPasswordResponse" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ResetPasswordResponse">
<s:complexContent mixed="false">
<s:extension base="tns:BaseResponse" />
</s:complexContent>
</s:complexType>
Run Code Online (Sandbox Code Playgroud)
我们使用Maven cxf codegen插件(jaxb / jax-ws)将其编译为Java类。为了避免名称冲突,我们以前使用了-AutoNameResolution选项。但是,我们发现这会导致意外的结果,在某些机器上,一类被重命名为ResetPasswordResponse2.java,而在其他机器上,另一类被重命名了。这使协作开发变得非常困难,也给我们带来了对未来的担忧(如果无法在Jenkins上正确编译该怎么办?)
问题: 我正在寻找一种手动确定翻译/重新命名方式的方法。
jaxb / jax-ws绑定是否可能解决?还有其他选择吗?
检查此问题并回答:
简而言之,您可以使用所谓的绑定文件来自定义名称。
<jxb:bindings version="2.1" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jxb:bindings schemaLocation="xsdschema.xsd" node="/xs:schema">
<jxb:bindings node="xs:complexType[@name='ResetPasswordResponse']">
<jxb:class name="ResetPasswordResponseType"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)
您可能对以下内容感兴趣jaxb:nameXmlTransform:
这将允许您全局自定义类型或元素命名规则:
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" jaxb:version="2.0">
<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
<jaxb:schemaBindings>
<jaxb:nameXmlTransform>
<jaxb:typeName suffix="Type"/>
<jaxb:elementName suffix="Element"/>
</jaxb:nameXmlTransform>
</jaxb:schemaBindings>
</jaxb:bindings>
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)
积分去布莱斯Doughan。
| 归档时间: |
|
| 查看次数: |
3875 次 |
| 最近记录: |