struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject struts git commit: WW-4517 UnknownHandlers should return null instead of throwing an exception
Date Sun, 21 Jun 2015 16:56:16 GMT
Repository: struts
Updated Branches:
  refs/heads/master 586f770d3 -> ce61023a4


WW-4517 UnknownHandlers should return null instead of throwing an
exception


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

Branch: refs/heads/master
Commit: ce61023a4ce9892b15a8a2eeae213dfe3328ce74
Parents: 586f770
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Sun Jun 21 18:56:07 2015 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Sun Jun 21 18:56:07 2015 +0200

----------------------------------------------------------------------
 .../xwork2/DefaultUnknownHandlerManager.java          |  6 +++++-
 .../java/com/opensymphony/xwork2/UnknownHandler.java  | 14 ++++++--------
 .../opensymphony/xwork2/UnknownHandlerManager.java    |  9 +++++++++
 .../com/opensymphony/xwork2/ActionInvocationTest.java |  2 +-
 .../xwork2/config/providers/SomeUnknownHandler.java   |  2 +-
 .../xwork2/util/UnknownHandlerManagerTest.java        |  7 ++++++-
 .../struts2/convention/ConventionUnknownHandler.java  |  2 +-
 7 files changed, 29 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/ce61023a/core/src/main/java/com/opensymphony/xwork2/DefaultUnknownHandlerManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/DefaultUnknownHandlerManager.java
b/core/src/main/java/com/opensymphony/xwork2/DefaultUnknownHandlerManager.java
index 92f7ba7..ef463b2 100644
--- a/core/src/main/java/com/opensymphony/xwork2/DefaultUnknownHandlerManager.java
+++ b/core/src/main/java/com/opensymphony/xwork2/DefaultUnknownHandlerManager.java
@@ -104,7 +104,11 @@ public class DefaultUnknownHandlerManager implements UnknownHandlerManager
{
             }
         }
 
-        return null;
+        if (unknownHandlers.isEmpty()) {
+            throw new NoSuchMethodException(String.format("No UnknownHandlers defined to
handle method [%s]", methodName));
+        } else {
+            throw new NoSuchMethodException(String.format("None of defined UnknownHandlers
can handle method [%s]", methodName));
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/struts/blob/ce61023a/core/src/main/java/com/opensymphony/xwork2/UnknownHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/UnknownHandler.java b/core/src/main/java/com/opensymphony/xwork2/UnknownHandler.java
index faabfc0..2558b78 100644
--- a/core/src/main/java/com/opensymphony/xwork2/UnknownHandler.java
+++ b/core/src/main/java/com/opensymphony/xwork2/UnknownHandler.java
@@ -33,7 +33,7 @@ public interface UnknownHandler {
      * @return An generated ActionConfig, can return <tt>null</tt>
      * @throws XWorkException
      */
-    public ActionConfig handleUnknownAction(String namespace, String actionName) throws XWorkException;
+    ActionConfig handleUnknownAction(String namespace, String actionName) throws XWorkException;
     
     /**
      * Handles the case when a result cannot be found for an action and result code. 
@@ -45,7 +45,7 @@ public interface UnknownHandler {
      * @return A result to be executed, can return <tt>null</tt>
      * @throws XWorkException
      */
-    public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig
actionConfig, String resultCode) throws XWorkException;
+    Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig
actionConfig, String resultCode) throws XWorkException;
     
     /**
      * Handles the case when an action method cannot be found.  This method is responsible
both for finding the method and executing it.
@@ -53,11 +53,9 @@ public interface UnknownHandler {
      * @since 2.1
      * @param action The action object
      * @param methodName The method name to call
-     * @return The result returned from invoking the action method, can return <tt>null</tt>
-     * @deprecated @throws NoSuchMethodException If the method cannot be found should return
null instead,
-     *                                           don't throw exception as other UnknownHandles
won't be invoked
-     *                                           'throws NoSuchMethodException' signature
will be removed with next
-     *                                           major release
+     * @return The result returned from invoking the action method, can return <tt>null</tt>
if this instance cannot
+     *         handle such methodName to allow other handlers give a chance
      */
-	public Object handleUnknownActionMethod(Object action, String methodName) throws NoSuchMethodException;
+	Object handleUnknownActionMethod(Object action, String methodName);
+
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/ce61023a/core/src/main/java/com/opensymphony/xwork2/UnknownHandlerManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/opensymphony/xwork2/UnknownHandlerManager.java b/core/src/main/java/com/opensymphony/xwork2/UnknownHandlerManager.java
index 325c0ff..f5e2542 100644
--- a/core/src/main/java/com/opensymphony/xwork2/UnknownHandlerManager.java
+++ b/core/src/main/java/com/opensymphony/xwork2/UnknownHandlerManager.java
@@ -25,8 +25,17 @@ import java.util.List;
  * @see com.opensymphony.xwork2.DefaultUnknownHandlerManager
  */
 public interface UnknownHandlerManager {
+
     Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig
actionConfig, String resultCode);
 
+    /**
+     * Tries to handle passed methodName if cannot find method should re
+     *
+     * @param action Action's instance
+     * @param methodName method name to handle
+     * @return Result representing result of given action method
+     * @throws NoSuchMethodException if method can be handled by defined UnknownHandlers
+     */
     Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException;
 
     ActionConfig handleUnknownAction(String namespace, String actionName);

http://git-wip-us.apache.org/repos/asf/struts/blob/ce61023a/core/src/test/java/com/opensymphony/xwork2/ActionInvocationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/ActionInvocationTest.java b/core/src/test/java/com/opensymphony/xwork2/ActionInvocationTest.java
index 58d02dd..05c09b2 100644
--- a/core/src/test/java/com/opensymphony/xwork2/ActionInvocationTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/ActionInvocationTest.java
@@ -52,7 +52,7 @@ public class ActionInvocationTest extends XWorkTestCase {
 			public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig
actionConfig, String resultCode) throws XWorkException {
 				return null;
 			}
-			public Object handleUnknownActionMethod(Object action, String methodName) throws NoSuchMethodException
{
+			public Object handleUnknownActionMethod(Object action, String methodName) {
 				if (methodName.equals("unknownmethod")) {
 					return "found";
 				} else {

http://git-wip-us.apache.org/repos/asf/struts/blob/ce61023a/core/src/test/java/com/opensymphony/xwork2/config/providers/SomeUnknownHandler.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/config/providers/SomeUnknownHandler.java
b/core/src/test/java/com/opensymphony/xwork2/config/providers/SomeUnknownHandler.java
index 494a16c..312f4c9 100644
--- a/core/src/test/java/com/opensymphony/xwork2/config/providers/SomeUnknownHandler.java
+++ b/core/src/test/java/com/opensymphony/xwork2/config/providers/SomeUnknownHandler.java
@@ -29,7 +29,7 @@ public class SomeUnknownHandler implements UnknownHandler{
         return actionConfig;
     }
 
-    public Object handleUnknownActionMethod(Object action, String methodName) throws NoSuchMethodException
{
+    public Object handleUnknownActionMethod(Object action, String methodName) {
         return actionMethodResult;
     }
 

http://git-wip-us.apache.org/repos/asf/struts/blob/ce61023a/core/src/test/java/com/opensymphony/xwork2/util/UnknownHandlerManagerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/com/opensymphony/xwork2/util/UnknownHandlerManagerTest.java
b/core/src/test/java/com/opensymphony/xwork2/util/UnknownHandlerManagerTest.java
index 9533eb0..42b41b7 100644
--- a/core/src/test/java/com/opensymphony/xwork2/util/UnknownHandlerManagerTest.java
+++ b/core/src/test/java/com/opensymphony/xwork2/util/UnknownHandlerManagerTest.java
@@ -77,6 +77,11 @@ public class UnknownHandlerManagerTest extends ConfigurationTestBase {
         //should not pick any
         uh1.setActionMethodResult(null);
         uh2.setActionMethodResult(null);
-        assertEquals(null, uhm.handleUnknownMethod(null, null));
+        try {
+            uhm.handleUnknownMethod(null, null);
+            fail("Should throw exception!");
+        } catch (NoSuchMethodException e) {
+            assertTrue(true);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/ce61023a/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java
----------------------------------------------------------------------
diff --git a/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java
b/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java
index bacc30d..85ce714 100644
--- a/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java
+++ b/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java
@@ -385,7 +385,7 @@ public class ConventionUnknownHandler implements UnknownHandler {
     /**
      * Not used
      */
-    public Object handleUnknownActionMethod(Object action, String methodName) throws NoSuchMethodException
{
+    public Object handleUnknownActionMethod(Object action, String methodName) {
         return null;
     }
 


Mime
View raw message