GUAC-906: Implement GuacamoleConnectionClosedException. Throw when read/write fails due to closure.

This commit is contained in:
Michael Jumper
2014-10-26 15:14:35 -07:00
parent 721d9125ab
commit b83c83c324
8 changed files with 140 additions and 10 deletions

View File

@@ -35,9 +35,9 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.glyptodon.guacamole.GuacamoleClientException;
import org.glyptodon.guacamole.GuacamoleConnectionClosedException;
import org.glyptodon.guacamole.GuacamoleException;
import org.glyptodon.guacamole.GuacamoleResourceNotFoundException;
import org.glyptodon.guacamole.GuacamoleSecurityException;
import org.glyptodon.guacamole.GuacamoleServerException;
import org.glyptodon.guacamole.io.GuacamoleReader;
import org.glyptodon.guacamole.io.GuacamoleWriter;
@@ -287,7 +287,7 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
// data yet.
char[] message = reader.read();
if (message == null)
throw new GuacamoleResourceNotFoundException("Tunnel reached end of stream.");
throw new GuacamoleConnectionClosedException("Tunnel reached end of stream.");
// For all messages, until another stream is ready (we send at least one message)
do {
@@ -317,20 +317,28 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
response.flushBuffer();
}
// Send end-of-stream marker if connection is closed
catch (GuacamoleConnectionClosedException e) {
out.write("0.;");
out.flush();
response.flushBuffer();
}
catch (GuacamoleException e) {
// Detach and close
session.detachTunnel(tunnel);
tunnel.close();
throw e;
}
// Always close output stream
finally {
out.close();
}
}
catch (GuacamoleException e) {
// Detach and close
session.detachTunnel(tunnel);
tunnel.close();
throw e;
}
catch (IOException e) {
// Log typically frequent I/O error if desired
@@ -411,6 +419,9 @@ public abstract class GuacamoleHTTPTunnelServlet extends HttpServlet {
}
}
catch (GuacamoleConnectionClosedException e) {
logger.debug("Connection closed.", e);
}
catch (IOException e) {
// Detach and close