解决一个URI在Jersey中匹配的资源+方法 [英] Resolve what resource+method a URI would match in Jersey

查看:135
本文介绍了解决一个URI在Jersey中匹配的资源+方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的Jersey应用程序中,我们希望根据角色呈现/限制API的不同部分。具体而言,我们希望仅提供角色可以访问的资源的链接 - 即,在准备响应A时,如果不允许用户不允许使用X,我们甚至不会提供到资源X的链接。

In our Jersey application we like to present/restrict different parts of our API based on roles. To be specific we would like to only offer links to resources which the role can visit - i.e. already when preparing response A we would not even offer a link to a resource X if the user would not be allowed to use X anyway.

为了能够区分这些链接,我们希望能够询问Jersey如何解析某个URI - 即该资源上的资源和方法。如果我们能够做到这一点,我们也能够检测它是否以一种不允许访问的方式(@RolesAllowed)进行注释......因此我们可以跳过将链接添加到正在进行的响应中。显然,泽西岛拥有这些知识/能力,因为它可以解决传入的请求。

To be able to distinguish those links we would like to be able to ask Jersey how it would resolve a certain URI - i.e. to what resource and to what method on that resource. If we could do that we would also be able to detect whether it is annotated in a way (@RolesAllowed) that would not permit access ... and hence we would be able to skip adding the link to the response in the making. Obviously Jersey has this knowledge/capabilities since it can resolve incoming requests.

问题是:有没有办法向泽西岛询问URI在类和方法方面会解决什么问题?

The question is: Is there a way to ask Jersey what a URI would resolve to in terms of both class and method?

编辑:是的...我们注意到有一个ResourceContext(可以注入),它可以为我们提供匹配的资源类......但是我们仍然找不到URI将解析的方法是什么。

Yes ... we noticed there is a ResourceContext (which can be injected) which can provide us with the matching resource class ... but we still cannot find what method a URI would resolve to.

推荐答案

Tobias,

ResourceContext.matchUriInfo(URI)< /a>. getDeclaringResource() ResourceContext.matchUriInfo(URI) getMatchedMethod() getMethod()将执行您要求的操作。

ResourceContext.matchUriInfo(URI).getDeclaringResource() and ResourceContext.matchUriInfo(URI).getMatchedMethod().getMethod() will do what you're asking for.

这篇关于解决一个URI在Jersey中匹配的资源+方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆