I have a simple flow in Mule 3.2.1 which is only supposed re-publish a webservice. The goal was to learn how the exception handling works in Mule. To test this I use a web service which always returns an exception (i.e. never proper or fault response) and I would like to catch this exception and process it (log into file for starters).
The problem is that the exception strategy does not seem to be called at all...
I've tried two versions - the first one with default-exception-strategy and the second one with custom-exception-strategy. The flow looks like this:
<flow name="LoginFlow">
<http:inbound-endpoint address="http://localhost:8081/WsFaultResponseMule" exchange-pattern="request-response">
<cxf:jaxws-service serviceClass="aaa.bbb.Soap">
<cxf:features>
<spring:bean class="sandbox.StackTraceFeature" id="stackTraceService"/>
</cxf:features>
</cxf:jaxws-service>
</http:inbound-endpoint>
<http:outbound-endpoint
host="localhost"
port="8080"
path="WsFaultResponse/services/Soap"
exchange-pattern="request-response">
<cxf:jaxws-client
clientClass="aaa.bbb.SforceService"
port="Soap"
wsdlLocation="classpath:wsdl/partner.wsdl"
operation="login"
soapVersion="1.1"
enableMuleSoapHeaders="false">
</cxf:jaxws-client>
</http:outbound-endpoint>
<default-exception-strategy>
<processor-chain>
<object-to-string-transformer/>
<file:outbound-endpoint path="data/exception" outputPattern="#[function:datestamp:yyyyMMddHHmmss].err"/>
</processor-chain>
</default-exception-strategy>
<!-- <custom-exception-strategy class="exception.TestExceptionListener"/> -->
</flow>
The custom strategy mentioned in the commented-out part of the flow is trivial (basically the same as the one in their documentation):
public class TestExceptionListener extends DefaultMessagingExceptionStrategy {
public TestExceptionListener(MuleContext muleContext) {
super(muleContext);
}
private MuleEvent handle(Exception ex, MuleEvent event, RollbackSourceCallback rollbackMethod) {
logger.warn("Exception: " + ex.getMessage());
Object payloadBefore = event.getMessage().getPayload();
MuleEvent result = super.handleException(ex, event, rollbackMethod);
result.getMessage().setPayload(payloadBefore);
return result;
}
@Override
public MuleEvent handleException(Exception ex, MuleEvent event) {
return handle(ex, event, null);
}
@Override
public MuleEvent handleException(Exception ex, MuleEvent event, RollbackSourceCallback rollbackMethod) {
return handle(ex, event, rollbackMethod);
}
}
When I run Mule server with the above configuration, I do not get the output I would expect. My expectation is that the default-exception-strategy should produce a file in the exception directory, but this does not happen. The Java strategy is supposed to log message into the console, but again, I cannot see anything... Breakpoint placed in the handle method does not trigger at all either.
Thanks in advance for any help.
The problem was with the Mule version. The flow works correctly in 3.3.0-R3.
The flow:
<default-exception-strategy>
<processor-chain>
<custom-transformer class="exception.StackTraceTransformer"/>
<file:outbound-endpoint path="data/exception" outputPattern="#[function:datestamp:yyyyMMddHHmmss].txt"/>
</processor-chain>
</default-exception-strategy>
Custom transformer:
public class StackTraceTransformer extends AbstractMessageTransformer {
public StackTraceTransformer() {
setName("StackTraceToText");
}
@Override
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
StringWriter writer = new StringWriter();
PrintWriter stream = new PrintWriter(writer);
Throwable t = ((ExceptionMessage) message.getPayload()).getException();
t.printStackTrace(stream);
return writer.toString();
}
}