java Axis2 Web 服务和 Eclipse WSDL 创作:在运行 wsdl2java 时向 wsdl 添加轴故障会导致异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2343514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Axis2 Web Services and Eclipse WSDL authoring: Adding an axis fault to wsdl causes exception when running wsdl2java
提问by Kristofer
I am trying to create a contract-first Web Service using Apache Axis2 1.4.1. Since Eclipse has what seems like a pretty complete wsdl editor I started autoring my wsdls using Eclipse′s editor. Everything works great, I can generate Java classes using wsdl2java and the Web Services work when deployed. However, adding an exception or fault to a Web Service results in an exception saying that Element QName is null for the Fault. Does anyone know what may cause this? Inspecting the wsdl doesn′t give me any direct answers either. It seems the Fault/exception is defined just like other elements.
我正在尝试使用 Apache Axis2 1.4.1 创建一个契约优先的 Web 服务。因为 Eclipse 有一个看起来非常完整的 wsdl 编辑器,所以我开始使用 Eclipse 的编辑器自动编辑我的 wsdl。一切都很好,我可以使用 wsdl2java 生成 Java 类,并且在部署时可以使用 Web 服务。但是,向 Web 服务添加异常或故障会导致异常,指出该故障的元素 QName 为空。有谁知道这可能导致什么?检查 wsdl 也不会给我任何直接的答案。似乎错误/异常的定义就像其他元素一样。
Here′s the command and stack trace:
这是命令和堆栈跟踪:
>d:\axis2-1.4.1\bin\wsdl2java.bat -o src-test -ss -uri JavaIntegrationModule.wsdl
Using AXIS2_HOME: D:\axis2-1.4.1
Using JAVA_HOME: D:\Java\jdk1.5.0_14
Retrieving document at 'JavaIntegrationModule.wsdl'.
[INFO] The src-test\src\org\example\www\javaintegrationmodule\JavaIntegrationModuleSkeleton.java file cannot be overwritten.
[INFO] The src-test\src\org\example\www\javaintegrationmodule\JavaIntegrationModuleMessageReceiverInOut.java file cannot be overwritten.
D:\>d:\axis2-1.4.1\bin\wsdl2java.bat -o src-test -ss -uri JavaIntegrationModule.wsdl
Using AXIS2_HOME: D:\axis2-1.4.1
Using JAVA_HOME: D:\Java\jdk1.5.0_14
Retrieving document at 'JavaIntegrationModule.wsdl'.
D:\>d:\axis2-1.4.1\bin\wsdl2java.bat -o src-test -ss -uri JavaIntegrationModule.wsdl
Using AXIS2_HOME: D:\axis2-1.4.1
Using JAVA_HOME: D:\Java\jdk1.5.0_14
Retrieving document at 'JavaIntegrationModule.wsdl'.
Exception in thread "main" org.apache.axis2.wsdl.codegen.CodeGenerationException: org.apache.axis2.wsdl.codegen.CodeGenerationException: jav
a.lang.RuntimeException: Element QName is null for getSolutionByIdFault!
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:271)
at org.apache.axis2.wsdl.WSDL2Code.main(WSDL2Code.java:35)
at org.apache.axis2.wsdl.WSDL2Java.main(WSDL2Java.java:24)
Caused by: org.apache.axis2.wsdl.codegen.CodeGenerationException: java.lang.RuntimeException: Element QName is null for getSolutionByIdFault
!
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.emitSkeleton(AxisServiceBasedMultiLanguageEmitter.java
:1370)
at org.apache.axis2.wsdl.codegen.CodeGenerationEngine.generate(CodeGenerationEngine.java:253)
... 2 more
Caused by: java.lang.RuntimeException: Element QName is null for getSolutionByIdFault!
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.getFaultParamElements(AxisServiceBasedMultiLanguageEmi
tter.java:2829)
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.getFaultElement(AxisServiceBasedMultiLanguageEmitter.j
ava:2748)
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.generateMethodElement(AxisServiceBasedMultiLanguageEmi
tter.java:2269)
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.loadOperations(AxisServiceBasedMultiLanguageEmitter.ja
va:2151)
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.createDOMDocumentForSkeleton(AxisServiceBasedMultiLang
uageEmitter.java:2065)
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.writeSkeleton(AxisServiceBasedMultiLanguageEmitter.jav
a:1991)
at org.apache.axis2.wsdl.codegen.emitter.AxisServiceBasedMultiLanguageEmitter.emitSkeleton(AxisServiceBasedMultiLanguageEmitter.java
:1327)
... 3 more
and the WSDL file:
和 WSDL 文件:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/JavaIntegrationModule/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="JavaIntegrationModule" targetNamespace="http://www.example.org/JavaIntegrationModule/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/JavaIntegrationModule/">
<xsd:element name="getSolutionById">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="in" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getSolutionByIdResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getSolutionByIdFault">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="getSolutionByIdFault"
type="xsd:string">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getSolutionByIdRequest">
<wsdl:part element="tns:getSolutionById" name="parameters"/>
</wsdl:message>
<wsdl:message name="getSolutionByIdResponse">
<wsdl:part element="tns:getSolutionByIdResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getSolutionByIdFault">
<wsdl:part name="parameters" element="tns:getSolutionByIdFault"></wsdl:part>
</wsdl:message>
<wsdl:portType name="JavaIntegrationModule">
<wsdl:operation name="getSolutionById">
<wsdl:input message="tns:getSolutionByIdRequest"/>
<wsdl:output message="tns:getSolutionByIdResponse"/>
<wsdl:fault name="fault" message="tns:getSolutionByIdFault"></wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="JavaIntegrationModuleSOAP" type="tns:JavaIntegrationModule">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getSolutionById">
<soap:operation soapAction="http://www.example.org/JavaIntegrationModule/getSolutionById"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="JavaIntegrationModule">
<wsdl:port binding="tns:JavaIntegrationModuleSOAP" name="JavaIntegrationModuleSOAP">
<soap:address location="http://www.example.org/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
回答by Kristofer
I think I have now solved this myself. It seems that for some reason the eclipse WSDL-editor did not add the fault to the binding part of the WSDL.
我想我现在已经自己解决了这个问题。似乎由于某种原因,Eclipse WSDL 编辑器没有将错误添加到 WSDL 的绑定部分。
So when I added:
所以当我添加:
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
to the binding, it compiles fine.
到绑定,它编译得很好。
The complete wsdl is now:
完整的 wsdl 现在是:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/JavaIntegrationModule/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="JavaIntegrationModule" targetNamespace="http://www.example.org/JavaIntegrationModule/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.example.org/JavaIntegrationModule/">
<xsd:element name="getSolutionById">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="in" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getSolutionByIdResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getSolutionByIdFault">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="getSolutionByIdFault"
type="xsd:string">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getSolutionByIdRequest">
<wsdl:part element="tns:getSolutionById" name="parameters"/>
</wsdl:message>
<wsdl:message name="getSolutionByIdResponse">
<wsdl:part element="tns:getSolutionByIdResponse" name="parameters"/>
</wsdl:message>
<wsdl:message name="getSolutionByIdFault">
<wsdl:part name="parameters" element="tns:getSolutionByIdFault"></wsdl:part>
</wsdl:message>
<wsdl:portType name="JavaIntegrationModule">
<wsdl:operation name="getSolutionById">
<wsdl:input message="tns:getSolutionByIdRequest"/>
<wsdl:output message="tns:getSolutionByIdResponse"/>
<wsdl:fault name="fault" message="tns:getSolutionByIdFault"></wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="JavaIntegrationModuleSOAP" type="tns:JavaIntegrationModule">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getSolutionById">
<soap:operation soapAction="http://www.example.org/JavaIntegrationModule/getSolutionById"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="JavaIntegrationModule">
<wsdl:port binding="tns:JavaIntegrationModuleSOAP" name="JavaIntegrationModuleSOAP">
<soap:address location="http://www.example.org/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
回答by tuan
Me too! Your solution saved me time for looking around :)
我也是!您的解决方案为我节省了环顾四周的时间:)
Btw, in Eclipse, when you click on Design tab for WSDL find, and select Binding element, you can "generate binding content" automatically from Properties view. By this way, you do not have to manually modify WSDL source code.
顺便说一句,在 Eclipse 中,当您单击 WSDL 的设计选项卡并选择绑定元素时,您可以从属性视图中自动“生成绑定内容”。通过这种方式,您不必手动修改 WSDL 源代码。

