protected void doRead(HttpServletRequest request,HttpServletResponse response,String tunnelUUID) throws GuacamoleException {
  GuacamoleTunnel tunnel=getTunnel(tunnelUUID);
  if (!tunnel.isOpen())   throw new GuacamoleResourceNotFoundException("Tunnel is closed.");
  GuacamoleReader reader=tunnel.acquireReader();
  try {
    response.setContentType("application/octet-stream");
    response.setHeader("Cache-Control","no-cache");
    Writer out=new BufferedWriter(new OutputStreamWriter(response.getOutputStream(),"UTF-8"));
    try {
      char[] message=reader.read();
      if (message == null)       throw new GuacamoleConnectionClosedException("Tunnel reached end of stream.");
      do {
        out.write(message,0,message.length);
        if (!reader.available()) {
          out.flush();
          response.flushBuffer();
        }
        if (tunnel.hasQueuedReaderThreads())         break;
      }
 while (tunnel.isOpen() && (message=reader.read()) != null);
      if (message == null) {
        deregisterTunnel(tunnel);
        tunnel.close();
      }
      out.write("0.;");
      out.flush();
      response.flushBuffer();
    }
 catch (    GuacamoleConnectionClosedException e) {
      deregisterTunnel(tunnel);
      tunnel.close();
      out.write("0.;");
      out.flush();
      response.flushBuffer();
    }
catch (    GuacamoleException e) {
      deregisterTunnel(tunnel);
      tunnel.close();
      throw e;
    }
 finally {
      out.close();
    }
  }
 catch (  IOException e) {
    logger.debug("Error writing to servlet output stream",e);
    deregisterTunnel(tunnel);
    tunnel.close();
  }
 finally {
    tunnel.releaseReader();
  }
}

protected void doRead ( HttpServletRequest request , HttpServletResponse response , String tunnelUUID ) throws GuacamoleException { GuacamoleTunnel tunnel = getTunnel ( tunnelUUID ) ; if ( ! tunnel . isOpen ( ) ) throw new GuacamoleResourceNotFoundException ( "Tunnel is closed." ) ; GuacamoleReader reader = tunnel . acquireReader ( ) ; try { response . setContentType ( "application/octet-stream" ) ; response . setHeader ( "Cache-Control" , "no-cache" ) ; Writer out = new BufferedWriter ( new OutputStreamWriter ( response . getOutputStream ( ) , "UTF-8" ) ) ; try { char [ ] message = reader . read ( ) ; if ( message == null ) throw new GuacamoleConnectionClosedException ( "Tunnel reached end of stream." ) ; do { out . write ( message , 0 , message . length ) ; if ( ! reader . available ( ) ) { out . flush ( ) ; response . flushBuffer ( ) ; } if ( tunnel . hasQueuedReaderThreads ( ) ) break ; } while ( tunnel . isOpen ( ) && ( message = reader . read ( ) ) != null ) ; if ( message == null ) { deregisterTunnel ( tunnel ) ; tunnel . close ( ) ; } out . write ( "0.;" ) ; out . flush ( ) ; response . flushBuffer ( ) ; } catch ( GuacamoleConnectionClosedException e ) { deregisterTunnel ( tunnel ) ; tunnel . close ( ) ; out . write ( "0.;" ) ; out . flush ( ) ; response . flushBuffer ( ) ; } catch ( GuacamoleException e ) { deregisterTunnel ( tunnel ) ; tunnel . close ( ) ; throw e ; } finally { out . close ( ) ; } } catch ( IOException e ) { logger . debug ( "Error writing to servlet output stream" , e ) ; deregisterTunnel ( tunnel ) ; tunnel . close ( ) ; } finally { tunnel . releaseReader ( ) ; } }
called whenever the javascript guacamole client makes a read request . this function should in general not be overridden , as it already contains a proper implementation of the read operation .
