Results 1 to 4 of 4

Thread: XSLT Error Handling in Views

  1. #1
    Join Date
    Aug 2004
    Location
    Dayton, OH
    Posts
    15

    Default 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. #2
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    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,
    Darren Davison.
    Public Key: 0xE855B3EA

  3. #3
    Join Date
    Aug 2004
    Location
    Dayton, OH
    Posts
    15

    Default

    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

  4. #4
    Join Date
    Aug 2004
    Location
    Dayton, OH
    Posts
    15

    Default

    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

Similar Threads

  1. Replies: 22
    Last Post: Feb 4th, 2010, 01:37 AM
  2. Spring and XSLT
    By EPiXNiCROS in forum Web
    Replies: 4
    Last Post: Aug 27th, 2007, 02:31 PM
  3. Multiple views and pages question
    By jwray in forum Swing
    Replies: 3
    Last Post: Feb 19th, 2005, 09:22 AM
  4. Newbie question on Pages and Views
    By ragnarwestad in forum Swing
    Replies: 8
    Last Post: Dec 13th, 2004, 10:47 PM
  5. How to map views
    By pak in forum Web
    Replies: 4
    Last Post: Sep 8th, 2004, 02:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •