Match Filter with specific Method through NameBinding on RESTeasy

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

I am trying to specify a pre-matching filter that is only associated to some of my API calls, by following what the RESTeasy documentation suggests. Here is what my code looks like:

Name binding:

@NameBinding public @interface ValidateFoo {} 

Resource:

@Path("/foo/bar") @Produces(MediaType.APPLICATION_JSON) public class FooBar {     @GET     @ValidateFoo     public Object doStuff() {         //do stuff     }      @POST     public Object doAnotherStuff() {         //do another stuff     } } 

Filter:

@ValidateFoo @Provider @PreMatching public class FooValidation implements ContainerRequestFilter {     @Override     public void filter(ContainerRequestContext reqContext) throws IOException {         //validate stuff     } } 

Problem is: the FooValidation filter runs before every method call (e.g.: before GETs and POSTs to /foo/bar), not only the ones annotated with @ValidateFoo (seems a bug to me). If I remove the @Provider annotation from the filter, it won't run before any call (as expected).

I am seeing this behavior consistently, either using WebLogic or Tomcat. My dependency management is done through Maven, and the RESTeasy version is 3.0-beta-3.

Anyone experiencing/experienced the same behavior? I have seen another user with a similar problem on JBoss forums, with no luck so far.

UPDATE: Still experiencing the same issue with RESTeasy 3.0.1-Final.

回答1:

I had similar problem. For me the solution was to add following annotation configuration (to @ValidateFoo):

@Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(value = RetentionPolicy.RUNTIME) @NameBinding 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!