Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

error pages that dispatch new request

9 views
Skip to first unread message

Brad Wood

unread,
May 12, 2023, 2:08:32 PM5/12/23
to Undertow Dev
I'm looking to approximate the error page functionality that the servlet gives me, but in a default response listener.   What I like about the servlet error pages is you can point to a file that's process by the servlet itself such as a jsp to have dynamic code responding to a 404, etc.  

Looking at Undertow's non-servlet classes, I see there is a SimpleErrorPageHandler, but that just outputs a pre-set generic error page.

Looking further, I see there is a FileErrorPageHandler which is close, but it only serves static files directly, and would not allow the error page to be a jsp or cfm which needs to be processed in the servlet.

If I needed to send an error page early on in the request, I could simply 'rewrite" the relative URL to change where the request pointed, but I'm not sure how to accomplish this at the end of the exchange in a default response listener.  Is there a way to dispatch a new request within my default response listener to a new URI of my choosing?

Brad Wood

unread,
May 24, 2023, 5:45:43 PM5/24/23
to Undertow Dev
I was able to approximate this via exchange.dispatch(new Runnable() {} ) where I set the relative path of the exchange to my error page and then call handleRequest() again on the first handler in my handler chain.  I had to put some info in an attachment to prevent infinite recursion, but it did allow me to basically start the request over again, this time potentially hitting the servlet.  I ran into issues setting up the same request attributes that the servlet would normally have set due to the issue I posted about in my other thread where exchange attributes are only allowed to have a string as a value so I can't set things like javax.servlet.error.exception, but other than that, it seems to work OK.
Reply all
Reply to author
Forward
0 new messages