@RequestMapping(value = "/stream/{language}/{name}", method = RequestMethod.GET)
public void getStreamContent(@PathVariable String language, @PathVariable String name, HttpServletResponse response)
throws IOException {
LOG.info(String.format("Getting resource for : stream:%s:%s", language, name));
OutputStream out = null;
AttachmentInputStream contentStream = null;
try {
out = response.getOutputStream();
contentStream = (AttachmentInputStream) cmsLiteService.getStreamContent(language, name).getInputStream();
response.setContentLength((int) contentStream.getContentLength());
response.setContentType(contentStream.getContentType());
response.setHeader("Accept-Ranges", "bytes");
response.setStatus(HttpServletResponse.SC_OK);
IOUtils.copy(contentStream, out);
} catch (ContentNotFoundException e) {
LOG.error(String.format("Content not found for : stream:%s:%s%n:%s", language, name,
Arrays.toString(e.getStackTrace())));
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, NOT_FOUND_RESPONSE);
} finally {
IOUtils.closeQuietly(contentStream);
IOUtils.closeQuietly(out);
}
}