2

I am using JBoss AS7. I already know how to use my own web.xml error pages for HTTP Errors (e.g. 404, 500, ...) - thats not a problem. But for debugging reasons I need to view the error StackTrace. How can I access the message that is shown by default and embed it in error page?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jp-jee
  • 1,502
  • 3
  • 16
  • 21

1 Answers1

2

The concrete exception instance is available as a request attribute with the name as keyed by RequestDispatcher#ERROR_EXCEPTION which has a value of javax.servlet.error.exception.

Thus, this will give you the exception:

#{requestScope['javax.servlet.error.exception']}

However, there's no standard facility to print its stack trace in the view. You'd need to homebrew an EL function, something like as JSF utility library OmniFaces already has in flavor of #{of:printStackTrace()}. You can see it in action in the OmniFaces FullAjaxExceptionHandler showcase page:

<ui:composition ... xmlns:of="http://omnifaces.org/functions">
...
<li>Stack trace: <pre><code>#{of:printStackTrace(requestScope['javax.servlet.error.exception'])}</code></pre></li>

whereby the function implementation look like this:

/**
 * Print the stack trace of the given exception.
 * @param exception The exception to print the stack trace for.
 * @return The printed stack trace.
 */
public static String printStackTrace(Throwable exception) {
    if (exception == null) {
        return null;
    }

    StringWriter stringWriter = new StringWriter();
    exception.printStackTrace(new PrintWriter(stringWriter, true));
    return stringWriter.toString();
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • sounds good so far. While trying this, I recognized that actually my HTTP 500 Error custom page is not working at all. Like in this posting (1), only my 404 page works. Are there any updates concerning the error 500 problem? (1) http://stackoverflow.com/questions/16694675/custom-500-error-page-not-working-with-jboss-as-7-1-1 – jp-jee Nov 23 '13 at 10:16
  • Have you already read the [OmniFaces `FullAjaxExceptionHandler` showcase](http://showcase.omnifaces.org/exceptionhandlers/FullAjaxExceptionHandler) as linked in my answer? It describes (and solves) many problems as to exception handling in JSF (ajax) requests. – BalusC Nov 23 '13 at 10:23
  • great article - I got it to work now. Error 500 is being caught and the page contains the error message. thx. – jp-jee Nov 23 '13 at 11:52