@Test public void dispatch() throws IOException, ServletException { final byte[] expectedOutputStream = IOUtils.toByteArray(this.getClass().getResourceAsStream("StaticRenditionDispatcherImplTest__cq5dam.web.1280.1280.png")); doAnswer(invocation -> { Object[] args = invocation.getArguments(); ((MockSlingHttpServletResponse) args[1]).getOutputStream().write(expectedOutputStream); return null; }).when(requestDispatcher).include(any(SlingHttpServletRequest.class), any(SlingHttpServletResponse.class)); ctx.registerInjectActivateService(new StaticRenditionDispatcherImpl(), ImmutableMap.<String, Object>builder(). put("rendition.mappings", new String[]{ "original=original", "testing=^cq5dam\\.web\\..*"}). build()); final AssetRenditionDispatcher assetRenditionDispatcher = ctx.getService(AssetRenditionDispatcher.class); ctx.requestPathInfo().setResourcePath("/content/dam/test.png"); ctx.requestPathInfo().setExtension("rendition"); ctx.requestPathInfo().setSuffix("testing/download/asset.rendition"); assetRenditionDispatcher.dispatch(ctx.request(), ctx.response()); assertArrayEquals(expectedOutputStream, ctx.response().getOutput()); }
@Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final Asset asset = DamUtil.resolveToAsset(request.getResource()); final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final Rendition rendition = asset.getRendition(new PatternRenditionPicker(mappings.get(parameters.getRenditionName()))); if (rendition != null) { log.debug("Serving internal static rendition [ {} ] with resolved rendition name [ {} ] through internal Sling Forward", rendition.getPath(), parameters.getRenditionName()); response.setHeader("Content-Type", rendition.getMimeType()); request.getRequestDispatcher(rendition.adaptTo(Resource.class)).include( new AssetRenditionDownloadRequest(request, "GET", rendition.adaptTo(Resource.class), new String[]{}, null, ""), response); log.debug("Finishing the include"); } else { throw new ServletException(String.format("Cloud not locate rendition [ %s ] for assets [ %s ]", parameters.getRenditionName(), asset.getPath())); } }
StaticRenditionDispatcherImpl extends AbstractRenditionDispatcherImpl implements AssetRenditionDispatcher { @Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final Asset asset = DamUtil.resolveToAsset(request.getResource()); final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final Rendition rendition = asset.getRendition(new PatternRenditionPicker(mappings.get(parameters.getRenditionName()))); if (rendition != null) { log.debug("Serving internal static rendition [ {} ] with resolved rendition name [ {} ] through internal Sling Forward", rendition.getPath(), parameters.getRenditionName()); response.setHeader("Content-Type", rendition.getMimeType()); request.getRequestDispatcher(rendition.adaptTo(Resource.class)).include( new AssetRenditionDownloadRequest(request, "GET", rendition.adaptTo(Resource.class), new String[]{}, null, ""), response); log.debug("Finishing the include"); } else { throw new ServletException(String.format("Cloud not locate rendition [ %s ] for assets [ %s ]", parameters.getRenditionName(), asset.getPath())); } } }
StaticRenditionDispatcherImpl extends AbstractRenditionDispatcherImpl implements AssetRenditionDispatcher { @Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final Asset asset = DamUtil.resolveToAsset(request.getResource()); final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final Rendition rendition = asset.getRendition(new PatternRenditionPicker(mappings.get(parameters.getRenditionName()))); if (rendition != null) { log.debug("Serving internal static rendition [ {} ] with resolved rendition name [ {} ] through internal Sling Forward", rendition.getPath(), parameters.getRenditionName()); response.setHeader("Content-Type", rendition.getMimeType()); request.getRequestDispatcher(rendition.adaptTo(Resource.class)).include( new AssetRenditionDownloadRequest(request, "GET", rendition.adaptTo(Resource.class), new String[]{}, null, ""), response); log.debug("Finishing the include"); } else { throw new ServletException(String.format("Cloud not locate rendition [ %s ] for assets [ %s ]", parameters.getRenditionName(), asset.getPath())); } }  }
StaticRenditionDispatcherImpl extends AbstractRenditionDispatcherImpl implements AssetRenditionDispatcher { @Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final Asset asset = DamUtil.resolveToAsset(request.getResource()); final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final Rendition rendition = asset.getRendition(new PatternRenditionPicker(mappings.get(parameters.getRenditionName()))); if (rendition != null) { log.debug("Serving internal static rendition [ {} ] with resolved rendition name [ {} ] through internal Sling Forward", rendition.getPath(), parameters.getRenditionName()); response.setHeader("Content-Type", rendition.getMimeType()); request.getRequestDispatcher(rendition.adaptTo(Resource.class)).include( new AssetRenditionDownloadRequest(request, "GET", rendition.adaptTo(Resource.class), new String[]{}, null, ""), response); log.debug("Finishing the include"); } else { throw new ServletException(String.format("Cloud not locate rendition [ %s ] for assets [ %s ]", parameters.getRenditionName(), asset.getPath())); } }  @Override String getLabel(); @Override String getName(); @Override Map<String, String> getOptions(); @Override boolean isHidden(); @Override Set<String> getRenditionNames(); @Override List<String> getTypes(); @Override void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response); }
StaticRenditionDispatcherImpl extends AbstractRenditionDispatcherImpl implements AssetRenditionDispatcher { @Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final Asset asset = DamUtil.resolveToAsset(request.getResource()); final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final Rendition rendition = asset.getRendition(new PatternRenditionPicker(mappings.get(parameters.getRenditionName()))); if (rendition != null) { log.debug("Serving internal static rendition [ {} ] with resolved rendition name [ {} ] through internal Sling Forward", rendition.getPath(), parameters.getRenditionName()); response.setHeader("Content-Type", rendition.getMimeType()); request.getRequestDispatcher(rendition.adaptTo(Resource.class)).include( new AssetRenditionDownloadRequest(request, "GET", rendition.adaptTo(Resource.class), new String[]{}, null, ""), response); log.debug("Finishing the include"); } else { throw new ServletException(String.format("Cloud not locate rendition [ %s ] for assets [ %s ]", parameters.getRenditionName(), asset.getPath())); } }  @Override String getLabel(); @Override String getName(); @Override Map<String, String> getOptions(); @Override boolean isHidden(); @Override Set<String> getRenditionNames(); @Override List<String> getTypes(); @Override void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response);  }