Skip to content

Commit 526043b

Browse files
CLOUDSTACK-4973: Specified keyboard language is not showing as default in consoleView passed during deployVM.
1 parent 029f4e3 commit 526043b

7 files changed

Lines changed: 55 additions & 26 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ConsoleProxyClientParam {
2323
private String clientHostPassword;
2424
private String clientTag;
2525
private String ticket;
26-
26+
private String locale;
2727
private String clientTunnelUrl;
2828
private String clientTunnelSession;
2929

@@ -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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@
5858
import com.cloud.utils.db.EntityManager;
5959
import com.cloud.utils.db.Transaction;
6060
import com.cloud.utils.db.TransactionLegacy;
61+
import com.cloud.vm.UserVmDetailVO;
6162
import com.cloud.vm.VirtualMachine;
6263
import com.cloud.vm.VirtualMachineManager;
63-
64+
import com.cloud.vm.dao.UserVmDetailsDao;
6465
/**
6566
* Thumbnail access : /console?cmd=thumbnail&vm=xxx&w=xxx&h=xxx
6667
* Console access : /conosole?cmd=access&vm=xxx
@@ -77,8 +78,8 @@ public class ConsoleProxyServlet extends HttpServlet {
7778
@Inject VirtualMachineManager _vmMgr;
7879
@Inject ManagementServer _ms;
7980
@Inject IdentityService _identityService;
80-
@Inject
81-
EntityManager _entityMgr;
81+
@Inject EntityManager _entityMgr;
82+
@Inject UserVmDetailsDao _userVmDetailsDao;
8283

8384
static ManagementServer s_ms;
8485

@@ -389,6 +390,7 @@ private String composeConsoleAccessUrl(String rootUrl, VirtualMachine vm, HostVO
389390

390391
Ternary<String, String, String> parsedHostInfo = parseHostInfo(portInfo.first());
391392

393+
UserVmDetailVO details = _userVmDetailsDao.findDetail(vm.getId(), "keyboard");
392394
String sid = vm.getVncPassword();
393395
String tag = vm.getUuid();
394396
String ticket = genAccessTicket(host, String.valueOf(portInfo.second()), sid, tag);
@@ -399,6 +401,9 @@ private String composeConsoleAccessUrl(String rootUrl, VirtualMachine vm, HostVO
399401
param.setClientHostPassword(sid);
400402
param.setClientTag(tag);
401403
param.setTicket(ticket);
404+
if (details != null) {
405+
param.setLocale(details.getValue());
406+
}
402407
if(parsedHostInfo.second() != null && parsedHostInfo.third() != null) {
403408
param.setClientTunnelUrl(parsedHostInfo.second());
404409
param.setClientTunnelSession(parsedHostInfo.third());

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

Lines changed: 4 additions & 2 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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ public String onAjaxClientStart(String title, List<String> languages, String gue
283283
return getAjaxViewerPageContent(sbTileSequence.toString(), imgUrl,
284284
updateUrl, width, height, tileWidth, tileHeight, title,
285285
ConsoleProxy.keyboardType == ConsoleProxy.KEYBOARD_RAW,
286-
languages, guest);
286+
languages, guest, this.clientParam.getLocale());
287287
}
288288

289289
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) {
290+
int height, int tileWidth, int tileHeight, String title, boolean rawKeyboard, List<String> languages, String guest, String locale) {
291291

292292
StringBuffer sbLanguages = new StringBuffer("");
293293
if(languages != null) {
@@ -342,7 +342,7 @@ private String getAjaxViewerPageContent(String tileSequence, String imgUrl, Stri
342342
"<script language=\"javascript\">",
343343
"var acceptLanguages = '" + sbLanguages.toString() + "';",
344344
"var tileMap = [ " + tileSequence + " ];",
345-
"var ajaxViewer = new AjaxViewer('main_panel', '" + imgUrl + "', '" + updateUrl + "', tileMap, ",
345+
"var ajaxViewer = new AjaxViewer('main_panel', '" + imgUrl + "', '" + updateUrl + "', '" + locale + "', tileMap, ",
346346
String.valueOf(width) + ", " + String.valueOf(height) + ", " + String.valueOf(tileWidth) + ", " + String.valueOf(tileHeight) + ");",
347347

348348
"$(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() {
@@ -96,11 +96,19 @@ public void setClientTunnelSession(String clientTunnelSession) {
9696
public String getAjaxSessionId() {
9797
return this.ajaxSessionId;
9898
}
99-
99+
100100
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
}

systemvm/js/ajaxviewer.js

Lines changed: 8 additions & 4 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,10 +358,14 @@ 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;
366+
363367
this.keyboardMappers = [];
364-
368+
365369
this.timer = 0;
366370
this.eventQueue = [];
367371
this.sendingEventInProgress = false;

0 commit comments

Comments
 (0)