1 package net.sourceforge.guacamole.net.basic;
4 * Guacamole - Clientless Remote Desktop
5 * Copyright (C) 2010 Michael Jumper
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import java.lang.reflect.InvocationTargetException;
22 import java.lang.reflect.Method;
23 import javax.servlet.Servlet;
24 import javax.servlet.ServletContext;
25 import javax.servlet.ServletContextEvent;
26 import javax.servlet.ServletContextListener;
27 import net.sourceforge.guacamole.GuacamoleException;
30 * Simple HttpServlet which outputs XML containing a list of all authorized
31 * configurations for the current user.
33 * @author Michael Jumper
35 public class WebSocketSupportLoader implements ServletContextListener {
38 public void contextDestroyed(ServletContextEvent sce) {
42 public void contextInitialized(ServletContextEvent sce) {
46 // Attempt to find WebSocket servlet
47 Class<Servlet> servlet = (Class<Servlet>) GuacamoleClassLoader.getInstance().findClass(
48 "net.sourceforge.guacamole.net.basic.BasicGuacamoleTunnelServlet"
49 //"net.sourceforge.guacamole.net.basic.BasicGuacamoleWebSocketTunnelServlet"
52 // Dynamically add servlet IF SERVLET 3.0 API AVAILABLE!
55 // Get servlet registration class
56 Class regClass = Class.forName("javax.servlet.ServletRegistration");
58 // Get and invoke addServlet()
59 Method addServlet = ServletContext.class.getMethod("addServlet", String.class, Class.class);
60 Object reg = addServlet.invoke(sce.getServletContext(), "WebSocketTunnel", servlet);
62 // Get and invoke addMapping()
63 Method addMapping = regClass.getMethod("addMapping", String[].class);
64 addMapping.invoke(reg, (Object) new String[]{"/websocket-tunnel"});
66 // If we succesfully load and register the WebSocket tunnel servlet,
67 // WebSocket is supported.
68 System.err.println("WebSocket support found!");
71 catch (ClassNotFoundException e) {
72 // Servlet API 3.0 unsupported
73 System.err.println("Servlet API 3.0 not found.");
75 catch (NoSuchMethodException e) {
76 // Servlet API 3.0 unsupported
77 System.err.println("Servlet API 3.0 not found.");
79 catch (IllegalAccessException e) {
81 catch (InvocationTargetException e) {
85 catch (ClassNotFoundException e) {
87 // If no such servlet class, WebSocket support not present
88 System.err.println("WebSocket support not found.");
91 catch (GuacamoleException e) {