mirror of
https://github.com/apache/struts.git
synced 2026-08-06 07:06:58 +00:00
Merge branch 'develop' into WW-4435
This commit is contained in:
@@ -426,10 +426,10 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
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);
|
||||
methodResult = ognlUtil.getValue(altMethodName, getStack().getContext(), action);
|
||||
} catch (MethodFailedException e1) {
|
||||
// if still method doesn't exist, try checking UnknownHandlers
|
||||
if (e.getReason() instanceof NoSuchMethodException) {
|
||||
if (e1.getReason() instanceof NoSuchMethodException) {
|
||||
if (unknownHandlerManager.hasUnknownHandlers()) {
|
||||
try {
|
||||
methodResult = unknownHandlerManager.handleUnknownMethod(action, methodName);
|
||||
@@ -438,6 +438,7 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
// throw the original one
|
||||
throw e;
|
||||
}
|
||||
// throw the original exception as UnknownHandlers weren't able to handle invocation as well
|
||||
@@ -445,12 +446,12 @@ public class DefaultActionInvocation implements ActionInvocation {
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
// exception isn't related to missing action method
|
||||
throw e;
|
||||
// exception isn't related to missing action method, throw it
|
||||
throw e1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// exception isn't related to missing action method
|
||||
// exception isn't related to missing action method, throw it
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +106,28 @@ public class DefaultActionInvocationTest extends XWorkTestCase {
|
||||
assertEquals("success", result);
|
||||
}
|
||||
|
||||
public void testInvokingExistingDoInputMethod() throws Exception {
|
||||
// given
|
||||
DefaultActionInvocation dai = new DefaultActionInvocation(new HashMap<String, Object>(), false) {
|
||||
public ValueStack getStack() {
|
||||
return new StubValueStack();
|
||||
}
|
||||
};
|
||||
|
||||
SimpleAction action = new SimpleAction();
|
||||
MockActionProxy proxy = new MockActionProxy();
|
||||
proxy.setMethod("with");
|
||||
|
||||
dai.proxy = proxy;
|
||||
dai.ognlUtil = new OgnlUtil();
|
||||
|
||||
// when
|
||||
String result = dai.invokeAction(action, null);
|
||||
|
||||
// then
|
||||
assertEquals("with", result);
|
||||
}
|
||||
|
||||
public void testInvokingMissingMethod() throws Exception {
|
||||
// given
|
||||
DefaultActionInvocation dai = new DefaultActionInvocation(new HashMap<String, Object>(), false) {
|
||||
@@ -135,16 +157,16 @@ public class DefaultActionInvocationTest extends XWorkTestCase {
|
||||
dai.unknownHandlerManager = uhm;
|
||||
|
||||
// when
|
||||
Throwable expected = null;
|
||||
Throwable actual = null;
|
||||
try {
|
||||
dai.invokeAction(action, null);
|
||||
} catch (Exception e) {
|
||||
expected = e;
|
||||
actual = e;
|
||||
}
|
||||
|
||||
// then
|
||||
assertNotNull(expected);
|
||||
assertTrue(expected instanceof NoSuchMethodException);
|
||||
assertNotNull(actual);
|
||||
assertTrue(actual instanceof NoSuchMethodException);
|
||||
}
|
||||
|
||||
public void testInvokingExistingMethodThatThrowsException() throws Exception {
|
||||
@@ -168,17 +190,154 @@ public class DefaultActionInvocationTest extends XWorkTestCase {
|
||||
dai.ognlUtil = new OgnlUtil();
|
||||
|
||||
// when
|
||||
// when
|
||||
Throwable expected = null;
|
||||
Throwable actual = null;
|
||||
try {
|
||||
dai.invokeAction(action, null);
|
||||
} catch (Exception e) {
|
||||
expected = e;
|
||||
actual = e;
|
||||
}
|
||||
|
||||
// then
|
||||
assertNotNull(expected);
|
||||
assertTrue(expected instanceof IllegalArgumentException);
|
||||
assertNotNull(actual);
|
||||
assertTrue(actual instanceof IllegalArgumentException);
|
||||
}
|
||||
|
||||
public void testInvokingExistingDoMethodThatThrowsException() throws Exception {
|
||||
// given
|
||||
DefaultActionInvocation dai = new DefaultActionInvocation(new HashMap<String, Object>(), false) {
|
||||
public ValueStack getStack() {
|
||||
return new StubValueStack();
|
||||
}
|
||||
};
|
||||
|
||||
UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {
|
||||
@Override
|
||||
public boolean hasUnknownHandlers() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
SimpleAction action = new SimpleAction() {
|
||||
@Override
|
||||
public String doWith() throws Exception {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
};
|
||||
MockActionProxy proxy = new MockActionProxy();
|
||||
proxy.setMethod("with");
|
||||
|
||||
dai.proxy = proxy;
|
||||
dai.ognlUtil = new OgnlUtil();
|
||||
dai.unknownHandlerManager = uhm;
|
||||
|
||||
// when
|
||||
// when
|
||||
Throwable actual = null;
|
||||
try {
|
||||
dai.invokeAction(action, null);
|
||||
} catch (Exception e) {
|
||||
actual = e;
|
||||
}
|
||||
|
||||
// then
|
||||
assertNotNull(actual);
|
||||
assertTrue(actual instanceof IllegalArgumentException);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void testUnknownHandlerManagerThatThrowsException() throws Exception {
|
||||
// given
|
||||
DefaultActionInvocation dai = new DefaultActionInvocation(new HashMap<String, Object>(), false) {
|
||||
public ValueStack getStack() {
|
||||
return new StubValueStack();
|
||||
}
|
||||
};
|
||||
|
||||
UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {
|
||||
@Override
|
||||
public boolean hasUnknownHandlers() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
|
||||
throw new NoSuchMethodException();
|
||||
}
|
||||
};
|
||||
|
||||
SimpleAction action = new SimpleAction() {
|
||||
@Override
|
||||
public String doWith() throws Exception {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
};
|
||||
MockActionProxy proxy = new MockActionProxy();
|
||||
proxy.setMethod("notExists");
|
||||
|
||||
dai.proxy = proxy;
|
||||
dai.ognlUtil = new OgnlUtil();
|
||||
dai.unknownHandlerManager = uhm;
|
||||
|
||||
// when
|
||||
// when
|
||||
Throwable actual = null;
|
||||
try {
|
||||
dai.invokeAction(action, null);
|
||||
} catch (Exception e) {
|
||||
actual = e;
|
||||
}
|
||||
|
||||
// then
|
||||
assertNotNull(actual);
|
||||
assertTrue(actual instanceof NoSuchMethodException);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void testUnknownHandlerManagerThatReturnsNull() throws Exception {
|
||||
// given
|
||||
DefaultActionInvocation dai = new DefaultActionInvocation(new HashMap<String, Object>(), false) {
|
||||
public ValueStack getStack() {
|
||||
return new StubValueStack();
|
||||
}
|
||||
};
|
||||
|
||||
UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {
|
||||
@Override
|
||||
public boolean hasUnknownHandlers() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
SimpleAction action = new SimpleAction() {
|
||||
@Override
|
||||
public String doWith() throws Exception {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
};
|
||||
MockActionProxy proxy = new MockActionProxy();
|
||||
proxy.setMethod("notExists");
|
||||
|
||||
dai.proxy = proxy;
|
||||
dai.ognlUtil = new OgnlUtil();
|
||||
dai.unknownHandlerManager = uhm;
|
||||
|
||||
// when
|
||||
// when
|
||||
Throwable actual = null;
|
||||
try {
|
||||
dai.invokeAction(action, null);
|
||||
} catch (Exception e) {
|
||||
actual = e;
|
||||
}
|
||||
|
||||
// then
|
||||
assertNotNull(actual);
|
||||
assertTrue(actual instanceof NoSuchMethodException);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -249,6 +249,9 @@ public class SimpleAction extends ActionSupport {
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
public String doWith() throws Exception {
|
||||
return "with";
|
||||
}
|
||||
|
||||
public long getLongFoo() {
|
||||
return longFoo;
|
||||
|
||||
Reference in New Issue
Block a user