mirror of https://github.com/apache/cloudstack.git
Fixed Thumbnail generated image to fit in cloud portal UI with default Width and Height (144x110)
Reviewed-by:Kelven Yang
This commit is contained in:
parent
828c5a9f40
commit
d3a81dd082
|
|
@ -12,6 +12,10 @@
|
|||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.consoleproxy;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
|
|
@ -63,8 +67,13 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
|
|||
String keyStr = queryMap.get("key");
|
||||
String console_url = queryMap.get("consoleurl");
|
||||
String console_host_session = queryMap.get("sessionref");
|
||||
|
||||
String w = queryMap.get("w");
|
||||
String h = queryMap.get("h");
|
||||
|
||||
|
||||
int key = 0;
|
||||
int width = 144;
|
||||
int height = 110;
|
||||
|
||||
if(tag == null)
|
||||
tag = "";
|
||||
|
|
@ -81,8 +90,14 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
|
|||
}
|
||||
|
||||
try {
|
||||
if (keyStr != null)
|
||||
key = Integer.parseInt(keyStr);
|
||||
if (keyStr != null)
|
||||
key = Integer.parseInt(keyStr);
|
||||
if(null != w)
|
||||
width = Integer.parseInt(w);
|
||||
|
||||
if(null != h)
|
||||
height = Integer.parseInt(h);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
s_logger.warn("Invalid numeric parameter in query string: " + keyStr);
|
||||
throw new IllegalArgumentException(e);
|
||||
|
|
@ -98,25 +113,44 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
|
|||
param.setClientTunnelSession(console_host_session);
|
||||
|
||||
ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(param);
|
||||
AjaxFIFOImageCache imageCache = viewer.getAjaxImageCache();
|
||||
|
||||
byte[] img = imageCache.getImage(key);
|
||||
|
||||
if(img != null) {
|
||||
Headers hds = t.getResponseHeaders();
|
||||
hds.set("Content-Type", "image/jpeg");
|
||||
t.sendResponseHeaders(200, img.length);
|
||||
|
||||
OutputStream os = t.getResponseBody();
|
||||
try {
|
||||
os.write(img, 0, img.length);
|
||||
} finally {
|
||||
os.close();
|
||||
}
|
||||
} else {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Image has already been swept out, key: " + key);
|
||||
t.sendResponseHeaders(404, -1);
|
||||
|
||||
if (key == 0) {
|
||||
Image scaledImage = viewer.getClientScaledImage(width, height);
|
||||
BufferedImage bufferedImage = new BufferedImage(width, height,
|
||||
BufferedImage.TYPE_3BYTE_BGR);
|
||||
Graphics2D bufImageGraphics = bufferedImage.createGraphics();
|
||||
bufImageGraphics.drawImage(scaledImage, 0, 0, null);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(8196);
|
||||
javax.imageio.ImageIO.write(bufferedImage, "jpg", bos);
|
||||
byte[] bs = bos.toByteArray();
|
||||
Headers hds = t.getResponseHeaders();
|
||||
hds.set("Content-Type", "image/jpeg");
|
||||
hds.set("Cache-Control", "no-cache");
|
||||
hds.set("Cache-Control", "no-store");
|
||||
t.sendResponseHeaders(200, bs.length);
|
||||
OutputStream os = t.getResponseBody();
|
||||
os.write(bs);
|
||||
os.close();
|
||||
} else {
|
||||
AjaxFIFOImageCache imageCache = viewer.getAjaxImageCache();
|
||||
byte[] img = imageCache.getImage(key);
|
||||
|
||||
if(img != null) {
|
||||
Headers hds = t.getResponseHeaders();
|
||||
hds.set("Content-Type", "image/jpeg");
|
||||
t.sendResponseHeaders(200, img.length);
|
||||
|
||||
OutputStream os = t.getResponseBody();
|
||||
try {
|
||||
os.write(img, 0, img.length);
|
||||
} finally {
|
||||
os.close();
|
||||
}
|
||||
} else {
|
||||
if(s_logger.isInfoEnabled())
|
||||
s_logger.info("Image has already been swept out, key: " + key);
|
||||
t.sendResponseHeaders(404, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue