@Test public void doPost() throws ServletException, IOException { final byte[] expectedOutputStream = IOUtils.toByteArray(this.getClass().getResourceAsStream("AssetRenditionsDownloadServletTest__original.png")); doAnswer(invocation -> { Object[] args = invocation.getArguments(); ((AssetRenditionDownloadResponse) args[1]).getOutputStream().write(expectedOutputStream); return null; }).when(requestDispatcher).include(any(SlingHttpServletRequest.class), any(SlingHttpServletResponse.class)); ctx.registerInjectActivateService(new AssetRenditionsDownloadServlet()); AssetRenditionsDownloadServlet servlet = (AssetRenditionsDownloadServlet) ctx.getService(Servlet.class); ctx.currentResource("/content/download-servlet"); ctx.request().setMethod("POST"); ctx.requestPathInfo().setResourcePath("/content/download-servlet"); ctx.requestPathInfo().setSelectorString("asset-renditions-download"); ctx.requestPathInfo().setExtension("zip"); ctx.request().setQueryString("path=/content/dam/test.png&renditionName=test"); servlet.service(ctx.request(), ctx.response()); assertEquals("application/zip", ctx.response().getContentType()); assertEquals(334, ctx.response().getOutput().length); }
@Override protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { servletHelper.addSlingBindings(request, response); final List<String> renditionNames = getRenditionNames(request); final List<AssetModel> assets = getAssets(request); final String id = getAssetRenditionsDownloadOrchestratorId(request); final AssetRenditionsDownloadOrchestrator orchestrator = getAssetRenditionsDownloadOrchestrator(id); if (orchestrator == null) { log.warn("Invalid AssetRenditionsDownloadOrchestrator ID [ {} ]", id); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { orchestrator.execute(request, response, assets, renditionNames); } catch (AssetRenditionsException e) { throw new ServletException(e); } }
AssetRenditionsDownloadServlet extends SlingAllMethodsServlet implements AssetRenditionsDownloadOrchestratorManager { @Override protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { servletHelper.addSlingBindings(request, response); final List<String> renditionNames = getRenditionNames(request); final List<AssetModel> assets = getAssets(request); final String id = getAssetRenditionsDownloadOrchestratorId(request); final AssetRenditionsDownloadOrchestrator orchestrator = getAssetRenditionsDownloadOrchestrator(id); if (orchestrator == null) { log.warn("Invalid AssetRenditionsDownloadOrchestrator ID [ {} ]", id); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { orchestrator.execute(request, response, assets, renditionNames); } catch (AssetRenditionsException e) { throw new ServletException(e); } } }
AssetRenditionsDownloadServlet extends SlingAllMethodsServlet implements AssetRenditionsDownloadOrchestratorManager { @Override protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { servletHelper.addSlingBindings(request, response); final List<String> renditionNames = getRenditionNames(request); final List<AssetModel> assets = getAssets(request); final String id = getAssetRenditionsDownloadOrchestratorId(request); final AssetRenditionsDownloadOrchestrator orchestrator = getAssetRenditionsDownloadOrchestrator(id); if (orchestrator == null) { log.warn("Invalid AssetRenditionsDownloadOrchestrator ID [ {} ]", id); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { orchestrator.execute(request, response, assets, renditionNames); } catch (AssetRenditionsException e) { throw new ServletException(e); } }  }
AssetRenditionsDownloadServlet extends SlingAllMethodsServlet implements AssetRenditionsDownloadOrchestratorManager { @Override protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { servletHelper.addSlingBindings(request, response); final List<String> renditionNames = getRenditionNames(request); final List<AssetModel> assets = getAssets(request); final String id = getAssetRenditionsDownloadOrchestratorId(request); final AssetRenditionsDownloadOrchestrator orchestrator = getAssetRenditionsDownloadOrchestrator(id); if (orchestrator == null) { log.warn("Invalid AssetRenditionsDownloadOrchestrator ID [ {} ]", id); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { orchestrator.execute(request, response, assets, renditionNames); } catch (AssetRenditionsException e) { throw new ServletException(e); } }  final AssetRenditionsDownloadOrchestrator getAssetRenditionsDownloadOrchestrator(final String id); }
AssetRenditionsDownloadServlet extends SlingAllMethodsServlet implements AssetRenditionsDownloadOrchestratorManager { @Override protected final void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException { servletHelper.addSlingBindings(request, response); final List<String> renditionNames = getRenditionNames(request); final List<AssetModel> assets = getAssets(request); final String id = getAssetRenditionsDownloadOrchestratorId(request); final AssetRenditionsDownloadOrchestrator orchestrator = getAssetRenditionsDownloadOrchestrator(id); if (orchestrator == null) { log.warn("Invalid AssetRenditionsDownloadOrchestrator ID [ {} ]", id); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); return; } try { orchestrator.execute(request, response, assets, renditionNames); } catch (AssetRenditionsException e) { throw new ServletException(e); } }  final AssetRenditionsDownloadOrchestrator getAssetRenditionsDownloadOrchestrator(final String id);  }