Announcement Announcement Module
Collapse
No announcement yet.
XSLT Error Handling in Views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • XSLT Error Handling in Views

    Hi,

    I am using AbstractXSLTView to prepare all my views. This works great.
    However, I cannot seem to get Spring to catch any exceptions coming
    out of the createDomNode method. To be specific, I have defined an
    unchecked Exception that I call ViewException. This can be thrown by
    a bean that generates the JDOM document. I have setup a mapping for
    the ViewException using the SimpleMappingExceptionResolver but the
    logs seem to show it is ignored. I do see the ViewException and its message in the logs but no matter how I set things up, I cannot grab it so I can redirect to a nice HTML error page.

    Any thoughts on how I might approach this? Right now any problems in my JDOM setup just crash the application.

    Thanks!

    John Westerkamp

  • #2
    exception resolvers won't work after the dispatcher servlet begins the view rendering (see dispatcher code). If the response has already been committed by the view, then it's basically too late to re-direct to a new one.

    Regards,

    Comment


    • #3
      Thank you very much for your reply. I was beginning to suspect that, as I can get the exception resolver to work in my regular controller code.

      Does anybody have an approach to handling problems when preparing a view using XSLT? I tried just outputing HTML from an error handler to the same HttpServletResponse passed to AbstractXsltView, but I get the infamous "response writer already open" exception. I will play with it some more and update with any success I have.

      Thanks again for your quick reply!

      John Westerkamp

      Comment


      • #4
        Ok, it appears that there are two approaches to error handling whil preparing XSLT views using AbstractXsltView:

        1. In the createDomNode method, catch all the errors and call an error handling method that prints out HTML using println statements on a PrintWriter obtained from the response. Do not set the response ContentType or you will get an exception. Also, be sure to issue a
        close() on the PrintWriter when finished to flush the buffer and print the page. Note that this will generate an IllegalStateException in the super class (which can be ignored). That leads to the second approach.

        2. In the createDomNode method, catch all the errors and just close() the PrintWriter using response.getWriter().close(). This will generate an IllegalStateException in the superclass which can be caught by setting an <error-page> in your web.xml. As noted in a previous response, the Spring exception resolver will not activate once the response is committed.

        Note that in both case, you want to return null in your catch block in the createDomeNode() method.

        I am not sure which approach is better. Perhaps the web.xml approach is a bit cleaner providing some separation of concerns. It can also be used to handle all uncaught exceptions in the application.

        Thanks!

        John Westerkamp

        Comment

        Working...
        X