Resource extends AbstractFormatService { @RequestMapping(value = "/{portal}/{lang}/md.formatter.resource") public void exec( @RequestParam(Params.ID) String xslid, @RequestParam(Params.FNAME) String fileName, @RequestParam(value = Params.SCHEMA, required = false) String schema, HttpServletResponse response ) throws Exception { final ConfigurableApplicationContext applicationContext = ApplicationContextHolder.get(); Path schemaDir = null; if (schema != null) { schemaDir = applicationContext.getBean(SchemaManager.class).getSchemaDir(schema); } try { FilePathChecker.verify(fileName); } catch (BadParameterEx ex) { response.sendError(403, fileName + " does not identify a file in the " + xslid + " format bundle"); return; } Path formatDir = getAndVerifyFormatDir(applicationContext.getBean(GeonetworkDataDirectory.class), Params.ID, xslid, schemaDir); Path desiredFile = formatDir.resolve(fileName); if (!Files.isRegularFile(desiredFile)) { response.sendError(404, fileName + " does not identify a file in formatter bundle: " + xslid); return; } if (!containsFile(formatDir, desiredFile)) { response.sendError(403, fileName + " does not identify a file in the " + xslid + " format bundle"); return; } response.setStatus(200); setContentType(response, getFileExtension(desiredFile.getFileName().toString())); Files.copy(desiredFile, response.getOutputStream()); }  @RequestMapping(value = "/{portal}/{lang}/md.formatter.resource") void exec(
        @RequestParam(Params.ID) String xslid,
        @RequestParam(Params.FNAME) String fileName,
        @RequestParam(value = Params.SCHEMA, required = false) String schema,
        HttpServletResponse response
    );  }
@Test public void testExec() throws Exception { final Path testFormatter = getFile("view.groovy").getParent(); IO.copyDirectoryOrFile(testFormatter, this.dataDirectory.getFormatterDir().resolve(RESOURCE_TEST_DIR), false); assertCorrectExec("test.js", 200, "application/javascript"); assertCorrectExec("css/test.css", 200, "text/css"); assertCorrectExec("test.html", 200, "text/html"); assertCorrectExec("test.gif", 200, "image/gif"); assertCorrectExec("test.bmp", 200, "image/bmp"); assertCorrectExec("test.jpg", 200, "image/jpeg"); assertCorrectExec("test.jpeg", 200, "image/jpeg"); assertCorrectExec("test.tif", 200, "image/tiff"); assertCorrectExec("test.png", 200, "image/png"); assertCorrectExec("test.xml", 200, "application/xml"); assertCorrectExec("test.json", 200, "application/json"); assertCorrectExec("testyxz", 200, "application/octet-stream"); assertCorrectExec("view.groovy", 200, "text/x-groovy-source,groovy"); assertCorrectExec("test.xsl", 200, "application/xslt+xml"); assertCorrectExec("test.xslt", 200, "application/xslt+xml"); assertCorrectExec("nosuchfile", 404, null); assertCorrectExec("../xml_view/view.groovy", 403, null); }