Return-Path: X-Original-To: apmail-struts-commits-archive@minotaur.apache.org Delivered-To: apmail-struts-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5894F183ED for ; Fri, 30 Oct 2015 08:22:17 +0000 (UTC) Received: (qmail 8656 invoked by uid 500); 30 Oct 2015 08:22:17 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 8540 invoked by uid 500); 30 Oct 2015 08:22:17 -0000 Mailing-List: contact commits-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 commits@struts.apache.org Received: (qmail 8506 invoked by uid 99); 30 Oct 2015 08:22:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Oct 2015 08:22:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E0579E083A; Fri, 30 Oct 2015 08:22:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lukaszlenart@apache.org To: commits@struts.apache.org Date: Fri, 30 Oct 2015 08:22:18 -0000 Message-Id: In-Reply-To: <0cbc91ee54d64e56a2f2a0242362c3fe@git.apache.org> References: <0cbc91ee54d64e56a2f2a0242362c3fe@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/4] struts git commit: WW-4134 Checks if Response wasn't committed to allow store messages (cherry picked from commit 0958077) WW-4134 Checks if Response wasn't committed to allow store messages (cherry picked from commit 0958077) Project: http://git-wip-us.apache.org/repos/asf/struts/repo Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/0a08f6b6 Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/0a08f6b6 Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/0a08f6b6 Branch: refs/heads/master Commit: 0a08f6b673a2334a76ab0ae64ad2956cc4f4947a Parents: ba361aa Author: Lukasz Lenart Authored: Tue Oct 27 09:01:09 2015 +0100 Committer: Lukasz Lenart Committed: Tue Oct 27 09:12:24 2015 +0100 ---------------------------------------------------------------------- .../interceptor/MessageStoreInterceptor.java | 16 ++++++++++++---- .../interceptor/MessageStoreInterceptorTest.java | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts/blob/0a08f6b6/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java index ee78563..8ff2522 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java @@ -27,6 +27,8 @@ import com.opensymphony.xwork2.interceptor.ValidationAware; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; + +import org.apache.struts2.ServletActionContext; import org.apache.struts2.result.ServletRedirectResult; import java.util.ArrayList; @@ -269,14 +271,16 @@ public class MessageStoreInterceptor extends AbstractInterceptor { String reqOperationMode = getRequestOperationMode(invocation); boolean isRedirect = invocation.getResult() instanceof ServletRedirectResult; + boolean isCommitted = ServletActionContext.getResponse().isCommitted(); + if (STORE_MODE.equalsIgnoreCase(reqOperationMode) || STORE_MODE.equalsIgnoreCase(operationMode) || (AUTOMATIC_MODE.equalsIgnoreCase(operationMode) && isRedirect)) { Object action = invocation.getAction(); - if (action instanceof ValidationAware) { + if (action instanceof ValidationAware && !isCommitted) { // store error / messages into session - Map session = (Map) invocation.getInvocationContext().get(ActionContext.SESSION); + Map session = invocation.getInvocationContext().getSession(); if (session == null) { LOG.debug("Could not store action [{}] error/messages into session, because session hasn't been opened yet.", action); @@ -289,13 +293,17 @@ public class MessageStoreInterceptor extends AbstractInterceptor { session.put(actionErrorsSessionKey, validationAwareAction.getActionErrors()); session.put(actionMessagesSessionKey, validationAwareAction.getActionMessages()); session.put(fieldErrorsSessionKey, validationAwareAction.getFieldErrors()); + } else { - LOG.debug("Action [{}] is not ValidationAware, no message / error that are storeable", action); + if (isCommitted) { + LOG.debug("Response was already committed, cannot store messages!"); + } else { + LOG.debug("Action [{}] is not ValidationAware, no message / error that are storeable", action); + } } } } - /** * Get the operationMode through request parameter, if allowRequestParameterSwitch * is 'true', else it simply returns 'NONE', meaning its neither in the 'STORE_MODE' nor http://git-wip-us.apache.org/repos/asf/struts/blob/0a08f6b6/core/src/test/java/org/apache/struts2/interceptor/MessageStoreInterceptorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/interceptor/MessageStoreInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/MessageStoreInterceptorTest.java index a419a18..2fc6442 100644 --- a/core/src/test/java/org/apache/struts2/interceptor/MessageStoreInterceptorTest.java +++ b/core/src/test/java/org/apache/struts2/interceptor/MessageStoreInterceptorTest.java @@ -27,6 +27,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsInternalTestCase; import org.apache.struts2.result.ServletActionRedirectResult; import org.easymock.EasyMock; @@ -36,6 +37,8 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.ActionSupport; +import javax.servlet.http.HttpServletResponse; + /** * Test case for MessageStoreInterceptor. @@ -44,6 +47,18 @@ import com.opensymphony.xwork2.ActionSupport; */ public class MessageStoreInterceptorTest extends StrutsInternalTestCase { + @Override + public void setUp() throws Exception { + super.setUp(); + + HttpServletResponse response = EasyMock.createNiceControl().createMock(HttpServletResponse.class); + response.isCommitted(); + EasyMock.expectLastCall().andReturn(Boolean.FALSE); + EasyMock.replay(response); + + ServletActionContext.setResponse(response); + } + public void testStoreMessage() throws Exception { MessageStoreInterceptor interceptor = new MessageStoreInterceptor(); interceptor.setAllowRequestParameterSwitch(true);