I am making my own customized web application which is going to replace guacamole web application front end. I am following guacamole manual, according to that we required one index.html and another one is servlet which a class that extends GuacamoleHTTPTunnelServlet. index.html page takes credential for virtual machine to authenticate user and on the background it goes to guacamole server and do authentication and provide respective virtual machine if there is connection establish.
index.html
<!DOCTYPE HTML>
<html>
<head>
<title>Guacamole Tutorial</title>
</head>
<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");
// 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>
<p>Hello World</p>
</body>
<!-- Init -->
<script type="text/javascript"> /* <![CDATA[ */
...
// Mouse
var mouse = new Guacamole.Mouse(guac.getDisplay().getElement());
mouse.onmousedown =
mouse.onmouseup =
mouse.onmousemove = function(mouseState) {
guac.sendMouseState(mouseState);
};
// Keyboard
var keyboard = new Guacamole.Keyboard(document);
keyboard.onkeydown = function (keysym) {
guac.sendKeyEvent(1, keysym);
};
keyboard.onkeyup = function (keysym) {
guac.sendKeyEvent(0, keysym);
};
/* ]]> */ </script>
</html>
Servlet:The doConnect() function returns a GuacamoleTunnel, which provides a persistent communication channel for GuacamoleHTTPTunnelServlet to use when talking with guacd and initiating a connection with some arbitrary remote desktop using some arbitrary remote desktop protocol. In our simple tunnel, this configuration will be hard-coded, and no authentication will be attempted.
package org.apache.guacamole.net.example;
import javax.servlet.http.HttpServletRequest;
import org.apache.guacamole.GuacamoleException;
import org.apache.guacamole.net.GuacamoleSocket;
import org.apache.guacamole.net.GuacamoleTunnel;
import org.apache.guacamole.net.InetGuacamoleSocket;
import org.apache.guacamole.net.SimpleGuacamoleTunnel;
import org.apache.guacamole.protocol.ConfiguredGuacamoleSocket;
import org.apache.guacamole.protocol.GuacamoleConfiguration;
import org.apache.guacamole.servlet.GuacamoleHTTPTunnelServlet;
public class TutorialGuacamoleTunnelServlet
extends GuacamoleHTTPTunnelServlet {
@Override
protected GuacamoleTunnel doConnect(HttpServletRequest request)
throws GuacamoleException {
// Create our configuration
GuacamoleConfiguration config = new GuacamoleConfiguration();
config.setProtocol("vnc");
config.setParameter("hostname", "localhost");
config.setParameter("port", "5901");
config.setParameter("password", "potato");
// Connect to guacd - everything is hard-coded here.
GuacamoleSocket socket = new ConfiguredGuacamoleSocket(
new InetGuacamoleSocket("localhost", 4822),
config
);
// Return a new tunnel which uses the connected socket
return new SimpleGuacamoleTunnel(socket);;
}
}