【问题标题】:Intercept jersey endpoint methods拦截球衣端点方法
【发布时间】:2012-12-02 19:07:01
【问题描述】:

我正在使用 jersey 构建 REST Web 服务。 我创建了一个类,实现了 ContainerRequestFilter 接口来确定用户是否登录。现在我想丢弃如果 user == null 提交的每个请求。如何做到这一点?我不想放一个

if (user != null ) {
 ...
} else {
 return //401
}

在每个动作中。

【问题讨论】:

    标签: java rest jersey endpoint


    【解决方案1】:

    抛出 WebApplicationException:

    public ContainerRequest filter(ContainerRequest request) {
        if (user != null ) {
               //...
            } else {
                throw new WebApplicationException(401);
            }
        return request;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-23
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多