Galera estou encontrando erro ao tentar deslogar, segue minhas classes FazTudo Filtro de auditoria e logout.
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException
br.com.alura.gerenciador.web.FazTudo.service(FazTudo.java:36)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
br.com.alura.gerenciador.web.FiltroDeAuditoria.doFilter(FiltroDeAuditoria.java:36)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.67 logs.
Minha Classe fazTudo
package br.com.alura.gerenciador.web;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(urlPatterns = "/fazTudo")
public class FazTudo extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 6626322586019870362L;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String tarefa = req.getParameter("tarefa");
if (tarefa == null)
throw new IllegalArgumentException("Você esqueceu de passar a tarefa");
tarefa = "br.com.alura.gerenciador.web" + tarefa;
try {
Class<?> tipo = Class.forName(tarefa);
Tarefa instancia = (Tarefa) tipo.newInstance();
String pagina = instancia.executa(req, resp);
RequestDispatcher requestDispatcher = req.getRequestDispatcher(pagina);
requestDispatcher.forward(req, resp);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
throw new ServletException();
}
}
}
Filtro de Auditoria
package br.com.alura.gerenciador.web;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.alura.gerenciador.Usuario;
@WebFilter(urlPatterns = "/*")
public class FiltroDeAuditoria implements Filter {
@Override
public void destroy() {
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
String uri = req.getRequestURI();
String usuario = getUsuario(req);
System.out.println("Usuario: " + usuario + "\nAcessando a URI: " + req.getRequestURI());
chain.doFilter(request, response);
}
private String getUsuario(HttpServletRequest req) {
Usuario usuario = (Usuario) req.getSession().getAttribute("usuario.logado");
if (usuario == null) {
return "<deslogado>";
}
return usuario.getEmail();
}
}
Classe Logout
package br.com.alura.gerenciador.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Logout implements Tarefa {
@Override
public String executa(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
session.removeAttribute("usuarioLogado");
return "/WEB-INF/paginas/logout.html";
}
}