Jersey ContainerRequestFilter not triggered

后端 未结 10 693
囚心锁ツ
囚心锁ツ 2020-12-05 06:34

I\'m trying to use a ContainerRequestFilter to enforce some authentication on a Tomcat based Jersey application. I followed this document. Problem : the filter

10条回答
  •  难免孤独
    2020-12-05 07:04

    Instead of using the @Provider annotation (which did not work in my case), you can register your ContainerRequestFilter manually with your JerseyServletFactory:

    JerseyServletFactory jerseyServletFactory = new JerseyServletFactory(config);
    HttpServlet myServiceServlet = jerseyServletFactory.create(myResource);
    
    // Register your ContainerRequestFilter like this
    jerseyServletFactory.addRequestFilter(new MyFilter());
    
    httpServer.register(myServiceServlet, "/api");
    httpServer.start();
    

提交回复
热议问题