JAX-RS:在ContainerRequestFilter中检索路径模式 [英] JAX-RS: Retrieve path pattern in ContainerRequestFilter

查看:109
本文介绍了JAX-RS:在ContainerRequestFilter中检索路径模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现预匹配ContainerRequestFilter,并想检索将要调用的资源的@Path模式.

I am implementing a pre matching ContainerRequestFilter and would like to retrieve the @Path pattern of my resource which is about to be invoked.

这是我的资源

Path("/v1/partner/{partnerId}/adresse")
public interface AdresseResource
{
   @GET
   @Produces({ MediaType.APPLICATION_JSON })
   public Response handleAdresseCollectionGet(@Context UriInfo uriInfo, @PathParam("partnerId") String partnerId);

   // Other methods omitted
}

在我的过滤器中,我想从路径注释中获取/v1/partner/{partnerId}/adresse模式.但是我不能从ContainerRequestContext实例中获取它.我本来希望在UriInfo中找到此信息,但encodedPathmatchingPath是相同的.

In my filter I would like to get the /v1/partner/{partnerId}/adresse pattern from my Path annotation. But I can't get it out of the ContainerRequestContext instance. I would have expected this information within the UriInfo but encodedPath and matchingPath are the same.

您能帮我吗?

推荐答案

可用于容器请求过滤器的全局绑定批注,以指示在实际资源匹配发生之前,应将此过滤器全局应用于应用程序中的所有资源.

Global binding annotation that can be applied to a container request filter to indicate that such filter should be applied globally on all resources in the application before the actual resource matching occurs.

在调用过滤器时,尚不清楚将匹配哪个资源.您的过滤器可能会更改requestUri甚至更改会影响匹配的方法,因此您无法在此处获取此信息.

At the time your filter is invoked it's not clear which resource will be matched. Your Filter could change the requestUri or even the method which would affect the matching so you can't get this information here.

在非@PreMatching ContainerRequestFilter中,您可以通过在这里回答.

In a non @PreMatching ContainerRequestFilter you can get more information via ContainerRequestContext.getUriInfo().getMatchedURIs() or by injecting the ResourceInfo like already answered here.

这篇关于JAX-RS:在ContainerRequestFilter中检索路径模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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