通过RESTeasy上的NameBinding将筛选器与特定方法匹配 [英] Match Filter with specific Method through NameBinding on RESTeasy

查看:157
本文介绍了通过RESTeasy上的NameBinding将筛选器与特定方法匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过遵循 RESTeasy文档建议。以下是我的代码:

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:

名称绑定:

@NameBinding
public @interface ValidateFoo {}

资源:

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

    @POST
    public Object doAnotherStuff() {
        //do another stuff
    }
}

过滤:

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

问题是:FooValidation过滤器在每个方法调用之前运行(例如:在GET和POST之前到/ f) oo / bar),不仅是用 @ValidateFoo 注释的(对我来说似乎是一个bug)。如果我从过滤器中删除 @Provider 注释,它将不会在任何调用之前运行(如预期的那样)。

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).

我一直在使用WebLogic或Tomcat看到这种行为。我的依赖管理是通过Maven完成的,RESTeasy版本是3.0-beta-3。

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.

任何体验/经历过相同行为的人?我在 JBoss论坛上看到了另一个有类似问题的用户,到目前为止没有运气。

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

更新:
仍然遇到与RESTeasy 3.0.1-Final相同的问题。

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

推荐答案

<我有类似的问题。对我来说,解决方案是添加以下注释配置(到@ValidateFoo):

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

这篇关于通过RESTeasy上的NameBinding将筛选器与特定方法匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆