Chariot Training Classes

Training Courses

I run Chariot's training and mentoring services. We provide training in AngularJS, HTML5, Spring, Hibernate, Maven, Scala, and more.

Chariot Education Services

Technology

Chariot Emerging Tech

Learn about upcoming technologies and trends from my colleagues at Chariot Solutions.

Resources

Chariot Conferences

Podcasts

« It's a comin' - Philly Emerging Tech | Main | Adding deeper logging to Webflow Exceptions »
Tuesday
Mar152011

Build a better Roo exception page

Ok, Roo fans. This is a quick post, in response to a forum post on the Manning Roo in Action forum. Wanna get Root Causes in your exceptions page? Do this!

Build an Exception Resolver

Start by building a class that extends SimpleMappingExceptionResolver. This example uses the Apache commons-lang utility class, ExceptionUtils, to get the root cause exception and push it to the page. I suspect I may need to check for nulls here so if you get a chance to debug this before me, post a message and I'll update the blog post:

public class FullTraceMappingExceptionResolver extends
  SimpleMappingExceptionResolver {

  @Override
  protected ModelAndView getModelAndView(String viewName, Exception ex) {
    ModelAndView modelAndView =  super.getModelAndView(viewName, ex);
    String stackTrace = ExceptionUtils.getFullStackTrace(ExceptionUtils.getRootCause(ex));
    modelAndView.addObject("rootCause", stackTrace);
    return modelAndView;
  }
}

Add commons-lang 2.5

Add this to your pom.xml file, in the dependencies section... A Roo shell command can do this for you, but here is the fragment:

<dependency>
  <groupId>commons-lang</groupId>
  <artifactId>commons-lang</artifactId>
  <version>2.5</version>
</dependency>

Install it!

Next, install it in the webmvc-config.xml file, by replacing the mounted class SimpleMappingExceptionResolver with the FullTraceMappingExceptionResolver.  Just swap the value in the class property below and leave the rest alone:

<bean class="package.path.to.FullTraceMappingExceptionResolver"
           p:defaultErrorView="uncaughtException">
  <property name="exceptionMappings">
    <props>
      <prop key=".DataAccessException">dataAccessFailure</prop>
      <prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
      <prop key=".TypeMismatchException">resourceNotFound</prop>
      <prop key=".MissingServletRequestParameterException">resourceNotFound</prop>
    </props>
  </property>
</bean>

Modify unhandledException.jspx

Ok, the final step - just add the unhandled exception to the jspx for the uncaught exceptions, WEB-INF/views/uncaughtException.jspx:

<c:if test="${not empty rootCause}">
  <util:panel id="_fullStackTrace" 
        title="Full Stack Trace" openPane="false">
    <h4>Full Stack Trace</h4>
    <br/>
    <div style="overflow: auto;" 
         dojoType="dijit.layout.ContentPane">
      <pre><c:out value="${rootCause}"/></pre>
    </div>          
  </util:panel>
</c:if>

Want more Roo in Action goodness? Subscribe to the MEAP!

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

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>