public ModelAndView serve(@RequestParam("file") String file, @RequestParam(required = false, value = "width") String width, @RequestParam(required = false, value = "height") String height, HttpServletResponse response) throws Exception {
try {
Assert.isEncrypted(decipherer, file);
String uri = decipherer.decrypt(file);
if (log.isDebugEnabled()) log.debug("Retrieving file from URI [" + uri + "]");
DocumentHolder doc = documentRepository.retrieve(uri);
if (StringUtils.hasText(doc.getMimeType())) response.setContentType(doc.getMimeType());
if (width != null) {
Assert.notNull(height);
BufferedImage im = getScaledInstance(ImageIO.read(doc.getStream()), Integer.parseInt(width), Integer.parseInt(height));
ImageIO.write(im, "PNG", response.getOutputStream());
} else {
FileCopyUtils.copy(doc.getStream(), response.getOutputStream());
}
} catch (RuntimeException r) {
if (log.isWarnEnabled()) log.warn("Error processing document download: " + r.getMessage());
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
}