Class CommandResolver

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected URIResolver ur
      The URI resolver which is wrapped, and which handles all non-command URIs.
      static java.lang.String VIEWERPROXY_COMMAND_NAME
      Fake host used as hostname when doing commands.
    • Constructor Summary

      Constructors 
      Constructor Description
      CommandResolver​(URIResolver ur)
      Constructor which sets the next resolver in the chain.
    • Constructor Detail

      • CommandResolver

        public CommandResolver​(URIResolver ur)
        Constructor which sets the next resolver in the chain.
        Parameters:
        ur - The URIResolver that handles URIs that are not handled by this resolver.
    • Method Detail

      • lookup

        public final int lookup​(Request request,
                                Response response)
        Parses the given URI and executes commands for all command URLs. The possible commands are of the form http://<>/<>?<>=<>* where command and param are defined in the subclass.

        If uri is none of these, the uri and response are forwarded to the wrapped URI resolver.

        Specified by:
        lookup in interface URIResolver
        Parameters:
        request - The HTTP request we are working on
        response - HTTP response to generate effect on or to forward
        Returns:
        response code
      • executeCommand

        protected abstract boolean executeCommand​(Request request,
                                                  Response response)
        Abstract method for parsing of the URL and delegating to relevant methods. This should start by calling isCommandHostRequest.
        Parameters:
        request - The request to check
        response - The response to give command results to if it is a command
        Returns:
        Whether this was a command URL
      • isCommandHostRequest

        protected static boolean isCommandHostRequest​(Request request)
        Returns true if the request specifies the host that we're running on. Alternative specifications such as 'localhost' or '127.0.0.1' or an actual IP of this machine are not considered command hosts. Local hosts would only be command hosts if we happen to get a request from a browser running on this machine.
        Parameters:
        request - An HTTP request.
        Returns:
        True if the HTTP request specifies a URI that indicates this machine, false otherwise.