mirror of
https://github.com/serverless/serverless.git
synced 2026-02-01 16:07:28 +00:00
Merge pull request #6791 from lasanthak/master
Issue 4867 - Allowing InvokeBridge to find handleRequest method from super classes
This commit is contained in:
commit
a002b6e949
@ -105,7 +105,7 @@ public class InvokeBridge {
|
||||
|
||||
private Method findHandlerMethod(Class clazz, String handlerName) throws Exception {
|
||||
Method candidateMethod = null;
|
||||
for(Method method: clazz.getDeclaredMethods()) {
|
||||
for(Method method: clazz.getMethods()) {
|
||||
if (method.getName().equals(handlerName) && !method.isBridge()) {
|
||||
// Select the method with the largest number of parameters
|
||||
// If two or more methods have the same number of parameters, AWS Lambda selects the method that has
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.serverless;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
|
||||
public abstract class AbstractRequestHandler
|
||||
implements com.amazonaws.services.lambda.runtime.RequestHandler<Map<String, Object>, Object> {
|
||||
|
||||
abstract Object handleMe();
|
||||
|
||||
@Override
|
||||
public Object handleRequest(Map<String, Object> stringObjectMap, Context context) {
|
||||
return "Parent Complete.|" + handleMe();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.serverless;
|
||||
|
||||
public class ConcreteRequestHandler extends AbstractRequestHandler {
|
||||
|
||||
@Override
|
||||
Object handleMe() {
|
||||
return "Child Complete.";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package com.serverless;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class InvokeBridgeInheritanceTest {
|
||||
@Before
|
||||
public void before() {
|
||||
System.setProperty("artifactPath", "target/test-classes/com/serverless/ConcreteRequestHandler.class");
|
||||
System.setProperty("className", "com.serverless.ConcreteRequestHandler");
|
||||
System.setProperty("handlerName", "handleRequest");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyInvoke() {
|
||||
System.setIn(getClass().getResourceAsStream("/test.json"));
|
||||
InvokeBridge.main(new String[] {});
|
||||
// Nothing to verify, if this doesn't throw NoSuchMethodException, we are good.
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user