Improves flow of exceptions and missing action method

This commit is contained in:
Lukasz Lenart
2014-12-20 09:02:28 +01:00
parent 3288096c2b
commit bf7714f7ae
@@ -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);