| 1 | package com.popx.presentazione; | |
| 2 | ||
| 3 | import com.popx.modello.ProdottoBean; | |
| 4 | import com.popx.persistenza.ProdottoDAO; | |
| 5 | import com.popx.persistenza.ProdottoDAOImpl; | |
| 6 | ||
| 7 | import javax.servlet.ServletException; | |
| 8 | import javax.servlet.annotation.WebServlet; | |
| 9 | import javax.servlet.http.HttpServlet; | |
| 10 | import javax.servlet.http.HttpServletRequest; | |
| 11 | import javax.servlet.http.HttpServletResponse; | |
| 12 | import javax.servlet.http.HttpSession; | |
| 13 | import java.io.IOException; | |
| 14 | import java.sql.SQLException; | |
| 15 | import java.util.List; | |
| 16 | ||
| 17 | @WebServlet("/logout") | |
| 18 | public class LogoutServlet extends HttpServlet { | |
| 19 | ||
| 20 | private ProdottoDAO prodottoDAO; | |
| 21 | ||
| 22 | // produzione | |
| 23 | public LogoutServlet() { | |
| 24 | this.prodottoDAO = new ProdottoDAOImpl(); | |
| 25 | } | |
| 26 | ||
| 27 | // test (dependency injection) | |
| 28 | public LogoutServlet(ProdottoDAO prodottoDAO) { | |
| 29 | this.prodottoDAO = prodottoDAO; | |
| 30 | } | |
| 31 | ||
| 32 | public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
| 33 | HttpSession session = request.getSession(); | |
| 34 | List<ProdottoBean> cart = (List<ProdottoBean>) session.getAttribute("cart"); | |
| 35 | ||
| 36 |
1
1. doGet : negated conditional → KILLED |
if (cart != null) { |
| 37 | String userEmail = (String) session.getAttribute("userEmail"); | |
| 38 | ||
| 39 |
1
1. doGet : negated conditional → KILLED |
if (userEmail != null) { |
| 40 | try { | |
| 41 |
1
1. doGet : removed call to com/popx/persistenza/ProdottoDAO::saveCartToDatabase → KILLED |
prodottoDAO.saveCartToDatabase(userEmail, cart); |
| 42 |
1
1. doGet : removed call to javax/servlet/http/HttpSession::removeAttribute → KILLED |
session.removeAttribute("cart"); |
| 43 | } catch (SQLException e) { | |
| 44 |
1
1. doGet : removed call to java/sql/SQLException::printStackTrace → SURVIVED |
e.printStackTrace(); |
| 45 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::setStatus → KILLED |
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); |
| 46 |
1
1. doGet : removed call to java/io/PrintWriter::write → KILLED |
response.getWriter().write("Errore durante il salvataggio del carrello."); |
| 47 | return; | |
| 48 | } | |
| 49 | } | |
| 50 | } | |
| 51 | ||
| 52 |
1
1. doGet : removed call to javax/servlet/http/HttpSession::invalidate → KILLED |
session.invalidate(); // Invalidare la sessione e quindi il logout |
| 53 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendRedirect → KILLED |
response.sendRedirect(request.getContextPath() + "/jsp/HomePage.jsp"); // Redirige alla HomePage |
| 54 | ||
| 55 | } | |
| 56 | } | |
Mutations | ||
| 36 |
1.1 |
|
| 39 |
1.1 |
|
| 41 |
1.1 |
|
| 42 |
1.1 |
|
| 44 |
1.1 |
|
| 45 |
1.1 |
|
| 46 |
1.1 |
|
| 52 |
1.1 |
|
| 53 |
1.1 |