Commit 61502bde authored by Phillip Webb's avatar Phillip Webb

Replace deprecated constructor with mutate builder

Update `ControllerEndpointHandlerMapping` to use the new `mutate()`
builder rather than deprecated constructors.

Closes gh-24999
parent c9a2c4e3
...@@ -30,7 +30,6 @@ import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEn ...@@ -30,7 +30,6 @@ import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEn
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.result.condition.PatternsRequestCondition;
import org.springframework.web.reactive.result.method.RequestMappingInfo; import org.springframework.web.reactive.result.method.RequestMappingInfo;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.util.pattern.PathPattern; import org.springframework.web.util.pattern.PathPattern;
...@@ -92,21 +91,13 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi ...@@ -92,21 +91,13 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
if (patterns.isEmpty()) { if (patterns.isEmpty()) {
patterns = Collections.singleton(getPathPatternParser().parse("")); patterns = Collections.singleton(getPathPatternParser().parse(""));
} }
PathPattern[] endpointMappedPatterns = patterns.stream() String[] endpointMappedPatterns = patterns.stream()
.map((pattern) -> getEndpointMappedPattern(endpoint, pattern)).toArray(PathPattern[]::new); .map((pattern) -> getEndpointMappedPattern(endpoint, pattern)).toArray(String[]::new);
return withNewPatterns(mapping, endpointMappedPatterns); return mapping.mutate().paths(endpointMappedPatterns).build();
} }
private PathPattern getEndpointMappedPattern(ExposableControllerEndpoint endpoint, PathPattern pattern) { private String getEndpointMappedPattern(ExposableControllerEndpoint endpoint, PathPattern pattern) {
return getPathPatternParser().parse(this.endpointMapping.createSubPath(endpoint.getRootPath() + pattern)); return this.endpointMapping.createSubPath(endpoint.getRootPath() + pattern);
}
@SuppressWarnings("deprecation")
private RequestMappingInfo withNewPatterns(RequestMappingInfo mapping, PathPattern[] patterns) {
PatternsRequestCondition patternsCondition = new PatternsRequestCondition(patterns);
return new RequestMappingInfo(patternsCondition, mapping.getMethodsCondition(), mapping.getParamsCondition(),
mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(),
mapping.getCustomCondition());
} }
@Override @Override
......
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -31,7 +31,6 @@ import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEn ...@@ -31,7 +31,6 @@ import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEn
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
...@@ -96,22 +95,13 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi ...@@ -96,22 +95,13 @@ public class ControllerEndpointHandlerMapping extends RequestMappingHandlerMappi
} }
String[] endpointMappedPatterns = patterns.stream() String[] endpointMappedPatterns = patterns.stream()
.map((pattern) -> getEndpointMappedPattern(endpoint, pattern)).toArray(String[]::new); .map((pattern) -> getEndpointMappedPattern(endpoint, pattern)).toArray(String[]::new);
return withNewPatterns(mapping, endpointMappedPatterns); return mapping.mutate().paths(endpointMappedPatterns).build();
} }
private String getEndpointMappedPattern(ExposableControllerEndpoint endpoint, String pattern) { private String getEndpointMappedPattern(ExposableControllerEndpoint endpoint, String pattern) {
return this.endpointMapping.createSubPath(endpoint.getRootPath() + pattern); return this.endpointMapping.createSubPath(endpoint.getRootPath() + pattern);
} }
@SuppressWarnings("deprecation")
private RequestMappingInfo withNewPatterns(RequestMappingInfo mapping, String[] patterns) {
PatternsRequestCondition patternsCondition = new PatternsRequestCondition(patterns, null, null,
useSuffixPatternMatch(), useTrailingSlashMatch(), null);
return new RequestMappingInfo(patternsCondition, mapping.getMethodsCondition(), mapping.getParamsCondition(),
mapping.getHeadersCondition(), mapping.getConsumesCondition(), mapping.getProducesCondition(),
mapping.getCustomCondition());
}
@Override @Override
protected boolean hasCorsConfigurationSource(Object handler) { protected boolean hasCorsConfigurationSource(Object handler) {
return this.corsConfiguration != null; return this.corsConfiguration != null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment