1
我试图拦截请求,我JAXRS basead上标注的API,我的过滤器很简单:JAXRS在资源定位器过滤
@Provider
public class Filter implements ContainerRequestFilter {
@Context
private ResourceInfo info;
@Override
public void filter(ContainerRequestContext crc) throws IOException {
// here I'm trying to get the annotate resource class or method.
info.getResourceClass().isAnnotationPresent(MyCustomAnnotation.class);
}
}
这工作得很好,像这样一个简单的资源(无论是在类的工作和方法)
@Path("/")
public class SimpleResource {
@GET
@MyCustomAnnotation
public String test() {
return "test";
}
}
但是在我的实际应用中,我的情况是这样的:
@Path("/")
public class RootResource {
@Inject
ChildResource childResource;
@Path("child")
public ChildResource child() {
return childResource;
}
}
小号o,我想仅将我的自定义注释放在ResourceLocator上并实时验证最终资源是否包含注释。
@Path("/")
@CustomAnnotation
public class RootResource {
@Inject
ChildResource childResource;
@Path("child")
public ChildResource child() {
return childResource;
}
}
是否有可能?或者我只能得到有关匹配资源的信息?
是否存在您正在使用的特定JAX-RS实现?还是你想保持它的标准?使用这些标准API将会很困难。 Jersey有一个API可以让你遍历资源模型。不知道其他实现。标准JAX-RS没有任何API来处理这个问题。 –
即时通讯使用resteasy。在球衣上这将是怎样的? –