saw303
saw303

Reputation: 9072

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?

enter image description here

Upvotes: 2

Views: 4094

Answers (1)

lefloh
lefloh

Reputation: 10961

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.

Upvotes: 3

Related Questions