Technology

I'm speaking at...

I teach and consult for

Practical, smart application development, mentoring, training.

Spring, Hibernate, Grails, Rails and Maven training from the experts!
Training Calendar

Roo in Action

Soon in print!

Spring Roo in Action
MEAP Available Now!

Author, Roo in Action - in MEAP now
Manning Book Forum
My Roo Blog Entries
Srini Penchikala InfoQ

Twittery!

@krimple
@techcast
@gdickens
@RooInAction

I host the
Chariot TechCast

« Build a better Roo exception page | Main | Spring Corner - What are those Post Processor Beans anyway? »
Monday
Feb282011

Adding deeper logging to Webflow Exceptions

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.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (2)

Isn't line 10 supposed to read:
Logger logger = LoggerFactory.getLogger(LoggingFlowExecutionListener.class);

or something like that?

March 5, 2011 | Unregistered CommenterMiB

Yes, I used getClass() in the example but somehow it didn't get put in the code. Fixed.

March 5, 2011 | Registered CommenterKen Rimple

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>