Class VersionRequestCondition

java.lang.Object
org.springframework.web.servlet.mvc.condition.AbstractRequestCondition<VersionRequestCondition>
org.springframework.web.servlet.mvc.condition.VersionRequestCondition
All Implemented Interfaces:
RequestCondition<VersionRequestCondition>

public final class VersionRequestCondition extends AbstractRequestCondition<VersionRequestCondition>
Request condition to map based on the API version of the request. Versions can be fixed (e.g. "1.2") or baseline (e.g. "1.2+") as described in RequestMapping.version().
Since:
7.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • VersionRequestCondition

      public VersionRequestCondition()
    • VersionRequestCondition

      public VersionRequestCondition(String configuredVersion, ApiVersionStrategy versionStrategy)
  • Method Details

    • getContent

      protected Collection<String> getContent()
      Description copied from class: AbstractRequestCondition
      Return the discrete items a request condition is composed of.

      For example URL patterns, HTTP request methods, param expressions, etc.

      Specified by:
      getContent in class AbstractRequestCondition<VersionRequestCondition>
      Returns:
      a collection of objects (never null)
    • getToStringInfix

      protected String getToStringInfix()
      Description copied from class: AbstractRequestCondition
      The notation to use when printing discrete items of content.

      For example " || " for URL patterns or " && " for param expressions.

      Specified by:
      getToStringInfix in class AbstractRequestCondition<VersionRequestCondition>
    • getVersion

      public @Nullable String getVersion()
    • combine

      Description copied from interface: RequestCondition
      Combine this condition with another such as conditions from a type-level and method-level @RequestMapping annotation.
      Parameters:
      other - the condition to combine with.
      Returns:
      a request condition instance that is the result of combining the two condition instances.
    • getMatchingCondition

      public @Nullable VersionRequestCondition getMatchingCondition(HttpServletRequest request)
      Description copied from interface: RequestCondition
      Check if the condition matches the request returning a potentially new instance created for the current request. For example a condition with multiple URL patterns may return a new instance only with those patterns that match the request.

      For CORS pre-flight requests, conditions should match to the would-be, actual request (for example, URL pattern, query parameters, and the HTTP method from the "Access-Control-Request-Method" header). If a condition cannot be matched to a pre-flight request it should return an instance with empty content thus not causing a failure to match.

      Returns:
      a condition instance in case of a match or null otherwise.
    • compareTo

      public int compareTo(VersionRequestCondition other, HttpServletRequest request)
      Description copied from interface: RequestCondition
      Compare this condition to another condition in the context of a specific request. This method assumes both instances have been obtained via RequestCondition.getMatchingCondition(HttpServletRequest) to ensure they have content relevant to current request only.
    • handleMatch

      public void handleMatch(HttpServletRequest request)
      Perform a final check on the matched request mapping version.

      In order to ensure baseline versions are properly capped by higher fixed versions, initially we match all versions as baseline versions in getMatchingCondition(HttpServletRequest). Once the highest of potentially multiple matches is selected, we enforce the strict match for fixed versions.

      For example, given controller methods for "1.2+" and "1.5", and a request for "1.6", both are matched, allowing "1.5" to be selected, but that is then rejected as not acceptable since it is not an exact match.

      Parameters:
      request - the current request
      Throws:
      NotAcceptableApiVersionException - if the matched condition has a fixed version that is not equal to the request version