Expose handler to ApiVersionDeprecationHandler implementations

Closes gh-35750
This commit is contained in:
rstoyanchev
2025-11-05 12:23:59 +00:00
parent cd67010518
commit b128f59714
12 changed files with 24 additions and 14 deletions
@@ -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);
}
@@ -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);
}
@@ -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);
}
}
@@ -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)) {
@@ -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);
@@ -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);
}
@@ -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);
}
@@ -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);
}
}
@@ -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();
@@ -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;
@@ -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");
@@ -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;
}
}