【发布时间】:2014-12-12 04:34:00
【问题描述】:
我正在使用 Jersey 2,我想获取 URI 模板。 原因是我创建了一个基于 URI 进行验证的身份验证系统。我设法工作了:
@Override
public void filter(ContainerRequestContext containerRequest) throws IOException {
String method = containerRequest.getMethod();
String uri = containerRequest.getUriInfo().getPath();
}
问题是 getPath 返回类似:
/companies/1
我希望它返回
/companies/{id}
我是这样声明的:
@Path("{id}")
谢谢
编辑我以为我在这里找到了它:
@Context
private ExtendedUriInfo uriInfo;
//...
Resource matchedModelResource = uriInfo.getMatchedModelResource();
System.out.println(matchedModelResource.getPathPattern().getTemplate().getTemplate());
但你猜怎么着? matchedModelResource 为空。
还有,这个:
List<UriTemplate> matchedTemplates = uriInfo.getMatchedTemplates();
返回一个空的 UriTemplate 列表。 :( 为什么没有设置数据?
【问题讨论】: