users@jax-ws.java.net

Soap Faults

From: Dima Gutzeit <dima_at_mailvision.com>
Date: Sun, 13 May 2007 15:01:18 +0300

Hi,

I have a webservice that is created using JAXWS 2.1.1. Different methods in
the webservices are declared to throw different type of exceptions, while
each exception should contain additional information, and not just the
"message". There is an abstract BaseException class that is the base class
of all exceptions, and it is annotated with @WebFault, as all the derived
classes.

From my java code I am throwing those with the correct info, but what is
being sent via SOAP is

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
 <S:Body>
  <ns2:Fault xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
   <faultcode>ns2:Server</faultcode>
   <faultstring>Unauthorized login attempt</faultstring>
   <detail>
    <ns2:exception xmlns:ns2="http://jax-ws.dev.java.net/"
class="com.company.PolicyException" note="To disable this feature, set
com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system
property to false">
     <message>Unauthorized login attempt</message>
     <ns2:stackTrace>
      <ns2:frame class="com.company.CommonsServiceImpl"
file="CommonsServiceImpl.java" line="587" method="loginProviderUser"/>
      <ns2:frame class="sun.reflect.NativeMethodAccessorImpl"
file="NativeMethodAccessorImpl.java" line="native" method="invoke0"/>
      <ns2:frame class="sun.reflect.NativeMethodAccessorImpl"
file="NativeMethodAccessorImpl.java" line="39" method="invoke"/>
      <ns2:frame class="sun.reflect.DelegatingMethodAccessorImpl"
file="DelegatingMethodAccessorImpl.java" line="25" method="invoke"/>
      <ns2:frame class="java.lang.reflect.Method" file="Method.java"
line="585" method="invoke"/>
      <ns2:frame class="com.sun.xml.ws.api.server.InstanceResolver$1"
file="InstanceResolver.java" line="210" method="invoke"/>
     </ns2:stackTrace>
    </ns2:exception>
   </detail>
  </ns2:Fault>
 </S:Body>
</S:Envelope>

The schema that is exposed for this type of exception is

    <xs:complexType name="BaseException">
    <xs:sequence>
  <xs:element name="detail" type="xs:string" minOccurs="0" />
  <xs:element name="exceptionCode" type="xs:int" />
  <xs:element name="message" type="xs:string" minOccurs="0" />
  <xs:element name="variables" type="xs:string" nillable="true"
minOccurs="0" maxOccurs="unbounded" />
  </xs:sequence>
  </xs:complexType>

and com.company.PolicyException inhertits from it.

What should I do, to make jaxws soapFaults to contain all the data in the
exception and not only the basic "message" ?

Thanks in advance.
Regards,
Dima Gutzeit.