O meu codigo final ficou assim, mas funciona sem problemas:
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
String usuario = getUsuario(req, resp);
System.out.println("Usuário " + usuario + " acessando a URI " + req.getRequestURL());
chain.doFilter(request, response);
}
private String getUsuario(HttpServletRequest req, HttpServletResponse resp) {
Cookie cookie = new Cookies(req.getCookies()).buscaUsuarioLogado();
if (cookie == null)
return "<deslogado>";
cookie.setMaxAge(10 * 60);
resp.addCookie(cookie);
return cookie.getValue();
}
Sera que esta errado?