Reduce API Surface in PathPatternRegistry
This commit reduces the exposition of `PathPattern` instances throughout the `HandlerMapping` API and removes some methods from its public API. Issue: SPR-14544
This commit is contained in:
@@ -84,12 +84,16 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
* from the Spring {@code ApplicationContext}. However if this property is
|
||||
* used, the auto-detection is turned off.
|
||||
*/
|
||||
public void setHandlerMap(Map<PathPattern, ResourceWebHandler> handlerMap) {
|
||||
public void setHandlerMap(Map<String, ResourceWebHandler> handlerMap) {
|
||||
if (handlerMap != null) {
|
||||
this.patternRegistry.clear();
|
||||
this.patternRegistry.addAll(handlerMap.keySet());
|
||||
this.handlerMap.clear();
|
||||
this.handlerMap.putAll(handlerMap);
|
||||
|
||||
handlerMap.forEach((pattern, handler) -> {
|
||||
this.patternRegistry
|
||||
.register(pattern)
|
||||
.forEach(pathPattern -> this.handlerMap.put(pathPattern, handler));
|
||||
});
|
||||
this.autodetect = false;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +147,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
"locations=" + resourceHandler.getLocations() + ", " +
|
||||
"resolvers=" + resourceHandler.getResourceResolvers());
|
||||
}
|
||||
this.patternRegistry.add(pattern);
|
||||
this.patternRegistry.register(pattern.getPatternString());
|
||||
this.handlerMap.put(pattern, resourceHandler);
|
||||
}
|
||||
}
|
||||
@@ -179,11 +183,11 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
private int getEndPathIndex(String lookupPath) {
|
||||
int suffixIndex = lookupPath.length();
|
||||
int queryIndex = lookupPath.indexOf("?");
|
||||
if(queryIndex > 0) {
|
||||
if (queryIndex > 0) {
|
||||
suffixIndex = queryIndex;
|
||||
}
|
||||
int hashIndex = lookupPath.indexOf("#");
|
||||
if(hashIndex > 0) {
|
||||
if (hashIndex > 0) {
|
||||
suffixIndex = Math.min(suffixIndex, hashIndex);
|
||||
}
|
||||
return suffixIndex;
|
||||
|
||||
@@ -133,8 +133,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
SortedSet<PathPattern> matches = getMatchingPatterns(lookupPath);
|
||||
|
||||
if(!matches.isEmpty()) {
|
||||
PathPatternRegistry registry = new PathPatternRegistry();
|
||||
registry.addAll(matches);
|
||||
PathPatternRegistry registry = new PathPatternRegistry(matches);
|
||||
return new PatternsRequestCondition(registry, this.pathHelper);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -93,7 +93,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
private final MultiValueMap<PathPattern, T> mappingLookup = new LinkedMultiValueMap<>();
|
||||
|
||||
private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
|
||||
|
||||
|
||||
private final MappingRegistry mappingRegistry = new MappingRegistry();
|
||||
|
||||
|
||||
@@ -129,10 +129,10 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
public void registerMapping(T mapping, Object handler, Method method) {
|
||||
this.readWriteLock.writeLock().lock();
|
||||
try {
|
||||
Set<PathPattern> patterns = getMappingPathPatterns(mapping);
|
||||
getPatternRegistry().addAll(patterns);
|
||||
patterns.forEach(pathPattern -> {
|
||||
this.mappingLookup.add(pathPattern, mapping);
|
||||
getMappingPathPatterns(mapping).forEach(pattern -> {
|
||||
getPatternRegistry().register(pattern).forEach(
|
||||
pathPattern -> this.mappingLookup.add(pathPattern, mapping)
|
||||
);
|
||||
});
|
||||
this.mappingRegistry.register(mapping, handler, method);
|
||||
}
|
||||
@@ -149,8 +149,11 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
public void unregisterMapping(T mapping) {
|
||||
this.readWriteLock.writeLock().lock();
|
||||
try {
|
||||
getMappingPathPatterns(mapping)
|
||||
.forEach(pathPattern -> getPatternRegistry().remove(pathPattern));
|
||||
getMappingPathPatterns(mapping).forEach(pattern -> {
|
||||
getPatternRegistry().unregister(pattern).forEach(
|
||||
pathPattern -> this.mappingLookup.remove(pathPattern, mapping)
|
||||
);
|
||||
});
|
||||
this.mappingRegistry.unregister(mapping);
|
||||
}
|
||||
finally {
|
||||
@@ -420,7 +423,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
/**
|
||||
* Extract and return the URL paths contained in a mapping.
|
||||
*/
|
||||
protected abstract Set<PathPattern> getMappingPathPatterns(T mapping);
|
||||
protected abstract Set<String> getMappingPathPatterns(T mapping);
|
||||
|
||||
/**
|
||||
* Check if a mapping matches the current request and return a (potentially
|
||||
|
||||
@@ -74,8 +74,10 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
||||
* Get the URL path patterns associated with this {@link RequestMappingInfo}.
|
||||
*/
|
||||
@Override
|
||||
protected Set<PathPattern> getMappingPathPatterns(RequestMappingInfo info) {
|
||||
return info.getPatternsCondition().getPatterns();
|
||||
protected Set<String> getMappingPathPatterns(RequestMappingInfo info) {
|
||||
return info.getPatternsCondition().getPatterns().stream()
|
||||
.map(p -> p.getPatternString())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user