use of org.xdi.util.io.DownloadWrapper in project oxTrust by GluuFederation.
the class LogoImageServlet method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse response) {
log.debug("Starting organization logo upload");
try {
GluuOrganization organization = organizationService.getOrganization();
GluuImage image = imageService.getGluuImageFromXML(organization.getLogoImage());
if (image != null) {
image.setLogo(true);
}
OutputStream os = null;
InputStream is = null;
try {
DownloadWrapper downloadWrapper = null;
// Send customized organization logo
if (image != null) {
File file = imageService.getSourceFile(image);
try {
is = FileUtils.openInputStream(file);
downloadWrapper = new DownloadWrapper(is, image.getSourceName(), image.getSourceContentType(), image.getCreationDate(), (int) file.length());
} catch (IOException ex) {
log.error("Organization logo image doesn't exist", ex);
FileDownloader.sendError(response);
return;
}
} else {
// If customized logo doesn't exist then send default
// organization logo
String defaultLogoFileName = "/WEB-INF/static/images/default_logo.png";
is = getServletContext().getResourceAsStream(defaultLogoFileName);
if (is == null) {
log.error("Default organization logo image doesn't exist");
FileDownloader.sendError(response);
return;
}
// Calculate default logo size
long contentLength;
try {
contentLength = is.skip(Long.MAX_VALUE);
} catch (IOException ex) {
log.error("Failed to calculate default organization logo image size", ex);
FileDownloader.sendError(response);
return;
} finally {
IOUtils.closeQuietly(is);
}
is = getServletContext().getResourceAsStream(defaultLogoFileName);
downloadWrapper = new DownloadWrapper(is, "default_logo.png", "image/png", new Date(), (int) contentLength);
}
try {
int logoSize = FileDownloader.writeOutput(downloadWrapper, ContentDisposition.INLINE, response);
response.getOutputStream().flush();
log.debug("Successfully send organization logo with size", logoSize);
} catch (IOException ex) {
log.error("Failed to send organization logo", ex);
FileDownloader.sendError(response);
}
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
} catch (Exception ex) {
log.error("Failed to send organization logo", ex);
}
}
use of org.xdi.util.io.DownloadWrapper in project oxTrust by GluuFederation.
the class FaviconImageServlet method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse response) throws ServletException, IOException {
log.debug("Starting organization favicon upload");
String preview = httpServletRequest.getParameter("preview");
GluuOrganization organization = null;
try {
organization = organizationService.getOrganization();
} catch (Exception ex) {
log.error("an Error Occured", ex);
}
GluuImage image = null;
if ("true".equals(preview)) {
image = imageService.getGluuImageFromXML(organization.getTempFaviconImage());
if (image != null) {
image.setStoreTemporary(true);
}
}
if (!"true".equals(preview) || image == null) {
image = imageService.getGluuImageFromXML(organization.getFaviconImage());
}
if (image != null) {
image.setLogo(false);
}
OutputStream os = null;
InputStream is = null;
try {
DownloadWrapper downloadWrapper = null;
// Send customized organization logo
if (image != null) {
File file = null;
try {
file = imageService.getSourceFile(image);
} catch (Exception ex) {
log.error("an Error Occured", ex);
}
try {
is = FileUtils.openInputStream(file);
if (is != null && file != null) {
downloadWrapper = new DownloadWrapper(is, image.getSourceName(), image.getSourceContentType(), image.getCreationDate(), (int) file.length());
}
} catch (IOException ex) {
log.error("Organization favicon image doesn't exist", ex);
FileDownloader.sendError(response);
return;
}
} else {
// If customized logo doesn't exist then send default
// organization logo
String defaultFaviconFileName = "/WEB-INF/static/images/favicon_ic.ico";
is = getServletContext().getResourceAsStream(defaultFaviconFileName);
if (is == null) {
log.error("Default organization favicon image doesn't exist");
FileDownloader.sendError(response);
return;
}
// Calculate default logo size
long contentLength;
try {
contentLength = is.skip(Long.MAX_VALUE);
} catch (IOException ex) {
log.error("Failed to calculate default organization favicon image size", ex);
FileDownloader.sendError(response);
return;
} finally {
IOUtils.closeQuietly(is);
}
is = getServletContext().getResourceAsStream(defaultFaviconFileName);
downloadWrapper = new DownloadWrapper(is, "favicon_ic.ico", "image/x-icon", new Date(), (int) contentLength);
}
try {
int logoSize = FileDownloader.writeOutput(downloadWrapper, ContentDisposition.INLINE, response);
response.getOutputStream().flush();
log.debug("Successfully send organization favicon with size", logoSize);
} catch (IOException ex) {
log.error("Failed to send organization favicon", ex);
FileDownloader.sendError(response);
}
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
Aggregations