guacamole-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmuehl...@apache.org
Subject [19/51] [abbrv] incubator-guacamole-client git commit: GUACAMOLE-1: Rename Basic* classes sensibly. Refactor tunnel classes into own packages.
Date Tue, 29 Mar 2016 04:20:28 GMT
http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/713fc7f8/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java
b/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java
deleted file mode 100644
index 2927584..0000000
--- a/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/GuacamoleWebSocketTunnelServlet.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (C) 2013 Glyptodon LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package org.apache.guacamole.websocket.tomcat;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-import org.apache.guacamole.GuacamoleException;
-import org.apache.guacamole.io.GuacamoleReader;
-import org.apache.guacamole.io.GuacamoleWriter;
-import org.apache.guacamole.net.GuacamoleTunnel;
-import org.apache.catalina.websocket.StreamInbound;
-import org.apache.catalina.websocket.WebSocketServlet;
-import org.apache.catalina.websocket.WsOutbound;
-import org.apache.guacamole.GuacamoleClientException;
-import org.apache.guacamole.GuacamoleConnectionClosedException;
-import org.apache.guacamole.HTTPTunnelRequest;
-import org.apache.guacamole.TunnelRequest;
-import org.apache.guacamole.protocol.GuacamoleStatus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A WebSocketServlet partial re-implementation of GuacamoleTunnelServlet.
- *
- * @author Michael Jumper
- */
-public abstract class GuacamoleWebSocketTunnelServlet extends WebSocketServlet {
-
-    /**
-     * The default, minimum buffer size for instructions.
-     */
-    private static final int BUFFER_SIZE = 8192;
-
-    /**
-     * Logger for this class.
-     */
-    private final Logger logger = LoggerFactory.getLogger(GuacamoleWebSocketTunnelServlet.class);
-
-    /**
-     * Sends the given status on the given WebSocket connection and closes the
-     * connection.
-     *
-     * @param outbound The outbound WebSocket connection to close.
-     * @param guac_status The status to send.
-     */
-    public void closeConnection(WsOutbound outbound, GuacamoleStatus guac_status) {
-
-        try {
-            byte[] message = Integer.toString(guac_status.getGuacamoleStatusCode()).getBytes("UTF-8");
-            outbound.close(guac_status.getWebSocketCode(), ByteBuffer.wrap(message));
-        }
-        catch (IOException e) {
-            logger.debug("Unable to close WebSocket tunnel.", e);
-        }
-
-    }
-
-    @Override
-    protected String selectSubProtocol(List<String> subProtocols) {
-
-        // Search for expected protocol
-        for (String protocol : subProtocols)
-            if ("guacamole".equals(protocol))
-                return "guacamole";
-        
-        // Otherwise, fail
-        return null;
-
-    }
-
-    @Override
-    public StreamInbound createWebSocketInbound(String protocol,
-            HttpServletRequest request) {
-
-        final TunnelRequest tunnelRequest = new HTTPTunnelRequest(request);
-
-        // Return new WebSocket which communicates through tunnel
-        return new StreamInbound() {
-
-            /**
-             * The GuacamoleTunnel associated with the connected WebSocket. If
-             * the WebSocket has not yet been connected, this will be null.
-             */
-            private GuacamoleTunnel tunnel = null;
-
-            @Override
-            protected void onTextData(Reader reader) throws IOException {
-
-                // Ignore inbound messages if there is no associated tunnel
-                if (tunnel == null)
-                    return;
-
-                GuacamoleWriter writer = tunnel.acquireWriter();
-
-                // Write all available data
-                try {
-
-                    char[] buffer = new char[BUFFER_SIZE];
-
-                    int num_read;
-                    while ((num_read = reader.read(buffer)) > 0)
-                        writer.write(buffer, 0, num_read);
-
-                }
-                catch (GuacamoleConnectionClosedException e) {
-                    logger.debug("Connection to guacd closed.", e);
-                }
-                catch (GuacamoleException e) {
-                    logger.debug("WebSocket tunnel write failed.", e);
-                }
-
-                tunnel.releaseWriter();
-            }
-
-            @Override
-            public void onOpen(final WsOutbound outbound) {
-
-                try {
-                    tunnel = doConnect(tunnelRequest);
-                }
-                catch (GuacamoleException e) {
-                    logger.error("Creation of WebSocket tunnel to guacd failed: {}", e.getMessage());
-                    logger.debug("Error connecting WebSocket tunnel.", e);
-                    closeConnection(outbound, e.getStatus());
-                    return;
-                }
-
-                // Do not start connection if tunnel does not exist
-                if (tunnel == null) {
-                    closeConnection(outbound, GuacamoleStatus.RESOURCE_NOT_FOUND);
-                    return;
-                }
-
-                Thread readThread = new Thread() {
-
-                    @Override
-                    public void run() {
-
-                        StringBuilder buffer = new StringBuilder(BUFFER_SIZE);
-                        GuacamoleReader reader = tunnel.acquireReader();
-                        char[] readMessage;
-
-                        try {
-
-                            try {
-
-                                // Attempt to read
-                                while ((readMessage = reader.read()) != null) {
-
-                                    // Buffer message
-                                    buffer.append(readMessage);
-
-                                    // Flush if we expect to wait or buffer is getting full
-                                    if (!reader.available() || buffer.length() >= BUFFER_SIZE)
{
-                                        outbound.writeTextMessage(CharBuffer.wrap(buffer));
-                                        buffer.setLength(0);
-                                    }
-
-                                }
-
-                                // No more data
-                                closeConnection(outbound, GuacamoleStatus.SUCCESS);
-
-                            }
-
-                            // Catch any thrown guacamole exception and attempt
-                            // to pass within the WebSocket connection, logging
-                            // each error appropriately.
-                            catch (GuacamoleClientException e) {
-                                logger.info("WebSocket connection terminated: {}", e.getMessage());
-                                logger.debug("WebSocket connection terminated due to client
error.", e);
-                                closeConnection(outbound, e.getStatus());
-                            }
-                            catch (GuacamoleConnectionClosedException e) {
-                                logger.debug("Connection to guacd closed.", e);
-                                closeConnection(outbound, GuacamoleStatus.SUCCESS);
-                            }
-                            catch (GuacamoleException e) {
-                                logger.error("Connection to guacd terminated abnormally:
{}", e.getMessage());
-                                logger.debug("Internal error during connection to guacd.",
e);
-                                closeConnection(outbound, e.getStatus());
-                            }
-
-                        }
-                        catch (IOException e) {
-                            logger.debug("I/O error prevents further reads.", e);
-                        }
-
-                    }
-
-                };
-
-                readThread.start();
-
-            }
-
-            @Override
-            public void onClose(int i) {
-                try {
-                    if (tunnel != null)
-                        tunnel.close();
-                }
-                catch (GuacamoleException e) {
-                    logger.debug("Unable to close connection to guacd.", e);
-                }
-            }
-
-            @Override
-            protected void onBinaryData(InputStream in) throws IOException {
-                throw new UnsupportedOperationException("Not supported yet.");
-            }
-
-        };
-
-    }
-
-    /**
-     * Called whenever the JavaScript Guacamole client makes a connection
-     * request. It it up to the implementor of this function to define what
-     * conditions must be met for a tunnel to be configured and returned as a
-     * result of this connection request (whether some sort of credentials must
-     * be specified, for example).
-     *
-     * @param request
-     *     The TunnelRequest associated with the connection request received.
-     *     Any parameters specified along with the connection request can be
-     *     read from this object.
-     *
-     * @return
-     *     A newly constructed GuacamoleTunnel if successful, null otherwise.
-     *
-     * @throws GuacamoleException
-     *     If an error occurs while constructing the GuacamoleTunnel, or if the
-     *     conditions required for connection are not met.
-     */
-    protected abstract GuacamoleTunnel doConnect(TunnelRequest request)
-            throws GuacamoleException;
-
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/713fc7f8/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/WebSocketTunnelModule.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/WebSocketTunnelModule.java
b/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/WebSocketTunnelModule.java
deleted file mode 100644
index 85caf1b..0000000
--- a/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/WebSocketTunnelModule.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2014 Glyptodon LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package org.apache.guacamole.websocket.tomcat;
-
-import com.google.inject.servlet.ServletModule;
-import org.apache.guacamole.TunnelLoader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Loads the Jetty 9 WebSocket tunnel implementation.
- * 
- * @author Michael Jumper
- */
-public class WebSocketTunnelModule extends ServletModule implements TunnelLoader {
-
-    /**
-     * Logger for this class.
-     */
-    private final Logger logger = LoggerFactory.getLogger(WebSocketTunnelModule.class);
-
-    @Override
-    public boolean isSupported() {
-
-        try {
-
-            // Attempt to find WebSocket servlet
-            Class.forName("org.apache.guacamole.websocket.tomcat.BasicGuacamoleWebSocketTunnelServlet");
-
-            // Support found
-            return true;
-
-        }
-
-        // If no such servlet class, this particular WebSocket support
-        // is not present
-        catch (ClassNotFoundException e) {}
-        catch (NoClassDefFoundError e) {}
-
-        // Support not found
-        return false;
-        
-    }
-    
-    @Override
-    public void configureServlets() {
-
-        logger.info("Loading Tomcat 7 WebSocket support...");
-        serve("/websocket-tunnel").with(BasicGuacamoleWebSocketTunnelServlet.class);
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/713fc7f8/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/package-info.java
----------------------------------------------------------------------
diff --git a/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/package-info.java
b/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/package-info.java
deleted file mode 100644
index 7083a3e..0000000
--- a/guacamole/src/main/java/org/apache/guacamole/websocket/tomcat/package-info.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2013 Glyptodon LLC
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-/**
- * Tomcat WebSocket tunnel implementation. The classes here require at least
- * Tomcat 7.0, and may change significantly as there is no common WebSocket
- * API for Java yet.
- */
-package org.apache.guacamole.websocket.tomcat;
-

http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/713fc7f8/guacamole/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/WEB-INF/web.xml b/guacamole/src/main/webapp/WEB-INF/web.xml
index 6e105f8..b268197 100644
--- a/guacamole/src/main/webapp/WEB-INF/web.xml
+++ b/guacamole/src/main/webapp/WEB-INF/web.xml
@@ -42,7 +42,7 @@
     </filter-mapping>
 
     <listener>
-        <listener-class>org.apache.guacamole.BasicServletContextListener</listener-class>
+        <listener-class>org.apache.guacamole.GuacamoleServletContextListener</listener-class>
     </listener>
 
     <!-- Audio file mimetype mappings -->


Mime
View raw message