DispatchUtils.sendNotModified(request, response);
return true;
}
// Load the image contents from the repository
ImageContent imageContents = imageResource.getContent(language);
// Add mime type header
String contentType = imageContents.getMimetype();
if (contentType == null)
contentType = MediaType.APPLICATION_OCTET_STREAM;
// Set the content type
String characterEncoding = response.getCharacterEncoding();
if (StringUtils.isNotBlank(characterEncoding))
response.setContentType(contentType + "; charset=" + characterEncoding.toLowerCase());
else
response.setContentType(contentType);
// Browser caches and proxies are allowed to keep a copy
response.setHeader("Cache-Control", "public, max-age=" + revalidationTime);
// Set Expires header
response.setDateHeader("Expires", expirationDate);
// Determine the resource's modification date
long resourceLastModified = ResourceUtils.getModificationDate(imageResource, language).getTime();
// Add last modified header
response.setDateHeader("Last-Modified", resourceLastModified);
// Add ETag header
response.setHeader("ETag", ResourceUtils.getETagValue(imageResource));
// Load the input stream from the repository
InputStream imageInputStream = null;
try {
imageInputStream = contentRepository.getContent(imageURI, language);
} catch (Throwable t) {
logger.error("Error loading {} image '{}' from {}: {}", new Object[] {
language,
imageResource,
contentRepository,
t.getMessage() });
logger.error(t.getMessage(), t);
IOUtils.closeQuietly(imageInputStream);
return false;
}
// Write the image back to the client
try {
response.setHeader("Content-Length", Long.toString(imageContents.getSize()));
response.setHeader("Content-Disposition", "inline; filename=" + imageContents.getFilename());
IOUtils.copy(imageInputStream, response.getOutputStream());
response.getOutputStream().flush();
} catch (EOFException e) {
logger.debug("Error writing image '{}' back to client: connection closed by client", imageResource);
return true;