Class GuacamoleHTTPTunnelServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
org.apache.guacamole.servlet.GuacamoleHTTPTunnelServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public abstract class GuacamoleHTTPTunnelServlet extends javax.servlet.http.HttpServlet
A HttpServlet implementing and abstracting the operations required by the HTTP implementation of the JavaScript Guacamole client's tunnel.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    deregisterTunnel(String tunnelSessionToken)
    Deregisters the HTTP tunnel associated with the given tunnel-specific session token such that future read/write requests to that tunnel will be rejected.
    protected void
    Deprecated.
    This function has been deprecated in favor of deregisterTunnel(java.lang.String), which decouples identification of HTTP tunnel sessions from the tunnel UUID.
    void
     
    protected abstract GuacamoleTunnel
    doConnect(javax.servlet.http.HttpServletRequest request)
    Called whenever the JavaScript Guacamole client makes a connection request via HTTP.
    protected void
    doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
     
    protected void
    doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
     
    protected void
    doRead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String tunnelSessionToken)
    Called whenever the JavaScript Guacamole client makes a read request.
    protected void
    doWrite(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String tunnelSessionToken)
    Called whenever the JavaScript Guacamole client makes a write request.
    protected String
    Generates a new, securely-random session token that may be used to represent the ongoing communication session of a distinct HTTP tunnel connection.
    protected GuacamoleTunnel
    getTunnel(String tunnelSessionToken)
    Returns the tunnel associated with the given tunnel-specific session token, if it has been registered with registerTunnel(java.lang.String, org.apache.guacamole.net.GuacamoleTunnel) and not yet deregistered with deregisterTunnel(java.lang.String).
    protected void
    handleTunnelRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Dispatches every HTTP GET and POST request to the appropriate handler function based on the query string.
    protected void
    registerTunnel(String tunnelSessionToken, GuacamoleTunnel tunnel)
    Registers the given HTTP tunnel such that future read/write requests including the given tunnel-specific session token will be properly directed.
    protected void
    Deprecated.
    This function has been deprecated in favor of registerTunnel(java.lang.String, org.apache.guacamole.net.GuacamoleTunnel), which decouples identification of HTTP tunnel sessions from the tunnel UUID.
    protected void
    sendError(javax.servlet.http.HttpServletResponse response, int guacamoleStatusCode, int guacamoleHttpCode, String message)
    Sends an error on the given HTTP response using the information within the given GuacamoleStatus.

    Methods inherited from class javax.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service

    Methods inherited from class javax.servlet.GenericServlet

    getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GuacamoleHTTPTunnelServlet

      public GuacamoleHTTPTunnelServlet()
  • Method Details

    • generateToken

      protected String generateToken()
      Generates a new, securely-random session token that may be used to represent the ongoing communication session of a distinct HTTP tunnel connection.
      Returns:
      A new, securely-random session token.
    • registerTunnel

      @Deprecated protected void registerTunnel(GuacamoleTunnel tunnel)
      Deprecated.
      This function has been deprecated in favor of registerTunnel(java.lang.String, org.apache.guacamole.net.GuacamoleTunnel), which decouples identification of HTTP tunnel sessions from the tunnel UUID.
      Registers the given tunnel such that future read/write requests to that tunnel will be properly directed.
      Parameters:
      tunnel - The tunnel to register.
    • registerTunnel

      protected void registerTunnel(String tunnelSessionToken, GuacamoleTunnel tunnel)
      Registers the given HTTP tunnel such that future read/write requests including the given tunnel-specific session token will be properly directed. The session token must be unpredictable (securely-random) and unique across all active HTTP tunnels. It is recommended that each HTTP tunnel session token be obtained through calling generateToken().
      Parameters:
      tunnelSessionToken - The tunnel-specific session token to associate with the HTTP tunnel being registered.
      tunnel - The tunnel to register.
    • deregisterTunnel

      @Deprecated protected void deregisterTunnel(GuacamoleTunnel tunnel)
      Deprecated.
      This function has been deprecated in favor of deregisterTunnel(java.lang.String), which decouples identification of HTTP tunnel sessions from the tunnel UUID.
      Deregisters the given tunnel such that future read/write requests to that tunnel will be rejected.
      Parameters:
      tunnel - The tunnel to deregister.
    • deregisterTunnel

      protected void deregisterTunnel(String tunnelSessionToken)
      Deregisters the HTTP tunnel associated with the given tunnel-specific session token such that future read/write requests to that tunnel will be rejected. Each HTTP tunnel must be associated with a session token unique to that tunnel via a call registerTunnel(java.lang.String, org.apache.guacamole.net.GuacamoleTunnel).
      Parameters:
      tunnelSessionToken - The tunnel-specific session token associated with the HTTP tunnel being deregistered.
    • getTunnel

      protected GuacamoleTunnel getTunnel(String tunnelSessionToken) throws GuacamoleException
      Returns the tunnel associated with the given tunnel-specific session token, if it has been registered with registerTunnel(java.lang.String, org.apache.guacamole.net.GuacamoleTunnel) and not yet deregistered with deregisterTunnel(java.lang.String).
      Parameters:
      tunnelSessionToken - The tunnel-specific session token associated with the HTTP tunnel to be retrieved.
      Returns:
      The tunnel corresponding to the given session token.
      Throws:
      GuacamoleException - If the requested tunnel does not exist because it has not yet been registered or it has been deregistered.
    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Throws:
      javax.servlet.ServletException
    • doPost

      protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Throws:
      javax.servlet.ServletException
    • sendError

      protected void sendError(javax.servlet.http.HttpServletResponse response, int guacamoleStatusCode, int guacamoleHttpCode, String message) throws javax.servlet.ServletException
      Sends an error on the given HTTP response using the information within the given GuacamoleStatus.
      Parameters:
      response - The HTTP response to use to send the error.
      guacamoleStatusCode - The GuacamoleStatus code to send.
      guacamoleHttpCode - The numeric HTTP code to send.
      message - The human-readable error message to send.
      Throws:
      javax.servlet.ServletException - If an error prevents sending of the error code.
    • handleTunnelRequest

      protected void handleTunnelRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
      Dispatches every HTTP GET and POST request to the appropriate handler function based on the query string.
      Parameters:
      request - The HttpServletRequest associated with the GET or POST request received.
      response - The HttpServletResponse associated with the GET or POST request received.
      Throws:
      javax.servlet.ServletException - If an error occurs while servicing the request.
    • doConnect

      protected abstract GuacamoleTunnel doConnect(javax.servlet.http.HttpServletRequest request) throws GuacamoleException
      Called whenever the JavaScript Guacamole client makes a connection request via HTTP. It it up to the implementor of this function to define what conditions must be met for a tunnel to be configured and returned as a result of this connection request (whether some sort of credentials must be specified, for example).
      Parameters:
      request - The HttpServletRequest associated with the connection request received. Any parameters specified along with the connection request can be read from this object.
      Returns:
      A newly constructed GuacamoleTunnel if successful, null otherwise.
      Throws:
      GuacamoleException - If an error occurs while constructing the GuacamoleTunnel, or if the conditions required for connection are not met.
    • doRead

      protected void doRead(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String tunnelSessionToken) throws GuacamoleException
      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.
      Parameters:
      request - The HttpServletRequest associated with the read request received.
      response - The HttpServletResponse associated with the write request received. Any data to be sent to the client in response to the write request should be written to the response body of this HttpServletResponse.
      tunnelSessionToken - The tunnel-specific session token of the HTTP tunnel to read from, as specified in the read request. This tunnel must have been created by a previous call to doConnect().
      Throws:
      GuacamoleException - If an error occurs while handling the read request.
    • doWrite

      protected void doWrite(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String tunnelSessionToken) throws GuacamoleException
      Called whenever the JavaScript Guacamole client makes a write request. This function should in general not be overridden, as it already contains a proper implementation of the write operation.
      Parameters:
      request - The HttpServletRequest associated with the write request received. Any data to be written will be specified within the body of this request.
      response - The HttpServletResponse associated with the write request received.
      tunnelSessionToken - The tunnel-specific session token of the HTTP tunnel to write to, as specified in the write request. This tunnel must have been created by a previous call to doConnect().
      Throws:
      GuacamoleException - If an error occurs while handling the write request.
    • destroy

      public void destroy()
      Specified by:
      destroy in interface javax.servlet.Servlet
      Overrides:
      destroy in class javax.servlet.GenericServlet