GUAC-878: Prefer WebSocket from JSR. Warn if HTTP used instead.

This commit is contained in:
Michael Jumper
2014-10-12 22:17:59 -07:00
parent 59356af44e
commit 115f647f7a
2 changed files with 45 additions and 2 deletions

View File

@@ -44,6 +44,10 @@ public class BasicGuacamoleTunnelServlet extends GuacamoleHTTPTunnelServlet {
@Override @Override
protected GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException { protected GuacamoleTunnel doConnect(HttpServletRequest request) throws GuacamoleException {
// Warn of lack of WebSocket
logger.warn("Using HTTP tunnel (not WebSocket). Performance may be sub-optimal.");
return BasicTunnelRequestUtility.createTunnel(new HTTPTunnelRequest(request)); return BasicTunnelRequestUtility.createTunnel(new HTTPTunnelRequest(request));
} }

View File

@@ -60,6 +60,39 @@ public class WebSocketSupportLoader implements ServletContextListener {
"org.glyptodon.guacamole.net.basic.websocket.tomcat.BasicGuacamoleWebSocketTunnelServlet" "org.glyptodon.guacamole.net.basic.websocket.tomcat.BasicGuacamoleWebSocketTunnelServlet"
}; };
/**
* Checks for JSR 356 support, returning true if such support is found, and
* false otherwise.
*
* @return true if support for JSR 356 is found, false otherwise.
*/
private boolean implementsJSR_356() {
try {
// Attempt to find WebSocket servlet
GuacamoleClassLoader.getInstance().findClass("javax.websocket.Endpoint");
// JSR 356 found
return true;
}
// If no such servlet class, this particular WebSocket support
// is not present
catch (ClassNotFoundException e) {}
catch (NoClassDefFoundError e) {}
// Log all GuacamoleExceptions
catch (GuacamoleException e) {
logger.error("Unable to load/detect WebSocket support.", e);
}
// JSR 356 not found
return false;
}
private boolean loadWebSocketTunnel(ServletContext context, String classname) { private boolean loadWebSocketTunnel(ServletContext context, String classname) {
try { try {
@@ -129,6 +162,12 @@ public class WebSocketSupportLoader implements ServletContextListener {
@Override @Override
public void contextInitialized(ServletContextEvent sce) { public void contextInitialized(ServletContextEvent sce) {
// Check for JSR 356 support
if (implementsJSR_356()) {
logger.info("JSR-356 WebSocket support present.");
return;
}
// Try to load each WebSocket tunnel in sequence // Try to load each WebSocket tunnel in sequence
for (String classname : WEBSOCKET_CLASSES) { for (String classname : WEBSOCKET_CLASSES) {
if (loadWebSocketTunnel(sce.getServletContext(), classname)) { if (loadWebSocketTunnel(sce.getServletContext(), classname)) {
@@ -137,8 +176,8 @@ public class WebSocketSupportLoader implements ServletContextListener {
} }
} }
// No legacy WebSocket support found (usually good) // Warn of lack of WebSocket
logger.debug("Legacy WebSocket support NOT loaded."); logger.debug("WebSocket support NOT present. Only HTTP will be used.");
} }