Giter VIP home page Giter VIP logo

Comments (9)

blakeney avatar blakeney commented on September 24, 2024

I did some more investigation and determined with more certainty that indeed, the current implementation does not support Filter registration (or Servlet registration, for that matter). I also determined that HandlerInterceptors will not serve my particular need, so I am just going to work around this in the handleRequest method of my own project for the time being, essentially bypassing Spring for part of my code.

I probably will not have time to patch this library to add Filter support myself any time soon, so unfortunately I can't offer a Pull Request at the moment. I'll leave the ticket open for now in case anyone else is interested in this as a feature, but I'm also okay with it if this is a "Won't Fix." Thanks!

from aws-serverless-java-container.

sapessi avatar sapessi commented on September 24, 2024

Correct, at the moment it does not. I'd be interested to take a look at your filter code and see if/how we can add support for it. Anything you can share on GitHub or here?

from aws-serverless-java-container.

AlainJanssens avatar AlainJanssens commented on September 24, 2024

Is this also the reason why '@Valid' isn't working?

from aws-serverless-java-container.

sapessi avatar sapessi commented on September 24, 2024

I'm no spring expert but doing some research I can see that the @Valid annotation does run as a filter. We are currently designing filters support based on this issue and we'll have something in a branch over the next few weeks.

from aws-serverless-java-container.

AlainJanssens avatar AlainJanssens commented on September 24, 2024

Thanks for the answer @sapessi ..

I created a separated issue for this...

from aws-serverless-java-container.

sapessi avatar sapessi commented on September 24, 2024

I'll keep that issue open until I can confirm for certain that this is the cause of the issue. If it is, then I'll close the separate issue and group everything in here. Otherwise we'll address it there.

from aws-serverless-java-container.

sapessi avatar sapessi commented on September 24, 2024

Hey @blakeney, could you share some sample code on how you initialize (and add) filters in your spring application?

from aws-serverless-java-container.

sapessi avatar sapessi commented on September 24, 2024

I've pushed a first version of the filter support to the servlet-improvements branch. This is the commit d7bec0a. You can register filters with the setStartupHandler lambda:

try {
    handler = SpringLambdaContainerHandler.getAwsProxyHandler(EchoSpringAppConfig.class);
    handler.setStartupHandler(c -> {
        FilterRegistration.Dynamic registration = c.addFilter("CustomHeaderFilter", CustomHeaderFilter.class);
        // update the registration to map to a path
        registration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
        // servlet name mappings are disabled and will throw an exception
    });
} catch (ContainerInitializationException e) {
    e.printStackTrace();
}

Next I will work on supporting the filter annotations.

from aws-serverless-java-container.

sapessi avatar sapessi commented on September 24, 2024

Version 0.4 is out and adds support for servlet filter:

handler.setStartupHandler(c -> {
    FilterRegistration.Dynamic registration = c.addFilter("CustomHeaderFilter", CustomHeaderFilter.class);
    // update the registration to map to a path
    registration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
    // servlet name mappings are disabled and will throw an exception
});

Closing this issue.

from aws-serverless-java-container.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.