Menu

Writing your own Guacamole application : Basic servlet

Help
2015-04-16
2015-04-17
  • beginnerGuac

    beginnerGuac - 2015-04-16

    Hi,
    I am following the tutorial Writing your own Guacamole application.
    How can i pass attributes in the "HttpServletRequest request" of the servlet "TutorialGuacamoleTunnelServlet" before creating the tunnel in the client?
    because i want to pass the protocol and the hostname from the html in the servlet request!

    ...
    <body>

        <!-- Guacamole -->
        <script type="text/javascript"
            src="guacamole-common-js/all.min.js"></script>
    
        <!-- Display -->
        <div id="display"></div>
    
        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */
    
            // Get display div from document
            var display = document.getElementById("display");
    

    //************
    //** I guess here
    //
    ***************

            // Instantiate client, using an HTTP tunnel for communications.
            var guac = new Guacamole.Client(
                new Guacamole.HTTPTunnel("tunnel")
            );
    
            // Add client to display div
            display.appendChild(guac.getDisplay().getElement());
    
            // Error handler
            guac.onerror = function(error) {
                alert(error);
            };
    
            // Connect
            guac.connect();
    
            // Disconnect on close
            window.onunload = function() {
                guac.disconnect();
            }
    
        /* ]]> */ </script>
    
    </body>
    ...
    
     

    Last edit: beginnerGuac 2015-04-16
  • beginnerGuac

    beginnerGuac - 2015-04-16

    i added this line :

        <!-- Guacamole -->
        <script type="text/javascript"
            src="guacamole-common-js/all.min.js"></script>
    
        <!-- Display -->
        <a href="test.html"></a>
        <div id="display"></div>
    
        <!-- Init -->
        <script type="text/javascript"> /* <![CDATA[ */
    
            // Get display div from document
            var display = document.getElementById("display");
    
            // Instantiate client, using an HTTP tunnel for communications.
            var tunnel = new Guacamole.HTTPTunnel("tunnel");
    

    // here
    tunnel.setAttribute("protocol","ssh");

            var guac = new Guacamole.Client(tunnel);
    
            // Add client to display div
            display.appendChild(guac.getDisplay().getElement());
    
            // Error handler
            guac.onerror = function(error) {
                alert(error);
            };
    
            // Connect
            guac.connect();
    
            // Disconnect on close
            window.onunload = function() {
                guac.disconnect();
            }
    
        </script>
    

    And in the servlet i added :
    String protocol = (String) request.getAttribute("protocol");

    but it doesn't work!

     
  • Michael Jumper

    Michael Jumper - 2015-04-16

    There is no setAttribute() on the JavaScript tunnel object, and attributes really aren't part of HTTP - they're specific to Java servlets. You can use them ... but not as a means of communicating with an HTTP client like the JavaScript HTTP tunnel.

    You want to use HTTP parameters. You access those via request.getParameter() within Java, and you can pass them to the tunnel via the connect() function: http://guac-dev.org/doc/guacamole-common-js/symbols/Guacamole.Tunnel.html#connect

    All current tunnel implementations for Guacamole accept data given to connect() in the form of URL encoded parameter/value pairs, separated by "&", just like a normal HTTP url. For example:

    tunnel.connect('protocol=ssh&thank=you');
    

    EDIT:

    ... and the Guacamole.Client object's connect() function provides the same mechanism, as it just invokes connect() on the underlying tunnel: http://guac-dev.org/doc/guacamole-common-js/symbols/Guacamole.Client.html#connect

     

    Last edit: Michael Jumper 2015-04-16
  • beginnerGuac

    beginnerGuac - 2015-04-17

    Thank you, it works.