Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E10B9200C64 for ; Fri, 28 Apr 2017 13:02:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DF8B6160BA3; Fri, 28 Apr 2017 11:02:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 32E28160BB8 for ; Fri, 28 Apr 2017 13:02:10 +0200 (CEST) Received: (qmail 7494 invoked by uid 500); 28 Apr 2017 11:02:09 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 7483 invoked by uid 99); 28 Apr 2017 11:02:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Apr 2017 11:02:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id C1277188F29 for ; Fri, 28 Apr 2017 11:02:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id AbZzL3jeBeCa for ; Fri, 28 Apr 2017 11:02:06 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id 592085FC1C for ; Fri, 28 Apr 2017 11:02:06 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A41B3E0C0D for ; Fri, 28 Apr 2017 11:02:05 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id 8554621DE2 for ; Fri, 28 Apr 2017 11:02:04 +0000 (UTC) Date: Fri, 28 Apr 2017 11:02:04 +0000 (UTC) From: "Lukasz Lenart (JIRA)" To: issues@struts.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (WW-4749) Buffer/Flush behaviour in FreemarkerResult MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 28 Apr 2017 11:02:11 -0000 [ https://issues.apache.org/jira/browse/WW-4749?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15988637#comment-15988637 ] Lukasz Lenart commented on WW-4749: ----------------------------------- Ach... pushed a new version :) Next time you will be preparing a PR ;) > 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 > Assignee: Lukasz Lenart > 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} > > big_feed.ftl > text/xml > false > > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346)