mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 05:07:41 +00:00
Merge branch 'multi-protocol-refactor' into releases/0.3.0
This commit is contained in:
@@ -20,9 +20,9 @@ package net.sourceforge.guacamole;
|
||||
*/
|
||||
|
||||
import net.sourceforge.guacamole.instruction.Instruction;
|
||||
import net.sourceforge.guacamole.net.GuacamoleException;
|
||||
import net.sourceforge.guacamole.vnc.event.KeyEvent;
|
||||
import net.sourceforge.guacamole.vnc.event.PointerEvent;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.event.KeyEvent;
|
||||
import net.sourceforge.guacamole.event.PointerEvent;
|
||||
|
||||
public abstract class Client {
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
|
||||
package net.sourceforge.guacamole.net;
|
||||
package net.sourceforge.guacamole;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
@@ -1,5 +1,5 @@
|
||||
|
||||
package net.sourceforge.guacamole.vnc.event;
|
||||
package net.sourceforge.guacamole.event;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
@@ -1,5 +1,5 @@
|
||||
|
||||
package net.sourceforge.guacamole.vnc.event;
|
||||
package net.sourceforge.guacamole.event;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
@@ -1,5 +1,5 @@
|
||||
|
||||
package net.sourceforge.guacamole.vnc.event;
|
||||
package net.sourceforge.guacamole.event;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
@@ -1,4 +1,4 @@
|
||||
package net.sourceforge.guacamole.vnc.event;
|
||||
package net.sourceforge.guacamole.event;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
@@ -1,4 +1,4 @@
|
||||
package net.sourceforge.guacamole.vnc.event;
|
||||
package net.sourceforge.guacamole.event;
|
||||
|
||||
/*
|
||||
* Guacamole - Pure JavaScript/HTML VNC Client
|
@@ -27,8 +27,7 @@ import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import net.sourceforge.guacamole.vnc.VNCException;
|
||||
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
|
||||
public class PNGImage {
|
||||
|
||||
@@ -36,7 +35,7 @@ public class PNGImage {
|
||||
private int height;
|
||||
private byte[] data;
|
||||
|
||||
public PNGImage(BufferedImage image) throws VNCException {
|
||||
public PNGImage(BufferedImage image) throws GuacamoleException {
|
||||
|
||||
width = image.getWidth();
|
||||
height = image.getHeight();
|
||||
@@ -48,7 +47,7 @@ public class PNGImage {
|
||||
bos.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new VNCException("I/O Error while creating PNG.", e);
|
||||
throw new GuacamoleException("I/O Error while creating PNG.", e);
|
||||
}
|
||||
|
||||
data = bos.toByteArray();
|
||||
@@ -66,13 +65,13 @@ public class PNGImage {
|
||||
return width;
|
||||
}
|
||||
|
||||
private static void writeImage(BufferedImage image, OutputStream outputStream) throws VNCException, IOException {
|
||||
private static void writeImage(BufferedImage image, OutputStream outputStream) throws GuacamoleException, IOException {
|
||||
|
||||
// Obtain list of image writers
|
||||
// If no such writers exist, fail with error, exit.
|
||||
Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType("image/png");
|
||||
if (!writers.hasNext())
|
||||
throw new VNCException("No useful image writers found.");
|
||||
throw new GuacamoleException("No useful image writers found.");
|
||||
|
||||
// Obtain JPEG writer
|
||||
ImageWriter imageWriter = writers.next();
|
||||
|
@@ -20,6 +20,7 @@ package net.sourceforge.guacamole.net;
|
||||
*/
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
|
||||
public abstract class Configuration {
|
||||
|
||||
|
@@ -20,31 +20,26 @@ package net.sourceforge.guacamole.net;
|
||||
*/
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
|
||||
public class GuacamoleConfiguration extends Configuration {
|
||||
|
||||
private String hostname;
|
||||
private int port;
|
||||
private String password;
|
||||
private int outputBPP;
|
||||
private boolean compressStream;
|
||||
private String protocol;
|
||||
|
||||
public GuacamoleConfiguration(ServletContext context) throws GuacamoleException {
|
||||
|
||||
super(context);
|
||||
|
||||
hostname = readParameter("host", null);
|
||||
port = readIntParameter("port", null);
|
||||
password = context.getInitParameter("password");
|
||||
outputBPP = readIntParameter("output-bpp", 8, 8, 24);
|
||||
compressStream = readBooleanParameter("compress-stream", false);
|
||||
protocol = readParameter("protocol", "vnc", "vnc");
|
||||
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public int getOutputBPP() {
|
||||
return outputBPP;
|
||||
}
|
||||
@@ -53,12 +48,12 @@ public class GuacamoleConfiguration extends Configuration {
|
||||
return password;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public boolean getCompressStream() {
|
||||
return compressStream;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,7 +24,7 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import net.sourceforge.guacamole.vnc.VNCException;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
|
||||
public abstract class GuacamoleServlet extends HttpServlet {
|
||||
|
||||
|
@@ -25,6 +25,10 @@ import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpSessionBindingEvent;
|
||||
import javax.servlet.http.HttpSessionBindingListener;
|
||||
import net.sourceforge.guacamole.Client;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.instruction.Instruction;
|
||||
import net.sourceforge.guacamole.event.KeyEvent;
|
||||
import net.sourceforge.guacamole.event.PointerEvent;
|
||||
import net.sourceforge.guacamole.vnc.VNCClient;
|
||||
import net.sourceforge.guacamole.vnc.VNCConfiguration;
|
||||
import net.sourceforge.guacamole.vnc.VNCException;
|
||||
@@ -36,10 +40,12 @@ public class GuacamoleSession {
|
||||
private Client client;
|
||||
private ReentrantLock instructionStreamLock;
|
||||
|
||||
private class SessionVNCClient extends VNCClient implements HttpSessionBindingListener {
|
||||
private class SessionClient extends Client implements HttpSessionBindingListener {
|
||||
|
||||
public SessionVNCClient(String host, int port, String password, int colorBits, int outputBPP) throws VNCException {
|
||||
super(host, port, password, colorBits, outputBPP);
|
||||
private Client client;
|
||||
|
||||
public SessionClient(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void valueBound(HttpSessionBindingEvent event) {
|
||||
@@ -55,6 +61,26 @@ public class GuacamoleSession {
|
||||
}
|
||||
}
|
||||
|
||||
public void send(KeyEvent event) throws GuacamoleException {
|
||||
client.send(event);
|
||||
}
|
||||
|
||||
public void send(PointerEvent event) throws GuacamoleException {
|
||||
client.send(event);
|
||||
}
|
||||
|
||||
public void setClipboard(String clipboard) throws GuacamoleException {
|
||||
client.setClipboard(clipboard);
|
||||
}
|
||||
|
||||
public void disconnect() throws GuacamoleException {
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
public Instruction nextInstruction(boolean blocking) throws GuacamoleException {
|
||||
return client.nextInstruction(blocking);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public GuacamoleSession(HttpSession session) throws GuacamoleException {
|
||||
@@ -80,24 +106,35 @@ public class GuacamoleSession {
|
||||
if (client != null)
|
||||
client.disconnect();
|
||||
|
||||
// Connect to VNC server
|
||||
try {
|
||||
|
||||
// Read VNC-specific parameters
|
||||
ServletContext context = session.getServletContext();
|
||||
VNCConfiguration vncconfig = new VNCConfiguration(context);
|
||||
String protocol = config.getProtocol();
|
||||
if (protocol.equals("vnc")) {
|
||||
|
||||
// Connect to VNC server
|
||||
try {
|
||||
|
||||
// Read VNC-specific parameters
|
||||
ServletContext context = session.getServletContext();
|
||||
VNCConfiguration vncconfig = new VNCConfiguration(context);
|
||||
|
||||
client = new SessionClient(
|
||||
new VNCClient(
|
||||
vncconfig.getHostname(),
|
||||
vncconfig.getPort(),
|
||||
vncconfig.getPassword(),
|
||||
vncconfig.getBPP(),
|
||||
config.getOutputBPP()
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
catch (VNCException e) {
|
||||
throw new GuacamoleException(e);
|
||||
}
|
||||
|
||||
client = new SessionVNCClient(
|
||||
config.getHostname(),
|
||||
config.getPort(),
|
||||
vncconfig.getPassword(),
|
||||
vncconfig.getBPP(),
|
||||
config.getOutputBPP()
|
||||
);
|
||||
}
|
||||
catch (VNCException e) {
|
||||
throw new GuacamoleException(e);
|
||||
}
|
||||
else
|
||||
throw new GuacamoleException("Unsupported protocol: " + protocol);
|
||||
|
||||
session.setAttribute("CLIENT", client);
|
||||
|
||||
|
@@ -36,6 +36,7 @@ import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import net.sourceforge.guacamole.Client;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
@@ -23,7 +23,7 @@ import javax.servlet.ServletRequest;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
|
||||
import net.sourceforge.guacamole.net.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||
|
||||
public class Connect extends XMLGuacamoleServlet {
|
||||
|
@@ -23,7 +23,7 @@ import javax.servlet.ServletRequest;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
|
||||
import net.sourceforge.guacamole.net.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||
|
||||
public class Disconnect extends XMLGuacamoleServlet {
|
||||
|
@@ -20,7 +20,7 @@ package net.sourceforge.guacamole.net.input;
|
||||
*/
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import net.sourceforge.guacamole.net.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||
|
@@ -20,9 +20,9 @@ package net.sourceforge.guacamole.net.input;
|
||||
*/
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import net.sourceforge.guacamole.net.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import org.w3c.dom.Element;
|
||||
import net.sourceforge.guacamole.vnc.event.KeyEvent;
|
||||
import net.sourceforge.guacamole.event.KeyEvent;
|
||||
|
||||
import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||
import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
|
||||
|
@@ -19,9 +19,9 @@ package net.sourceforge.guacamole.net.input;
|
||||
*/
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import net.sourceforge.guacamole.net.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import org.w3c.dom.Element;
|
||||
import net.sourceforge.guacamole.vnc.event.PointerEvent;
|
||||
import net.sourceforge.guacamole.event.PointerEvent;
|
||||
|
||||
import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||
import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
|
||||
|
@@ -29,7 +29,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import net.sourceforge.guacamole.Client;
|
||||
import net.sourceforge.guacamole.net.GuacamoleServlet;
|
||||
import net.sourceforge.guacamole.net.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import net.sourceforge.guacamole.net.GuacamoleSession;
|
||||
import net.sourceforge.guacamole.instruction.Instruction;
|
||||
import net.sourceforge.guacamole.instruction.ErrorInstruction;
|
||||
|
Binary file not shown.
@@ -22,10 +22,10 @@ import java.awt.image.WritableRaster;
|
||||
import net.sourceforge.guacamole.instruction.framebuffer.PNGInstruction;
|
||||
import net.sourceforge.guacamole.instruction.framebuffer.CursorInstruction;
|
||||
import net.sourceforge.guacamole.instruction.framebuffer.CopyRectInstruction;
|
||||
import net.sourceforge.guacamole.vnc.event.PointerEvent;
|
||||
import net.sourceforge.guacamole.vnc.event.EventQueue;
|
||||
import net.sourceforge.guacamole.vnc.event.KeyEvent;
|
||||
import net.sourceforge.guacamole.vnc.event.EventHandler;
|
||||
import net.sourceforge.guacamole.event.PointerEvent;
|
||||
import net.sourceforge.guacamole.event.EventQueue;
|
||||
import net.sourceforge.guacamole.event.KeyEvent;
|
||||
import net.sourceforge.guacamole.event.EventHandler;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
@@ -58,7 +58,7 @@ import net.sourceforge.guacamole.instruction.Instruction;
|
||||
import net.sourceforge.guacamole.instruction.NameInstruction;
|
||||
import net.sourceforge.guacamole.instruction.SizeInstruction;
|
||||
import net.sourceforge.guacamole.instruction.framebuffer.PNGImage;
|
||||
import net.sourceforge.guacamole.net.GuacamoleException;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
|
||||
public class VNCClient extends Client {
|
||||
|
||||
@@ -355,7 +355,7 @@ public class VNCClient extends Client {
|
||||
|
||||
|
||||
// Handles all messages, blocking until at least one message is read if desired.
|
||||
private void handleMessages(boolean blocking) throws IOException, VNCException {
|
||||
private void handleMessages(boolean blocking) throws IOException, VNCException, GuacamoleException {
|
||||
|
||||
synchronized (input) {
|
||||
|
||||
@@ -414,7 +414,7 @@ public class VNCClient extends Client {
|
||||
|
||||
}
|
||||
|
||||
private void handleFramebufferUpdate() throws IOException, VNCException {
|
||||
private void handleFramebufferUpdate() throws IOException, VNCException, GuacamoleException {
|
||||
|
||||
input.read(); // Padding
|
||||
int numberOfRectangles = input.readUnsignedShort();
|
||||
|
@@ -19,11 +19,14 @@ package net.sourceforge.guacamole.vnc;
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import net.sourceforge.guacamole.net.*;
|
||||
import net.sourceforge.guacamole.net.Configuration;
|
||||
import net.sourceforge.guacamole.GuacamoleException;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
public class VNCConfiguration extends Configuration {
|
||||
|
||||
private String hostname;
|
||||
private int port;
|
||||
private String password;
|
||||
private int bpp;
|
||||
|
||||
@@ -31,6 +34,8 @@ public class VNCConfiguration extends Configuration {
|
||||
|
||||
super(context);
|
||||
|
||||
hostname = readParameter("host", null);
|
||||
port = readIntParameter("port", null);
|
||||
password = context.getInitParameter("password");
|
||||
bpp = readIntParameter("bpp", 24, 8, 16, 24);
|
||||
|
||||
@@ -44,4 +49,12 @@ public class VNCConfiguration extends Configuration {
|
||||
return password;
|
||||
}
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user