P***@blm.gov
2009-10-21 18:36:05 UTC
While developing a web application using Spring and FreeMarker I've found
that exceptions during template processing (caused, for example, by keys
referenced in the template but missing from the model map) result in stack
traces being thrown out all the way to the client browser. One of the main
reasons for migrating away from JSPs (apart from them being inefficient,
dangerous, difficult to work with, nightmarish to debug, etc., etc., etc.)
is that JSPs have a nasty tendency to send stack traces to the browser. I
was really hoping FreeMarker wouldn't do the same thing. The problem
appears to be that FM sends the stack trace to the same output stream that
the processed output would normally be sent to, and in a web environment
that's going to be the response output stream.
I need to make sure that one way or another template processing exceptions
are caught in a way that lets the application (or the View) throw out a
response.sendError() call (ideally with a configurable error code, but a
hard-coded '500' error would be acceptable) and log the error trace in the
server log. At the very least I need a way to make certain that the client
doesn't see a stack trace, ever, under any circumstances.
So the question is, does FreeMarker (or the Spring FreeMarkerConfigurer or
FreeMarkerView) have any kind of configuration setting to cover for this? I
could probably create a proprietary View class that catches the exception,
but I'd rather stick with the out-of-the-packet code if I can.
that exceptions during template processing (caused, for example, by keys
referenced in the template but missing from the model map) result in stack
traces being thrown out all the way to the client browser. One of the main
reasons for migrating away from JSPs (apart from them being inefficient,
dangerous, difficult to work with, nightmarish to debug, etc., etc., etc.)
is that JSPs have a nasty tendency to send stack traces to the browser. I
was really hoping FreeMarker wouldn't do the same thing. The problem
appears to be that FM sends the stack trace to the same output stream that
the processed output would normally be sent to, and in a web environment
that's going to be the response output stream.
I need to make sure that one way or another template processing exceptions
are caught in a way that lets the application (or the View) throw out a
response.sendError() call (ideally with a configurable error code, but a
hard-coded '500' error would be acceptable) and log the error trace in the
server log. At the very least I need a way to make certain that the client
doesn't see a stack trace, ever, under any circumstances.
So the question is, does FreeMarker (or the Spring FreeMarkerConfigurer or
FreeMarkerView) have any kind of configuration setting to cover for this? I
could probably create a proprietary View class that catches the exception,
but I'd rather stick with the out-of-the-packet code if I can.