incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject git commit: commit for https://reviews.apache.org/r/6608/
Date Mon, 27 Aug 2012 17:51:48 GMT
Updated Branches:
  refs/heads/master 93ac01db0 -> 3609e44b5


commit for https://reviews.apache.org/r/6608/


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/3609e44b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/3609e44b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/3609e44b

Branch: refs/heads/master
Commit: 3609e44b58cb1c3fe6d29014d807b42c7eafed3a
Parents: 93ac01d
Author: Kelven Yang <kelven.yang@citrix.com>
Authored: Mon Aug 27 10:39:49 2012 -0700
Committer: Kelven Yang <kelven.yang@citrix.com>
Committed: Mon Aug 27 10:39:49 2012 -0700

----------------------------------------------------------------------
 .../com/cloud/consoleproxy/AjaxFIFOImageCache.java |   39 ++++---
 .../consoleproxy/ConsoleProxyAjaxImageHandler.java |   85 +++++++++++----
 .../src/com/cloud/servlet/ConsoleProxyServlet.java |    5 +-
 3 files changed, 88 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3609e44b/console-proxy/src/com/cloud/consoleproxy/AjaxFIFOImageCache.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/AjaxFIFOImageCache.java b/console-proxy/src/com/cloud/consoleproxy/AjaxFIFOImageCache.java
index c9b5b60..a745d0d 100644
--- a/console-proxy/src/com/cloud/consoleproxy/AjaxFIFOImageCache.java
+++ b/console-proxy/src/com/cloud/consoleproxy/AjaxFIFOImageCache.java
@@ -29,7 +29,7 @@ public class AjaxFIFOImageCache {
 	private List<Integer> fifoQueue;
 	private Map<Integer, byte[]> cache;
 	private int cacheSize;
-	private int nextKey = 1;
+    private int nextKey = 0;
 	
 	public AjaxFIFOImageCache(int cacheSize) {
 		this.cacheSize = cacheSize;
@@ -61,20 +61,23 @@ public class AjaxFIFOImageCache {
 		return key;
 	}
 	
-	public synchronized byte[] getImage(int key) {
-		if(cache.containsKey(key)) {
-			if(s_logger.isTraceEnabled())
-				s_logger.trace("Retrieve image from cache, key: " + key);
-			
-			return cache.get(key);
-		}
-		
-		if(s_logger.isTraceEnabled())
-			s_logger.trace("Image is no long in cache, key: " + key);
-		return null;
-	}
-	
-	public synchronized int getNextKey() {
-		return nextKey++;
-	}
-}
+    public synchronized byte[] getImage(int key) {
+        if (key == 0) {
+            key = nextKey;
+        }
+        if (cache.containsKey(key)) {
+            if (s_logger.isTraceEnabled())
+                s_logger.trace("Retrieve image from cache, key: " + key);
+
+            return cache.get(key);
+        }
+
+        if (s_logger.isTraceEnabled())
+            s_logger.trace("Image is no long in cache, key: " + key);
+        return null;
+    }
+
+    public synchronized int getNextKey() {
+        return ++nextKey;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3609e44b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java
index 1fdda2e..9c00948 100644
--- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java
+++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyAjaxImageHandler.java
@@ -16,6 +16,10 @@
 // under the License.
 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;
@@ -65,7 +69,14 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
 		String tag = queryMap.get("tag");
 		String ticket = queryMap.get("ticket");
 		String keyStr = queryMap.get("key");
-		int key = 0;
+		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,9 +92,16 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
 			throw new IllegalArgumentException(e);
 		}
 		
-		try {
-			key = Integer.parseInt(keyStr);
-		} catch (NumberFormatException e) {
+		try {
+                    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);
 		}
@@ -94,23 +112,48 @@ public class ConsoleProxyAjaxImageHandler implements HttpHandler {
 		param.setClientHostPassword(sid);
 		param.setClientTag(tag);
 		param.setTicket(ticket);
-		ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(param);
-		byte[] img = viewer.getAjaxImageCache().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);
+		param.setClientTunnelUrl(console_url);
+		param.setClientTunnelSession(console_host_session);
+
+		ConsoleProxyClient viewer = ConsoleProxy.getVncViewer(param);
+
+		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);
+			}
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3609e44b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/servlet/ConsoleProxyServlet.java b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
index a8519fe..7f073f1 100644
--- a/server/src/com/cloud/servlet/ConsoleProxyServlet.java
+++ b/server/src/com/cloud/servlet/ConsoleProxyServlet.java
@@ -336,8 +336,9 @@ public class ConsoleProxyServlet extends HttpServlet {
             param.setClientTunnelSession(parsedHostInfo.third());
         }
 
-        sb.append("/ajaximg?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class,
param));
-        sb.append("&w=").append(w).append("&h=").append(h);
+        sb.append("/ajaximg?token="
+                + encryptor.encryptObject(ConsoleProxyClientParam.class, param));
+        sb.append("&w=").append(w).append("&h=").append(h).append("&key=0");
 
         if(s_logger.isDebugEnabled()) {
             s_logger.debug("Compose thumbnail url: " + sb.toString());


Mime
View raw message