3

I have the following problem: I am using SAAJ for web services. I have a SOAPMessage with the following soap fault:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
        <faultcode>S:Server</faultcode> 
        <faultstring>java.lang.NullPointerException</faultstring> 
        <detail>
        <ns2:exception xmlns:ns2="http://jax-ws.dev.java.net/" class="java.lang.NullPointerException" note="To disable this feature, set com.sun.xml.internal.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false">
            <ns2:stackTrace>
                <ns2:frame class="myClass" file="HandlerFile.java" line="261" method="invoke" /><ns2:frame class="myClass" file="HandlerFile.java" line="1" method="invoke" /><ns2:frame class="com.sun.xml.internal.ws.api.server.InstanceResolver$1" line="unknown" method="invokeProvider" /></ns2:stackTrace>
        </ns2:exception>    
        </detail>
        </S:Fault>
       </S:Body>
</S:Envelope>

But if I try to get the details I get nothing!
I do it as follows:

String code = soapMsg.getSOAPBody().getFault().getFaultCode();
String faultString = soapMsg.getSOAPBody().getFault().getFaultString();
Detail detail = reply.getSOAPBody().getFault().getDetail();
if(detail == null)
   System.out.println("No detail");
else
   System.out.println("Detail value is "+detail.getNodeValue());
Iterator it = reply.getSOAPBody().getFault().getDetail().getDetailEntries();
StringBuilder details = new StringBuilder();
details.append("Detail:");
while(it.hasNext())
{
  System.out.println("Has details");
  DetailEntry temp = (DetailEntry) it.next();
  System.out.println(temp.getTextContent());
  System.out.println(temp.getValue());
  details.append(temp.getValue());
  details.append("-");
  Iterator it2 = temp.getChildElements();
  while(it2.hasNext())
  {
    Node t = (Node) it2.next();
    System.out.println("Node value:"+t.getNodeValue());
  }
}
System.out.println("Details:"+details.toString());

It is printed:
Detail value is null
Has details
Details:null-
Node value:null
Can someone help on this? Why can I not get the details of SOAP fault? It is included in the SOAP message?

UPDATE: The code and the faultstring is printed correctly.
I.e.
code:S:Server
FaultString:java.lang.NullPointerException

Thanks

2
  • 1
    Your example does not show if the detail element actually has any textual content in the ns2:frame element. Have you tried accessing the childnodes of DetailEntry using getChildElements or any of the dom methods? Commented Oct 27, 2010 at 11:59
  • @Jorn:I see what you mean. The fault detail seems to report the stack trace in the server(have updated post). Tried to use getChildElements, I get in the while loop but null value is printed. Have updated code in post as well Commented Oct 27, 2010 at 12:33

1 Answer 1

1

The Method getNodeValue will always return null for a DOM element, getTextContent would be better but in your case all information is contained in attributes of nested elements. You would have to traverse these nested elements with code like the following. Please note that I haven't tested the code yet.

String uri = "http://jax-ws.dev.java.net/";
QName qnException = new QName(uri, "exception");
QName qnStackTrace = new QName(uri, "stackTrace");
QName qnFrame = new QName(uri, "frame");

SOAPFault fault = soapMsg.getSOAPBody().getFault();
System.out.println("code=" + fault.getFaultCode());
System.out.println("faultString=" + fault.getFaultString());

for (Iterator i=fault.getDetail().getDetailEntries(); i.hasNext(); ) {
    DetailEntry detailEntry = (DetailEntry)i.next();

    for (Iterator j=detailEntry.getChildElements(qnException); j.hasNext(); ) {
        SOAPElement exception = (SOAPElement)j.next();
        System.out.println("exception class=" + exception.getAttribute("class"));

        for (Iterator k=exception.getChildElements(qnStackTrace); k.hasNext(); ) {
            SOAPElement stackTrace = (SOAPElement)k.next();

            for (Iterator l=stackTrace.getChildElements(qnFrame); l.hasNext(); ) {
                SOAPElement frame = (SOAPElement)l.next();
                System.out.println(" class=" + frame.getAttribute("class"));
                System.out.println(" file =" + frame.getAttribute("file"));
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you.As soon as I test it, I will let you know if it worked
its works ? or someone can help to get the source code for debug this at java 1.8 RT.jar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.