mirror of
https://github.com/apache/struts.git
synced 2026-08-11 17:46:57 +00:00
Improves flow of exceptions and missing action method
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user