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/06/12 13:41:39 UTC

[2/2] struts git commit: WW-4640 Adds more informative message when method is not allowed

WW-4640 Adds more informative message when method is not allowed


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

Branch: refs/heads/master
Commit: 1afb48aa765a96a9d183bb4ac249bfcc8f7daf3a
Parents: ca256a7
Author: Lukasz Lenart <lu...@apache.org>
Authored: Sun Jun 12 15:41:28 2016 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Sun Jun 12 15:41:28 2016 +0200

----------------------------------------------------------------------
 .../opensymphony/xwork2/DefaultActionProxy.java | 14 +++++++++---
 .../xwork2/xwork-messages.properties            |  2 +-
 .../xwork2/DefaultActionProxyTest.java          | 24 ++++++++++++++++++++
 3 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/1afb48aa/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java b/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java
index 72c6e9e..2d8bc38 100644
--- a/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java
+++ b/core/src/main/java/com/opensymphony/xwork2/DefaultActionProxy.java
@@ -197,22 +197,30 @@ public class DefaultActionProxy implements ActionProxy, Serializable {
             if (config.isAllowedMethod(method)) {
                 invocation.init(this);
             } else {
-                throw new ConfigurationException("This method: " + method + " for action " + actionName + " is not allowed!");
+                throw new ConfigurationException(prepareNotAllowedErrorMessage());
             }
         } finally {
             UtilTimerStack.pop(profileKey);
         }
     }
 
+    protected String prepareNotAllowedErrorMessage() {
+        return LocalizedTextUtil.findDefaultText(
+                "struts.exception.method-not-allowed",
+                Locale.getDefault(),
+                new String[]{method, actionName}
+        );
+    }
+
     protected String getErrorMessage() {
         if ((namespace != null) && (namespace.trim().length() > 0)) {
             return LocalizedTextUtil.findDefaultText(
-                    XWorkMessages.MISSING_PACKAGE_ACTION_EXCEPTION,
+                    "xwork.exception.missing-package-action",
                     Locale.getDefault(),
                     new String[]{namespace, actionName});
         } else {
             return LocalizedTextUtil.findDefaultText(
-                    XWorkMessages.MISSING_ACTION_EXCEPTION,
+                    "xwork.exception.missing-action",
                     Locale.getDefault(),
                     new String[]{actionName});
         }

http://git-wip-us.apache.org/repos/asf/struts/blob/1afb48aa/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties
----------------------------------------------------------------------
diff --git a/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties b/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties
index 6068879..94781f5 100644
--- a/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties
+++ b/core/src/main/resources/com/opensymphony/xwork2/xwork-messages.properties
@@ -7,4 +7,4 @@ xwork.error.action.execution=Error during Action invocation
 xwork.exception.missing-action=There is no Action mapped for action name {0}.
 xwork.exception.missing-package-action=There is no Action mapped for namespace {0} and action name {1}.
 xwork.default.invalid.fieldvalue=Invalid field value for field "{0}".
-
+struts.exception.method-not-allowed=Method {0} for action {1} is not allowed!

http://git-wip-us.apache.org/repos/asf/struts/blob/1afb48aa/core/src/test/java/com/opensymphony/xwork2/DefaultActionProxyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/DefaultActionProxyTest.java b/core/src/test/java/com/opensymphony/xwork2/DefaultActionProxyTest.java
new file mode 100644
index 0000000..17d7c68
--- /dev/null
+++ b/core/src/test/java/com/opensymphony/xwork2/DefaultActionProxyTest.java
@@ -0,0 +1,24 @@
+package com.opensymphony.xwork2;
+
+import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
+import com.opensymphony.xwork2.mock.MockActionInvocation;
+import org.apache.struts2.StrutsInternalTestCase;
+import org.junit.Test;
+
+public class DefaultActionProxyTest extends StrutsInternalTestCase {
+
+    @Test
+    public void testThorwExceptionOnNotAllowedMethod() throws Exception {
+        final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-allowed-methods.xml";
+        loadConfigurationProviders(new XmlConfigurationProvider(filename));
+        DefaultActionProxy dap = new DefaultActionProxy(new MockActionInvocation(), "strict", "Default", "notAllowed", true, true);
+        container.inject(dap);
+
+        try {
+            dap.prepare();
+            fail("Must throw exception!");
+        } catch (Exception e) {
+            assertEquals(e.getMessage(), "Method notAllowed for action Default is not allowed!");
+        }
+    }
+}
\ No newline at end of file