From bf7714f7ae648ef9e7e59ae00a9bbf34c746fffb Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Sat, 20 Dec 2014 09:02:28 +0100 Subject: [PATCH] Improves flow of exceptions and missing action method --- .../xwork2/DefaultActionInvocation.java | 42 ++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) 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 dd44b140e..f2c28eaab 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);