Merge pull request #6791 from lasanthak/master

Issue 4867 - Allowing InvokeBridge to find handleRequest method from super classes
This commit is contained in:
Philipp Muens 2019-10-07 16:43:20 +02:00 committed by GitHub
commit a002b6e949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 1 deletions

View File

@ -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

View File

@ -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();
}
}

View File

@ -0,0 +1,10 @@
package com.serverless;
public class ConcreteRequestHandler extends AbstractRequestHandler {
@Override
Object handleMe() {
return "Child Complete.";
}
}

View File

@ -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.
}
}