diff --git a/spring-web/src/main/java/org/springframework/web/accept/ApiVersionDeprecationHandler.java b/spring-web/src/main/java/org/springframework/web/accept/ApiVersionDeprecationHandler.java index a9e04621ca4..199ec5d938b 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ApiVersionDeprecationHandler.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ApiVersionDeprecationHandler.java @@ -35,9 +35,12 @@ public interface ApiVersionDeprecationHandler { * accordingly, e.g. by setting response headers to signal the deprecation, * to specify relevant dates and provide links to further details. * @param version the resolved and parsed request version + * @param handler the handler chosen for the request * @param request the current request * @param response the current response */ - void handleVersion(Comparable version, HttpServletRequest request, HttpServletResponse response); + void handleVersion( + Comparable version, Object handler, + HttpServletRequest request, HttpServletResponse response); } diff --git a/spring-web/src/main/java/org/springframework/web/accept/ApiVersionStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ApiVersionStrategy.java index 8b4d700f0f2..f57fbf62616 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ApiVersionStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ApiVersionStrategy.java @@ -91,10 +91,12 @@ public interface ApiVersionStrategy { * accordingly, e.g. by setting response headers to signal the deprecation, * to specify relevant dates and provide links to further details. * @param version the resolved and parsed request version + * @param handler the handler chosen for the request * @param request the current request * @param response the current response * @see ApiVersionDeprecationHandler */ - void handleDeprecations(Comparable version, HttpServletRequest request, HttpServletResponse response); + void handleDeprecations( + Comparable version, Object handler, HttpServletRequest request, HttpServletResponse response); } diff --git a/spring-web/src/main/java/org/springframework/web/accept/DefaultApiVersionStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/DefaultApiVersionStrategy.java index 070433f777f..ab92cbb0561 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/DefaultApiVersionStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/DefaultApiVersionStrategy.java @@ -180,9 +180,11 @@ public class DefaultApiVersionStrategy implements ApiVersionStrategy { } @Override - public void handleDeprecations(Comparable version, HttpServletRequest request, HttpServletResponse response) { + public void handleDeprecations( + Comparable version, Object handler, HttpServletRequest request, HttpServletResponse response) { + if (this.deprecationHandler != null) { - this.deprecationHandler.handleVersion(version, request, response); + this.deprecationHandler.handleVersion(version, handler, request, response); } } diff --git a/spring-web/src/main/java/org/springframework/web/accept/StandardApiVersionDeprecationHandler.java b/spring-web/src/main/java/org/springframework/web/accept/StandardApiVersionDeprecationHandler.java index 54ed9dcb76a..e203e142c09 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/StandardApiVersionDeprecationHandler.java +++ b/spring-web/src/main/java/org/springframework/web/accept/StandardApiVersionDeprecationHandler.java @@ -87,7 +87,8 @@ public class StandardApiVersionDeprecationHandler implements ApiVersionDeprecati @Override public void handleVersion( - Comparable requestVersion, HttpServletRequest request, HttpServletResponse response) { + Comparable requestVersion, Object handler, + HttpServletRequest request, HttpServletResponse response) { for (VersionInfo info : this.infos.values()) { if (info.match(requestVersion, request)) { diff --git a/spring-web/src/test/java/org/springframework/web/accept/StandardApiVersionDeprecationHandlerTests.java b/spring-web/src/test/java/org/springframework/web/accept/StandardApiVersionDeprecationHandlerTests.java index a094da00961..be96b91f384 100644 --- a/spring-web/src/test/java/org/springframework/web/accept/StandardApiVersionDeprecationHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/accept/StandardApiVersionDeprecationHandlerTests.java @@ -53,7 +53,7 @@ public class StandardApiVersionDeprecationHandlerTests { .setSunsetDate(getDate(sunsetDate)) .setSunsetLink(URI.create(sunsetUrl)); - handler.handleVersion("1.1", request, response); + handler.handleVersion("1.1", new Object(), request, response); assertThat(response.getHeader("Deprecation")).isEqualTo("@1688169599"); assertThat(response.getHeader("Sunset")).isEqualTo(sunsetDate); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionDeprecationHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionDeprecationHandler.java index 60951a763d1..cdf5e31de02 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionDeprecationHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionDeprecationHandler.java @@ -33,8 +33,9 @@ public interface ApiVersionDeprecationHandler { * accordingly, e.g. by setting response headers to signal the deprecation, * to specify relevant dates and provide links to further details. * @param version the resolved and parsed request version + * @param handler the handler chosen for the exchange * @param exchange the current exchange */ - void handleVersion(Comparable version, ServerWebExchange exchange); + void handleVersion(Comparable version, Object handler, ServerWebExchange exchange); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionStrategy.java index 762c7cc623d..ff8cc2038e6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionStrategy.java @@ -93,9 +93,10 @@ public interface ApiVersionStrategy { * accordingly, e.g. by setting response headers to signal the deprecation, * to specify relevant dates and provide links to further details. * @param version the resolved and parsed request version + * @param handler the handler chosen for the exchange * @param exchange the current exchange * @see ApiVersionDeprecationHandler */ - void handleDeprecations(Comparable version, ServerWebExchange exchange); + void handleDeprecations(Comparable version, Object handler, ServerWebExchange exchange); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/DefaultApiVersionStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/DefaultApiVersionStrategy.java index 709e75c8026..d2dac706b69 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/DefaultApiVersionStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/DefaultApiVersionStrategy.java @@ -181,9 +181,9 @@ public class DefaultApiVersionStrategy implements ApiVersionStrategy { } @Override - public void handleDeprecations(Comparable version, ServerWebExchange exchange) { + public void handleDeprecations(Comparable version, Object handler, ServerWebExchange exchange) { if (this.deprecationHandler != null) { - this.deprecationHandler.handleVersion(version, exchange); + this.deprecationHandler.handleVersion(version, handler, exchange); } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandler.java index 231f7f57c4b..3788349ac2b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandler.java @@ -86,7 +86,7 @@ public class StandardApiVersionDeprecationHandler implements ApiVersionDeprecati } @Override - public void handleVersion(Comparable requestVersion, ServerWebExchange exchange) { + public void handleVersion(Comparable requestVersion, Object handler, ServerWebExchange exchange) { for (VersionInfo info : this.infos.values()) { if (info.match(requestVersion, exchange)) { HttpHeaders headers = exchange.getResponse().getHeaders(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java index bca4ce92a64..b20577bea99 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java @@ -206,7 +206,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport if (getApiVersionStrategy() != null) { Comparable version = exchange.getAttribute(API_VERSION_ATTRIBUTE); if (version != null) { - getApiVersionStrategy().handleDeprecations(version, exchange); + getApiVersionStrategy().handleDeprecations(version, handler, exchange); } } return handler; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandlerTests.java index 2cb0b953c5c..81947509347 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandlerTests.java @@ -54,7 +54,7 @@ public class StandardApiVersionDeprecationHandlerTests { .setSunsetDate(getDate(sunsetDate)) .setSunsetLink(URI.create(sunsetUrl)); - handler.handleVersion("1.1", exchange); + handler.handleVersion("1.1", handler, exchange); HttpHeaders headers = exchange.getResponse().getHeaders(); assertThat(headers.getFirst("Deprecation")).isEqualTo("@1688169599"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index 5e4b0866a1e..da4aaa0f269 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -803,7 +803,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { - this.versionStrategy.handleDeprecations(this.version, request, response); + this.versionStrategy.handleDeprecations(this.version, handler, request, response); return true; } }