Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 jersey 构建 REST Web 服务。我创建了一个类,实现了 ContainerRequestFilter 接口来确定用户是否登录。现在我想丢弃如果 user == null 提交的每个请求。如何做到这一点?我不想放一个
if (user != null ) { ... } else { return //401 }
在每一个动作中。
抛出 WebApplicationException:
public ContainerRequest filter(ContainerRequest request) { if (user != null ) { //... } else { throw new WebApplicationException(401); } return request; }