views:

96

answers:

3

Hello experts!

I have an Axis2 web service which throws different detail messages in the fault response to signal problems in the call.

At some point, due to server errors (others than the ones treated by the web service), in the fault detail string I get the full stacktrace of what happened. I do not want the client to see the stack trace, so (as a catch all errors) I want to output a simple "Server error" message with no stacktrace, no nothing.

What is the simplest way of intercepting fault responses and changing the fault message. Are modules the only way of (complicated) doing this?

Or, is there a configuration in Axis2 that says not to display stacktrace in fault?

Thanks!

A: 

Can you not just catch the AxisFault

try {
    // do stuff
} catch (AxisFault f) {
    log.error("Encountered error doing stuff", f);
    throw new IOException("Server error");
}
Jon Freedman
Where will I place this code? The error propagates from the generated MessageReceiverInOut class where I have this catch all code: **...} catch (java.lang.Exception e) { throw org.apache.axis2.AxisFault.makeFault(e); ...**
userOfAxis2
You must be using the `MessageReceiverInOut` class somewhere though?
Jon Freedman
org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver uses this. The *MessageReceiverInOut class is generated automatically by the codegen tool from my wsdl file. It seems fragile to hack it and add my things in it.
userOfAxis2
Do you have an example stack trace?
Jon Freedman
Sorry, but I am not allowed to post the stacktrace
userOfAxis2
At some point you must have written some code - thats where you can catch the `AxisFault` thrown by classes generated by wsdl2java
Jon Freedman
A: 

I once had a similar problem. Not sure if there is some config to turn off the stacktrace showing, at least none that I could find at that moment (that would have been the best solution). Instead, I opted for a quick and dirty approach, mostly due to lack of time.

What I did was to provide Axis2 with the detail of the fault myself. The Axis2 servlet has a method called handleFault which deals with generating the fault. More exactly (deeper in the call) the MessageContextBuilder.createFaultEnvelope method is used to construct the fault element.

Having the stacktrace in the detail is the default behavior, but there are ways to specify your custom detail. One way is to use the the AxisFault's detail field in which you can add an OMElement (refer to AXIOM) to be placed into the fault. So you do something like:

public class MyServlet extends AxisServlet {
  ...
  public void handleFault(MessageContext msgContext, OutputStream out, AxisFault e) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMElement detail = factory.createElement(...);
    e.setDetail(detail);
    // now let axis do its thing with the new improved AxisFault
    super.handleFault(msgContext, out, e);
  }
}

Now, instead of the exception stacktrace, your detail will be added instead.

dpb
A: 

Axis2 uses Apache commons logging and the AxisFault messages that you are seeing are generated by code in Axis2 that looks similar to:

try {
    executeMethod(httpClient, msgContext, url, getMethod);
    handleResponse(msgContext, getMethod);
} catch (IOException e) {
    log.info("Unable to sendViaGet to url[" + url + "]", e);
    throw AxisFault.makeFault(e);
} finally {
    cleanup(msgContext, getMethod);
}

[This code segment comes from org.apache.axis2.transport.http.HTTPSender]

So refer to apache commons logging user guide for instructions on how to set the logging levels and destination of the messages.

Hope this helps.

Greg H