Build a better Roo exception page

DZone 's Guide to

Build a better Roo exception page

· Java Zone ·
Free Resource

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 {

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:


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"
<property name="exceptionMappings">
<prop key=".DataAccessException">dataAccessFailure</prop>
<prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
<prop key=".TypeMismatchException">resourceNotFound</prop>
<prop key=".MissingServletRequestParameterException">resourceNotFound</prop>

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>
<div style="overflow: auto;"
<pre><c:out value="${rootCause}"/></pre>


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


From http://www.rimple.com/tech/2011/3/15/build-a-better-roo-exception-page.html


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}