@Test public void testInValidRequest() throws ServletException, IOException { context.requestPathInfo().setSuffix("/content/apache/sling-apache-org/index/notafile.png"); DownloadFileServlet dfs = new DownloadFileServlet(); dfs.doGet(context.request(), context.response()); assertEquals(404, context.response().getStatus()); assertFalse(context.response().getHeaderNames().contains("Content-Disposition")); }
@Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource suffixResource = request.getRequestPathInfo().getSuffixResource(); if (suffixResource != null) { response.setContentType(suffixResource.getValueMap().get("jcr:content/jcr:mimeType", "")); response.setHeader("Content-Disposition", "attachment; " + suffixResource.getName()); IOUtils.copy(suffixResource.adaptTo(InputStream.class), response.getOutputStream()); } else { response.sendError(404); } }
DownloadFileServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource suffixResource = request.getRequestPathInfo().getSuffixResource(); if (suffixResource != null) { response.setContentType(suffixResource.getValueMap().get("jcr:content/jcr:mimeType", "")); response.setHeader("Content-Disposition", "attachment; " + suffixResource.getName()); IOUtils.copy(suffixResource.adaptTo(InputStream.class), response.getOutputStream()); } else { response.sendError(404); } } }
DownloadFileServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource suffixResource = request.getRequestPathInfo().getSuffixResource(); if (suffixResource != null) { response.setContentType(suffixResource.getValueMap().get("jcr:content/jcr:mimeType", "")); response.setHeader("Content-Disposition", "attachment; " + suffixResource.getName()); IOUtils.copy(suffixResource.adaptTo(InputStream.class), response.getOutputStream()); } else { response.sendError(404); } }  }
DownloadFileServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource suffixResource = request.getRequestPathInfo().getSuffixResource(); if (suffixResource != null) { response.setContentType(suffixResource.getValueMap().get("jcr:content/jcr:mimeType", "")); response.setHeader("Content-Disposition", "attachment; " + suffixResource.getName()); IOUtils.copy(suffixResource.adaptTo(InputStream.class), response.getOutputStream()); } else { response.sendError(404); } }   }
DownloadFileServlet extends SlingSafeMethodsServlet { @Override protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { Resource suffixResource = request.getRequestPathInfo().getSuffixResource(); if (suffixResource != null) { response.setContentType(suffixResource.getValueMap().get("jcr:content/jcr:mimeType", "")); response.setHeader("Content-Disposition", "attachment; " + suffixResource.getName()); IOUtils.copy(suffixResource.adaptTo(InputStream.class), response.getOutputStream()); } else { response.sendError(404); } }    }