You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2016/02/04 08:20:20 UTC

[4/7] struts git commit: Uses the new listener

Uses the new listener


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

Branch: refs/heads/master
Commit: 8071052f86c5196bf771eb6ede442b9823753703
Parents: 0754027
Author: Lukasz Lenart <lu...@apache.org>
Authored: Thu Feb 4 08:05:21 2016 +0100
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Thu Feb 4 08:05:21 2016 +0100

----------------------------------------------------------------------
 .../interceptor/MessageStoreInterceptor.java    | 61 +++-----------------
 1 file changed, 8 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/8071052f/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 848c5bf..4b7220e 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/MessageStoreInterceptor.java
@@ -28,7 +28,6 @@ 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;
@@ -176,6 +175,7 @@ public class MessageStoreInterceptor extends AbstractInterceptor {
     public void setAllowRequestParameterSwitch(boolean allowRequestParameterSwitch) {
         this.allowRequestParameterSwitch = allowRequestParameterSwitch;
     }
+
     public boolean getAllowRequestParameterSwitch() {
         return this.allowRequestParameterSwitch;
     }
@@ -183,6 +183,7 @@ public class MessageStoreInterceptor extends AbstractInterceptor {
     public void setRequestParameterSwitch(String requestParameterSwitch) {
         this.requestParameterSwitch = requestParameterSwitch;
     }
+
     public String getRequestParameterSwitch() {
         return this.requestParameterSwitch;
     }
@@ -190,16 +191,20 @@ public class MessageStoreInterceptor extends AbstractInterceptor {
     public void setOperationMode(String operationMode) {
         this.operationMode = operationMode;
     }
+
     public String getOperationModel() {
         return this.operationMode;
     }
 
     public String intercept(ActionInvocation invocation) throws Exception {
-        LOG.debug("entering MessageStoreInterceptor ...");
+        LOG.trace("entering MessageStoreInterceptor ...");
 
         before(invocation);
+
+        LOG.trace("Registering listener to store messages before result will be executed");
+        invocation.addPreResultListener(new MessageStorePreResultListener(this));
+
         String result = invocation.invoke();
-        after(invocation, result);
 
         LOG.debug("exit executing MessageStoreInterceptor");
 
@@ -260,56 +265,6 @@ public class MessageStoreInterceptor extends AbstractInterceptor {
     }
 
     /**
-     * Handle the storing of field errors / action messages / field errors, which is
-     * done after action invocation, and the <code>operationMode</code> is in 'STORE'.
-     *
-     * @param invocation the action invocation
-     * @param result the result
-     * @throws Exception in case of any error
-     */
-    protected void after(ActionInvocation invocation, String result) throws Exception {
-
-        boolean isCommitted = ServletActionContext.getResponse().isCommitted();
-        if (isCommitted) {
-            LOG.trace("Response was already committed, cannot store messages!");
-            return;
-        }
-
-        boolean isInvalidated = ServletActionContext.getRequest().getSession(false) == null;
-        if (isInvalidated) {
-            LOG.trace("Session was invalidated or never created, cannot store messages!");
-            return;
-        }
-
-        Map<String, Object> session = invocation.getInvocationContext().getSession();
-        if (session == null) {
-            LOG.trace("Could not store action [{}] error/messages into session, because session hasn't been opened yet.", invocation.getAction());
-            return;
-        }
-
-        String reqOperationMode = getRequestOperationMode(invocation);
-        boolean isRedirect = invocation.getResult() instanceof ServletRedirectResult;
-
-        if (STORE_MODE.equalsIgnoreCase(reqOperationMode) ||
-                STORE_MODE.equalsIgnoreCase(operationMode) ||
-                (AUTOMATIC_MODE.equalsIgnoreCase(operationMode) && isRedirect)) {
-
-            Object action = invocation.getAction();
-            if (action instanceof ValidationAware) {
-                LOG.debug("Storing action [{}] error/messages into session ", action);
-
-                ValidationAware validationAwareAction = (ValidationAware) action;
-                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);
-            }
-        }
-    }
-
-    /**
      * Get the operationMode through request parameter, if <code>allowRequestParameterSwitch</code>
      * is 'true', else it simply returns 'NONE', meaning its neither in the 'STORE_MODE' nor
      * 'RETRIEVE_MODE'.