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(java.lang.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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal class
A spec to configure deprecation details for an API version. -
Constructor Summary
ConstructorsConstructorDescriptionCreate an instance.Variant of the default constructor with a customApiVersionParser
. -
Method Summary
Modifier and TypeMethodDescriptionconfigureVersion
(String version) Mark the given API version as deprecated, and use the returnedStandardApiVersionDeprecationHandler.VersionSpec
to configure the deprecation details to send to clients.void
handleVersion
(Comparable<?> requestVersion, HttpServletRequest request, HttpServletResponse response) Check if the requested API version is deprecated, and if so handle it accordingly, e.g.toString()
-
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 theStandardApiVersionDeprecationHandler(ApiVersionParser)
constructor. -
StandardApiVersionDeprecationHandler
Variant of the default constructor with a customApiVersionParser
. This needs to be the same as the parser type used at runtime to parse request versions.
-
-
Method Details
-
configureVersion
Mark the given API version as deprecated, and use the returnedStandardApiVersionDeprecationHandler.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, HttpServletRequest request, 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 interfaceApiVersionDeprecationHandler
- Parameters:
requestVersion
- the resolved and parsed request versionrequest
- the current requestresponse
- the current response
-
toString
-