Skip to content

Commit d188534

Browse files
sanjaytripathirajesh-battala
authored andcommitted
CLOUDSTACK-4612: Specified locale keyboard language is not showing as default in consoleView passed during deployVM.
While deploying a VM, user passes the "keyboard" parameter to specify the default language for that VM but in the consoleView, the default language selected is en-us irrespective of the default language of the VM.
1 parent 295a87e commit d188534

7 files changed

Lines changed: 54 additions & 24 deletions

File tree

‎server/src/com/cloud/servlet/ConsoleProxyClientParam.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ConsoleProxyClientParam {
2626

2727
private String clientTunnelUrl;
2828
private String clientTunnelSession;
29-
29+
private String locale;
3030
private String ajaxSessionId;
3131

3232
public ConsoleProxyClientParam() {
@@ -97,6 +97,14 @@ public void setAjaxSessionId(String ajaxSessionId) {
9797
this.ajaxSessionId = ajaxSessionId;
9898
}
9999

100+
public String getLocale() {
101+
return this.locale;
102+
}
103+
104+
public void setLocale(String locale) {
105+
this.locale = locale;
106+
}
107+
100108
public String getClientMapKey() {
101109
if(clientTag != null && !clientTag.isEmpty())
102110
return clientTag;

‎server/src/com/cloud/servlet/ConsoleProxyServlet.java‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import com.cloud.vm.VMInstanceVO;
5656
import com.cloud.vm.VirtualMachine;
5757
import com.cloud.vm.VirtualMachineManager;
58+
import com.cloud.vm.dao.UserVmDetailsDaoImpl;
5859
import com.google.gson.Gson;
5960
import com.google.gson.GsonBuilder;
6061

@@ -74,7 +75,7 @@ public class ConsoleProxyServlet extends HttpServlet {
7475
@Inject VirtualMachineManager _vmMgr;
7576
@Inject ManagementServer _ms;
7677
@Inject IdentityService _identityService;
77-
78+
@Inject UserVmDetailsDaoImpl _userVmDetailsDaoImpl;
7879
static ManagementServer s_ms;
7980

8081
private Gson _gson = new GsonBuilder().create();
@@ -384,6 +385,7 @@ private String composeConsoleAccessUrl(String rootUrl, VMInstanceVO vm, HostVO h
384385

385386
Ternary<String, String, String> parsedHostInfo = parseHostInfo(portInfo.first());
386387

388+
Map<String, String> details = _userVmDetailsDaoImpl.findDetails(vm.getId());
387389
String sid = vm.getVncPassword();
388390
String tag = vm.getUuid();
389391
String ticket = genAccessTicket(host, String.valueOf(portInfo.second()), sid, tag);
@@ -394,6 +396,9 @@ private String composeConsoleAccessUrl(String rootUrl, VMInstanceVO vm, HostVO h
394396
param.setClientHostPassword(sid);
395397
param.setClientTag(tag);
396398
param.setTicket(ticket);
399+
if (details != null && details.containsKey("keyboard")) {
400+
param.setLocale(details.get("keyboard"));
401+
}
397402
if(parsedHostInfo.second() != null && parsedHostInfo.third() != null) {
398403
param.setClientTunnelUrl(parsedHostInfo.second());
399404
param.setClientTunnelSession(parsedHostInfo.third());

‎services/console-proxy/server/js/ajaxviewer.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ KeyboardMapper.prototype = {
332332
/////////////////////////////////////////////////////////////////////////////
333333
// class AjaxViewer
334334
//
335-
function AjaxViewer(panelId, imageUrl, updateUrl, tileMap, width, height, tileWidth, tileHeight) {
335+
function AjaxViewer(panelId, imageUrl, updateUrl, locale, tileMap, width, height, tileWidth, tileHeight) {
336336
// logging is disabled by default so that it won't have negative impact on performance
337337
// however, a back door key-sequence can trigger to open the logger window, it is designed to help
338338
// trouble-shooting
@@ -358,8 +358,11 @@ function AjaxViewer(panelId, imageUrl, updateUrl, tileMap, width, height, tileWi
358358
this.tileWidth = tileWidth;
359359
this.tileHeight = tileHeight;
360360
this.maxTileZIndex = 1;
361-
362-
this.currentKeyboard = AjaxViewer.KEYBOARD_TYPE_ENGLISH;
361+
362+
if (locale == AjaxViewer.KEYBOARD_TYPE_UK_ENGLISH || locale == AjaxViewer.KEYBOARD_TYPE_JAPANESE)
363+
this.currentKeyboard = locale;
364+
else
365+
this.currentKeyboard = AjaxViewer.KEYBOARD_TYPE_ENGLISH;
363366
this.keyboardMappers = [];
364367

365368
this.timer = 0;

‎services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyAjaxHandler.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ private void doHandle(HttpExchange t) throws Exception, IllegalArgumentException
7777
String eventStr = queryMap.get("event");
7878
String console_url = queryMap.get("consoleurl");
7979
String console_host_session = queryMap.get("sessionref");
80-
80+
String vm_locale = queryMap.get("locale");
81+
8182
if(tag == null)
8283
tag = "";
8384

@@ -124,7 +125,8 @@ private void doHandle(HttpExchange t) throws Exception, IllegalArgumentException
124125
param.setTicket(ticket);
125126
param.setClientTunnelUrl(console_url);
126127
param.setClientTunnelSession(console_host_session);
127-
128+
param.setLocale(vm_locale);
129+
128130
viewer = ConsoleProxy.getAjaxVncViewer(param, ajaxSessionIdStr);
129131
} catch(Exception e) {
130132

@@ -181,7 +183,7 @@ private void doHandle(HttpExchange t) throws Exception, IllegalArgumentException
181183
}
182184
}
183185
}
184-
186+
185187
private static String convertStreamToString(InputStream is, boolean closeStreamAfterRead) {
186188
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
187189
StringBuilder sb = new StringBuilder();

‎services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyClientBase.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.awt.Rectangle;
2121
import java.util.List;
2222

23+
import javassist.tools.web.Viewer;
24+
2325
import org.apache.log4j.Logger;
2426

2527
import com.cloud.consoleproxy.util.TileInfo;
@@ -283,11 +285,11 @@ public String onAjaxClientStart(String title, List<String> languages, String gue
283285
return getAjaxViewerPageContent(sbTileSequence.toString(), imgUrl,
284286
updateUrl, width, height, tileWidth, tileHeight, title,
285287
ConsoleProxy.keyboardType == ConsoleProxy.KEYBOARD_RAW,
286-
languages, guest);
288+
languages, guest, this.clientParam.getLocale());
287289
}
288290

289291
private String getAjaxViewerPageContent(String tileSequence, String imgUrl, String updateUrl, int width,
290-
int height, int tileWidth, int tileHeight, String title, boolean rawKeyboard, List<String> languages, String guest) {
292+
int height, int tileWidth, int tileHeight, String title, boolean rawKeyboard, List<String> languages, String guest, String locale) {
291293

292294
StringBuffer sbLanguages = new StringBuffer("");
293295
if(languages != null) {
@@ -342,7 +344,7 @@ private String getAjaxViewerPageContent(String tileSequence, String imgUrl, Stri
342344
"<script language=\"javascript\">",
343345
"var acceptLanguages = '" + sbLanguages.toString() + "';",
344346
"var tileMap = [ " + tileSequence + " ];",
345-
"var ajaxViewer = new AjaxViewer('main_panel', '" + imgUrl + "', '" + updateUrl + "', tileMap, ",
347+
"var ajaxViewer = new AjaxViewer('main_panel', '" + imgUrl + "', '" + updateUrl + "', '" + locale + "', tileMap, ",
346348
String.valueOf(width) + ", " + String.valueOf(height) + ", " + String.valueOf(tileWidth) + ", " + String.valueOf(tileHeight) + ");",
347349

348350
"$(function() {",

‎services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyClientParam.java‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ConsoleProxyClientParam {
3030

3131
private String clientTunnelUrl;
3232
private String clientTunnelSession;
33-
33+
private String locale;
3434
private String ajaxSessionId;
3535

3636
public ConsoleProxyClientParam() {
@@ -92,7 +92,7 @@ public String getClientTunnelSession() {
9292
public void setClientTunnelSession(String clientTunnelSession) {
9393
this.clientTunnelSession = clientTunnelSession;
9494
}
95-
95+
9696
public String getAjaxSessionId() {
9797
return this.ajaxSessionId;
9898
}
@@ -101,6 +101,14 @@ public void setAjaxSessionId(String ajaxSessionId) {
101101
this.ajaxSessionId = ajaxSessionId;
102102
}
103103

104+
public String getLocale() {
105+
return this.locale;
106+
}
107+
108+
public void setLocale(String locale) {
109+
this.locale = locale;
110+
}
111+
104112
public String getClientMapKey() {
105113
if(clientTag != null && !clientTag.isEmpty())
106114
return clientTag;

‎services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxyHttpHandlerHelper.java‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,24 @@ public static Map<String, String> getQueryMap(String query) {
6969
map.put("sessionref", param.getClientTunnelSession());
7070
if(param.getTicket() != null)
7171
map.put("ticket", param.getTicket());
72+
if(param.getLocale() != null)
73+
map.put("locale", param.getLocale());
7274
}
7375
} else {
74-
// we no longer accept information from parameter other than token
75-
guardUserInput(map);
76+
// we no longer accept information from parameter other than token
77+
guardUserInput(map);
7678
}
77-
7879
return map;
7980
}
80-
81+
8182
private static void guardUserInput(Map<String, String> map) {
82-
map.remove("host");
83-
map.remove("port");
84-
map.remove("tag");
85-
map.remove("sid");
86-
map.remove("consoleurl");
87-
map.remove("sessionref");
88-
map.remove("ticket");
83+
map.remove("host");
84+
map.remove("port");
85+
map.remove("tag");
86+
map.remove("sid");
87+
map.remove("consoleurl");
88+
map.remove("sessionref");
89+
map.remove("ticket");
90+
map.remove("locale");
8991
}
9092
}

0 commit comments

Comments
 (0)