Polish use of LookupPath
This commit is contained in:
@@ -175,12 +175,12 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport im
|
||||
}
|
||||
|
||||
protected LookupPath getLookupPath(ServerWebExchange exchange) {
|
||||
Optional<LookupPath> attribute = exchange.getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE);
|
||||
return attribute.orElseGet(() -> {
|
||||
LookupPath lookupPath = createLookupPath(exchange);
|
||||
exchange.getAttributes().put(LookupPath.LOOKUP_PATH_ATTRIBUTE, lookupPath);
|
||||
return lookupPath;
|
||||
});
|
||||
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) {
|
||||
|
||||
@@ -185,7 +185,9 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
||||
private int getLookupPathIndex(ServerWebExchange exchange) {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
String requestPath = request.getURI().getPath();
|
||||
LookupPath lookupPath = getPathHelper().getLookupPathForRequest(exchange);
|
||||
LookupPath lookupPath = exchange
|
||||
.<LookupPath>getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE)
|
||||
.orElseGet(() -> getPathHelper().getLookupPathForRequest(exchange));
|
||||
return requestPath.indexOf(lookupPath.getPath());
|
||||
}
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.util.PathMatcher;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.server.support.LookupPath;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.support.LookupPath;
|
||||
import org.springframework.web.util.pattern.ParsingPathMatcher;
|
||||
|
||||
/**
|
||||
@@ -187,8 +187,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
return this;
|
||||
}
|
||||
|
||||
LookupPath lookupPath = exchange
|
||||
.<LookupPath>getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE).get();
|
||||
LookupPath lookupPath = getLookupPath(exchange);
|
||||
List<String> matches = getMatchingPatterns(lookupPath);
|
||||
|
||||
return matches.isEmpty() ? null :
|
||||
@@ -196,6 +195,11 @@ 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
|
||||
@@ -259,8 +263,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(PatternsRequestCondition other, ServerWebExchange exchange) {
|
||||
LookupPath lookupPath = exchange
|
||||
.<LookupPath>getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE).get();
|
||||
LookupPath lookupPath = getLookupPath(exchange);
|
||||
Comparator<String> patternComparator = this.pathMatcher.getPatternComparator(lookupPath.getPath());
|
||||
Iterator<String> iterator = this.patterns.iterator();
|
||||
Iterator<String> iteratorOther = other.patterns.iterator();
|
||||
|
||||
@@ -32,13 +32,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolverBuilder;
|
||||
import org.springframework.web.reactive.result.condition.RequestCondition;
|
||||
import org.springframework.web.reactive.result.method.RequestMappingInfo;
|
||||
import org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping;
|
||||
import org.springframework.web.server.support.LookupPath;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* An extension of {@link RequestMappingInfoHandlerMapping} that creates
|
||||
@@ -169,11 +167,6 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi
|
||||
AnnotatedElementUtils.hasAnnotation(beanType, RequestMapping.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LookupPath createLookupPath(ServerWebExchange exchange) {
|
||||
return getPathHelper().getLookupPathForRequest(exchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses method and type-level @{@link RequestMapping} annotations to create
|
||||
* the RequestMappingInfo.
|
||||
|
||||
@@ -257,7 +257,9 @@ 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).get().getPath();
|
||||
String path = exchange.<LookupPath>getAttribute(LookupPath.LOOKUP_PATH_ATTRIBUTE)
|
||||
.map(LookupPath::getPath)
|
||||
.orElseThrow(() -> new IllegalStateException("No LookupPath attribute."));
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user