public void execute(WebAppController controller, HttpServletRequest req, HttpServletResponse res) throws Exception {
String resourceId = req.getParameter("resourceId");
res.setHeader("Cache-Control", "private max-age=600, s-maxage=120");
ExoContainer container = ExoContainerContext.getCurrentContainer();
DownloadService dservice = (DownloadService) container.getComponentInstanceOfType(DownloadService.class);
DownloadResource dresource = dservice.getDownloadResource(resourceId);
if (dresource == null) {
res.setContentType("text/plain");
res.getWriter().write("NO DOWNDLOAD RESOURCE CONTENT OR YOU DO NOT HAVE THE RIGHT TO ACCESS THE CONTENT");
return;
}
String userAgent = req.getHeader("User-Agent");
if (dresource.getDownloadName() != null) {
if (userAgent != null && userAgent.contains("Firefox")) {
res.setHeader("Content-Disposition",
"attachment; filename*=utf-8''" + URLEncoder.encode(dresource.getDownloadName(), "UTF-8") + "");
} else {
res.setHeader("Content-Disposition",
"attachment;filename=\"" + URLEncoder.encode(dresource.getDownloadName(), "UTF-8") + "\"");
}
}
res.setContentType(dresource.getResourceMimeType());
InputStream is = dresource.getInputStream();
try {
optimalRead(is, res.getOutputStream());
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {