dimanche 1 mars 2015

JSF 2.x - Filter infinite redirection?




@WebFilter(urlPatterns = "/faces/*")
public class AuthenticationFilter implements Filter {

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {

HttpServletRequest req = (HttpServletRequest) request;
HttpSession session = req.getSession(true);

System.out.println("doFilter");

if (session.isNew() || session.getAttribute("username")==null) {

System.out.println("directed");
HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect(req.getContextPath() + "/index.xhtml");

} else {
System.out.println("not directed");
chain.doFilter(request, response);
}

}

@Override
public void init(FilterConfig filterConfig) throws ServletException {
}

@Override
public void destroy() {
}
}


The first time I run the project, "doFilter" will be printed, but then on updating or submitting a form, "doFilter" isn't printed,It's like execution cannot reach this statement.


I think that the filter is run in an infinite loop that keeps redirects user to the "index.xhtml" page? What's Wrong?




Aucun commentaire:

Enregistrer un commentaire