http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b25122bd/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java
----------------------------------------------------------------------
diff --git a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java 
b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java
index f14cd5a..158f9fe 100644
--- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java
+++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyGCThread.java
@@ -14,96 +14,95 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-package com.cloud.consoleproxy;
-
-import java.io.File;
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import org.apache.log4j.Logger;
-
-/**
- * 
- * @author Kelven Yang
- * ConsoleProxyGCThread does house-keeping work for the process, it helps 
cleanup log files,
- * recycle idle client sessions without front-end activities and report client 
stats to external
- * management software 
- */
-public class ConsoleProxyGCThread extends Thread {
-       private static final Logger s_logger = 
Logger.getLogger(ConsoleProxyGCThread.class);
-       
-       private final static int MAX_SESSION_IDLE_SECONDS = 180;
-
-       private Hashtable<String, ConsoleProxyClient> connMap;
-       private long lastLogScan = 0;
-       
-       public ConsoleProxyGCThread(Hashtable<String, ConsoleProxyClient> 
connMap) {
-               this.connMap = connMap;
-       }
-       
-       private void cleanupLogging() {
-               if(lastLogScan != 0 && System.currentTimeMillis() - lastLogScan 
< 3600000)
-                       return;
-               
-               lastLogScan = System.currentTimeMillis();
-               
-               File logDir = new File("./logs");
-               File files[] = logDir.listFiles();
-               if(files != null) {
-                       for(File file : files) {
-                               if(System.currentTimeMillis() - 
file.lastModified() >= 86400000L) {
-                                       try {
-                                               file.delete();
-                                       } catch(Throwable e) {
-                                       }
-                               }
-                       }
-               }
-       }
-       
-       @Override
+package com.cloud.consoleproxy;
+
+import java.io.File;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.apache.log4j.Logger;
+
+/**
+ * 
+ * ConsoleProxyGCThread does house-keeping work for the process, it helps 
cleanup log files,
+ * recycle idle client sessions without front-end activities and report client 
stats to external
+ * management software 
+ */
+public class ConsoleProxyGCThread extends Thread {
+    private static final Logger s_logger = 
Logger.getLogger(ConsoleProxyGCThread.class);
+    
+    private final static int MAX_SESSION_IDLE_SECONDS = 180;
+
+    private Hashtable<String, ConsoleProxyClient> connMap;
+    private long lastLogScan = 0;
+    
+    public ConsoleProxyGCThread(Hashtable<String, ConsoleProxyClient> connMap) 
{
+        this.connMap = connMap;
+    }
+    
+    private void cleanupLogging() {
+        if(lastLogScan != 0 && System.currentTimeMillis() - lastLogScan < 
3600000)
+            return;
+        
+        lastLogScan = System.currentTimeMillis();
+        
+        File logDir = new File("./logs");
+        File files[] = logDir.listFiles();
+        if(files != null) {
+            for(File file : files) {
+                if(System.currentTimeMillis() - file.lastModified() >= 
86400000L) {
+                    try {
+                        file.delete();
+                    } catch(Throwable e) {
+                    }
+                }
+            }
+        }
+    }
+    
+    @Override
     public void run() {
-               
-               boolean bReportLoad = false;
-               while (true) {
-                       cleanupLogging();
-                       bReportLoad = false;
-                       
-                       if(s_logger.isDebugEnabled())
-                               s_logger.debug("connMap=" + connMap);
-                       Enumeration<String> e = connMap.keys();
-                   while (e.hasMoreElements()) {
-                       String key;
-                       ConsoleProxyClient client;
-                       
-                       synchronized (connMap) {
-                       key  = e.nextElement();
-                       client  = connMap.get(key);
-                       }
-
-                   long seconds_unused = (System.currentTimeMillis() - 
client.getClientLastFrontEndActivityTime()) / 1000;
-                   if (seconds_unused < MAX_SESSION_IDLE_SECONDS) {
-                       continue;
-                   }
-                   
-                       synchronized (connMap) {
-                               connMap.remove(key);
-                       }
-                       
-                   // close the server connection
-                   s_logger.info("Dropping " + client + " which has not been 
used for " + seconds_unused + " seconds");
-                   client.closeClient();
-                   }
-                   
-                   if(bReportLoad) {
-                   // report load changes
-                               String loadInfo = new 
ConsoleProxyClientStatsCollector(connMap).getStatsReport(); 
-                               ConsoleProxy.reportLoadInfo(loadInfo);
-                               if(s_logger.isDebugEnabled())
-                                       s_logger.debug("Report load change : " 
+ loadInfo);
-                   }
-                   
-                       try { Thread.sleep(5000); } catch (InterruptedException 
ex) {}
-               }
-       }
-}
+        
+        boolean bReportLoad = false;
+        while (true) {
+            cleanupLogging();
+            bReportLoad = false;
+            
+            if(s_logger.isDebugEnabled())
+                s_logger.debug("connMap=" + connMap);
+            Enumeration<String> e = connMap.keys();
+            while (e.hasMoreElements()) {
+                String key;
+                ConsoleProxyClient client;
+                
+                synchronized (connMap) {
+                    key  = e.nextElement();
+                    client  = connMap.get(key);
+                }
+
+                long seconds_unused = (System.currentTimeMillis() - 
client.getClientLastFrontEndActivityTime()) / 1000;
+                if (seconds_unused < MAX_SESSION_IDLE_SECONDS) {
+                    continue;
+                }
+                
+                synchronized (connMap) {
+                    connMap.remove(key);
+                }
+                
+                // close the server connection
+                s_logger.info("Dropping " + client + " which has not been used 
for " + seconds_unused + " seconds");
+                client.closeClient();
+            }
+            
+            if(bReportLoad) {
+                // report load changes
+                String loadInfo = new 
ConsoleProxyClientStatsCollector(connMap).getStatsReport(); 
+                ConsoleProxy.reportLoadInfo(loadInfo);
+                if(s_logger.isDebugEnabled())
+                    s_logger.debug("Report load change : " + loadInfo);
+            }
+            
+            try { Thread.sleep(5000); } catch (InterruptedException ex) {}
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b25122bd/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyPasswordBasedEncryptor.java
----------------------------------------------------------------------
diff --git 
a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyPasswordBasedEncryptor.java
 
b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyPasswordBasedEncryptor.java
index 3ef22c5..29826f0 100644
--- 
a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyPasswordBasedEncryptor.java
+++ 
b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyPasswordBasedEncryptor.java
@@ -14,130 +14,129 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-package com.cloud.consoleproxy;
-
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
-
-import javax.crypto.BadPaddingException;
-import javax.crypto.Cipher;
-import javax.crypto.IllegalBlockSizeException;
-import javax.crypto.NoSuchPaddingException;
-import javax.crypto.spec.SecretKeySpec;
-
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-/**
- * 
- * @author Kelven Yang
- * A simple password based encyrptor based on DES. It can serialize simple 
POJO object into URL safe string
- * and deserialize it back.
- * 
- */
-public class ConsoleProxyPasswordBasedEncryptor {
-       private static final Logger s_logger = 
Logger.getLogger(ConsoleProxyPasswordBasedEncryptor.class);
-       
-       private String password;
-       private Gson gson;
-       
-       public ConsoleProxyPasswordBasedEncryptor(String password) {
-               this.password = password;
-               gson = new GsonBuilder().create();
-       }
-       
-       public String encryptText(String text) {
-               if(text == null || text.isEmpty())
-                       return text;
-               
-               assert(password != null);
-               assert(!password.isEmpty());
-               
-               try {
-                       Cipher cipher = Cipher.getInstance("DES");
-                       int maxKeySize = 8;
-                       SecretKeySpec keySpec = new 
SecretKeySpec(normalizeKey(password.getBytes(), maxKeySize), "DES");
-                       cipher.init(Cipher.ENCRYPT_MODE, keySpec);
-                       byte[] encryptedBytes = cipher.doFinal(text.getBytes());
-                       return Base64.encodeBase64URLSafeString(encryptedBytes);
-               } catch (NoSuchAlgorithmException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               } catch (NoSuchPaddingException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               } catch (IllegalBlockSizeException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               } catch (BadPaddingException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               } catch (InvalidKeyException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               }
-       }
-
-       public String decryptText(String encryptedText) {
-               if(encryptedText == null || encryptedText.isEmpty())
-                       return encryptedText;
-
-               assert(password != null);
-               assert(!password.isEmpty());
-
-               try {
-                       Cipher cipher = Cipher.getInstance("DES");
-            int maxKeySize = 8;
-                       SecretKeySpec keySpec = new 
SecretKeySpec(normalizeKey(password.getBytes(), maxKeySize), "DES");
-                       cipher.init(Cipher.DECRYPT_MODE, keySpec);
-                       
-                       byte[] encryptedBytes = 
Base64.decodeBase64(encryptedText);
-                       return new String(cipher.doFinal(encryptedBytes));
-               } catch (NoSuchAlgorithmException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               } catch (NoSuchPaddingException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               } catch (IllegalBlockSizeException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               } catch (BadPaddingException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               } catch (InvalidKeyException e) {
-                       s_logger.error("Unexpected exception ", e);
-                       return null;
-               }
-       }
-       
-       public <T> String encryptObject(Class<?> clz, T obj) {
-               if(obj == null)
-                       return null;
-               
-               String json = gson.toJson(obj);
-               return encryptText(json);
-       }
-       
-       @SuppressWarnings("unchecked")
-       public <T> T decryptObject(Class<?> clz, String encrypted) {
-               if(encrypted == null || encrypted.isEmpty())
-                       return null;
-               
-               String json = decryptText(encrypted);
-               return (T)gson.fromJson(json, clz);
-       }
-       
-       private static byte[] normalizeKey(byte[] keyBytes, int keySize) {
-               assert(keySize > 0);
-               byte[] key = new byte[keySize];
-               
-               for(int i = 0; i < keyBytes.length; i++)
-                       key[i%keySize] ^= keyBytes[i];
-               
-               return key;
-       }
-}
+package com.cloud.consoleproxy;
+
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+/**
+ * 
+ * A simple password based encyrptor based on DES. It can serialize simple 
POJO object into URL safe string
+ * and deserialize it back.
+ * 
+ */
+public class ConsoleProxyPasswordBasedEncryptor {
+    private static final Logger s_logger = 
Logger.getLogger(ConsoleProxyPasswordBasedEncryptor.class);
+    
+    private String password;
+    private Gson gson;
+    
+    public ConsoleProxyPasswordBasedEncryptor(String password) {
+        this.password = password;
+        gson = new GsonBuilder().create();
+    }
+    
+    public String encryptText(String text) {
+        if(text == null || text.isEmpty())
+            return text;
+        
+        assert(password != null);
+        assert(!password.isEmpty());
+        
+        try {
+            Cipher cipher = Cipher.getInstance("DES");
+            int maxKeySize = 8;
+            SecretKeySpec keySpec = new 
SecretKeySpec(normalizeKey(password.getBytes(), maxKeySize), "DES");
+            cipher.init(Cipher.ENCRYPT_MODE, keySpec);
+            byte[] encryptedBytes = cipher.doFinal(text.getBytes());
+            return Base64.encodeBase64URLSafeString(encryptedBytes);
+        } catch (NoSuchAlgorithmException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        } catch (NoSuchPaddingException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        } catch (IllegalBlockSizeException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        } catch (BadPaddingException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        } catch (InvalidKeyException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        }
+    }
+
+    public String decryptText(String encryptedText) {
+        if(encryptedText == null || encryptedText.isEmpty())
+            return encryptedText;
+
+        assert(password != null);
+        assert(!password.isEmpty());
+
+        try {
+            Cipher cipher = Cipher.getInstance("DES");
+            int maxKeySize = 8;
+            SecretKeySpec keySpec = new 
SecretKeySpec(normalizeKey(password.getBytes(), maxKeySize), "DES");
+            cipher.init(Cipher.DECRYPT_MODE, keySpec);
+            
+            byte[] encryptedBytes = Base64.decodeBase64(encryptedText);
+            return new String(cipher.doFinal(encryptedBytes));
+        } catch (NoSuchAlgorithmException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        } catch (NoSuchPaddingException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        } catch (IllegalBlockSizeException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        } catch (BadPaddingException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        } catch (InvalidKeyException e) {
+            s_logger.error("Unexpected exception ", e);
+            return null;
+        }
+    }
+    
+    public <T> String encryptObject(Class<?> clz, T obj) {
+        if(obj == null)
+            return null;
+        
+        String json = gson.toJson(obj);
+        return encryptText(json);
+    }
+    
+    @SuppressWarnings("unchecked")
+    public <T> T decryptObject(Class<?> clz, String encrypted) {
+        if(encrypted == null || encrypted.isEmpty())
+            return null;
+        
+        String json = decryptText(encrypted);
+        return (T)gson.fromJson(json, clz);
+    }
+    
+    private static byte[] normalizeKey(byte[] keyBytes, int keySize) {
+        assert(keySize > 0);
+        byte[] key = new byte[keySize];
+        
+        for(int i = 0; i < keyBytes.length; i++)
+            key[i%keySize] ^= keyBytes[i];
+        
+        return key;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/b25122bd/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java
----------------------------------------------------------------------
diff --git 
a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java 
b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java
index 77a9977..6a473b5 100644
--- a/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java
+++ b/console-proxy/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java
@@ -14,223 +14,222 @@
 // KIND, either express or implied.  See the License for the
 // specific language governing permissions and limitations
 // under the License.
-package com.cloud.consoleproxy;
-
-import java.io.IOException;
+package com.cloud.consoleproxy;
+
+import java.io.IOException;
 import java.net.URI;
-import java.net.UnknownHostException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.consoleproxy.vnc.FrameBufferCanvas;
-import com.cloud.consoleproxy.vnc.RfbConstants;
-import com.cloud.consoleproxy.vnc.VncClient;
-
-/**
- * 
- * @author Kelven Yang
- * ConsoleProxyVncClient bridges a VNC engine with the front-end AJAX viewer
- * 
- */
-public class ConsoleProxyVncClient extends ConsoleProxyClientBase {
-       private static final Logger s_logger = 
Logger.getLogger(ConsoleProxyVncClient.class);
+import java.net.UnknownHostException;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.consoleproxy.vnc.FrameBufferCanvas;
+import com.cloud.consoleproxy.vnc.RfbConstants;
+import com.cloud.consoleproxy.vnc.VncClient;
+
+/**
+ * 
+ * ConsoleProxyVncClient bridges a VNC engine with the front-end AJAX viewer
+ * 
+ */
+public class ConsoleProxyVncClient extends ConsoleProxyClientBase {
+    private static final Logger s_logger = 
Logger.getLogger(ConsoleProxyVncClient.class);
+
+    private static final int SHIFT_KEY_MASK = 64;
+    private static final int CTRL_KEY_MASK = 128;
+    private static final int META_KEY_MASK = 256;
+    private static final int ALT_KEY_MASK = 512;
+    
+    private static final int X11_KEY_SHIFT = 0xffe1;
+    private static final int X11_KEY_CTRL = 0xffe3;
+    private static final int X11_KEY_ALT = 0xffe9;
+    private static final int X11_KEY_META = 0xffe7;
+    
+    private VncClient client;
+    private Thread worker;
+    private boolean workerDone = false;
+    
+    private int lastModifierStates = 0;
+    private int lastPointerMask = 0;
+    
+    public ConsoleProxyVncClient() {
+    }
+    
+    public boolean isHostConnected() {
+        if(client != null)
+            return client.isHostConnected();
+        
+        return false;
+    }
+    
+    @Override
+    public boolean isFrontEndAlive() {
+        if(workerDone || System.currentTimeMillis() - 
getClientLastFrontEndActivityTime() > ConsoleProxy.VIEWER_LINGER_SECONDS*1000) {
+            s_logger.info("Front end has been idle for too long");
+            return false;
+        }
+        return true;
+    }
+
+    @Override
+    public void initClient(ConsoleProxyClientParam param) {
+        setClientParam(param);
+        
+        client = new VncClient(this);
+        worker = new Thread(new Runnable() {
+            public void run() {
+                String tunnelUrl = getClientParam().getClientTunnelUrl();
+                String tunnelSession = 
getClientParam().getClientTunnelSession();
+                
+                for(int i = 0; i < 15; i++) {
+                    try {
+                        if(tunnelUrl != null && !tunnelUrl.isEmpty() && 
tunnelSession != null && !tunnelSession.isEmpty()) {
+                            URI uri = new URI(tunnelUrl);
+                            s_logger.info("Connect to VNC server via tunnel. 
url: " + tunnelUrl + ", session: " + tunnelSession);
+                            
+                            ConsoleProxy.ensureRoute(uri.getHost());
+                            client.connectTo(
+                                uri.getHost(), uri.getPort(), 
+                                uri.getPath() + "?" + uri.getQuery(), 
+                                tunnelSession, 
"https".equalsIgnoreCase(uri.getScheme()),
+                                getClientHostPassword());
+                        } else {
+                            s_logger.info("Connect to VNC server directly. 
host: " + getClientHostAddress() + ", port: " + getClientHostPort());
+                            ConsoleProxy.ensureRoute(getClientHostAddress());
+                            client.connectTo(getClientHostAddress(), 
getClientHostPort(), getClientHostPassword());
+                        }
+                    } catch (UnknownHostException e) {
+                        s_logger.error("Unexpected exception (will retry until 
timeout)", e);
+                    } catch (IOException e) {
+                        s_logger.error("Unexpected exception (will retry until 
timeout) ", e);
+                    } catch (Throwable e) {
+                        s_logger.error("Unexpected exception (will retry until 
timeout) ", e);
+                    }
+                    
+                    try {
+                        Thread.sleep(1000);
+                    } catch (InterruptedException e) {
+                    }
+
+                    if(tunnelUrl != null && !tunnelUrl.isEmpty() && 
tunnelSession != null && !tunnelSession.isEmpty()) {
+                        ConsoleProxyAuthenticationResult authResult = 
ConsoleProxy.reAuthenticationExternally(getClientParam());
+                        if(authResult != null && authResult.isSuccess()) {
+                            if(authResult.getTunnelUrl() != null && 
!authResult.getTunnelUrl().isEmpty() && 
+                                authResult.getTunnelSession() != null && 
!authResult.getTunnelSession().isEmpty()) {
+                                tunnelUrl = authResult.getTunnelUrl();
+                                tunnelSession = authResult.getTunnelSession();
+                                
+                                s_logger.info("Reset XAPI session. url: " + 
tunnelUrl + ", session: " + tunnelSession);
+                            }
+                        }
+                    }
+                }
 
-       private static final int SHIFT_KEY_MASK = 64;
-       private static final int CTRL_KEY_MASK = 128;
-       private static final int META_KEY_MASK = 256;
-       private static final int ALT_KEY_MASK = 512;
-       
-       private static final int X11_KEY_SHIFT = 0xffe1;
-       private static final int X11_KEY_CTRL = 0xffe3;
-       private static final int X11_KEY_ALT = 0xffe9;
-       private static final int X11_KEY_META = 0xffe7;
-       
-       private VncClient client;
-       private Thread worker;
-       private boolean workerDone = false;
-       
-       private int lastModifierStates = 0;
-       private int lastPointerMask = 0;
-       
-       public ConsoleProxyVncClient() {
-       }
-       
-       public boolean isHostConnected() {
-               if(client != null)
-                       return client.isHostConnected();
-               
-               return false;
-       }
-       
-       @Override
-       public boolean isFrontEndAlive() {
-               if(workerDone || System.currentTimeMillis() - 
getClientLastFrontEndActivityTime() > ConsoleProxy.VIEWER_LINGER_SECONDS*1000) {
-                       s_logger.info("Front end has been idle for too long");
-                       return false;
-               }
-               return true;
-       }
-
-       @Override
-       public void initClient(ConsoleProxyClientParam param) {
-               setClientParam(param);
-               
-               client = new VncClient(this);
-               worker = new Thread(new Runnable() {
-                       public void run() {
-                               String tunnelUrl = 
getClientParam().getClientTunnelUrl();
-                               String tunnelSession = 
getClientParam().getClientTunnelSession();
-                               
-                               for(int i = 0; i < 15; i++) {
-                                       try {
-                                               if(tunnelUrl != null && 
!tunnelUrl.isEmpty() && tunnelSession != null && !tunnelSession.isEmpty()) {
-                                                       URI uri = new 
URI(tunnelUrl);
-                                                       s_logger.info("Connect 
to VNC server via tunnel. url: " + tunnelUrl + ", session: " + tunnelSession);
-                                                       
-                                                       
ConsoleProxy.ensureRoute(uri.getHost());
-                                                       client.connectTo(
-                                                               uri.getHost(), 
uri.getPort(), 
-                                                               uri.getPath() + 
"?" + uri.getQuery(), 
-                                                               tunnelSession, 
"https".equalsIgnoreCase(uri.getScheme()),
-                                                               
getClientHostPassword());
-                                               } else {
-                                                       s_logger.info("Connect 
to VNC server directly. host: " + getClientHostAddress() + ", port: " + 
getClientHostPort());
-                                                       
ConsoleProxy.ensureRoute(getClientHostAddress());
-                                                       
client.connectTo(getClientHostAddress(), getClientHostPort(), 
getClientHostPassword());
-                                               }
-                                       } catch (UnknownHostException e) {
-                                               s_logger.error("Unexpected 
exception (will retry until timeout)", e);
-                                       } catch (IOException e) {
-                                               s_logger.error("Unexpected 
exception (will retry until timeout) ", e);
-                                       } catch (Throwable e) {
-                                               s_logger.error("Unexpected 
exception (will retry until timeout) ", e);
-                                       }
-                                       
-                                       try {
-                                               Thread.sleep(1000);
-                                       } catch (InterruptedException e) {
-                                       }
+                s_logger.info("Receiver thread stopped.");
+                workerDone = true;
+                client.getClientListener().onClientClose();
+            }
+        });
+        
+        worker.setDaemon(true);
+        worker.start();
+    }
+    
+    @Override
+    public void closeClient() {
+        if(client != null)
+            client.shutdown();
+    }
+    
+    @Override
+    public void onClientConnected() {
+    }
+    
+    public void onClientClose() {
+        s_logger.info("Received client close indication. remove viewer from 
map.");
+        
+        ConsoleProxy.removeViewer(this);
+    }
+    
+    @Override
+    public void onFramebufferUpdate(int x, int y, int w, int h) {
+        super.onFramebufferUpdate(x, y, w, h);
+        client.requestUpdate(false);
+    }
 
-                                       if(tunnelUrl != null && 
!tunnelUrl.isEmpty() && tunnelSession != null && !tunnelSession.isEmpty()) {
-                                               
ConsoleProxyAuthenticationResult authResult = 
ConsoleProxy.reAuthenticationExternally(getClientParam());
-                                               if(authResult != null && 
authResult.isSuccess()) {
-                                                       
if(authResult.getTunnelUrl() != null && !authResult.getTunnelUrl().isEmpty() && 
-                                                               
authResult.getTunnelSession() != null && 
!authResult.getTunnelSession().isEmpty()) {
-                                                               tunnelUrl = 
authResult.getTunnelUrl();
-                                                               tunnelSession = 
authResult.getTunnelSession();
-                                                               
-                                                               
s_logger.info("Reset XAPI session. url: " + tunnelUrl + ", session: " + 
tunnelSession);
-                                                       }
-                                               }
-                                       }
-                               }
+    public void sendClientRawKeyboardEvent(InputEventType event, int code, int 
modifiers) {
+        if(client == null)
+            return;
+        
+        updateFrontEndActivityTime();
+        
+        switch(event) {
+        case KEY_DOWN :
+            sendModifierEvents(modifiers);
+            client.sendClientKeyboardEvent(RfbConstants.KEY_DOWN, code, 0);
+            break;
+            
+        case KEY_UP :
+            client.sendClientKeyboardEvent(RfbConstants.KEY_UP, code, 0);
+            sendModifierEvents(0);
+            break;
+            
+        case KEY_PRESS :
+            break;
+            
+        default :
+            assert(false);
+            break;
+        }
+    }
+    
+    public void sendClientMouseEvent(InputEventType event, int x, int y, int 
code, int modifiers) {
+        if(client == null)
+            return;
+        
+        updateFrontEndActivityTime();
 
-                               s_logger.info("Receiver thread stopped.");
-                               workerDone = true;
-                           client.getClientListener().onClientClose();
-                       }
-               });
-               
-               worker.setDaemon(true);
-               worker.start();
-       }
-       
-       @Override
-       public void closeClient() {
-               if(client != null)
-                       client.shutdown();
-       }
-       
-       @Override
-       public void onClientConnected() {
-       }
-       
-       public void onClientClose() {
-               s_logger.info("Received client close indication. remove viewer 
from map.");
-               
-               ConsoleProxy.removeViewer(this);
-       }
-       
-       @Override
-       public void onFramebufferUpdate(int x, int y, int w, int h) {
-               super.onFramebufferUpdate(x, y, w, h);
-               client.requestUpdate(false);
-       }
-
-       public void sendClientRawKeyboardEvent(InputEventType event, int code, 
int modifiers) {
-               if(client == null)
-                       return;
-               
-               updateFrontEndActivityTime();
-               
-               switch(event) {
-               case KEY_DOWN :
-                       sendModifierEvents(modifiers);
-                       client.sendClientKeyboardEvent(RfbConstants.KEY_DOWN, 
code, 0);
-                       break;
-                       
-               case KEY_UP :
-                       client.sendClientKeyboardEvent(RfbConstants.KEY_UP, 
code, 0);
-                       sendModifierEvents(0);
-                       break;
-                       
-               case KEY_PRESS :
-                       break;
-                       
-               default :
-                       assert(false);
-                       break;
-               }
-       }
-       
-       public void sendClientMouseEvent(InputEventType event, int x, int y, 
int code, int modifiers) {
-               if(client == null)
-                       return;
-               
-               updateFrontEndActivityTime();
-
-           if (event == InputEventType.MOUSE_DOWN) {
-               if (code == 2) {
-                       lastPointerMask |= 4;
-               } else if (code == 0) {
-                       lastPointerMask |= 1;
-               }
-           }
-           
-           if (event == InputEventType.MOUSE_UP) {
-               if (code == 2) {
-                       lastPointerMask ^= 4;
-               } else if (code == 0) {
-                       lastPointerMask ^= 1;
-               }
-           }
-               
-               sendModifierEvents(modifiers);
-               client.sendClientMouseEvent(lastPointerMask, x, y, code, 
modifiers);
-               if(lastPointerMask == 0)
-                       sendModifierEvents(0);
-       }
-       
-       @Override
-       protected FrameBufferCanvas getFrameBufferCavas() {
-               if(client != null)
-                       return client.getFrameBufferCanvas();
-               return null;
-       }
-       
-       private void sendModifierEvents(int modifiers) {
-               if((modifiers & SHIFT_KEY_MASK) != (lastModifierStates & 
SHIFT_KEY_MASK))
-                       client.sendClientKeyboardEvent((modifiers & 
SHIFT_KEY_MASK) != 0 ? RfbConstants.KEY_DOWN : RfbConstants.KEY_UP, 
X11_KEY_SHIFT, 0);
-                       
-               if((modifiers & CTRL_KEY_MASK) != (lastModifierStates & 
CTRL_KEY_MASK))
-                       client.sendClientKeyboardEvent((modifiers & 
CTRL_KEY_MASK) != 0 ? RfbConstants.KEY_DOWN : RfbConstants.KEY_UP, 
X11_KEY_CTRL, 0);
+        if (event == InputEventType.MOUSE_DOWN) {
+            if (code == 2) {
+                lastPointerMask |= 4;
+            } else if (code == 0) {
+                lastPointerMask |= 1;
+            }
+        }
+        
+        if (event == InputEventType.MOUSE_UP) {
+            if (code == 2) {
+                lastPointerMask ^= 4;
+            } else if (code == 0) {
+                lastPointerMask ^= 1;
+            }
+        }
+            
+        sendModifierEvents(modifiers);
+        client.sendClientMouseEvent(lastPointerMask, x, y, code, modifiers);
+        if(lastPointerMask == 0)
+            sendModifierEvents(0);
+    }
+    
+    @Override
+    protected FrameBufferCanvas getFrameBufferCavas() {
+        if(client != null)
+            return client.getFrameBufferCanvas();
+        return null;
+    }
+    
+    private void sendModifierEvents(int modifiers) {
+        if((modifiers & SHIFT_KEY_MASK) != (lastModifierStates & 
SHIFT_KEY_MASK))
+            client.sendClientKeyboardEvent((modifiers & SHIFT_KEY_MASK) != 0 ? 
RfbConstants.KEY_DOWN : RfbConstants.KEY_UP, X11_KEY_SHIFT, 0);
+            
+        if((modifiers & CTRL_KEY_MASK) != (lastModifierStates & CTRL_KEY_MASK))
+            client.sendClientKeyboardEvent((modifiers & CTRL_KEY_MASK) != 0 ? 
RfbConstants.KEY_DOWN : RfbConstants.KEY_UP, X11_KEY_CTRL, 0);
 
-               if((modifiers & META_KEY_MASK) != (lastModifierStates & 
META_KEY_MASK))
-                       client.sendClientKeyboardEvent((modifiers & 
META_KEY_MASK) != 0 ? RfbConstants.KEY_DOWN : RfbConstants.KEY_UP, 
X11_KEY_META, 0);
-               
-               if((modifiers & ALT_KEY_MASK) != (lastModifierStates & 
ALT_KEY_MASK))
-                       client.sendClientKeyboardEvent((modifiers & 
ALT_KEY_MASK) != 0 ? RfbConstants.KEY_DOWN : RfbConstants.KEY_UP, X11_KEY_ALT, 
0);
-               
-               lastModifierStates = modifiers;
-       }
-}
+        if((modifiers & META_KEY_MASK) != (lastModifierStates & META_KEY_MASK))
+            client.sendClientKeyboardEvent((modifiers & META_KEY_MASK) != 0 ? 
RfbConstants.KEY_DOWN : RfbConstants.KEY_UP, X11_KEY_META, 0);
+        
+        if((modifiers & ALT_KEY_MASK) != (lastModifierStates & ALT_KEY_MASK))
+            client.sendClientKeyboardEvent((modifiers & ALT_KEY_MASK) != 0 ? 
RfbConstants.KEY_DOWN : RfbConstants.KEY_UP, X11_KEY_ALT, 0);
+        
+        lastModifierStates = modifiers;
+    }
+}

Reply via email to