diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/Client.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/Client.java
index e57d479a0..076f0c371 100644
--- a/guacamole-common/src/main/java/net/sourceforge/guacamole/Client.java
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/Client.java
@@ -19,8 +19,6 @@ package net.sourceforge.guacamole;
* along with this program. If not, see .
*/
-import net.sourceforge.guacamole.GuacamoleException;
-
public abstract class Client {
public abstract void write(char[] chunk, int off, int len) throws GuacamoleException;
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleClient.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleClient.java
index f0748d8df..1dc4f69f2 100644
--- a/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleClient.java
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/GuacamoleClient.java
@@ -23,15 +23,12 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
-import java.io.InputStream;
import java.io.Reader;
import java.io.InputStreamReader;
-import java.io.OutputStream;
import java.io.Writer;
import java.io.OutputStreamWriter;
-import net.sourceforge.guacamole.GuacamoleException;
public class GuacamoleClient extends Client {
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/net/GuacamoleSession.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/net/GuacamoleSession.java
index 2eb01326b..57568e5ad 100644
--- a/guacamole-common/src/main/java/net/sourceforge/guacamole/net/GuacamoleSession.java
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/net/GuacamoleSession.java
@@ -19,8 +19,8 @@ package net.sourceforge.guacamole.net;
* along with this program. If not, see .
*/
+import java.util.HashMap;
import java.util.concurrent.locks.ReentrantLock;
-import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
@@ -31,41 +31,36 @@ import net.sourceforge.guacamole.GuacamoleException;
public class GuacamoleSession {
private GuacamoleConfiguration config;
+
private final HttpSession session;
private SessionClient client;
private ReentrantLock instructionStreamLock;
private String protocol;
- private String hostname;
- private int port;
- private String password;
+ private HashMap parameters = new HashMap();
+
+ public String getProtocol() {
+ return protocol;
+ }
+
+ public void setProtocol(String protocol) {
+ this.protocol = protocol;
+ }
+
+ public String getParameter(String name) {
+ return parameters.get(name);
+ }
+
+ public void setParameter(String name, String value) {
+ parameters.put(name, value);
+ }
public class SessionClient extends Client implements HttpSessionBindingListener {
private Client client;
- private ReentrantLock authorizedLock;
public SessionClient(Client client) {
this.client = client;
-
- authorizedLock = new ReentrantLock();
- authorizedLock.lock();
- }
-
- public void authorize() {
- authorizedLock.unlock();
- }
-
- public void waitForAuthorization() {
- if (authorizedLock.isLocked()) {
- try {
- authorizedLock.lock();
- authorizedLock.unlock();
- }
- catch (Throwable t) {
- throw new Error("Internal error waiting for authorization", t);
- }
- }
}
public void valueBound(HttpSessionBindingEvent event) {
@@ -109,15 +104,16 @@ public class GuacamoleSession {
client = (SessionClient) session.getAttribute("CLIENT");
instructionStreamLock = (ReentrantLock) session.getAttribute("INSTRUCTION_STREAM_LOCK");
}
+
}
public void connect() throws GuacamoleException {
+
synchronized (session) {
if (client != null)
client.disconnect();
-
client = new SessionClient(
new GuacamoleClient (
config.getProxyHostname(),
@@ -125,12 +121,15 @@ public class GuacamoleSession {
)
);
+ // TODO: Send "select" and "connect" messages here.
+
session.setAttribute("CLIENT", client);
instructionStreamLock = new ReentrantLock();
session.setAttribute("INSTRUCTION_STREAM_LOCK", instructionStreamLock);
}
+
}
public boolean isConnected() {
@@ -143,8 +142,12 @@ public class GuacamoleSession {
return config;
}
- public SessionClient getClient() {
+ public SessionClient getClient() throws GuacamoleException {
synchronized (session) {
+
+ if (client == null)
+ throw new GuacamoleException("Client not yet connected.");
+
return client;
}
}
@@ -154,56 +157,21 @@ public class GuacamoleSession {
}
public void disconnect() throws GuacamoleException {
- if (client != null) {
- client.disconnect();
- session.removeAttribute("CLIENT");
- client = null;
+ synchronized (session) {
+
+ if (client != null) {
+ client.disconnect();
+ session.removeAttribute("CLIENT");
+ client = null;
+ }
+
}
+
}
public ReentrantLock getInstructionStreamLock() {
return instructionStreamLock;
}
- public void setConnection(String protocol, String hostname, int port) {
- this.protocol = protocol;
- this.hostname = hostname;
- this.port = port;
- }
-
- public String getProtocol() {
- return protocol;
- }
-
- public String getHostname() {
- return hostname;
- }
-
- public int getPort() {
- return port;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public String getConnectMessage() throws GuacamoleException {
-
- if (getProtocol() == null)
- throw new GuacamoleException("Protocol not specified");
-
- if (getHostname() == null)
- throw new GuacamoleException("Hostname not specified");
-
- if (getPassword() == null)
- return "connect:" + getProtocol() + "," + getHostname() + "," + getPort() + ";";
- else
- return "connect:" + getProtocol() + "," + getHostname() + "," + getPort() + "," + getPassword() + ";";
- }
-
}
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Connect.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Connect.java
index 79aa94d40..273aab895 100644
--- a/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Connect.java
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Connect.java
@@ -43,16 +43,6 @@ public class Connect extends GuacamoleServlet {
// Obtain new connection
session.connect();
- // Send data
- try {
- char[] connect = session.getConnectMessage().toCharArray();
- session.getClient().write(connect, 0, connect.length);
- session.getClient().authorize();
- }
- catch (GuacamoleException e) {
- throw new GuacamoleException("Error sending data to server: " + e.getMessage(), e);
- }
-
}
}
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Inbound.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Inbound.java
index 415d639bf..8a939c07c 100644
--- a/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Inbound.java
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Inbound.java
@@ -33,8 +33,6 @@ public class Inbound extends GuacamoleServlet {
@Override
protected void handleRequest(GuacamoleSession session, HttpServletRequest request, HttpServletResponse response) throws GuacamoleException {
- session.getClient().waitForAuthorization();
-
// Send data
try {
diff --git a/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Outbound.java b/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Outbound.java
index 76aa34c76..942a2d72d 100644
--- a/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Outbound.java
+++ b/guacamole-common/src/main/java/net/sourceforge/guacamole/net/tunnel/Outbound.java
@@ -35,8 +35,6 @@ public class Outbound extends GuacamoleServlet {
@Override
protected void handleRequest(GuacamoleSession session, HttpServletRequest request, HttpServletResponse response) throws GuacamoleException {
- session.getClient().waitForAuthorization();
-
ReentrantLock instructionStreamLock = session.getInstructionStreamLock();
instructionStreamLock.lock();