views:

1039

answers:

4

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.

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:

<?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/"&gt;
  <wsdl:types>
    <xsd:schema targetNamespace="http://www.example.org/JavaIntegrationModule/"&gt;
      <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"/&gt;
    <wsdl:operation name="getSolutionById">
      <soap:operation soapAction="http://www.example.org/JavaIntegrationModule/getSolutionById"/&gt;
      <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/"/&gt;
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
+2  A: 

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.

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:

<?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/"&gt;
  <wsdl:types>
    <xsd:schema targetNamespace="http://www.example.org/JavaIntegrationModule/"&gt;
      <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"/&gt;
    <wsdl:operation name="getSolutionById">
      <soap:operation soapAction="http://www.example.org/JavaIntegrationModule/getSolutionById"/&gt;
      <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/"/&gt;
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
Kristofer
A: 

Thanks for publishing the solution. I was looking for that also =).

Victor
A: 

Me too! Thanks for your q&a!

A: 

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.

tuan