| 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.*; | |
| 8 | import javax.servlet.http.*; | |
| 9 | import javax.servlet.annotation.*; | |
| 10 | import java.io.IOException; | |
| 11 | ||
| 12 | @WebServlet(name = "GetProductServlet", urlPatterns = {"/getProduct"}) | |
| 13 | public class GetProductServlet extends HttpServlet { | |
| 14 | ||
| 15 | private ProdottoDAO prodottoDAO; | |
| 16 | ||
| 17 | // costruttore production | |
| 18 | public GetProductServlet() { | |
| 19 | this.prodottoDAO = new ProdottoDAOImpl(); | |
| 20 | } | |
| 21 | ||
| 22 | // costruttore test | |
| 23 | public GetProductServlet(ProdottoDAO prodottoDAO) { | |
| 24 | this.prodottoDAO = prodottoDAO; | |
| 25 | } | |
| 26 | ||
| 27 | @Override | |
| 28 | public void doGet(HttpServletRequest request, HttpServletResponse response) | |
| 29 | throws ServletException, IOException { | |
| 30 | ||
| 31 | String productId = request.getParameter("id"); | |
| 32 | ||
| 33 |
2
1. doGet : negated conditional → KILLED 2. doGet : negated conditional → KILLED |
if (productId == null || productId.isEmpty()) { |
| 34 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED |
response.sendError( |
| 35 | HttpServletResponse.SC_BAD_REQUEST, | |
| 36 | "ID prodotto non fornito." | |
| 37 | ); | |
| 38 | return; | |
| 39 | } | |
| 40 | ||
| 41 | try { | |
| 42 | ProdottoBean prodotto = prodottoDAO.getProdottoById(productId); | |
| 43 | ||
| 44 |
1
1. doGet : negated conditional → KILLED |
if (prodotto == null) { |
| 45 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED |
response.sendError( |
| 46 | HttpServletResponse.SC_NOT_FOUND, | |
| 47 | "Prodotto non trovato." | |
| 48 | ); | |
| 49 | return; | |
| 50 | } | |
| 51 | ||
| 52 |
1
1. doGet : removed call to javax/servlet/http/HttpServletRequest::setAttribute → KILLED |
request.setAttribute("prod", prodotto); |
| 53 | request.getRequestDispatcher("/jsp/product.jsp") | |
| 54 |
1
1. doGet : removed call to javax/servlet/RequestDispatcher::forward → KILLED |
.forward(request, response); |
| 55 | ||
| 56 | } catch (Exception e) { | |
| 57 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED |
response.sendError( |
| 58 | HttpServletResponse.SC_INTERNAL_SERVER_ERROR, | |
| 59 | "Errore durante il recupero del prodotto." | |
| 60 | ); | |
| 61 | } | |
| 62 | } | |
| 63 | } | |
Mutations | ||
| 33 |
1.1 2.2 |
|
| 34 |
1.1 |
|
| 44 |
1.1 |
|
| 45 |
1.1 |
|
| 52 |
1.1 |
|
| 54 |
1.1 |
|
| 57 |
1.1 |