Improves flow of exceptions and missing action method

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

Branch: refs/heads/master
Commit: bf7714f7ae648ef9e7e59ae00a9bbf34c746fffb
Parents: 3288096
Author: Lukasz Lenart <lukaszlen...@apache.org>
Authored: Sat Dec 20 09:02:28 2014 +0100
Committer: Lukasz Lenart <lukaszlen...@apache.org>
Committed: Sat Dec 20 09:02:28 2014 +0100

----------------------------------------------------------------------
 .../xwork2/DefaultActionInvocation.java         | 42 +++++++++++++-------
 1 file changed, 28 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/bf7714f7/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
----------------------------------------------------------------------
diff --git 
a/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java 
b/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
index dd44b14..f2c28ea 100644
--- 
a/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
+++ 
b/xwork-core/src/main/java/com/opensymphony/xwork2/DefaultActionInvocation.java
@@ -421,23 +421,37 @@ public class DefaultActionInvocation implements 
ActionInvocation {
             Object methodResult;
             try {
                 methodResult = ognlUtil.getValue(methodName + "()", 
getStack().getContext(), action);
-            } catch (OgnlException e) {
-                // hmm -- OK, try doXxx instead
-                try {
-                    String altMethodName = "do" + methodName.substring(0, 
1).toUpperCase() + methodName.substring(1)  + "()";
-                    methodResult = ognlUtil.getValue(altMethodName, 
ActionContext.getContext().getContextMap(), action);
-                } catch (OgnlException e1) {
-                    // well, give the unknown handler a shot
-                    if (unknownHandlerManager.hasUnknownHandlers()) {
-                        try {
-                            methodResult = 
unknownHandlerManager.handleUnknownMethod(action, methodName);
-                        } catch (NoSuchMethodException e2) {
-                            // throw the original one
+            } catch (MethodFailedException e) {
+                // if reason is missing method, try find version with "do" 
prefix
+                if (e.getReason() instanceof NoSuchMethodException) {
+                    try {
+                        String altMethodName = "do" + methodName.substring(0, 
1).toUpperCase() + methodName.substring(1) + "()";
+                        methodResult = ognlUtil.getValue(altMethodName, 
ActionContext.getContext().getContextMap(), action);
+                    } catch (MethodFailedException e1) {
+                        // if still method doesn't exist, try checking 
UnknownHandlers
+                        if (e.getReason() instanceof NoSuchMethodException) {
+                            if (unknownHandlerManager.hasUnknownHandlers()) {
+                                try {
+                                    methodResult = 
unknownHandlerManager.handleUnknownMethod(action, methodName);
+                                } catch (NoSuchMethodException e2) {
+                                    // throw the original one
+                                    throw e;
+                                }
+                            } else {
+                                throw e;
+                            }
+                            // throw the original exception as UnknownHandlers 
weren't able to handle invocation as well
+                            if (methodResult == null) {
+                                throw e;
+                            }
+                        } else {
+                            // exception isn't related to missing action method
                             throw e;
                         }
-                    } else {
-                        throw e;
                     }
+                } else {
+                    // exception isn't related to missing action method
+                    throw e;
                 }
             }
             return saveResult(actionConfig, methodResult);

Reply via email to