Re: Better handling of template exceptions in web applications.
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Thursday, August 4, 2011, 2:56:04 AM, Geoff Shuetrim wrote: > The suggestion to just set the buffer size to something big is a > lot simpler than trying to change the actual writer being used by > the response. I will try it out and see if the performance impact > of always using a large buffer is manageable. Assuming the implementators of the Servlet API wasn't lame, why would any other solution be more efficient? You have to buffer the output somewhere if you don't send it immediately. > One last warning to anyone else looking to use this approach when > they are also using Stripes layout tags: the template process method > is called every time a template is used by the layout system. That > means that if the template processing exception is thrown by one of > the content components used by a layout and not by the layout > itself, then any attempt to redirect the response in the > ServletExceptionHandler seems to be ignored. What I have found to > work is to send appropriate HTML content to the response writer when > the exception is encountered and then that content is included in > the layout instead of the content that would have been generated by > the template that triggered the exception. It is not ideal but I > cannot figure any way to get back to the original response and to redirect it. That's not good. Is it only so with FreeMarker? If Template.process fails, the exception should propagate up to the layout causing that to fail too... I guess... > Regards > > Geoff S > > On 1 August 2011 20:24, Daniel Dekany <[email protected]> wrote: > Monday, August 1, 2011, 6:44:03 AM, Geoff Shuetrim wrote: > >> Daniel, >> >> Thanks for the detailed response. It works a treat. The >> additional notes about flushing issues are particularly helpful. In >> the end I modified the process() method of a copy of the >> FreemarkerServlet class. I already have a custom extension of the >> FreemarkerServlet class and my first attempt involved copying the >> process method from the original FreemarkerServlet class, >> distributed with Freemarker, into my own custom Servlet but >> unfortunately, the process method in the FreemarkerServlet class >> depends on package-private access to methods of the >> freemarker.ext.servlet.HTTPSessionHashModel. Because of that, I >> have duplicated the whole FreemarkerServlet and HTTPSessionHashModel >> classes into my own code base. > > (Folks do that sometimes it seems, copying it. FreemarkerServlet has > not enough customization points it seems. OTOH modern frameworks > probably will not use it anyway.) > >> Maybe there something smarter I should be doing to gain control of >> the writer being passed to the Template.process() method but this >> has got me where I needed to be. > > Can't you just override FreemarkerServlet.preprocessRequest and there > call request.setBufferSize(somethingHuge)? > > > [snip] -- Best regards, Daniel Dekany ------------------------------------------------------------------------------ BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1