@Test public void dispatch() throws IOException, ServletException { ctx.registerInjectActivateService(new InternalRedirectRenditionDispatcherImpl(), ImmutableMap.<String, Object>builder(). put("rendition.mappings", new String[]{ "testing=${asset.path}.test.500.500.${asset.extension}"}). 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"); doAnswer(invocation -> { Object[] args = invocation.getArguments(); ((MockSlingHttpServletResponse) args[1]).getOutputStream().print("test"); return null; }).when(requestDispatcher).include(any(ExtensionOverrideRequestWrapper.class), eq(ctx.response())); assetRenditionDispatcher.dispatch(ctx.request(), ctx.response()); assertEquals("test", ctx.response().getOutputAsString()); }
@Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final String expression = mappings.get(parameters.getRenditionName()); if (StringUtils.isNotBlank(expression)) { final String evaluatedExpression = assetRenditions.evaluateExpression(request, expression); final PathInfo pathInfo = new PathInfo(request.getResourceResolver(), evaluatedExpression); final String resourcePath = Text.unescape(cleanPathInfoRequestPath(pathInfo.getResourcePath())); log.debug("Serving internal redirect rendition [ {} ] for expression [ {} ] and resolved rendition name [ {} ]", resourcePath, evaluatedExpression, parameters.getRenditionName()); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(StringUtils.removeStart(pathInfo.getSelectorString(), ".")); options.setReplaceSuffix(pathInfo.getSuffix()); request.getRequestDispatcher(resourcePath, options) .include(new ExtensionOverrideRequestWrapper(request, pathInfo.getExtension()), response); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Could not serve asset rendition."); } }
InternalRedirectRenditionDispatcherImpl extends AbstractRenditionDispatcherImpl implements AssetRenditionDispatcher { @Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final String expression = mappings.get(parameters.getRenditionName()); if (StringUtils.isNotBlank(expression)) { final String evaluatedExpression = assetRenditions.evaluateExpression(request, expression); final PathInfo pathInfo = new PathInfo(request.getResourceResolver(), evaluatedExpression); final String resourcePath = Text.unescape(cleanPathInfoRequestPath(pathInfo.getResourcePath())); log.debug("Serving internal redirect rendition [ {} ] for expression [ {} ] and resolved rendition name [ {} ]", resourcePath, evaluatedExpression, parameters.getRenditionName()); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(StringUtils.removeStart(pathInfo.getSelectorString(), ".")); options.setReplaceSuffix(pathInfo.getSuffix()); request.getRequestDispatcher(resourcePath, options) .include(new ExtensionOverrideRequestWrapper(request, pathInfo.getExtension()), response); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Could not serve asset rendition."); } } }
InternalRedirectRenditionDispatcherImpl extends AbstractRenditionDispatcherImpl implements AssetRenditionDispatcher { @Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final String expression = mappings.get(parameters.getRenditionName()); if (StringUtils.isNotBlank(expression)) { final String evaluatedExpression = assetRenditions.evaluateExpression(request, expression); final PathInfo pathInfo = new PathInfo(request.getResourceResolver(), evaluatedExpression); final String resourcePath = Text.unescape(cleanPathInfoRequestPath(pathInfo.getResourcePath())); log.debug("Serving internal redirect rendition [ {} ] for expression [ {} ] and resolved rendition name [ {} ]", resourcePath, evaluatedExpression, parameters.getRenditionName()); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(StringUtils.removeStart(pathInfo.getSelectorString(), ".")); options.setReplaceSuffix(pathInfo.getSuffix()); request.getRequestDispatcher(resourcePath, options) .include(new ExtensionOverrideRequestWrapper(request, pathInfo.getExtension()), response); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Could not serve asset rendition."); } }  }
InternalRedirectRenditionDispatcherImpl extends AbstractRenditionDispatcherImpl implements AssetRenditionDispatcher { @Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final String expression = mappings.get(parameters.getRenditionName()); if (StringUtils.isNotBlank(expression)) { final String evaluatedExpression = assetRenditions.evaluateExpression(request, expression); final PathInfo pathInfo = new PathInfo(request.getResourceResolver(), evaluatedExpression); final String resourcePath = Text.unescape(cleanPathInfoRequestPath(pathInfo.getResourcePath())); log.debug("Serving internal redirect rendition [ {} ] for expression [ {} ] and resolved rendition name [ {} ]", resourcePath, evaluatedExpression, parameters.getRenditionName()); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(StringUtils.removeStart(pathInfo.getSelectorString(), ".")); options.setReplaceSuffix(pathInfo.getSuffix()); request.getRequestDispatcher(resourcePath, options) .include(new ExtensionOverrideRequestWrapper(request, pathInfo.getExtension()), response); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Could not serve asset rendition."); } }  @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); }
InternalRedirectRenditionDispatcherImpl extends AbstractRenditionDispatcherImpl implements AssetRenditionDispatcher { @Override public void dispatch(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException, ServletException { final AssetRenditionParameters parameters = new AssetRenditionParameters(request); final String expression = mappings.get(parameters.getRenditionName()); if (StringUtils.isNotBlank(expression)) { final String evaluatedExpression = assetRenditions.evaluateExpression(request, expression); final PathInfo pathInfo = new PathInfo(request.getResourceResolver(), evaluatedExpression); final String resourcePath = Text.unescape(cleanPathInfoRequestPath(pathInfo.getResourcePath())); log.debug("Serving internal redirect rendition [ {} ] for expression [ {} ] and resolved rendition name [ {} ]", resourcePath, evaluatedExpression, parameters.getRenditionName()); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(StringUtils.removeStart(pathInfo.getSelectorString(), ".")); options.setReplaceSuffix(pathInfo.getSuffix()); request.getRequestDispatcher(resourcePath, options) .include(new ExtensionOverrideRequestWrapper(request, pathInfo.getExtension()), response); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Could not serve asset rendition."); } }  @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);  }