Class StandardApiVersionDeprecationHandler

java.lang.Object
org.springframework.web.accept.StandardApiVersionDeprecationHandler
All Implemented Interfaces:
ApiVersionDeprecationHandler

public class StandardApiVersionDeprecationHandler extends Object implements ApiVersionDeprecationHandler
ApiVersionDeprecationHandler based on RFC 9745 and RFC 8594 that provides the option to set the "Deprecation" and "Sunset" response headers, as well as to add "Link" headers with further details about both.

To use this handler, create an instance, call configureVersion(String) for each deprecated version, and use the returned StandardApiVersionDeprecationHandler.VersionSpec to provide the deprecation details to send to clients.

Since:
7.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • StandardApiVersionDeprecationHandler

      public StandardApiVersionDeprecationHandler()
      Create an instance.

      By default, SemanticApiVersionParser is used to parse configured API versions, so those can be compared to request versions parsed at runtime. If you have a custom parser, then please use the StandardApiVersionDeprecationHandler(ApiVersionParser) constructor.

    • StandardApiVersionDeprecationHandler

      public StandardApiVersionDeprecationHandler(ApiVersionParser<?> parser)
      Variant of the default constructor with a custom ApiVersionParser. This needs to be the same as the parser type used at runtime to parse request versions.
  • Method Details

    • configureVersion

      public StandardApiVersionDeprecationHandler.VersionSpec configureVersion(String version)
      Mark the given API version as deprecated, and use the returned StandardApiVersionDeprecationHandler.VersionSpec to configure the deprecation details to send to clients.
      Parameters:
      version - the version to mark as deprecated
      Returns:
      a spec to configure deprecation details
    • handleVersion

      public void handleVersion(Comparable<?> requestVersion, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Description copied from interface: ApiVersionDeprecationHandler
      Check if the requested API version is deprecated, and if so handle it accordingly, e.g. by setting response headers to signal the deprecation, to specify relevant dates and provide links to further details.
      Specified by:
      handleVersion in interface ApiVersionDeprecationHandler
      Parameters:
      requestVersion - the resolved and parsed request version
      request - the current request
      response - the current response
    • toString

      public String toString()
      Overrides:
      toString in class Object