JAX-RS: Retrieve path pattern in ContainerRequestFilter

陌路散爱 提交于 2019-12-13 16:22:18

问题


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

Here is my resource

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
}

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.

Can you help me on this?


回答1:


From the @PreMatching documentation:

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.

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.

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



来源:https://stackoverflow.com/questions/27043093/jax-rs-retrieve-path-pattern-in-containerrequestfilter

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