users@glassfish.java.net

Bug in how GlassFish handles SOAPFaultException

From: Mark Hansen <marklists_at_javector.com>
Date: Sat, 17 Mar 2007 17:36:36 -0400

GlassFish mapps SOAPFaultException to SOAP 1.1 incorrectly. See ->
https://glassfish.dev.java.net/issues/show_bug.cgi?id=2645 and the
details below.

The <detail> element of a SOAPFaultException is serialized incorrectly
when an @WebService retuens a SOAP Fault. An extra wrapper element is
added so that the <detail> has the form <detail><detail> ... contents
... </detail></detail>. See details in the example below.

As shown in the example, the bug is not with the SOAPFaultException
class itself, because then the class is serialized and printed to the
server.log, the <detail> element is handled correctly. However, the
SOAP Fault that GlassFish sends over the wire appears to contain the
extra <deail> wrapper element.

This @WebService always returns a SOAP Fault message:
=====================================================
public class SaajDetailBug {
 
  public void saajBug() {

    SOAPFaultException sfe;
    try {
      SOAPFactory fac = SOAPFactory.newInstance();
      SOAPFault sf = fac.createFault(
          "This is a fault.",
          new QName("http://schemas.xmlsoap.org/soap/envelope/", "Client"));
      Detail d = sf.addDetail();
      SOAPElement de = d.addChildElement(new QName(
          "http://www.example.com/faults", "myDetail"));
      de.addAttribute(new QName("", "msg"), "This is the detail message.");
      sfe = new SOAPFaultException(sf);
      printSOAPFault(sfe.getFault());
    } catch (Exception e) {
      throw new WebServiceException(e);
    }
    throw sfe;

  }

  private static void printSOAPFault(SOAPFault sf) throws Exception {
   
    Transformer xfmr = TransformerFactory.newInstance().newTransformer();
    xfmr.setOutputProperty(OutputKeys.INDENT, "yes");
    xfmr.transform(new DOMSource(sf), new StreamResult(System.out));
    System.out.println();
   
  }

}


SOAP Fault received by client
=============================
<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <faultstring>This is a fault.</faultstring>
  <faultcode
xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/">ns2:Client</faultcode>
  <detail>
    <detail xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
      <myDetail:myDetail xmlns:myDetail="http://www.example.com/faults"
xmlns:ns6="http://www.example.com/faults" msg="This is the detail
message."/>
    </detail>
  </detail>
</SOAP-ENV:Fault>


SOAP Fault as printed in server.log
====================================
<SOAP-ENV:Fault xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <faultstring>This is a fault.</faultstring>
  <faultcode>SOAP-ENV:Client</faultcode>
  <detail>
    <myDetail xmlns="http://www.example.com/faults" msg="This is the
detail message."/>
  </detail>
</SOAP-ENV:Fault>