in src/main/java/org/apache/sling/thumbnails/internal/TransformServlet.java [109:142]
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
log.trace("doGet");
String transformationName = StringUtils.substringBeforeLast(request.getRequestPathInfo().getSuffix(), ".");
String renditionName = request.getRequestPathInfo().getSuffix();
String format = StringUtils.substringAfterLast(request.getRequestPathInfo().getSuffix(), ".");
response.setHeader("Content-Disposition", "filename=" + request.getResource().getName());
log.debug("Transforming resource: {} with transformation: {} to {}", request.getResource(), transformationName,
format);
try {
Resource file = request.getResource();
if (renditionSupport.renditionExists(file, renditionName)) {
response.setContentType(OutputFileFormat.forRequest(request).getMimeType());
IOUtils.copy(renditionSupport.getRenditionContent(file, renditionName), response.getOutputStream());
} else {
try (ResourceResolver servicResolver = transformationServiceUser.getTransformationServiceUser()) {
performTransformation(request, response, transformationName, renditionName, servicResolver);
}
}
} catch (BadRequestException e) {
log.error("Could not render thumbnail due to bad request", e);
response.sendError(400, "Could not render thumbnail due to bad request: " + e.getMessage());
} catch (Exception e) {
log.error("Exception rendering transformed resource", e);
response.setStatus(500);
RequestDispatcherOptions op = new RequestDispatcherOptions();
op.setReplaceSuffix(thumbnailSupport.getServletErrorSuffix());
op.setReplaceSelectors("transform");
RequestDispatcher disp = request.getRequestDispatcher(thumbnailSupport.getServletErrorResourcePath(), op);
disp.forward(request, response);
}
}