Merge branch 'zhangmaike/multi-protocol-refactor' into tickets/35

This commit is contained in:
Michael Jumper
2010-06-28 20:12:53 -07:00
21 changed files with 108 additions and 62 deletions

View File

@@ -20,9 +20,9 @@ package net.sourceforge.guacamole;
*/ */
import net.sourceforge.guacamole.instruction.Instruction; import net.sourceforge.guacamole.instruction.Instruction;
import net.sourceforge.guacamole.net.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.vnc.event.KeyEvent; import net.sourceforge.guacamole.event.KeyEvent;
import net.sourceforge.guacamole.vnc.event.PointerEvent; import net.sourceforge.guacamole.event.PointerEvent;
public abstract class Client { public abstract class Client {

View File

@@ -1,5 +1,5 @@
package net.sourceforge.guacamole.net; package net.sourceforge.guacamole;
/* /*
* Guacamole - Pure JavaScript/HTML VNC Client * Guacamole - Pure JavaScript/HTML VNC Client

View File

@@ -1,5 +1,5 @@
package net.sourceforge.guacamole.vnc.event; package net.sourceforge.guacamole.event;
/* /*
* Guacamole - Pure JavaScript/HTML VNC Client * Guacamole - Pure JavaScript/HTML VNC Client

View File

@@ -1,5 +1,5 @@
package net.sourceforge.guacamole.vnc.event; package net.sourceforge.guacamole.event;
/* /*
* Guacamole - Pure JavaScript/HTML VNC Client * Guacamole - Pure JavaScript/HTML VNC Client

View File

@@ -1,5 +1,5 @@
package net.sourceforge.guacamole.vnc.event; package net.sourceforge.guacamole.event;
/* /*
* Guacamole - Pure JavaScript/HTML VNC Client * Guacamole - Pure JavaScript/HTML VNC Client

View File

@@ -1,4 +1,4 @@
package net.sourceforge.guacamole.vnc.event; package net.sourceforge.guacamole.event;
/* /*
* Guacamole - Pure JavaScript/HTML VNC Client * Guacamole - Pure JavaScript/HTML VNC Client

View File

@@ -1,4 +1,4 @@
package net.sourceforge.guacamole.vnc.event; package net.sourceforge.guacamole.event;
/* /*
* Guacamole - Pure JavaScript/HTML VNC Client * Guacamole - Pure JavaScript/HTML VNC Client

View File

@@ -27,8 +27,7 @@ import javax.imageio.IIOImage;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.imageio.ImageWriter; import javax.imageio.ImageWriter;
import javax.imageio.stream.ImageOutputStream; import javax.imageio.stream.ImageOutputStream;
import net.sourceforge.guacamole.vnc.VNCException; import net.sourceforge.guacamole.GuacamoleException;
public class PNGImage { public class PNGImage {
@@ -36,7 +35,7 @@ public class PNGImage {
private int height; private int height;
private byte[] data; private byte[] data;
public PNGImage(BufferedImage image) throws VNCException { public PNGImage(BufferedImage image) throws GuacamoleException {
width = image.getWidth(); width = image.getWidth();
height = image.getHeight(); height = image.getHeight();
@@ -48,7 +47,7 @@ public class PNGImage {
bos.flush(); bos.flush();
} }
catch (IOException e) { 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(); data = bos.toByteArray();
@@ -66,13 +65,13 @@ public class PNGImage {
return width; 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 // Obtain list of image writers
// If no such writers exist, fail with error, exit. // If no such writers exist, fail with error, exit.
Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType("image/png"); Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType("image/png");
if (!writers.hasNext()) if (!writers.hasNext())
throw new VNCException("No useful image writers found."); throw new GuacamoleException("No useful image writers found.");
// Obtain JPEG writer // Obtain JPEG writer
ImageWriter imageWriter = writers.next(); ImageWriter imageWriter = writers.next();

View File

@@ -20,6 +20,7 @@ package net.sourceforge.guacamole.net;
*/ */
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import net.sourceforge.guacamole.GuacamoleException;
public abstract class Configuration { public abstract class Configuration {

View File

@@ -20,31 +20,26 @@ package net.sourceforge.guacamole.net;
*/ */
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import net.sourceforge.guacamole.GuacamoleException;
public class GuacamoleConfiguration extends Configuration { public class GuacamoleConfiguration extends Configuration {
private String hostname;
private int port;
private String password; private String password;
private int outputBPP; private int outputBPP;
private boolean compressStream; private boolean compressStream;
private String protocol;
public GuacamoleConfiguration(ServletContext context) throws GuacamoleException { public GuacamoleConfiguration(ServletContext context) throws GuacamoleException {
super(context); super(context);
hostname = readParameter("host", null);
port = readIntParameter("port", null);
password = context.getInitParameter("password"); password = context.getInitParameter("password");
outputBPP = readIntParameter("output-bpp", 8, 8, 24); outputBPP = readIntParameter("output-bpp", 8, 8, 24);
compressStream = readBooleanParameter("compress-stream", false); compressStream = readBooleanParameter("compress-stream", false);
protocol = readParameter("protocol", "vnc", "vnc");
} }
public String getHostname() {
return hostname;
}
public int getOutputBPP() { public int getOutputBPP() {
return outputBPP; return outputBPP;
} }
@@ -53,12 +48,12 @@ public class GuacamoleConfiguration extends Configuration {
return password; return password;
} }
public int getPort() {
return port;
}
public boolean getCompressStream() { public boolean getCompressStream() {
return compressStream; return compressStream;
} }
public String getProtocol() {
return protocol;
}
} }

View File

@@ -24,7 +24,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import net.sourceforge.guacamole.vnc.VNCException; import net.sourceforge.guacamole.GuacamoleException;
public abstract class GuacamoleServlet extends HttpServlet { public abstract class GuacamoleServlet extends HttpServlet {

View File

@@ -24,6 +24,10 @@ import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener; import javax.servlet.http.HttpSessionBindingListener;
import net.sourceforge.guacamole.Client; 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.VNCClient;
import net.sourceforge.guacamole.vnc.VNCConfiguration; import net.sourceforge.guacamole.vnc.VNCConfiguration;
import net.sourceforge.guacamole.vnc.VNCException; import net.sourceforge.guacamole.vnc.VNCException;
@@ -34,10 +38,12 @@ public class GuacamoleSession {
private final HttpSession session; private final HttpSession session;
private Client client; private Client client;
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 { private Client client;
super(host, port, password, colorBits, outputBPP);
public SessionClient(Client client) {
this.client = client;
} }
public void valueBound(HttpSessionBindingEvent event) { public void valueBound(HttpSessionBindingEvent event) {
@@ -53,6 +59,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 { public GuacamoleSession(HttpSession session) throws GuacamoleException {
@@ -77,24 +103,35 @@ public class GuacamoleSession {
if (client != null) if (client != null)
client.disconnect(); client.disconnect();
// Connect to VNC server
try {
// Read VNC-specific parameters String protocol = config.getProtocol();
ServletContext context = session.getServletContext(); if (protocol.equals("vnc")) {
VNCConfiguration vncconfig = new VNCConfiguration(context);
// 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); session.setAttribute("CLIENT", client);

View File

@@ -36,6 +36,7 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamResult;
import net.sourceforge.guacamole.Client; import net.sourceforge.guacamole.Client;
import net.sourceforge.guacamole.GuacamoleException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;

View File

@@ -23,7 +23,7 @@ import javax.servlet.ServletRequest;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import net.sourceforge.guacamole.net.XMLGuacamoleServlet; import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
import net.sourceforge.guacamole.net.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.GuacamoleSession; import net.sourceforge.guacamole.net.GuacamoleSession;
public class Connect extends XMLGuacamoleServlet { public class Connect extends XMLGuacamoleServlet {

View File

@@ -23,7 +23,7 @@ import javax.servlet.ServletRequest;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import net.sourceforge.guacamole.net.XMLGuacamoleServlet; import net.sourceforge.guacamole.net.XMLGuacamoleServlet;
import net.sourceforge.guacamole.net.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import net.sourceforge.guacamole.net.GuacamoleSession; import net.sourceforge.guacamole.net.GuacamoleSession;
public class Disconnect extends XMLGuacamoleServlet { public class Disconnect extends XMLGuacamoleServlet {

View File

@@ -20,7 +20,7 @@ package net.sourceforge.guacamole.net.input;
*/ */
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import net.sourceforge.guacamole.net.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import net.sourceforge.guacamole.net.GuacamoleSession; import net.sourceforge.guacamole.net.GuacamoleSession;

View File

@@ -20,9 +20,9 @@ package net.sourceforge.guacamole.net.input;
*/ */
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import net.sourceforge.guacamole.net.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import org.w3c.dom.Element; 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.GuacamoleSession;
import net.sourceforge.guacamole.net.XMLGuacamoleServlet; import net.sourceforge.guacamole.net.XMLGuacamoleServlet;

View File

@@ -19,9 +19,9 @@ package net.sourceforge.guacamole.net.input;
*/ */
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import net.sourceforge.guacamole.net.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
import org.w3c.dom.Element; 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.GuacamoleSession;
import net.sourceforge.guacamole.net.XMLGuacamoleServlet; import net.sourceforge.guacamole.net.XMLGuacamoleServlet;

View File

@@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import net.sourceforge.guacamole.Client; import net.sourceforge.guacamole.Client;
import net.sourceforge.guacamole.net.GuacamoleServlet; 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.net.GuacamoleSession;
import net.sourceforge.guacamole.instruction.Instruction; import net.sourceforge.guacamole.instruction.Instruction;
import net.sourceforge.guacamole.instruction.ErrorInstruction; import net.sourceforge.guacamole.instruction.ErrorInstruction;

View File

@@ -22,10 +22,10 @@ import java.awt.image.WritableRaster;
import net.sourceforge.guacamole.instruction.framebuffer.PNGInstruction; import net.sourceforge.guacamole.instruction.framebuffer.PNGInstruction;
import net.sourceforge.guacamole.instruction.framebuffer.CursorInstruction; import net.sourceforge.guacamole.instruction.framebuffer.CursorInstruction;
import net.sourceforge.guacamole.instruction.framebuffer.CopyRectInstruction; import net.sourceforge.guacamole.instruction.framebuffer.CopyRectInstruction;
import net.sourceforge.guacamole.vnc.event.PointerEvent; import net.sourceforge.guacamole.event.PointerEvent;
import net.sourceforge.guacamole.vnc.event.EventQueue; import net.sourceforge.guacamole.event.EventQueue;
import net.sourceforge.guacamole.vnc.event.KeyEvent; import net.sourceforge.guacamole.event.KeyEvent;
import net.sourceforge.guacamole.vnc.event.EventHandler; import net.sourceforge.guacamole.event.EventHandler;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; 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.NameInstruction;
import net.sourceforge.guacamole.instruction.SizeInstruction; import net.sourceforge.guacamole.instruction.SizeInstruction;
import net.sourceforge.guacamole.instruction.framebuffer.PNGImage; import net.sourceforge.guacamole.instruction.framebuffer.PNGImage;
import net.sourceforge.guacamole.net.GuacamoleException; import net.sourceforge.guacamole.GuacamoleException;
public class VNCClient extends Client { 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. // 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) { 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 input.read(); // Padding
int numberOfRectangles = input.readUnsignedShort(); int numberOfRectangles = input.readUnsignedShort();

View File

@@ -19,11 +19,14 @@ package net.sourceforge.guacamole.vnc;
* along with this program. If not, see <http://www.gnu.org/licenses/>. * 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; import javax.servlet.ServletContext;
public class VNCConfiguration extends Configuration { public class VNCConfiguration extends Configuration {
private String hostname;
private int port;
private String password; private String password;
private int bpp; private int bpp;
@@ -31,6 +34,8 @@ public class VNCConfiguration extends Configuration {
super(context); super(context);
hostname = readParameter("host", null);
port = readIntParameter("port", null);
password = context.getInitParameter("password"); password = context.getInitParameter("password");
bpp = readIntParameter("bpp", 24, 8, 16, 24); bpp = readIntParameter("bpp", 24, 8, 16, 24);
@@ -44,4 +49,12 @@ public class VNCConfiguration extends Configuration {
return password; return password;
} }
public String getHostname() {
return hostname;
}
public int getPort() {
return port;
}
} }