You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Tinus Tate (JIRA)" <ji...@apache.org> on 2019/01/01 22:09:00 UTC

[jira] [Comment Edited] (FREEMARKER-113) TemplateExceptionHandler not working with Jetty

    [ https://issues.apache.org/jira/browse/FREEMARKER-113?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16731681#comment-16731681 ] 

Tinus Tate edited comment on FREEMARKER-113 at 1/1/19 10:08 PM:
----------------------------------------------------------------

After installing jetty locally i did a bit debugging and it seemed that my TemplateExceptionHandler was called.

I did retrow the exception because i wanted it in the log system. Tomcat seems to be fine with this and swallows the exception without printing it to the httpresponse (Writer out param of TemplateExceptionHandler). Did read this trick on stackoverflow.

Jetty on the other hand catches the exception and prints it. Anything the TemplateExceptionHandler writes to the Writer out param of TemplateExceptionHandler is lost.

I suspect this isn't something related to Freemarker but more how servlet containers handle exceptions under certain conditions.

[edit]

After a bit more testing it appears that when not retrowing the exception in the TemplateExceptionHandler the freemarker template will continue to render. Throwing the exception causes the rendering to stop and not extra html is generated after the template statement that caused the error.

But you can't retrow the exception cause when using jetty the output TemplateExceptionHandler is ignored and the default jetty handler kicks in.

I'm not sure where the source of this problem is located.

 


was (Author: tinustate):
After installing jetty locally i did a bit debugging and it seemed that my TemplateExceptionHandler was called.

I did retrow the exception because i wanted it in the log system. Tomcat seems to be fine with this and swallows the exception without printing it to the httpresponse (Writer out param of TemplateExceptionHandler). Did read this trick on stackoverflow.

Jetty on the other hand catches the exception and prints it. Anything the TemplateExceptionHandler writes to the Writer out param of TemplateExceptionHandler is lost.

I suspect this isn't something related to Freemarker but more how servlet containers handle exceptions under certain conditions.

Feel free to close this ticket if you agree.

 

> TemplateExceptionHandler not working with Jetty
> -----------------------------------------------
>
>                 Key: FREEMARKER-113
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-113
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.28
>         Environment: java 8, jetty 9.4, freemarker 2.3.28, spring 5.1.2
>            Reporter: Tinus Tate
>            Priority: Major
>
> Setting a custom TemplateExceptionHandler doesn't seem to work when the application is deployed and running on the latest Jetty server.
> When deployed and running on a Tomcat server the TemplateExceptionHandler works as expected.
> To set a TemplateExceptionHandler i extended FreeMarkerConfigurer and override getConfiguration():
> Configuration configuration = super.getConfiguration();
>  configuration.setTemplateExceptionHandler(new MyTemplateExceptionHandler());
>  return configuration;
> When a template contains an error (${null}) i can see that the getConfiguration() is called (i added a log line).
> With tomcat MyTemplateExceptionHandler gets called next, with jetty this doesn't happen. With jetty a jetty error page appears with the full freemarker exceptions and stacktrace,which starts with:
> HTTP ERROR 500
> Problem accessing /dash/sitesettings/change. Reason:
>     Server Error
> ...
> This happens with the latest version of freemarker.
> I hope someone can take a quick peek at what is going on.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)