ConfigView implements View { @SuppressWarnings("rawtypes") @Override public void render(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { boolean headersOnly = (Boolean) model.get(HEADERS_ONLY); RDFFormat rdfFormat = (RDFFormat) model.get(FORMAT_KEY); try { try (OutputStream out = response.getOutputStream()) { response.setStatus(SC_OK); String mimeType = rdfFormat.getDefaultMIMEType(); if (rdfFormat.hasCharset()) { Charset charset = rdfFormat.getCharset(); mimeType += "; charset=" + charset.name(); } response.setContentType(mimeType); String filename = "config"; if (rdfFormat.getDefaultFileExtension() != null) { filename += "." + rdfFormat.getDefaultFileExtension(); } response.setHeader("Content-Disposition", "attachment; filename=" + filename); if (!headersOnly) { Model configuration = (Model) model.get(CONFIG_DATA_KEY); Rio.write(configuration, out, rdfFormat); } } } catch (RDFHandlerException e) { throw new ServerHTTPException("Serialization error: " + e.getMessage(), e); } catch (RepositoryException e) { throw new ServerHTTPException("Repository error: " + e.getMessage(), e); } } private  ConfigView(); static ConfigView getInstance(); @Override String getContentType(); @SuppressWarnings("rawtypes") @Override void render(Map model, HttpServletRequest request, HttpServletResponse response); static final String CONFIG_DATA_KEY; static final String FORMAT_KEY; static final String HEADERS_ONLY; }
@Test public void testRender() throws Exception { ConfigView configView = ConfigView.getInstance(); Model configData = new LinkedHashModelFactory().createEmptyModel(); configData.add(RDF.ALT, RDF.TYPE, RDFS.CLASS); Map<Object, Object> map = new LinkedHashMap<>(); map.put(ConfigView.HEADERS_ONLY, false); map.put(ConfigView.CONFIG_DATA_KEY, configData); map.put(ConfigView.FORMAT_KEY, RDFFormat.NTRIPLES); final MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod(HttpMethod.GET.name()); request.addHeader("Accept", RDFFormat.NTRIPLES.getDefaultMIMEType()); MockHttpServletResponse response = new MockHttpServletResponse(); configView.render(map, request, response); String ntriplesData = response.getContentAsString(); Model renderedData = Rio.parse(new StringReader(ntriplesData), "", RDFFormat.NTRIPLES); assertThat(renderedData).isNotEmpty(); }