Browse Source

Expose handler to ApiVersionDeprecationHandler implementations

Closes gh-35750
pull/35768/head
rstoyanchev 1 month ago
parent
commit
b128f59714
  1. 5
      spring-web/src/main/java/org/springframework/web/accept/ApiVersionDeprecationHandler.java
  2. 4
      spring-web/src/main/java/org/springframework/web/accept/ApiVersionStrategy.java
  3. 6
      spring-web/src/main/java/org/springframework/web/accept/DefaultApiVersionStrategy.java
  4. 3
      spring-web/src/main/java/org/springframework/web/accept/StandardApiVersionDeprecationHandler.java
  5. 2
      spring-web/src/test/java/org/springframework/web/accept/StandardApiVersionDeprecationHandlerTests.java
  6. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionDeprecationHandler.java
  7. 3
      spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionStrategy.java
  8. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/accept/DefaultApiVersionStrategy.java
  9. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandler.java
  10. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java
  11. 2
      spring-webflux/src/test/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandlerTests.java
  12. 2
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

5
spring-web/src/main/java/org/springframework/web/accept/ApiVersionDeprecationHandler.java

@ -35,9 +35,12 @@ public interface ApiVersionDeprecationHandler { @@ -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);
}

4
spring-web/src/main/java/org/springframework/web/accept/ApiVersionStrategy.java

@ -91,10 +91,12 @@ public interface ApiVersionStrategy { @@ -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);
}

6
spring-web/src/main/java/org/springframework/web/accept/DefaultApiVersionStrategy.java

@ -180,9 +180,11 @@ public class DefaultApiVersionStrategy implements ApiVersionStrategy { @@ -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);
}
}

3
spring-web/src/main/java/org/springframework/web/accept/StandardApiVersionDeprecationHandler.java

@ -87,7 +87,8 @@ public class StandardApiVersionDeprecationHandler implements ApiVersionDeprecati @@ -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)) {

2
spring-web/src/test/java/org/springframework/web/accept/StandardApiVersionDeprecationHandlerTests.java

@ -53,7 +53,7 @@ public class StandardApiVersionDeprecationHandlerTests { @@ -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);

3
spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionDeprecationHandler.java

@ -33,8 +33,9 @@ public interface ApiVersionDeprecationHandler { @@ -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);
}

3
spring-webflux/src/main/java/org/springframework/web/reactive/accept/ApiVersionStrategy.java

@ -93,9 +93,10 @@ public interface ApiVersionStrategy { @@ -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);
}

4
spring-webflux/src/main/java/org/springframework/web/reactive/accept/DefaultApiVersionStrategy.java

@ -181,9 +181,9 @@ public class DefaultApiVersionStrategy implements ApiVersionStrategy { @@ -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);
}
}

2
spring-webflux/src/main/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandler.java

@ -86,7 +86,7 @@ public class StandardApiVersionDeprecationHandler implements ApiVersionDeprecati @@ -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();

2
spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java

@ -206,7 +206,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport @@ -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;

2
spring-webflux/src/test/java/org/springframework/web/reactive/accept/StandardApiVersionDeprecationHandlerTests.java

@ -54,7 +54,7 @@ public class StandardApiVersionDeprecationHandlerTests { @@ -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");

2
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

@ -803,7 +803,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport @@ -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;
}
}

Loading…
Cancel
Save