Class UriRouterContext

  • All Implemented Interfaces:
    Context

    public final class UriRouterContext
    extends AbstractContext
    A Context which is created when a request has been routed. The context includes:
    • the portion of the request URI which matched the URI template
    • the portion of the request URI which is remaining to be matched
    • a method for obtaining the base URI, which represents the portion of the request URI which has been routed so far. This is obtained dynamically by concatenating the matched URI with matched URIs in parent router contexts
    • a map which contains the parsed URI template variables, keyed on the URI template variable name.
    The originalUri represents the incoming request URI, as sent by the client. So it can be used to generate redirects or links that will be usable in the context of the caller (user-agent). This is considered as the starting point of the current routing process. Most of the time, that will be the URI received by web server, but it may happen that the URI received by the web server is not the same one that the one sent by the user-agent (e.g. : behind a load balancer, in a cloud environment, ... ). The real URI can be found by other means, it is possible to “overwrite” it in other UriRouterContexts that can be accessed in the contexts chain. Then in that case, we need to start a new routing process by considering that given URI as the new originalUri. Otherwise child UriRouterContext may just redefine only the {code matchedUri}, remainingUri, uriTemplateVariables as part of their routing process.
    • Constructor Detail

      • UriRouterContext

        public UriRouterContext​(Context parent,
                                String matchedUri,
                                String remainingUri,
                                Map<String,​String> uriTemplateVariables)
        Creates a new routing context having the provided parent, URI template variables, and an ID automatically generated using UUID.randomUUID(). The parameters provided in this UriRouterContext will override any parameters inherited from parent UriRouterContexts.
        Parameters:
        parent - The parent server context.
        matchedUri - The matched URI
        remainingUri - The remaining URI to be matched.
        uriTemplateVariables - A Map containing the parsed URI template variables, keyed on the URI template variable name.
      • UriRouterContext

        public UriRouterContext​(Context parent,
                                String matchedUri,
                                String remainingUri,
                                Map<String,​String> uriTemplateVariables,
                                URI originalUri)
        Creates a new routing context having the provided parent, URI template variables, and an ID automatically generated using UUID.randomUUID(). The parameters provided in this UriRouterContext will override any parameters inherited from parent UriRouterContexts.
        Parameters:
        parent - The parent server context. (not null)
        matchedUri - The matched URI
        remainingUri - The remaining URI to be matched.
        uriTemplateVariables - A Map containing the parsed URI template variables, keyed on the URI template variable name. (not null)
        originalUri - The original URI. If not null it will override the originalUri defined in the closest UriRouterContext referenced in the context's chain.
      • UriRouterContext

        public UriRouterContext​(JsonValue savedContext,
                                ClassLoader classLoader)
        Restore from JSON representation.
        Parameters:
        savedContext - The JSON representation from which this context's attributes should be parsed.
        classLoader - The ClassLoader which can properly resolve the persisted class-name.
    • Method Detail

      • getBaseUri

        public String getBaseUri()
        Returns the portion of the request URI which has been routed so far. This is obtained dynamically by concatenating the matched URI with the base URI of the parent router context if present. The base URI is never null but may be "" (empty string).
        Returns:
        The non-null portion of the request URI which has been routed so far.
      • getMatchedUri

        public String getMatchedUri()
        Returns the portion of the request URI which matched the URI template. The matched URI is never null but may be "" (empty string).
        Returns:
        The non-null portion of the request URI which matched the URI template.
      • getRemainingUri

        public String getRemainingUri()
        Returns the portion of the request URI which is remaining to be matched be the next router. The remaining URI is never null but may be "" (empty string).
        Returns:
        The non-null portion of the request URI which is remaining to be matched.
      • getUriTemplateVariables

        public Map<String,​String> getUriTemplateVariables()
        Returns an unmodifiable Map containing the parsed URI template variables, keyed on the URI template variable name.
        Returns:
        The unmodifiable Map containing the parsed URI template variables, keyed on the URI template variable name.
      • getOriginalUri

        public URI getOriginalUri()
        Get the original URI.
        Returns:
        The original URI