java - JAX-RS:检索 ContainerRequestFilter 中的路径模式

标签 java jax-rs resteasy

我正在实现预匹配的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 中找到此信息,但 encodedPathmatchingPath 是相同的。

你能帮我解决这个问题吗?

enter image description here

最佳答案

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/

相关文章:

Java - 私有(private)和包私有(private)枚举构造函数之间的区别

java - Spring 休息 : upload file

Java RestEasy : Base64 encoded sign over REST

java - 后处理拦截器 : How to access HTTP request?

java - 使用 Jackson 在运行时将实体动态序列化为其 ID 或其完整表示

java - Android、Gradle 产品 flavor ;包不存在

java - 如何找到数组中唯一不出现两次的数字

tomcat - javax.naming.NameNotFoundException : Name > [com] is not bound in this Context. 无法找到 [com]

java - 接受不同类型的 JSON 数组输入?

java - Jersey/JAXB : Use same POJO for HTTP POST and GET, 但在 JSON 响应中仅返回 GET 属性的子集。