简体   繁体   English

Axis2 Web服务和Eclipse WSDL创作:在运行wsdl2java的wsdl中添加一个轴错误会导致异常

[英]Axis2 Web Services and Eclipse WSDL authoring: Adding an axis fault to wsdl causes exception when running wsdl2java

I am trying to create a contract-first Web Service using Apache Axis2 1.4.1. 我正在尝试使用Apache Axis2 1.4.1创建合同优先的Web服务。 Since Eclipse has what seems like a pretty complete wsdl editor I started autoring my wsdls using Eclipse´s editor. 由于Eclipse具有看起来很完整的wsdl编辑器,因此我开始使用Eclipse的编辑器自动执行wsdls。 Everything works great, I can generate Java classes using wsdl2java and the Web Services work when deployed. 一切都很好,我可以使用wsdl2java生成Java类,并且在部署Web服务时可以工作。 However, adding an exception or fault to a Web Service results in an exception saying that Element QName is null for the Fault. 但是,将异常或故障添加到Web服务会导致异常,该异常表示Fault的Element QName为null。 Does anyone know what may cause this? 有谁知道这可能是什么原因? Inspecting the wsdl doesn´t give me any direct answers either. 检查wsdl也不给我任何直接的答案。 It seems the Fault/exception is defined just like other elements. 似乎故障/异常的定义与其他元素一样。

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>

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. 似乎由于某种原因,蚀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>

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. 顺便说一句,在Eclipse中,当单击“设计”选项卡上的WSDL查找并选择“绑定元素”时,可以从“属性”视图中自动“生成绑定内容”。 By this way, you do not have to manually modify WSDL source code. 通过这种方式,您不必手动修改WSDL源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM