You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/04/26 06:53:34 UTC

[jira] [Commented] (WW-4749) Buffer/Flush behaviour in FreemarkerResult

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

ASF GitHub Bot commented on WW-4749:
------------------------------------

GitHub user lukaszlenart opened a pull request:

    https://github.com/apache/struts/pull/134

    WW-4749: Buffer/Flush behaviour in FreemarkerResult

    Implements [WW-4749](https://issues.apache.org/jira/browse/WW-4749)

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/lukaszlenart/struts buffer-flush

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/struts/pull/134.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #134
    
----
commit d739be34bccebbde2972c9e2c6225b94bad68d27
Author: Lukasz Lenart <lu...@apache.org>
Date:   2017-04-26T06:42:42Z

    WW-4749 Implements buffered write

commit 787150d041e32e8e579df5d44c1258881fad6c94
Author: Lukasz Lenart <lu...@apache.org>
Date:   2017-04-26T06:48:01Z

    Moves documentation to wiki

commit f5125bcd1bb97a75ab54e266399c2bf96987c1dc
Author: Lukasz Lenart <lu...@apache.org>
Date:   2017-04-26T06:51:45Z

    WW-4749 Defines setter to allow specify useBufferedWriter

----


> Buffer/Flush behaviour in FreemarkerResult
> ------------------------------------------
>
>                 Key: WW-4749
>                 URL: https://issues.apache.org/jira/browse/WW-4749
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Core Results
>    Affects Versions: 2.3.31, 2.5.1
>            Reporter: Lorenzo Bernacchioni
>            Priority: Minor
>             Fix For: 2.5.next
>
>
> Scenario: the application use freemarker with a {{TemplateExceptionHandler.RETHROW_HANDLER}} policy, but occasionally needs to produce large XML (20~200Mb) and goes out of memory.
> In [FreemarkerResult|http://grepcode.com/file/repo1.maven.org/maven2/org.apache.struts/struts2-core/2.5-BETA1/org/apache/struts2/views/freemarker/FreemarkerResult.java#191] there are two possible behaviours (line 191):
>  * *Buffer-behaviour*: the whole template is processed and if everything is OK it is flushed to the output, otherwise an exception is thrown and handled at higher level before any output has been sent. This is intended to be used when {{TemplateExceptionHandler.RETHROW_HANDLER}} is active
> * *Flush-behaviour*: template is processed and flushed according to freemarker library policies, used with any other {{TemplateExceptionHandler}}
> Since {{TemplateExceptionHandler}} cannot be switched for a given request (it is a global configuration embedded in {{FreemarkerManager}}) there is no way to force a Flush-behaviour. (you can only force a Buffer-behaviour using {{isWriteIfCompleted}})
> I implemented a more flexible solution that let you force the behaviour in both ways:
> {code:title=FreemarkerResult.java|borderStyle=solid}
>     final boolean willUsebufferedWriter;
>     if (useBufferedWriter != null){
>         willUsebufferedWriter = useBufferedWriter;
>     }else{
>         willUsebufferedWriter = configuration.getTemplateExceptionHandler() == TemplateExceptionHandler.RETHROW_HANDLER;
>     }
>                 
>     if (willUsebufferedWriter){
>     ...
>     }else{
>     ...
>     }       
> {code}
> where {{useBufferedWriter}} is a parameter that can be modified per request
> {code}
> <result type="freemarker">
>     <param name="location">big_feed.ftl</param>
>     <param name="contentType">text/xml</param>
>     <param name="useBufferedWriter">false</param>
> </result>
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)