I am not an expert for Websphere and cannot tell you whether there is a configuration option that lets you do this.
or is there way how to add it manually (not by creating custom element)?
You can always add details and modify the fault string and code in your web service when you throw the fault. Now, there are many ways to construct and throw the fault and I do not know how your web service does it. Here is a very simple example that puts the stack trace of an exception into the fault string.
@WebMethod
public void throwFault(){
try {
SOAPFactory factory = SOAPFactory.newInstance();
IndexOutOfBoundsException e = new IndexOutOfBoundsException("index out of bounds");
SOAPFault fault = factory.createFault(getStackTraceString(e), new QName("http://whatever.com","CustomFault"));
throw new SOAPFaultException(fault);
} catch (SOAPException e) {
// ignore for the example
}
}
private String getStackTraceString(Exception e){
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
}
The method throwFault
is exposed by the service and simply creates and throws a new SOAPFault
. This may look different in your code. The private method getStackTraceString
converts the stack trace into a String representation.
This solution does add an additional element to your WSDL, it simply reuses the fault string for the stack trace.
Calling the web service, I get the following response:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
<faultcode xmlns:ns0="http://whatever.com">ns0:CustomFault</faultcode>
<faultstring>java.lang.IndexOutOfBoundsException: index out of bounds at Faulter.throwUndeclaredFault(Faulter.java:23) at <!--rest of stacktrace omitted for readability--!> </faultstring>
</S:Fault>
</S:Body>
</S:Envelope>
EDIT:
Assuming that the variable error
in your code is an exception, you can change your throw statement to
throw new CustomException(getStackTraceString(error),error);
This should provide you with the stack trace in a fashion as described above.