GH-639 Fix NPE for when using Supplier with AWS API Gateway
Resolves #639
This commit is contained in:
@@ -202,7 +202,7 @@ final class AWSLambdaUtils {
|
||||
}
|
||||
|
||||
private static boolean isTypeAnApiGatewayRequest(Type type) {
|
||||
return isAPIGatewayProxyRequestEventPresent()
|
||||
return type != null && isAPIGatewayProxyRequestEventPresent()
|
||||
? type.getTypeName().endsWith(APIGatewayProxyRequestEvent.class.getSimpleName())
|
||||
: false;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
|
||||
import com.amazonaws.services.lambda.runtime.events.KinesisEvent;
|
||||
@@ -625,6 +626,22 @@ public class FunctionInvokerTests {
|
||||
assertThat(result.get("body")).isEqualTo("\"hello\"");
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testApiGatewayAsSupplier() throws Exception {
|
||||
System.setProperty("MAIN_CLASS", ApiGatewayConfiguration.class.getName());
|
||||
System.setProperty("spring.cloud.function.definition", "supply");
|
||||
FunctionInvoker invoker = new FunctionInvoker();
|
||||
|
||||
InputStream targetStream = new ByteArrayInputStream(this.apiGatewayEvent.getBytes());
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
invoker.handleRequest(targetStream, output, null);
|
||||
|
||||
Map result = mapper.readValue(output.toByteArray(), Map.class);
|
||||
System.out.println(result);
|
||||
assertThat(result.get("body")).isEqualTo("\"boom\"");
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testApiGatewayEventAsMessage() throws Exception {
|
||||
@@ -840,6 +857,12 @@ public class FunctionInvokerTests {
|
||||
@Configuration
|
||||
public static class ApiGatewayConfiguration {
|
||||
|
||||
@Bean
|
||||
public Supplier<String> supply() {
|
||||
return () -> "boom";
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Consumer<String> consume() {
|
||||
return v -> System.out.println(v);
|
||||
|
||||
Reference in New Issue
Block a user