gpt4 book ai didi

java - 带注释的剩余过滤器

转载 作者:行者123 更新时间:2023-12-01 10:50:30 25 4
gpt4 key购买 nike

我正在编写restful webservice,我必须使用静态名称绑定(bind)注释编写REST服务器端过滤器。我有两个过滤器,一个过滤器有注释 @one,另一个过滤器有注释 @two 我必须将这两个注释放在 Rest Webservices 上。

@one 
@two
public String getName()
{
return "xyz";
}

第一个过滤器中的逻辑是,它将检查某些条件“说条件 A”,然后只有这样才允许请求命中此其余部分,第二个过滤器中的逻辑是,它将检查某些条件“说条件 B”,然后只有这样才能允许请求到达此休息。但我有一种情况,满足这两个条件 A 或 B 中的任何一个,那么该请求也将达到此要求。 如果满足任何一个条件,那么请求也会到达此 Web 服务,您能告诉我如何执行此操作吗?

最佳答案

@Priority()来控制filter and interceptors执行顺序。

In case you register more filters and interceptors you might want to define an exact order in which they should be invoked. The order can be controlled by the @Priority annotation defined by the javax.annotation.Priority class. The annotation accepts an integer parameter of priority. Providers used in request processing (ContainerRequestFilter, ClientRequestFilter) as well as entity interceptors (ReaderInterceptor, WriterInterceptor) are sorted based on the priority in an ascending manner. So, a request filter with priority defined with @Priority(1000) will be executed before another request filter with priority defined as @Priority(2000). Providers used during response processing (ContainerResponseFilter, ClientResponseFilter) are executed in the reverse order (using descending manner), so a provider with the priority defined with @Priority(2000) will be executed before another provider with priority defined with @Priority(1000).

https://jersey.github.io/documentation/latest/filters-and-interceptors.html#d0e9816

关于java - 带注释的剩余过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33944386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com