axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steinar Haugen <stei...@haugenconsulting.no>
Subject Automatic rename of field "message" in a custom Exception.
Date Thu, 06 Oct 2005 22:09:38 GMT
Hello,

I am using WSDL2Java on the client side of a web-service to generate
Java classes from a wsdl file. This wsdl file contains a custom
Exception that is used, which seems to be set up correctly. It seems,
however, that they have overridden the getMessage method to enable
retrieving the error message using that method.

The problem I'm having is that Axis renames the "message" field when it
generates the Java class. It is renamed to "message1". Corresponding
getter and setter is named getMessage1() and setMessage1(). I assume
this is due to the fact that a method exists on the super class for
Throwable.getMessage().

It doesn't work, however. There is no setMessage() method and I get a
parse exception when parsing the SOAP message. 

If I manually rename the field and the getter & setter in the generated
class, it all works well.

The question: 
Is it possible to make WSDL2Java to generate an Exception class that
does not rename the field. 
Or is this possible to achieve by changing the wsdl file?

We're using Axis 1.2, is this a problem in all versions?

Example:

----

Error message:
org.xml.sax.SAXException: Invalid element in
location.my.soap.exceptions.MyException - message
 	at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
 	at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:701)
 	at org.apache.axis.Message.getSOAPEnvelope(Message.java:424)
 	at
org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstan
dChecker.java:62)

----

An example wsdl file recreating the problem:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://soap.my.location"
xmlns:impl="http://soap.my.location"
xmlns:intf="http://soap.my.location"
xmlns:tns2="http://exceptions.soap.my.location"
xmlns:tns3="http://dto.common.my.location"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <wsdl:types>
  <schema targetNamespace="http://exceptions.soap.my.location"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:impl="http://soap.my.location"
xmlns:intf="http://soap.my.location"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <complexType name="MyException">
    <sequence>
     <element name="message" nillable="true" type="xsd:string"/>
     <element name="exceptionDetail" nillable="true"
type="tns2:FaultDetail"/>
    </sequence>
   </complexType>
   <complexType name="FaultDetail">
    <sequence>
     <element name="errorId" nillable="true" type="xsd:string"/>
     <element name="exceptionType" nillable="true" type="xsd:string"/>
     <element name="referenceID" nillable="true" type="xsd:string"/>
     <element name="localisedMessage" nillable="true"
type="xsd:string"/>
    </sequence>
   </complexType>
   <element name="MyException" nillable="true" type="tns2:MyException"/>
  </schema>
 </wsdl:types>
   <wsdl:message name="pingRequest">
   </wsdl:message>
   <wsdl:message name="MyException">
      <wsdl:part name="fault" type="tns2:MyException"/>
   </wsdl:message>
   <wsdl:message name="pingResponse">
      <wsdl:part name="pingReturn" type="xsd:string"/>
   </wsdl:message>
   <wsdl:portType name="MyService">
      <wsdl:operation name="ping">
         <wsdl:input message="intf:pingRequest" name="pingRequest"/>
         <wsdl:output message="intf:pingResponse" name="pingResponse"/>
         <wsdl:fault message="intf:MyException" name="MyException"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="MyServiceSoapBinding" type="intf:MyService">
      <wsdlsoap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="ping">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="pingRequest">
            <wsdlsoap:body namespace="http://soap.my.location"
use="literal"/>
         </wsdl:input>
         <wsdl:output name="pingResponse">
            <wsdlsoap:body namespace="http://soap.my.location"
use="literal"/>
         </wsdl:output>
         <wsdl:fault name="MyException">
            <wsdlsoap:fault name="MyException" use="literal"/>
         </wsdl:fault>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="MyServiceService">
      <wsdl:port binding="intf:MyServiceSoapBinding" name="MyService">
         <wsdlsoap:address location="http://localhost:9080/myssrvice"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

----

The generated exception class from this wsdl looks like this:

package location.my.soap.exceptions;

public class MyException  extends org.apache.axis.AxisFault  implements
java.io.Serializable {
    private java.lang.String message1;
    private location.my.soap.exceptions.FaultDetail exceptionDetail;

    public MyException() {
    }

    public MyException(
           java.lang.String message1,
           location.my.soap.exceptions.FaultDetail exceptionDetail) {
        this.message1 = message1;
        this.exceptionDetail = exceptionDetail;
    }

    public java.lang.String getMessage1() {
        return message1;
    }

    public void setMessage1(java.lang.String message1) {
        this.message1 = message1;
    }

[clipped the end]

----

Thanks in advance for any help on this matter.

Regards, 
Steinar Haugen

--
steinar@haugenconsulting.no, +47 932 08 373
www.haugenconsulting.no


Mime
View raw message