Class BaseURLResourceName<T,​E extends Exception>

  • Type Parameters:
    T - The type that the compare method is going to return instances of.
    E - The exception type thrown by the canonicalize method.
    All Implemented Interfaces:
    BaseResourceName<T,​E>
    Direct Known Subclasses:
    URLResourceName, URLResourceName, URLResourceName

    public abstract class BaseURLResourceName<T,​E extends Exception>
    extends BasePrefixResourceName<T,​E>
    This is a base implementation of a URLResourceName, extending the functionality found in BasePrefixResourceName to provide special handling to URL type prefix resource names in canonicalize method like validating port, assigning default port of 80, if port absent etc.
    See Also:
    BaseResourceName, BasePrefixResourceName
    • Field Detail

      • comparator

        protected static Comparator<String> comparator
        Query parameter comparator.
    • Constructor Detail

      • BaseURLResourceName

        protected BaseURLResourceName​(Debug debug,
                                      T exactMatch,
                                      T noMatch,
                                      T subResourceMatch,
                                      T superResourceMatch,
                                      T wildcardMatch)
        Constructs a new BaseURLResourceName instance.
        Parameters:
        debug - The debug instance.
        exactMatch - The object to return on an exact match.
        noMatch - The object to return on no match.
        subResourceMatch - The object to return on a sub-resource match.
        superResourceMatch - The object to return on a super-resource match.
        wildcardMatch - The object to return on a wildcard match.
    • Method Detail

      • compare

        public T compare​(String requestResource,
                         String targetResource,
                         boolean wildcardCompare)
        Specific comparison for URLs, where a wildcard in the host/port should not match any of the path. Strings should be canonicalized prior to entering this comparison, else they will be compared by the super class' comparison function.
        Specified by:
        compare in interface BaseResourceName<T,​E extends Exception>
        Overrides:
        compare in class BasePrefixResourceName<T,​E extends Exception>
        Parameters:
        requestResource - name of the resource which will be compared
        targetResource - name of the resource which will be compared with
        wildcardCompare - flag for wildcard comparison
        Returns:
        If a wildcard is in the host/port, separately compares the path/query and scheme/host/port, returning NO_MATCH if any don't match. Otherwise returns the match of the port/path/query.
      • canonicalize

        public String canonicalize​(String urlStr)
                            throws E extends Exception
        This method is used to canonicalize a url string. It removes leading delimiters after the protocol http:////abc becomes http://abc. If port number is provided validates it to be either wildcard a valid integer, if not provided, adds default port 80. Makes sure URL is not malformed, also if query parameters are present sorts them based on the comparator's sort method.
        Specified by:
        canonicalize in interface BaseResourceName<T,​E extends Exception>
        Overrides:
        canonicalize in class BasePrefixResourceName<T,​E extends Exception>
        Parameters:
        urlStr - the url string to be canonicalized
        Returns:
        the url string in its canonicalized form.
        Throws:
        E - if the url string is invalid
        E extends Exception