简体   繁体   中英

JAX-RS: Retrieve path pattern in ContainerRequestFilter

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?

在此处输入图片说明

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM