Class AntPathRequestMatcher

  • All Implemented Interfaces:
    RequestMatcher, RequestVariablesExtractor

    public final class AntPathRequestMatcher
    extends java.lang.Object
    implements RequestMatcher, RequestVariablesExtractor
    Matcher which compares a pre-defined ant-style pattern against the URL ( servletPath + pathInfo) of an HttpServletRequest. The query string of the URL is ignored and matching is case-insensitive or case-sensitive depending on the arguments passed into the constructor.

    Using a pattern value of /** or ** is treated as a universal match, which will match any request. Patterns which end with /** (and have no other wildcards) are optimized by using a substring match — a pattern of /aaa/** will match /aaa, /aaa/ and any sub-directories, such as /aaa/bbb/ccc.

    For all other cases, Spring's AntPathMatcher is used to perform the match. See the Spring documentation for this class for comprehensive information on the syntax used.

    Since:
    3.1
    See Also:
    AntPathMatcher
    • Constructor Summary

      Constructors 
      Constructor Description
      AntPathRequestMatcher​(java.lang.String pattern)
      Creates a matcher with the specific pattern which will match all HTTP methods in a case sensitive manner.
      AntPathRequestMatcher​(java.lang.String pattern, java.lang.String httpMethod)
      Creates a matcher with the supplied pattern and HTTP method in a case sensitive manner.
      AntPathRequestMatcher​(java.lang.String pattern, java.lang.String httpMethod, boolean caseSensitive)
      Creates a matcher with the supplied pattern which will match the specified Http method
      AntPathRequestMatcher​(java.lang.String pattern, java.lang.String httpMethod, boolean caseSensitive, org.springframework.web.util.UrlPathHelper urlPathHelper)
      Creates a matcher with the supplied pattern which will match the specified Http method
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static AntPathRequestMatcher antMatcher​(java.lang.String pattern)
      Creates a matcher with the specific pattern which will match all HTTP methods in a case-sensitive manner.
      static AntPathRequestMatcher antMatcher​(org.springframework.http.HttpMethod method)
      Creates a matcher that will match all request with the supplied HTTP method in a case-sensitive manner.
      static AntPathRequestMatcher antMatcher​(org.springframework.http.HttpMethod method, java.lang.String pattern)
      Creates a matcher with the supplied pattern and HTTP method in a case-sensitive manner.
      boolean equals​(java.lang.Object obj)  
      java.util.Map<java.lang.String,​java.lang.String> extractUriTemplateVariables​(javax.servlet.http.HttpServletRequest request)
      Deprecated.
      java.lang.String getPattern()  
      int hashCode()  
      RequestMatcher.MatchResult matcher​(javax.servlet.http.HttpServletRequest request)
      Returns a MatchResult for this RequestMatcher The default implementation returns Collections.emptyMap() when RequestMatcher.MatchResult.getVariables() is invoked.
      boolean matches​(javax.servlet.http.HttpServletRequest request)
      Returns true if the configured pattern (and HTTP-Method) match those of the supplied request.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AntPathRequestMatcher

        public AntPathRequestMatcher​(java.lang.String pattern)
        Creates a matcher with the specific pattern which will match all HTTP methods in a case sensitive manner.
        Parameters:
        pattern - the ant pattern to use for matching
      • AntPathRequestMatcher

        public AntPathRequestMatcher​(java.lang.String pattern,
                                     java.lang.String httpMethod)
        Creates a matcher with the supplied pattern and HTTP method in a case sensitive manner.
        Parameters:
        pattern - the ant pattern to use for matching
        httpMethod - the HTTP method. The matches method will return false if the incoming request doesn't have the same method.
      • AntPathRequestMatcher

        public AntPathRequestMatcher​(java.lang.String pattern,
                                     java.lang.String httpMethod,
                                     boolean caseSensitive)
        Creates a matcher with the supplied pattern which will match the specified Http method
        Parameters:
        pattern - the ant pattern to use for matching
        httpMethod - the HTTP method. The matches method will return false if the incoming request doesn't doesn't have the same method.
        caseSensitive - true if the matcher should consider case, else false
      • AntPathRequestMatcher

        public AntPathRequestMatcher​(java.lang.String pattern,
                                     java.lang.String httpMethod,
                                     boolean caseSensitive,
                                     org.springframework.web.util.UrlPathHelper urlPathHelper)
        Creates a matcher with the supplied pattern which will match the specified Http method
        Parameters:
        pattern - the ant pattern to use for matching
        httpMethod - the HTTP method. The matches method will return false if the incoming request doesn't have the same method.
        caseSensitive - true if the matcher should consider case, else false
        urlPathHelper - if non-null, will be used for extracting the path from the HttpServletRequest
    • Method Detail

      • antMatcher

        public static AntPathRequestMatcher antMatcher​(java.lang.String pattern)
        Creates a matcher with the specific pattern which will match all HTTP methods in a case-sensitive manner.
        Parameters:
        pattern - the ant pattern to use for matching
        Since:
        5.8
      • antMatcher

        public static AntPathRequestMatcher antMatcher​(org.springframework.http.HttpMethod method)
        Creates a matcher that will match all request with the supplied HTTP method in a case-sensitive manner.
        Parameters:
        method - the HTTP method. The matches method will return false if the incoming request doesn't have the same method.
        Since:
        5.8
      • antMatcher

        public static AntPathRequestMatcher antMatcher​(org.springframework.http.HttpMethod method,
                                                       java.lang.String pattern)
        Creates a matcher with the supplied pattern and HTTP method in a case-sensitive manner.
        Parameters:
        method - the HTTP method. The matches method will return false if the incoming request doesn't have the same method.
        pattern - the ant pattern to use for matching
        Since:
        5.8
      • matches

        public boolean matches​(javax.servlet.http.HttpServletRequest request)
        Returns true if the configured pattern (and HTTP-Method) match those of the supplied request.
        Specified by:
        matches in interface RequestMatcher
        Parameters:
        request - the request to match against. The ant pattern will be matched against the servletPath + pathInfo of the request.
        Returns:
        true if the request matches, false otherwise
      • extractUriTemplateVariables

        @Deprecated
        public java.util.Map<java.lang.String,​java.lang.String> extractUriTemplateVariables​(javax.servlet.http.HttpServletRequest request)
        Deprecated.
        Description copied from interface: RequestVariablesExtractor
        Extract URL template variables from the request.
        Specified by:
        extractUriTemplateVariables in interface RequestVariablesExtractor
        Parameters:
        request - the HttpServletRequest to obtain a URL to extract the variables from
        Returns:
        the URL variables or empty if no variables are found
      • getPattern

        public java.lang.String getPattern()
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object