Assuming I understand this correctly, this doesn't work.
The way I have things now works: I can throw my
exceptions at the service and catch them as my exceptions
and read 'minorCode' and 'majorCode' at the client.
When I try to set this up, wsdl2java creates the
following classes:
public class MyBaseException
extends
org.apache.axis.AxisFault
implements java.io.Serializable {
private int majorcode;
private int minorcode;
...
}
public class MyDetailedException
extends
com.example.MyBaseException
implements
java.io.Serializable {
...
}
public class _faultDetail
implements
java.io.Serializable {
private com.example.MyDetailedException fault;
private java.lang.String exceptionName;
...
}
public interface MyServicePortType
extends
java.rmi.Remote {
public void doSomething(...args...)
throws java.rmi.RemoteException,
com.example._faultDetail;
...
}
_faultDetail is not an exception class, but the generated
code keeps trying to throw and catch it, so when I try to
compile these classes I get many errors.
I could change the XML contained within the AxisFaults I
throw from the service to match that given below, but
since that wouldn't match up with the WSDL, that doesn't
seem like it would work.
It'd be nice if there was a full example that would start
with a WSDL file and a test class and that would show how
to throw interoperable exceptions from Axis as well as
other popular topics like arrays, etc.
I might, of course, have misunderstood what I need to
change in my WSDL.
On 28 Sep 2004 at 23:57, Anne Thomas Manes wrote:
> No -- this fault isn't interoperable because you have not defined it
> properly in your WSDL.
>
> You didn't provide us with the element definition of "tns1:fault". My
> assumption, though, is that it's defined as follows:
> <element name="fault" type="MyDetailedException"/>
>
> But -- it appears that your fault detail contains two elements:
> <ns1:fault> and <ns2:exceptionName>. There are two problems with that:
> 1- Your WSDL message definition doesn't describe the <ns2:exceptionName>
> element. (To produce the fault message you describe, you would need to
> define two message parts.)
> 2- A fault message should have only one part. If you want to return both
> elements in your detail, they should be defined as a sequence of elements
> within a single wrapper element.
>
> What you need to do is define a single element which will be the child of
> the <detail> element. This single element should be defined as a sequence
> containing the <fault> element and the <exceptionName> element, e.g.,
>
> <element name=faultDetail>
> <complexType>
> <sequence>
> <element ref="tns1:fault"/>
> <element ref="tns2:exceptionName"/>
> </sequence>
> </complexType>
> </element>
>
> And your message description should look like this:
>
> <wsdl:message name="MyDetailedException">
> <wsdl:part element="tns0:faultDetail" name="fault"/>
> </wsdl:message>
>
> The fault response should look like this (notice the faultDetail wrapper
> element):
>
> ----- BEGIN FAULT RESPONSE ----
> <?xml version="1.0" encoding="UTF-8"?>
> <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <soapenv:Body>
> <soapenv:Fault>
> <faultcode>soapenv:Server.generalException</faultcode>
> <faultstring></faultstring>
> <detail>
> <ns0:faultDetail xmlns:ns0="urn:FaultWrapper">
> <ns1:fault xmlns:ns1="urn:MyNamespace">
> <ns1:majorcode>1</ns1:majorcode>
> <ns1:minorcode>2</ns1:minorcode>
> </ns1:fault>
> <ns2:exceptionName
> xmlns:ns2="http://xml.apache.org/axis/">
> com.example.MyDetailedException
> </ns2:exceptionName>
> </faultDetail>
> </detail>
> </soapenv:Fault>
> </soapenv:Body>
> </soapenv:Envelope>
> ----- END FAULT RESPONSE ----
>
> Regards,
> Anne
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: Monday, September 27, 2004 11:25 PM
> To: [EMAIL PROTECTED]
> Subject: Is this fault interoperable?
>
> I've included a fault response and excerpts from the WSDL
> below. Will .NET and other implementations understand
> this fault? If not, what do I need to do to get something
> that most implementations will understand?
>
> Note that the faultstring in the response below is empty.
> However, I'll provide a human-understandable faultstring
> using the following technique:
>
> MyServiceBindingImpl {
> doSomething() {
> try {
> // code that does the actual work
> }
> catch ( MyNonAxisSpecificException e ) {
> throw new MyDetailedException( e );
> }
> }
> }
>
> MyNonAxisSpecificException will be very similar to an
> AxisFault, but it won't be Axis-specific.
>
> MyDetailedException was created by Axis, and it extends
> MyBaseException which in turn extends AxisFault. A new
> constructor (or similar) will be added to the axis-
> generated MyDetailedException code which will take a
> MyNonAxisSpecificException and fill out the various
> fields, including faultstring.
>
>
> ----- BEGIN FAULT RESPONSE ----
> <?xml version="1.0" encoding="UTF-8"?>
> <soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <soapenv:Body>
> <soapenv:Fault>
> <faultcode>soapenv:Server.generalException</faultcode>
> <faultstring></faultstring>
> <detail>
> <ns1:fault xmlns:ns1="urn:MyNamespace">
> <ns1:majorcode>1</ns1:majorcode>
> <ns1:minorcode>2</ns1:minorcode>
> </ns1:fault>
> <ns2:exceptionName
>
> xmlns:ns2="http://xml.apache.org/axis/">com.example.MyDet
> ailedException</ns2:exceptionName>
> </detail>
> </soapenv:Fault>
> </soapenv:Body>
> </soapenv:Envelope>
> ----- END FAULT RESPONSE ----
>
>
>
>
> ----- BEGIN WSDL EXCERPT ----
> <wsdl:types>
> <complexType name="MyBaseException">
> <sequence>
> <element name="majorcode" type="xsd:int"/>
> <element name="minorcode" type="xsd:int"/>
> </sequence>
> </complexType>
> </wsdl:types>
>
> <complexType name="MyDetailedException">
> <complexContent>
> <extension base="tns1:MyBaseException">
> <sequence/>
> </extension>
> </complexContent>
> </complexType>
>
> <wsdl:message name="MyDetailedException">
> <wsdl:part element="tns1:fault" name="fault"/>
> </wsdl:message>
>
> <wsdl:portType name="MyServicePortType">
> <wsdl:operation name="doSomething" parameterOrder="">
> <wsdl:input message="impl:doSomethingRequest"
> name="doSomethingRequest"/>
> <wsdl:output message="impl:doSomethingResponse"
> name="doSomethingResponse"/>
> <wsdl:fault message="impl:MyDetailedException"
> name="MyDetailedException"/>
> </wsdl:operation>
>
> <wsdl:binding name="MyServiceSOAPPortSoapBinding"
> type="impl:MyServicePortType">
> <wsdlsoap:binding style="document"
> transport="http://schemas.xmlsoap.org/soap/http"/>
> <wsdl:operation name="doSomething">
> <wsdlsoap:operation soapAction="doSomething"/>
>
> <wsdl:input name="doSomethingRequest">
> <wsdlsoap:body namespace="MyNamespace" use="literal"/>
> </wsdl:input>
>
> <wsdl:output name="doSomethingResponse">
> <wsdlsoap:body namespace="MyNamespace" use="literal"/>
> </wsdl:output>
>
> <wsdl:fault name="MyDetailedException">
> <wsdlsoap:fault use="literal"/>
> </wsdl:fault>
> </wsdl:operation>
> ----- END WSDL EXCERPT ----