我正在实现预匹配的ContainerRequestFilter
,并希望检索即将调用的资源的@Path
模式。
这是我的资源
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
中找到此信息,但 encodedPath
和 matchingPath
是相同的。
你能帮我解决这个问题吗?
最佳答案
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.
在调用过滤器时,并不清楚将匹配哪个资源。您的过滤器可能会更改 requestUri 甚至会影响匹配的方法,因此您无法在此处获取此信息。
在非@PreMatching
ContainerRequestFilter中,您可以通过 ContainerRequestContext.getUriInfo().getMatchedURIs() 获取更多信息或通过注入(inject) ResourceInfo就像已经answered here .
关于java - JAX-RS:检索 ContainerRequestFilter 中的路径模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27043093/