2


we have deployed Webservice into websphere server and i want ask about setting for controlling soap fault response. I want add stack trace log into reply when soap fault happens. I know it is possible in weblogic. How to achieve this in websphere? or is there way how to add it manually (not by creating custom element)?

Thanks

EDIT: i use apache cxf to generate base java classes so i have :

@WebMethod public returnType method(param) throws CustomException

and creating fault

CustomExceptionWSDLType ex = new CustomExceptionWSDLType ()
throw new CustomException(error.getMessage(), ex , error);

CustomException is Exception and
CustomExceptionWSDLType is complex type (both generated by cxf)

EDIT2: i use CXF for generate POJO but Websphere use own axis implementation to deploy my WS.

JIV
  • 813
  • 2
  • 12
  • 30
  • i found http://stackoverflow.com/a/3437062/571816 but where is axis2.xml? should be in my ear? – JIV Aug 22 '12 at 14:03
  • You state that you are using CXF. Axis2 is a different WS-stack. There shouldn't be an axis2.xml in your ear, because you are not using axis2. – joergl Aug 24 '12 at 12:09
  • i use cxf only to generate POJO. Websphere deploy @Webservice with axis2 framework so i need to focus on axis. Anyway i found axis2.xml inside plugins\org.apache.axis2.jar but setting sendStacktraceDetailsWithFaults has no effect – JIV Aug 24 '12 at 13:01
  • Ah, I think I understand now. You are generating the POJO using wsdl2java, right? I would strongly suggest to use wsimport instead. This tool is part of the JAX-WS RI (it's in the JDK). For some more context, see this answer: http://stackoverflow.com/a/3590252/1127892 – joergl Aug 24 '12 at 13:39

1 Answers1

1

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.

joergl
  • 2,850
  • 4
  • 36
  • 42
  • probably i should have mentioned i use apache CXF to generate Java classes from WSDL. – JIV Aug 22 '12 at 13:47
  • That is fine. If have this code in a CXF service that implements classes generated from WSDL. The service is also deployed with this WSDL. – joergl Aug 22 '12 at 14:25
  • yes i could put stacktrace into fault message but thats not exactly what i want. – JIV Aug 24 '12 at 13:04
  • Where do you want the stacktrace do be placed? If not the in the faultstring, then you only have the faultcode or a detail subelement of the fault. – joergl Aug 24 '12 at 13:41
  • ok i added it into custom element by myself, screw axis :) thx 4 help – JIV Sep 14 '12 at 12:48