Monday
Feb282011
Adding deeper logging to Webflow Exceptions
Monday, February 28, 2011 at 7:26AM If you've been using Roo and the JSPX views with WebFlow, you've probably noticed that you don't get the embedded stack trace in the errors that result. You can fix this with a lifecycle listener:
First, define the class:
package mypackage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.webflow.execution.FlowExecutionException;
import org.springframework.webflow.execution.FlowExecutionListenerAdapter;
import org.springframework.webflow.execution.RequestContext;
public class LoggingFlowExecutionListener extends FlowExecutionListenerAdapter {
Logger logger = LoggerFactory.getLogger(getClass());
@Override
public void exceptionThrown(RequestContext context,
FlowExecutionException exception) {
super.exceptionThrown(context, exception);
logger.error("Webflow " + context.getActiveFlow().getId() +
" threw exception in " + context.getCurrentState().getId(), exception);
}
}
Then, in webflow-config.xml, replace
<webflow:flow-executor id="flowExecutor" />
with
<webflow:flow-executor id="flowExecutor">
<webflow:flow-execution-listeners>
<webflow:listener ref="loggingListener"/>
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<bean class="mypackage.LoggingFlowExecutionListener" id="loggingListener" />
Now you can enjoy useful logging from your Webflow exceptions.
Ken Rimple |
2 Comments | tagged
SpringSource Roo,
chariot-news,
webflow in
Tips
SpringSource Roo,
chariot-news,
webflow in
Tips 


Reader Comments (2)
Isn't line 10 supposed to read:
Logger logger = LoggerFactory.getLogger(LoggingFlowExecutionListener.class);
or something like that?
Yes, I used getClass() in the example but somehow it didn't get put in the code. Fixed.