【问题标题】:JAX-RS: Retrieve path pattern in ContainerRequestFilterJAX-RS:在 ContainerRequestFilter 中检索路径模式
【发布时间】:2015-08-13 20:20:43
【问题描述】:

我正在实现一个预匹配 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 是相同的。

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

【问题讨论】:

    标签: java jax-rs resteasy


    【解决方案1】:

    From the @PreMatching documentation:

    可应用于容器请求过滤器的全局绑定注释,以指示此类过滤器应在实际资源匹配发生之前全局应用于应用程序中的所有资源。

    在调用您的过滤器时,不清楚将匹配哪个资源。您的过滤器可能会更改 requestUri 甚至会影响匹配的方法,因此您无法在此处获取此信息。

    在非@PreMatching ContainerRequestFilter 中,您可以通过ContainerRequestContext.getUriInfo().getMatchedURIs() 或通过注入ResourceInfo 来获取更多信息,就像已经answered here 一样。

    【讨论】:

    • 有没有办法使用帖子匹配过滤器检索这些信息?
    • 这里的“requestContext”是什么?
    • 上述ContainerRequestFilter中单个方法的单个参数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-14
    • 2017-09-02
    • 1970-01-01
    • 2017-09-14
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多