Add static factory/accessor methods to LookupPath
Issue: SPR-15397
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.reactive.handler;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -33,7 +32,6 @@ import org.springframework.web.cors.reactive.CorsUtils;
|
||||
import org.springframework.web.cors.reactive.DefaultCorsProcessor;
|
||||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.reactive.HandlerMapping;
|
||||
import org.springframework.web.server.support.LookupPath;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.WebHandler;
|
||||
import org.springframework.web.server.support.HttpRequestPathHelper;
|
||||
@@ -174,19 +172,6 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport im
|
||||
});
|
||||
}
|
||||
|
||||
protected LookupPath getLookupPath(ServerWebExchange exchange) {
|
||||
return exchange.<LookupPath>getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE)
|
||||
.orElseGet(() -> {
|
||||
LookupPath lookupPath = createLookupPath(exchange);
|
||||
exchange.getAttributes().put(LookupPath.LOOKUP_PATH_ATTRIBUTE, lookupPath);
|
||||
return lookupPath;
|
||||
});
|
||||
}
|
||||
|
||||
protected LookupPath createLookupPath(ServerWebExchange exchange) {
|
||||
return getPathHelper().getLookupPathForRequest(exchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up a handler for the given request, returning an empty {@code Mono}
|
||||
* if no specific one is found. This method is called by {@link #getHandler}.
|
||||
|
||||
@@ -101,7 +101,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping {
|
||||
|
||||
@Override
|
||||
public Mono<Object> getHandlerInternal(ServerWebExchange exchange) {
|
||||
LookupPath lookupPath = getLookupPath(exchange);
|
||||
LookupPath lookupPath = LookupPath.getOrCreate(exchange, getPathHelper());
|
||||
Object handler;
|
||||
try {
|
||||
handler = lookupHandler(lookupPath, exchange);
|
||||
|
||||
@@ -185,9 +185,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
private int getLookupPathIndex(ServerWebExchange exchange) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
String requestPath = request.getURI().getPath();
|
||||
LookupPath lookupPath = exchange
|
||||
.<LookupPath>getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE)
|
||||
.orElseGet(() -> getPathHelper().getLookupPathForRequest(exchange));
|
||||
LookupPath lookupPath = LookupPath.getOrCreate(exchange, getPathHelper());
|
||||
return requestPath.indexOf(lookupPath.getPath());
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
return this;
|
||||
}
|
||||
|
||||
LookupPath lookupPath = getLookupPath(exchange);
|
||||
LookupPath lookupPath = LookupPath.getCurrent(exchange);
|
||||
List<String> matches = getMatchingPatterns(lookupPath);
|
||||
|
||||
return matches.isEmpty() ? null :
|
||||
@@ -195,11 +195,6 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
this.useTrailingSlashMatch, this.fileExtensions);
|
||||
}
|
||||
|
||||
private LookupPath getLookupPath(ServerWebExchange exchange) {
|
||||
return exchange.<LookupPath>getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE)
|
||||
.orElseThrow(() -> new IllegalStateException("No LookupPath attribute."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the patterns matching the given lookup path. Invoking this method should
|
||||
* yield results equivalent to those of calling
|
||||
@@ -263,8 +258,8 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(PatternsRequestCondition other, ServerWebExchange exchange) {
|
||||
LookupPath lookupPath = getLookupPath(exchange);
|
||||
Comparator<String> patternComparator = this.pathMatcher.getPatternComparator(lookupPath.getPath());
|
||||
String path = LookupPath.getCurrent(exchange).getPath();
|
||||
Comparator<String> patternComparator = this.pathMatcher.getPatternComparator(path);
|
||||
Iterator<String> iterator = this.patterns.iterator();
|
||||
Iterator<String> iteratorOther = other.patterns.iterator();
|
||||
while (iterator.hasNext() && iteratorOther.hasNext()) {
|
||||
|
||||
@@ -257,7 +257,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
|
||||
*/
|
||||
@Override
|
||||
public Mono<HandlerMethod> getHandlerInternal(ServerWebExchange exchange) {
|
||||
LookupPath lookupPath = getLookupPath(exchange);
|
||||
LookupPath lookupPath = LookupPath.getOrCreate(exchange, getPathHelper());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Looking up handler method for path " + lookupPath);
|
||||
}
|
||||
|
||||
@@ -257,9 +257,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport
|
||||
* Use the request path the leading and trailing slash stripped.
|
||||
*/
|
||||
private String getDefaultViewName(ServerWebExchange exchange) {
|
||||
String path = exchange.<LookupPath>getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE)
|
||||
.map(LookupPath::getPath)
|
||||
.orElseThrow(() -> new IllegalStateException("No LookupPath attribute."));
|
||||
String path = LookupPath.getCurrent(exchange).getPath();
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user