AnalysisController { @GetMapping(value = "/analysis/images/{imageName}") @SuppressWarnings("squid:S2083") public ResponseEntity<Resource> getImage(@PathVariable String imageName) { LOGGER.info("Get image {}", imageName); assumeReady(); String sanitizedName = InputSanitizer.validateImageName(imageName); File file = new File(analysisResult.getBaseDir(), sanitizedName); if (!file.exists()) { throw new NotFoundException("Image not found: " + sanitizedName); } HttpHeaders httpHeaders = getHeaders(sanitizedName); return new ResponseEntity<>(new FileSystemResource(file), httpHeaders, HttpStatus.OK); }  @Value("${de.qaware.qav.analysis.filename}") void setFilename(String filename); @Value("${de.qaware.qav.graph.filename}") void setGraphFilename(String graphFilename); @PostConstruct void init(); @GetMapping(value = "/analysis") AnalysisResult getAnalysisResult(); @GetMapping(value = "/analysis/images") List<ImageDTO> getImages(); @GetMapping(value = "/analysis/images/{imageName}") @SuppressWarnings("squid:S2083") // Sonar does not believe that the input is checked. But it really is. ResponseEntity<Resource> getImage(@PathVariable String imageName);  }
@Test public void testGetImage() throws IOException { AnalysisController ac = new AnalysisController(); ac.setFilename(BASEDIR + "qav-analysis-result.json"); ac.init(); ResponseEntity<Resource> img = ac.getImage("p1.png"); assertThat(img).isNotNull(); assertThat(img.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(img.getBody()).isNotNull(); assertThat(img.getBody().contentLength()).isEqualTo(4679L); img = ac.getImage("p1.svg"); assertThat(img).isNotNull(); assertThat(img.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(img.getBody()).isNotNull(); assertThat(img.getBody().contentLength()).isEqualTo(2248L); img = ac.getImage("p1.graphml"); assertThat(img).isNotNull(); assertThat(img.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(img.getBody()).isNotNull(); assertThat(img.getBody().contentLength()).isEqualTo(0L); assertThat(img.getHeaders().getFirst("Content-Disposition")).isEqualTo("attachment; filename=\"p1.graphml\""); }