我有一個@POST休息方法,我想爲它做過濾器,所以只有在應用程序中登錄的人才能夠訪問它。 這裏是我的@POST方法:<url-pattern>在過濾器映射無效
@POST
@Path("/buy")
public Response buyTicket(@QueryParam("projectionId") String projectionId, @QueryParam("place") String place){
Projection projection = projectionDAO.findById(Long.parseLong(projectionId));
if(projection != null){
System.out.println(projection.getMovieTitle());
System.out.println(place);
projectionDAO.buyTicket(projection, userContext.getCurrentUser(), place);
}
return Response.noContent().build();
}
這裏是我寫此方法的過濾器:
@WebFilter("rest/projection/buy")
public class ProtectedBuyFunction implements Filter {
@Inject
UserContext userContext;
public void init(FilterConfig fConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (!isHttpCall(request, response)) {
return;
}
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
User currentUser = userContext.getCurrentUser();
if (currentUser == null) {
String loginUrl = httpServletRequest.getContextPath()
+ "/login.html";
httpServletResponse.sendRedirect(loginUrl);
return;
}
chain.doFilter(request, response);
}
private boolean isHttpCall(ServletRequest request, ServletResponse response) {
return (request instanceof HttpServletRequest)
&& (response instanceof HttpServletResponse);
}
public void destroy() {
}}
的問題是,我總是得到一個異常,服務器拒絕啓動時,例外是:
Invalid <url-pattern> rest/projection/buy in filter mapping
我正在使用Jae-RS的TomEE服務器。有什麼辦法可以解決這個問題嗎?