Commits

Anonymous committed 35a0e26

Issue number: WW-1127
Obtained from:
Submitted by:
Reviewed by:

Keep pageflow from being modified depending on devMode if nonexistent property is tried to be set.
Instead, log errormessage and add comprehensive actionMessage for frontside display.

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@785e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 4c25fd5

Comments (0)

Files changed (2)

File src/java/com/opensymphony/xwork/interceptor/ParametersInterceptor.java

 
 import com.opensymphony.xwork.ActionContext;
 import com.opensymphony.xwork.ActionInvocation;
-import com.opensymphony.xwork.util.InstantiatingNullHandler;
-import com.opensymphony.xwork.util.OgnlValueStack;
-import com.opensymphony.xwork.util.XWorkConverter;
-import com.opensymphony.xwork.util.XWorkMethodAccessor;
+import com.opensymphony.xwork.ValidationAware;
+import com.opensymphony.xwork.util.*;
 
 import java.util.Iterator;
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 
 /**
  * <!-- START SNIPPET: description -->
  */
 public class ParametersInterceptor extends AroundInterceptor {
 
+    private static final Log LOG = LogFactory.getLog(ParametersInterceptor.class);
+
     protected void after(ActionInvocation dispatcher, String result) throws Exception {
     }
 
 
             if (acceptableName) {
                 Object value = entry.getValue();
-                stack.setValue(name, value);
+                try {
+                    stack.setValue(name, value);
+                } catch (RuntimeException e) {
+                    final Boolean devMode = (Boolean) stack.getContext().get(ActionContext.DEV_MODE);
+                    if (devMode != null && devMode.booleanValue()) {
+                        String developerNotification = LocalizedTextUtil.findText(ParametersInterceptor.class, "webwork.messages.devmode.notification", ActionContext.getContext().getLocale(), "Developer Notification (set webwork.devMode to false to disable this message):\n{0}", new Object[]{
+                                e.getMessage()
+                        });
+                        LOG.error(developerNotification);
+                        if (action instanceof ValidationAware) {
+                            ((ValidationAware) action).addActionMessage(developerNotification);
+                        }
+                    } else {
+                        throw new RuntimeException(e);
+                    }
+                }
             }
         }
     }

File src/test/com/opensymphony/xwork/interceptor/ParametersInterceptorTest.java

         }
     }
 
+    public void testNonexistentParametersGetLoggedInDevMode() {
+        Map params = new HashMap();
+        params.put("not_a_property", "There is no action property named like this");
+
+        HashMap extraContext = new HashMap();
+        extraContext.put(ActionContext.PARAMETERS, params);
+        extraContext.put(ActionContext.DEV_MODE, Boolean.TRUE);
+
+        try {
+            ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, extraContext);
+            proxy.execute();
+            final String actionMessage = ""+((SimpleAction) proxy.getAction()).getActionMessages().toArray()[0];
+            assertTrue(actionMessage.indexOf("No object in the CompoundRoot has a property named 'not_a_property'")>-1);
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+
+    public void testNonexistentParametersAreIgnoredInProductionMode() {
+        Map params = new HashMap();
+        params.put("not_a_property", "There is no action property named like this");
+
+        HashMap extraContext = new HashMap();
+        extraContext.put(ActionContext.PARAMETERS, params);
+        extraContext.put(ActionContext.DEV_MODE, Boolean.FALSE);
+
+        try {
+            ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("", MockConfigurationProvider.PARAM_INTERCEPTOR_ACTION_NAME, extraContext);
+            proxy.execute();
+            assertTrue(((SimpleAction) proxy.getAction()).getActionMessages().isEmpty());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+    }
+
     protected void setUp() throws Exception {
         ConfigurationManager.clearConfigurationProviders();
         ConfigurationManager.addConfigurationProvider(new MockConfigurationProvider());