![](/img/trans.png)
[英]ContainerRequestFilter is not executed in JAX-RS / RESTEasy application
[英]JAX-RS: Retrieve path pattern in ContainerRequestFilter
我正在實現一個預先匹配的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
是相同的。
你能幫我嗎?
可以應用於容器請求過濾器的全局綁定注釋,以指示在實際資源匹配發生之前,應將此過濾器全局應用於應用程序中的所有資源。
在調用過濾器時,尚不清楚將匹配哪個資源。 您的過濾器可能會更改requestUri甚至更改會影響匹配的方法,因此您無法在此處獲取此信息。
在非@PreMatching
ContainerRequestFilter中,您可以通過ContainerRequestContext.getUriInfo()。getMatchedURIs()或通過注入ResourceInfo來獲得更多信息,就像已經在這里回答的那樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.