Intercept JAX-RS Request: Register a ContainerRequestFilter with tomcat

后端 未结 3 1998
太阳男子
太阳男子 2020-12-30 09:15

I am trying to intercept a request to my JAX-RS webservice by a ContainerRequestFilter. I want to use it with a custom annotation, so I can decorate certain methods of the w

相关标签:
3条回答
  • 2020-12-30 09:24

    Just compiling the answer from Michael Gajdos to help someone who do not want open more tabs:

    When you are using Jersey-2 you must use the follow configuration to register your filter into the web.xml

    jersey.config.server.provider.classnames

    instead of

    com.sun.jersey.spi.container.ContainerRequestFilters (jersey-1x)

     <!-- This is the config needed -->
    <servlet>    
          //...         
         <init-param>
             <param-name>jersey.config.server.provider.classnames</param-name>
             <param-value>com.your_package_path.yourClassFilter</param-value>
         </init-param>
          //...
    </servlet>
    
    0 讨论(0)
  • 2020-12-30 09:26

    You're using JAX-RS 2.0 APIs (request filters, name binding, ...) in your classes but Jersey 1 proprietary init params in your web.xml (package starting with com.sun.jersey, Jersey 2 uses org.glassfish.jersey). Take a look at this answer and at these articles:

    • Registering Resources and Providers in Jersey 2
    • Binding JAX-RS Providers to Resource Methods
    0 讨论(0)
  • 2020-12-30 09:44

    Have a look at this blog post for the more 'classical' approaches (without using the annotation)

    0 讨论(0)
提交回复
热议问题