| 1 | package com.popx.presentazione; | |
| 2 | ||
| 3 | import com.popx.persistenza.ProdottoDAO; | |
| 4 | import com.popx.persistenza.ProdottoDAOImpl; | |
| 5 | ||
| 6 | import javax.servlet.ServletException; | |
| 7 | import javax.servlet.annotation.WebServlet; | |
| 8 | import javax.servlet.http.HttpServlet; | |
| 9 | import javax.servlet.http.HttpServletRequest; | |
| 10 | import javax.servlet.http.HttpServletResponse; | |
| 11 | import java.io.IOException; | |
| 12 | import java.io.OutputStream; | |
| 13 | ||
| 14 | @WebServlet(name = "GetPictureServlet", urlPatterns = {"/getPictureServlet"}) | |
| 15 | public class GetPictureServlet extends HttpServlet { | |
| 16 | ||
| 17 | private ProdottoDAO prodottoDAO; | |
| 18 | ||
| 19 | // costruttore production | |
| 20 | public GetPictureServlet() { | |
| 21 | this.prodottoDAO = new ProdottoDAOImpl(); | |
| 22 | } | |
| 23 | ||
| 24 | // costruttore test | |
| 25 | public GetPictureServlet(ProdottoDAO prodottoDAO) { | |
| 26 | this.prodottoDAO = prodottoDAO; | |
| 27 | } | |
| 28 | ||
| 29 | @Override | |
| 30 | public void doGet(HttpServletRequest request, HttpServletResponse response) | |
| 31 | throws ServletException, IOException { | |
| 32 | ||
| 33 | String id = request.getParameter("id"); | |
| 34 | ||
| 35 |
2
1. doGet : negated conditional → KILLED 2. doGet : negated conditional → KILLED |
if (id == null || id.isEmpty()) { |
| 36 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED |
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "ID prodotto mancante."); |
| 37 | return; | |
| 38 | } | |
| 39 | ||
| 40 | try { | |
| 41 | byte[] imageData = prodottoDAO.getProductImageById(id); | |
| 42 | ||
| 43 |
1
1. doGet : negated conditional → KILLED |
if (imageData != null) { |
| 44 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::setContentType → KILLED |
response.setContentType("image/jpeg"); |
| 45 |
1
1. doGet : removed call to javax/servlet/ServletOutputStream::write → KILLED |
response.getOutputStream().write(imageData); |
| 46 | } else { | |
| 47 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED |
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Immagine non trovata."); |
| 48 | } | |
| 49 | ||
| 50 | } catch (Exception e) { | |
| 51 |
1
1. doGet : removed call to javax/servlet/http/HttpServletResponse::sendError → KILLED |
response.sendError( |
| 52 | HttpServletResponse.SC_INTERNAL_SERVER_ERROR, | |
| 53 | "Errore durante il recupero dell'immagine." | |
| 54 | ); | |
| 55 | } | |
| 56 | } | |
| 57 | } | |
Mutations | ||
| 35 |
1.1 2.2 |
|
| 36 |
1.1 |
|
| 43 |
1.1 |
|
| 44 |
1.1 |
|
| 45 |
1.1 |
|
| 47 |
1.1 |
|
| 51 |
1.1 |