struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [3/3] struts git commit: WW-4134 Checks if Response wasn't committed to allow store messages
Date Tue, 27 Oct 2015 08:01:23 GMT
WW-4134 Checks if Response wasn't committed to allow store messages


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/09580777
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/09580777
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/09580777

Branch: refs/heads/support-2-3
Commit: 095807776288ce982ee064f820de428cd3969761
Parents: 7848534
Author: Lukasz Lenart <lukasz.lenart@gmail.com>
Authored: Tue Oct 27 09:01:09 2015 +0100
Committer: Lukasz Lenart <lukasz.lenart@gmail.com>
Committed: Tue Oct 27 09:01:09 2015 +0100

----------------------------------------------------------------------
 .../interceptor/MessageStoreInterceptor.java      | 18 ++++++++++++------
 .../interceptor/MessageStoreInterceptorTest.java  | 15 +++++++++++++++
 2 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/09580777/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 b7509f0..f34cee0 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java
@@ -26,6 +26,7 @@ import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
+import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.dispatcher.ServletRedirectResult;
 
 import com.opensymphony.xwork2.ActionContext;
@@ -273,14 +274,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<String, Object> session = invocation.getInvocationContext().getSession();
 
                 if (session == null) {
                     if (LOG.isDebugEnabled()) {
@@ -297,14 +300,17 @@ public class MessageStoreInterceptor extends AbstractInterceptor {
                 session.put(actionErrorsSessionKey, validationAwareAction.getActionErrors());
                 session.put(actionMessagesSessionKey, validationAwareAction.getActionMessages());
                 session.put(fieldErrorsSessionKey, validationAwareAction.getFieldErrors());
-            }
-            else if(LOG.isDebugEnabled()) {
-        	LOG.debug("Action ["+action+"] is not ValidationAware, no message / error that are
storeable");
+
+            } else if(LOG.isDebugEnabled()) {
+                if (isCommitted) {
+                    LOG.debug("Response was already committed, cannot store messages!");
+                } else {
+                    LOG.debug("Action [" + action + "] is not ValidationAware, no message
/ error that are storeable");
+                }
             }
         }
     }
 
-
     /**
      * Get the operationMode through request paramter, if <code>allowRequestParameterSwitch</code>
      * 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/09580777/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 3ba76c2..d5e339a 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.dispatcher.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);


Mime
View raw message