Skip to content

Commit c854f28

Browse files
committed
minor changes
1 parent be8ae98 commit c854f28

42 files changed

Lines changed: 12408 additions & 254 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
181181
return;
182182
}
183183

184+
String websocketConsole = req.getParameter("websocketconsole");
185+
184186
if (cmd.equalsIgnoreCase("thumbnail")) {
185187
handleThumbnailRequest(req, resp, vmId);
186188
} else if (cmd.equalsIgnoreCase("access")) {
187-
handleAccessRequest(req, resp, vmId);
189+
handleAccessRequest(req, resp, vmId, Boolean.valueOf(websocketConsole));
188190
} else {
189191
handleAuthRequest(req, resp, vmId);
190192
}
@@ -245,8 +247,15 @@ private void handleThumbnailRequest(HttpServletRequest req, HttpServletResponse
245247
}
246248
}
247249

248-
private void handleAccessRequest(HttpServletRequest req, HttpServletResponse resp, long vmId) {
250+
private void handleAccessRequest(HttpServletRequest req, HttpServletResponse resp, long vmId,Boolean webSocketRequest) {
249251
VirtualMachine vm = _vmMgr.findById(vmId);
252+
253+
if (webSocketRequest == null){
254+
s_logger.warn("Websocket console paramter is null");
255+
sendResponse(resp, "");
256+
return;
257+
}
258+
250259
if (vm == null) {
251260
s_logger.warn("VM " + vmId + " does not exist, sending blank response for console access request");
252261
sendResponse(resp, "");
@@ -287,7 +296,7 @@ private void handleAccessRequest(HttpServletRequest req, HttpServletResponse res
287296
}
288297

289298
StringBuffer sb = new StringBuffer();
290-
sb.append("<html><title>").append(escapeHTML(vmName)).append("</title><frameset><frame src=\"").append(composeConsoleAccessUrl(rootUrl, vm, host));
299+
sb.append("<html><title>").append(escapeHTML(vmName)).append("</title><frameset><frame src=\"").append(composeConsoleAccessUrl(rootUrl, vm, host, webSocketRequest));
291300
sb.append("\"></frame></frameset></html>");
292301
s_logger.debug("the console url is :: " + sb.toString());
293302
sendResponse(resp, sb.toString());
@@ -414,7 +423,7 @@ private String composeThumbnailUrl(String rootUrl, VirtualMachine vm, HostVO hos
414423
return sb.toString();
415424
}
416425

417-
private String composeConsoleAccessUrl(String rootUrl, VirtualMachine vm, HostVO hostVo) {
426+
private String composeConsoleAccessUrl(String rootUrl, VirtualMachine vm, HostVO hostVo, Boolean webSocketRequest) {
418427
StringBuffer sb = new StringBuffer(rootUrl);
419428
String host = hostVo.getPrivateIpAddress();
420429

@@ -461,7 +470,12 @@ private String composeConsoleAccessUrl(String rootUrl, VirtualMachine vm, HostVO
461470
param.setClientTunnelSession(parsedHostInfo.third());
462471
}
463472

464-
sb.append("/ajax?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param));
473+
474+
if (webSocketRequest) {
475+
sb.append("/novnc/?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param));
476+
} else {
477+
sb.append("/ajax/?token=" + encryptor.encryptObject(ConsoleProxyClientParam.class, param));
478+
}
465479

466480
// for console access, we need guest OS type to help implement keyboard
467481
long guestOs = vm.getGuestOSId();
@@ -549,8 +563,7 @@ private boolean checkSessionPermision(HttpServletRequest req, long vmId, Account
549563
case ConsoleProxy:
550564
case SecondaryStorageVm:
551565
return false;
552-
553-
default:
566+
default:
554567
s_logger.warn("Unrecoginized virtual machine type, deny access by default. type: " + vm.getType());
555568
return false;
556569
}

services/console-proxy/server/pom.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>org.apache.cloudstack</groupId>
2525
<artifactId>cloudstack-service-console-proxy</artifactId>
26-
<version>4.11.0.0-SNAPSHOT</version>
26+
<version>4.10.0.0-SNAPSHOT</version>
2727
<relativePath>../pom.xml</relativePath>
2828
</parent>
2929
<dependencies>
@@ -49,6 +49,16 @@
4949
<artifactId>cloudstack-service-console-proxy-rdpclient</artifactId>
5050
<version>${project.version}</version>
5151
</dependency>
52+
<dependency>
53+
<groupId>org.eclipse.jetty</groupId>
54+
<artifactId>jetty-server</artifactId>
55+
<version>9.2.20.v20161216</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.eclipse.jetty.websocket</groupId>
59+
<artifactId>websocket-server</artifactId>
60+
<version>9.2.20.v20161216</version>
61+
</dependency>
5262
</dependencies>
5363
<build>
5464
<resources>
@@ -60,4 +70,4 @@
6070
</resource>
6171
</resources>
6272
</build>
63-
</project>
73+
</project>

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

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141

4242
import com.cloud.consoleproxy.util.Logger;
4343
import com.cloud.utils.PropertiesUtil;
44+
import org.eclipse.jetty.server.Handler;
45+
import org.eclipse.jetty.server.Server;
46+
import org.eclipse.jetty.server.handler.ContextHandler;
47+
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
4448

4549
/**
4650
*
@@ -345,27 +349,6 @@ public static void start(Properties conf) {
345349
cthread.start();
346350
}
347351

348-
private static void startupHttpMain() {
349-
try {
350-
ConsoleProxyServerFactory factory = getHttpServerFactory();
351-
if (factory == null) {
352-
s_logger.error("Unable to load HTTP server factory");
353-
System.exit(1);
354-
}
355-
356-
HttpServer server = factory.createHttpServerInstance(httpListenPort);
357-
server.createContext("/getscreen", new ConsoleProxyThumbnailHandler());
358-
server.createContext("/resource/", new ConsoleProxyResourceHandler());
359-
server.createContext("/ajax", new ConsoleProxyAjaxHandler());
360-
server.createContext("/ajaximg", new ConsoleProxyAjaxImageHandler());
361-
server.setExecutor(new ThreadExecutor()); // creates a default executor
362-
server.start();
363-
} catch (Exception e) {
364-
s_logger.error(e.getMessage(), e);
365-
System.exit(1);
366-
}
367-
}
368-
369352
private static void startupHttpCmdPort() {
370353
try {
371354
s_logger.info("Listening for HTTP CMDs on port " + httpCmdListenPort);
@@ -379,7 +362,61 @@ private static void startupHttpCmdPort() {
379362
}
380363
}
381364

382-
public static void main(String[] argv) {
365+
private static void startupHttpMain() {
366+
try {
367+
ConsoleProxyServerFactory factory = getHttpServerFactory();
368+
if (factory == null) {
369+
s_logger.error("Unable to load HTTP server factory");
370+
System.exit(1);
371+
}
372+
Server webServer = factory.
373+
createHttpServerInstance(httpListenPort);
374+
Handler[] handlerList = new Handler[6];
375+
ContextHandler contextHandlerForScreen = new ContextHandler();
376+
contextHandlerForScreen.setContextPath("/getscreen/");
377+
contextHandlerForScreen.setHandler(new ConsoleProxyThumbnailHandler());
378+
handlerList[0] = contextHandlerForScreen;
379+
380+
ContextHandler contextHandlerForResources = new ContextHandler();
381+
contextHandlerForScreen.setContextPath("/resource/");
382+
contextHandlerForScreen.setHandler(new ConsoleProxyResourceHandler());
383+
handlerList[1] = contextHandlerForResources;
384+
385+
386+
ContextHandler contextHandlerForAjax = new ContextHandler();
387+
contextHandlerForAjax.setContextPath("/ajax/");
388+
contextHandlerForAjax.setHandler(new ConsoleProxyAjaxHandler());
389+
handlerList[2] = contextHandlerForAjax;
390+
391+
392+
ContextHandler contextHandlerForAjaxImage = new ContextHandler();
393+
contextHandlerForAjaxImage.setContextPath("/ajaximg/");
394+
contextHandlerForAjaxImage.setHandler(new ConsoleProxyAjaxImageHandler());
395+
handlerList[3] = contextHandlerForAjaxImage;
396+
397+
398+
ContextHandler contextHandlerForNoVnc = new ContextHandler();
399+
contextHandlerForNoVnc.setContextPath("/novnc/");
400+
contextHandlerForNoVnc.setHandler(new NoVncConsoleHandler());
401+
handlerList[4] = contextHandlerForNoVnc;
402+
403+
404+
ContextHandler contextHandlerForWebSockify = new ContextHandler();
405+
contextHandlerForWebSockify.setContextPath("/websockify/");
406+
contextHandlerForWebSockify.setHandler(new WebSocketHandlerForNovnc());
407+
handlerList[5] = contextHandlerForWebSockify;
408+
409+
ContextHandlerCollection contexts = new ContextHandlerCollection();
410+
contexts.setHandlers(handlerList);
411+
webServer.setHandler(contexts);
412+
webServer.start();
413+
} catch (Exception e) {
414+
s_logger.error(" could not start webserver at " + httpListenPort, e);
415+
throw new RuntimeException("could not start webserver at " + httpListenPort);
416+
}
417+
}
418+
419+
public static void main(String[] argv) throws Exception {
383420
standaloneStart = true;
384421
configLog4j();
385422
Logger.setFactory(new ConsoleProxyLoggerFactory());

0 commit comments

Comments
 (0)