Description
Summary
Filters are not working as expected (at least for SpringLambdaContainerHandler). Filters are called only the first time a URL is called. I used the sample pet-store for Spring and added a filter as described in the documentation.
First time I called an URL (i.e. /pets/1), the filter is executed as expected. If I call the same URL again, the filter is not executed.
If I call another URL, (i.e. /pets/2), the filter is executed the first time, but not executed for the subsequent calls to that same URL.
Steps to reproduce
From aws-serverless-java-container-master\samples\spring\pet-store, modify LambdaHandler.java to add a filter, named TestFilter which will only logged (into CloudWatch) when the doFilter method is called (see in attachments).
try {
handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.class);
handler.onStartup(c -> {
FilterRegistration.Dynamic registration = c.addFilter("TestFilter", TestFilter.class);
registration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
});
} catch (ContainerInitializationException e) {
Add the TestFilter class (see in attachments):
public class TestFilter implements Filter {
@Override
public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException {
System.out.println("DoFilter TestFilter");
chain.doFilter(req, res);
}
Expected Result
I expected the TestFilter doFilter() method to be executed each time I access any URL
Actual Result
First time I called an URL (i.e. /pets/1), the filter is executed as expected. If I call the same URL again, the filter is not executed.
If I call another URL, (i.e. /pets/2), the filter is executed the first time, but not executed for the subsequent calls to that same URL.