Browse Source

Return Set<PathPattern> from AbstractHandlerMethodMapping.getMappingPathPatterns

This commit revises the signature of getMappingPathPatterns() in
AbstractHandlerMethodMapping to return a set of PathPatterns instead of
a set of Strings.

See gh-22543
pull/22758/head
Sam Brannen 6 years ago
parent
commit
510c0c5ef7
  1. 6
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java
  2. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java
  3. 2
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/HandlerMethodMappingTests.java
  4. 5
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java

6
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java

@ -48,6 +48,7 @@ import org.springframework.web.method.HandlerMethod; @@ -48,6 +48,7 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.reactive.HandlerMapping;
import org.springframework.web.reactive.handler.AbstractHandlerMapping;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.pattern.PathPattern;
/**
* Abstract base class for {@link HandlerMapping} implementations that define
@ -418,7 +419,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap @@ -418,7 +419,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
* Extract and return the URL paths contained in the supplied mapping.
* @since 5.2
*/
protected abstract Set<String> getMappingPathPatterns(T mapping);
protected abstract Set<PathPattern> getMappingPathPatterns(T mapping);
/**
* Check if a mapping matches the current request and return a (potentially
@ -508,7 +509,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap @@ -508,7 +509,8 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
private void validateMethodMapping(HandlerMethod handlerMethod, T mapping) {
// Log a warning if the supplied mapping maps the supplied HandlerMethod
// only to empty paths.
if (logger.isWarnEnabled() && getMappingPathPatterns(mapping).stream().noneMatch(StringUtils::hasText)) {
if (logger.isWarnEnabled() && getMappingPathPatterns(mapping).stream()
.map(PathPattern::getPatternString).noneMatch(StringUtils::hasText)) {
logger.warn(String.format(
"Handler method '%s' in bean '%s' is not mapped to an explicit path. " +
"If you wish to map to all paths, please map explicitly to \"/**\" or \"**\".",

4
spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java

@ -170,8 +170,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi @@ -170,8 +170,8 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
* @since 5.2
*/
@Override
protected Set<String> getMappingPathPatterns(RequestMappingInfo info) {
return info.getPatternsCondition().getPatterns().stream().map(PathPattern::getPatternString).collect(Collectors.toSet());
protected Set<PathPattern> getMappingPathPatterns(RequestMappingInfo info) {
return info.getPatternsCondition().getPatterns();
}
/**

2
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/HandlerMethodMappingTests.java

@ -159,7 +159,7 @@ public class HandlerMethodMappingTests { @@ -159,7 +159,7 @@ public class HandlerMethodMappingTests {
}
@Override
protected Set<String> getMappingPathPatterns(String mapping) {
protected Set<PathPattern> getMappingPathPatterns(String mapping) {
return Collections.emptySet();
}

5
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java

@ -26,7 +26,6 @@ import java.util.List; @@ -26,7 +26,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
@ -480,8 +479,8 @@ public class RequestMappingInfoHandlerMappingTests { @@ -480,8 +479,8 @@ public class RequestMappingInfoHandlerMappingTests {
}
@Override
protected Set<String> getMappingPathPatterns(RequestMappingInfo info) {
return info.getPatternsCondition().getPatterns().stream().map(PathPattern::getPatternString).collect(Collectors.toSet());
protected Set<PathPattern> getMappingPathPatterns(RequestMappingInfo info) {
return info.getPatternsCondition().getPatterns();
}
}

Loading…
Cancel
Save