class ExternalRedirectRenditionDispatcherImpl 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());
        final String evaluatedExpression = assetRenditions.evaluateExpression(request, expression);

        if (StringUtils.isNotBlank(evaluatedExpression)) {
            log.debug("Serving External redirect rendition [ {} ] for resolved rendition name [ {} ]",
                    evaluatedExpression,
                    parameters.getRenditionName());

            if (cfg.redirect() == HttpServletResponse.SC_MOVED_TEMPORARILY) {
                response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
            } else {
                response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
            }

            response.setHeader("Location", UrlUtil.escape(evaluatedExpression));

        } else {
            log.error("Could not convert [ {} ] into a valid URI", evaluatedExpression);
            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Could not serve asset rendition.");
        }
    }

}