private void invokeLambda(Class functionClass, ByteBuffer payload) throws IllegalAccessException, InstantiationException, InvocationTargetException, ExecutionException, InterruptedException { Class lambdaPayloadClass = getLambdaPayloadClass(functionClass); Object lambdaPayload = getPayloadObjectFromJson(payload, lambdaPayloadClass); RequestHandler functionClassInstance = ((RequestHandler) functionClass.newInstance()); threadPool.submit(() -> functionClassInstance.handleRequest(lambdaPayload, new MockContext())); }
@Test @SuppressWarnings("unchecked") public void handle() { final RequestHandler handler = mock(RequestHandler.class); when(mockApplicationContext.getBean(RequestHandler.class)).thenReturn(handler); final TestSpringVoidRequestHandler testHandler = new TestSpringVoidRequestHandler(); final Context mockContext = mock(Context.class); final String input = "foo"; testHandler.handleRequest(input, mockContext); verify(mockApplicationContext).getBean(RequestHandler.class); verify(handler).handleRequest(input, mockContext); }
private Optional<EventResultT> handleEvent(Supplier<Optional<EventT>> eventSupplier, Context context) { return eventSupplier.get().map(e -> { RequestHandler<EventT, EventResultT> handler = getEventHandler().get(); return handler.handleRequest(e, context); }); }
@Override public Supplier<RequestHandler<ScheduledEvent, ScheduledEventResult>> getEventHandler() { return () -> new ScheduledEventHandler(getApplicationContext()); }
@Override public Supplier<RequestHandler<SnsEvent, SnsEventResult>> getEventHandler() { return () -> new SnsEventHandler(getApplicationContext()); }
@Override public Supplier<RequestHandler<DynamoDbEvent, DynamoDbEventResult>> getEventHandler() { return supplier; }
@Override public Supplier<RequestHandler<S3EventNotification, S3EventResult>> getEventHandler() { return () -> new S3EventHandler(getApplicationContext(), s3Action); }
public SpringRequestHandler() { handler = getApplicationContext().getBean(RequestHandler.class); }
/** * To work around type erasure, pass the input type class here. AWS Lambda * requires a no-arg constructor for their handler classes however, so be * sure to provide one while calling this constructor in it. * * @param inputClass the class of this class's input type parameter, I. */ protected JacksonSpringRequestHandler(@NotNull final Class<I> inputClass) { this.inputClass = inputClass; this.handler = getApplicationContext().getBean(RequestHandler.class); }
Supplier<RequestHandler<EventT, R>> getEventHandler();