Skip to content

Commit b128f59

Browse files
committed
Expose handler to ApiVersionDeprecationHandler implementations
Closes gh-35750
1 parent cd67010 commit b128f59

File tree

12 files changed

+24
-14
lines changed

12 files changed

+24
-14
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ public interface ApiVersionDeprecationHandler {
3535
* accordingly, e.g. by setting response headers to signal the deprecation,
3636
* to specify relevant dates and provide links to further details.
3737
* @param version the resolved and parsed request version
38+
* @param handler the handler chosen for the request
3839
* @param request the current request
3940
* @param response the current response
4041
*/
41-
void handleVersion(Comparable<?> version, HttpServletRequest request, HttpServletResponse response);
42+
void handleVersion(
43+
Comparable<?> version, Object handler,
44+
HttpServletRequest request, HttpServletResponse response);
4245

4346
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ void validateVersion(@Nullable Comparable<?> requestVersion, HttpServletRequest
9191
* accordingly, e.g. by setting response headers to signal the deprecation,
9292
* to specify relevant dates and provide links to further details.
9393
* @param version the resolved and parsed request version
94+
* @param handler the handler chosen for the request
9495
* @param request the current request
9596
* @param response the current response
9697
* @see ApiVersionDeprecationHandler
9798
*/
98-
void handleDeprecations(Comparable<?> version, HttpServletRequest request, HttpServletResponse response);
99+
void handleDeprecations(
100+
Comparable<?> version, Object handler, HttpServletRequest request, HttpServletResponse response);
99101

100102
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,11 @@ public void validateVersion(@Nullable Comparable<?> requestVersion, HttpServletR
180180
}
181181

182182
@Override
183-
public void handleDeprecations(Comparable<?> version, HttpServletRequest request, HttpServletResponse response) {
183+
public void handleDeprecations(
184+
Comparable<?> version, Object handler, HttpServletRequest request, HttpServletResponse response) {
185+
184186
if (this.deprecationHandler != null) {
185-
this.deprecationHandler.handleVersion(version, request, response);
187+
this.deprecationHandler.handleVersion(version, handler, request, response);
186188
}
187189
}
188190

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ public VersionSpec configureVersion(String version) {
8787

8888
@Override
8989
public void handleVersion(
90-
Comparable<?> requestVersion, HttpServletRequest request, HttpServletResponse response) {
90+
Comparable<?> requestVersion, Object handler,
91+
HttpServletRequest request, HttpServletResponse response) {
9192

9293
for (VersionInfo info : this.infos.values()) {
9394
if (info.match(requestVersion, request)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void basic() {
5353
.setSunsetDate(getDate(sunsetDate))
5454
.setSunsetLink(URI.create(sunsetUrl));
5555

56-
handler.handleVersion("1.1", request, response);
56+
handler.handleVersion("1.1", new Object(), request, response);
5757

5858
assertThat(response.getHeader("Deprecation")).isEqualTo("@1688169599");
5959
assertThat(response.getHeader("Sunset")).isEqualTo(sunsetDate);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ public interface ApiVersionDeprecationHandler {
3333
* accordingly, e.g. by setting response headers to signal the deprecation,
3434
* to specify relevant dates and provide links to further details.
3535
* @param version the resolved and parsed request version
36+
* @param handler the handler chosen for the exchange
3637
* @param exchange the current exchange
3738
*/
38-
void handleVersion(Comparable<?> version, ServerWebExchange exchange);
39+
void handleVersion(Comparable<?> version, Object handler, ServerWebExchange exchange);
3940

4041
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ void validateVersion(@Nullable Comparable<?> requestVersion, ServerWebExchange e
9393
* accordingly, e.g. by setting response headers to signal the deprecation,
9494
* to specify relevant dates and provide links to further details.
9595
* @param version the resolved and parsed request version
96+
* @param handler the handler chosen for the exchange
9697
* @param exchange the current exchange
9798
* @see ApiVersionDeprecationHandler
9899
*/
99-
void handleDeprecations(Comparable<?> version, ServerWebExchange exchange);
100+
void handleDeprecations(Comparable<?> version, Object handler, ServerWebExchange exchange);
100101

101102
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ public void validateVersion(@Nullable Comparable<?> requestVersion, ServerWebExc
181181
}
182182

183183
@Override
184-
public void handleDeprecations(Comparable<?> version, ServerWebExchange exchange) {
184+
public void handleDeprecations(Comparable<?> version, Object handler, ServerWebExchange exchange) {
185185
if (this.deprecationHandler != null) {
186-
this.deprecationHandler.handleVersion(version, exchange);
186+
this.deprecationHandler.handleVersion(version, handler, exchange);
187187
}
188188
}
189189

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public VersionSpec configureVersion(String version) {
8686
}
8787

8888
@Override
89-
public void handleVersion(Comparable<?> requestVersion, ServerWebExchange exchange) {
89+
public void handleVersion(Comparable<?> requestVersion, Object handler, ServerWebExchange exchange) {
9090
for (VersionInfo info : this.infos.values()) {
9191
if (info.match(requestVersion, exchange)) {
9292
HttpHeaders headers = exchange.getResponse().getHeaders();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public Mono<Object> getHandler(ServerWebExchange exchange) {
206206
if (getApiVersionStrategy() != null) {
207207
Comparable<?> version = exchange.getAttribute(API_VERSION_ATTRIBUTE);
208208
if (version != null) {
209-
getApiVersionStrategy().handleDeprecations(version, exchange);
209+
getApiVersionStrategy().handleDeprecations(version, handler, exchange);
210210
}
211211
}
212212
return handler;

0 commit comments

Comments
 (0)