Apache CXF wsdl2java InternalError: unresolved reference
Apache CXF wsdl2java InternalError: unresolved reference
我正在尝试使用 Apache CXF wsdl2java 可执行文件为 Web 服务生成 Java 源代码(我已经尝试过 2.7.8 和 3.2.0 版本)。
我的 wsdl 文件来自外部机构 (TMDD),所以我假设 生成良好
当我第一次尝试生成文件时,发生 "Non-unique body parts" 错误:
org.apache.cxf.tools.common.ToolException: Non-unique body parts! In a port, operations must have unique operation signatures on the wire for successful dispatching. In port {http://www.tmdd.org/303/dialogs}tmddOCSoapHttpServicePort, operations "{http://www.tmdd.org/303/dialogs}dlVideoSwitchStatusRequest" and "{http://www.tmdd.org/303/dialogs}dlIntersectionSignalStatusRequest" have the same request body block {http://www.tmdd.org/303/messages}deviceInformationRequestMsg
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.validate(WSDLToJavaContainer.java:735)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:276)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:164)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:412)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:185)
我解决了在 dlVideoSwitchStatusRequest 操作中创建新的输入消息类型以避免这种情况。我的步骤是:
创建新消息类型
<message name="MSG_VideoSwitchStatusRequest">
<part name="message" element="tmdd:videoSwitchStatusRequestMsg"/>
</message>
声明 videoSwitchStatusRequestMsg
<xs:element name="videoSwitchStatusRequestMsg" type="VideoSwitchStatusRequest">
<xs:annotation>
<xs:documentation>
<objectClass>VideoSwitch</objectClass>
<requirement>REQ1109</requirement>
</xs:documentation>
</xs:annotation>
</xs:element>
这个在.xsd
文件中定义为其他操作的类似。
修改该操作的输入类型
<operation name="dlVideoSwitchStatusRequest">
<documentation><objectClass>VideoSwitch</objectClass><objectClass>ExternalCenter</objectClass><objectClass>OwnerCenter</objectClass><msgPattern>R-R</msgPattern><requirement>REQ538</requirement></documentation>
<input message="tns:MSG_VideoSwitchStatusRequest"/> <!-- This is the new type -->
<!--<input message="tns:MSG_DeviceInformationRequest"/> This is the old one -->
<output message="tns:MSG_VideoSwitchStatus"/>
<fault name="errorReport" message="tns:MSG_ErrorReport"/>
</operation>
有了这个,那个错误就解决了(我想),但现在我又遇到了另一个错误
Exception in thread "main" java.lang.InternalError: unresolved reference
at com.sun.xml.xsom.impl.parser.DelayedRef._get(DelayedRef.java:103)
at com.sun.xml.xsom.impl.parser.DelayedRef$Type.getType(DelayedRef.java:148)
at com.sun.xml.xsom.impl.ElementDecl.getType(ElementDecl.java:110)
at com.sun.xml.xsom.impl.ElementDecl.updateSubstitutabilityMap(ElementDecl.java:174)
at com.sun.xml.xsom.impl.parser.ParserContext.getResult(ParserContext.java:141)
at com.sun.xml.xsom.parser.XSOMParser.getResult(XSOMParser.java:214)
at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:538)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:269)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:95)
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:459)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.generateTypes(WSDLToJavaContainer.java:723)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:267)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:164)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:412)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:185)
这个太笼统了,我没有从 Apache 站点找到任何信息或文档。
首先,您不能假设 TMDD wsdl 生成良好。我前段时间使用过它并且有很多错误。
我建议您重新创建自己的 TMDD.wsdl
文件版本,将其限制为您将要使用的项目。
试一试并告诉我们你得到了什么。
好吧,正如 B. Leal 所建议的,我放弃了旧的 tmdd.wsdl
并重新制作了我的 wsdl
文件,其中包含我需要数据的每个设备的单独文件。
由于大部分工作已经重新完成,我不能 100% 确定错误的来源,但我很确定它与旧 wsdl
中使用的某些类型有关xsd
文件中未正确声明。
我知道这没什么用,但如果有人犯同样的错误,我想你只有两个选择:
- 像我一样重做你的
wsdl
文件。 (我推荐这个,它比看起来更容易)
- 检查
wsdl
中使用的每种类型是否存在于 xsd
文件中,以及它们是否正确。
感谢您的帮助。
我遇到了同样的问题,我的问题在 XSD。忘记在类型前添加名称空间。 tns 和 targetNamespace 相同 url。
之前:
<xs:element name="getRequest" type="Request">
之后
<xs:element name="getRequest" type="tns:Request">
使用 complexType/simpleType 对所有元素进行的这种简单更改解决了问题。
我正在尝试使用 Apache CXF wsdl2java 可执行文件为 Web 服务生成 Java 源代码(我已经尝试过 2.7.8 和 3.2.0 版本)。
我的 wsdl 文件来自外部机构 (TMDD),所以我假设 生成良好
当我第一次尝试生成文件时,发生 "Non-unique body parts" 错误:
org.apache.cxf.tools.common.ToolException: Non-unique body parts! In a port, operations must have unique operation signatures on the wire for successful dispatching. In port {http://www.tmdd.org/303/dialogs}tmddOCSoapHttpServicePort, operations "{http://www.tmdd.org/303/dialogs}dlVideoSwitchStatusRequest" and "{http://www.tmdd.org/303/dialogs}dlIntersectionSignalStatusRequest" have the same request body block {http://www.tmdd.org/303/messages}deviceInformationRequestMsg
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.validate(WSDLToJavaContainer.java:735)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:276)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:164)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:412)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:185)
我解决了在 dlVideoSwitchStatusRequest 操作中创建新的输入消息类型以避免这种情况。我的步骤是:
创建新消息类型
<message name="MSG_VideoSwitchStatusRequest"> <part name="message" element="tmdd:videoSwitchStatusRequestMsg"/> </message>
声明 videoSwitchStatusRequestMsg
<xs:element name="videoSwitchStatusRequestMsg" type="VideoSwitchStatusRequest"> <xs:annotation> <xs:documentation> <objectClass>VideoSwitch</objectClass> <requirement>REQ1109</requirement> </xs:documentation> </xs:annotation> </xs:element>
这个在
.xsd
文件中定义为其他操作的类似。修改该操作的输入类型
<operation name="dlVideoSwitchStatusRequest"> <documentation><objectClass>VideoSwitch</objectClass><objectClass>ExternalCenter</objectClass><objectClass>OwnerCenter</objectClass><msgPattern>R-R</msgPattern><requirement>REQ538</requirement></documentation> <input message="tns:MSG_VideoSwitchStatusRequest"/> <!-- This is the new type --> <!--<input message="tns:MSG_DeviceInformationRequest"/> This is the old one --> <output message="tns:MSG_VideoSwitchStatus"/> <fault name="errorReport" message="tns:MSG_ErrorReport"/> </operation>
有了这个,那个错误就解决了(我想),但现在我又遇到了另一个错误
Exception in thread "main" java.lang.InternalError: unresolved reference
at com.sun.xml.xsom.impl.parser.DelayedRef._get(DelayedRef.java:103)
at com.sun.xml.xsom.impl.parser.DelayedRef$Type.getType(DelayedRef.java:148)
at com.sun.xml.xsom.impl.ElementDecl.getType(ElementDecl.java:110)
at com.sun.xml.xsom.impl.ElementDecl.updateSubstitutabilityMap(ElementDecl.java:174)
at com.sun.xml.xsom.impl.parser.ParserContext.getResult(ParserContext.java:141)
at com.sun.xml.xsom.parser.XSOMParser.getResult(XSOMParser.java:214)
at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:538)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:269)
at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:95)
at org.apache.cxf.tools.wsdlto.databinding.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:459)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.generateTypes(WSDLToJavaContainer.java:723)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.processWsdl(WSDLToJavaContainer.java:267)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:164)
at org.apache.cxf.tools.wsdlto.WSDLToJavaContainer.execute(WSDLToJavaContainer.java:412)
at org.apache.cxf.tools.common.toolspec.ToolRunner.runTool(ToolRunner.java:105)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:113)
at org.apache.cxf.tools.wsdlto.WSDLToJava.run(WSDLToJava.java:86)
at org.apache.cxf.tools.wsdlto.WSDLToJava.main(WSDLToJava.java:185)
这个太笼统了,我没有从 Apache 站点找到任何信息或文档。
首先,您不能假设 TMDD wsdl 生成良好。我前段时间使用过它并且有很多错误。
我建议您重新创建自己的 TMDD.wsdl
文件版本,将其限制为您将要使用的项目。
试一试并告诉我们你得到了什么。
好吧,正如 B. Leal 所建议的,我放弃了旧的 tmdd.wsdl
并重新制作了我的 wsdl
文件,其中包含我需要数据的每个设备的单独文件。
由于大部分工作已经重新完成,我不能 100% 确定错误的来源,但我很确定它与旧 wsdl
中使用的某些类型有关xsd
文件中未正确声明。
我知道这没什么用,但如果有人犯同样的错误,我想你只有两个选择:
- 像我一样重做你的
wsdl
文件。 (我推荐这个,它比看起来更容易) - 检查
wsdl
中使用的每种类型是否存在于xsd
文件中,以及它们是否正确。
感谢您的帮助。
我遇到了同样的问题,我的问题在 XSD。忘记在类型前添加名称空间。 tns 和 targetNamespace 相同 url。 之前:
<xs:element name="getRequest" type="Request">
之后
<xs:element name="getRequest" type="tns:Request">
使用 complexType/simpleType 对所有元素进行的这种简单更改解决了问题。