org.springframework.web.util.pattern.PathPattern Java Examples

The following examples show how to use org.springframework.web.util.pattern.PathPattern. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractUrlHandlerMapping.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Look up a handler instance for the given URL lookup path.
 * <p>Supports direct matches, e.g. a registered "/test" matches "/test",
 * and various path pattern matches, e.g. a registered "/t*" matches
 * both "/test" and "/team". For details, see the PathPattern class.
 * @param lookupPath the URL the handler is mapped to
 * @param exchange the current exchange
 * @return the associated handler instance, or {@code null} if not found
 * @see org.springframework.web.util.pattern.PathPattern
 */
@Nullable
protected Object lookupHandler(PathContainer lookupPath, ServerWebExchange exchange) throws Exception {

	List<PathPattern> matches = this.handlerMap.keySet().stream()
			.filter(key -> key.matches(lookupPath))
			.collect(Collectors.toList());

	if (matches.isEmpty()) {
		return null;
	}

	if (matches.size() > 1) {
		matches.sort(PathPattern.SPECIFICITY_COMPARATOR);
		if (logger.isTraceEnabled()) {
			logger.debug(exchange.getLogPrefix() + "Matching patterns " + matches);
		}
	}

	PathPattern pattern = matches.get(0);
	PathContainer pathWithinMapping = pattern.extractPathWithinPattern(lookupPath);
	return handleMatch(this.handlerMap.get(pattern), pattern, pathWithinMapping, exchange);
}
 
Example #2
Source File: PatternsRequestCondition.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Compare the two conditions based on the URL patterns they contain.
 * Patterns are compared one at a time, from top to bottom. If all compared
 * patterns match equally, but one instance has more patterns, it is
 * considered a closer match.
 * <p>It is assumed that both instances have been obtained via
 * {@link #getMatchingCondition(ServerWebExchange)} to ensure they
 * contain only patterns that match the request and are sorted with
 * the best matches on top.
 */
@Override
public int compareTo(PatternsRequestCondition other, ServerWebExchange exchange) {
	Iterator<PathPattern> iterator = this.patterns.iterator();
	Iterator<PathPattern> iteratorOther = other.getPatterns().iterator();
	while (iterator.hasNext() && iteratorOther.hasNext()) {
		int result = PathPattern.SPECIFICITY_COMPARATOR.compare(iterator.next(), iteratorOther.next());
		if (result != 0) {
			return result;
		}
	}
	if (iterator.hasNext()) {
		return -1;
	}
	else if (iteratorOther.hasNext()) {
		return 1;
	}
	else {
		return 0;
	}
}
 
Example #3
Source File: AbstractUrlHandlerMapping.java    From java-technology-stack with MIT License 6 votes vote down vote up
private Object handleMatch(Object handler, PathPattern bestMatch, PathContainer pathWithinMapping,
		ServerWebExchange exchange) {

	// Bean name or resolved handler?
	if (handler instanceof String) {
		String handlerName = (String) handler;
		handler = obtainApplicationContext().getBean(handlerName);
	}

	validateHandler(handler, exchange);

	exchange.getAttributes().put(BEST_MATCHING_HANDLER_ATTRIBUTE, handler);
	exchange.getAttributes().put(BEST_MATCHING_PATTERN_ATTRIBUTE, bestMatch);
	exchange.getAttributes().put(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, pathWithinMapping);

	return handler;
}
 
Example #4
Source File: PatternsRequestCondition.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Returns a new instance with URL patterns from the current instance ("this") and
 * the "other" instance as follows:
 * <ul>
 * <li>If there are patterns in both instances, combine the patterns in "this" with
 * the patterns in "other" using {@link PathPattern#combine(PathPattern)}.
 * <li>If only one instance has patterns, use them.
 * <li>If neither instance has patterns, use an empty String (i.e. "").
 * </ul>
 */
@Override
public PatternsRequestCondition combine(PatternsRequestCondition other) {
	List<PathPattern> combined = new ArrayList<>();
	if (!this.patterns.isEmpty() && !other.patterns.isEmpty()) {
		for (PathPattern pattern1 : this.patterns) {
			for (PathPattern pattern2 : other.patterns) {
				combined.add(pattern1.combine(pattern2));
			}
		}
	}
	else if (!this.patterns.isEmpty()) {
		combined.addAll(this.patterns);
	}
	else if (!other.patterns.isEmpty()) {
		combined.addAll(other.patterns);
	}
	return new PatternsRequestCondition(combined);
}
 
Example #5
Source File: PatternsRequestCondition.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Returns a new instance with URL patterns from the current instance ("this") and
 * the "other" instance as follows:
 * <ul>
 * <li>If there are patterns in both instances, combine the patterns in "this" with
 * the patterns in "other" using {@link PathPattern#combine(PathPattern)}.
 * <li>If only one instance has patterns, use them.
 * <li>If neither instance has patterns, use an empty String (i.e. "").
 * </ul>
 */
@Override
public PatternsRequestCondition combine(PatternsRequestCondition other) {
	SortedSet<PathPattern> combined;
	if (!this.patterns.isEmpty() && !other.patterns.isEmpty()) {
		combined = new TreeSet<>();
		for (PathPattern pattern1 : this.patterns) {
			for (PathPattern pattern2 : other.patterns) {
				combined.add(pattern1.combine(pattern2));
			}
		}
	}
	else if (!this.patterns.isEmpty()) {
		combined = this.patterns;
	}
	else if (!other.patterns.isEmpty()) {
		combined = other.patterns;
	}
	else {
		combined = EMPTY_PATTERNS;
	}
	return new PatternsRequestCondition(combined);
}
 
Example #6
Source File: DispatcherHandlerHandleMethodInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                          Object ret) throws Throwable {
    ServerWebExchange exchange = (ServerWebExchange) allArguments[0];
    AbstractSpan span = (AbstractSpan) objInst.getSkyWalkingDynamicField();

    return ((Mono) ret).doFinally(s -> {
        try {
            Object pathPattern = exchange.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
            if (pathPattern != null) {
                span.setOperationName(((PathPattern) pathPattern).getPatternString());
            }
            HttpStatus httpStatus = exchange.getResponse().getStatusCode();
            // fix webflux-2.0.0-2.1.0 version have bug. httpStatus is null. not support
            if (httpStatus != null) {
                Tags.STATUS_CODE.set(span, Integer.toString(httpStatus.value()));
                if (httpStatus.isError()) {
                    span.errorOccurred();
                }
            }
        } finally {
            span.asyncFinish();
        }
    });

}
 
Example #7
Source File: NestedRouteIntegrationTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Mono<ServerResponse> variables(ServerRequest request) {
	Map<String, String> pathVariables = request.pathVariables();
	Map<String, String> attributePathVariables =
			(Map<String, String>) request.attributes().get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
	assertTrue( (pathVariables.equals(attributePathVariables))
			|| (pathVariables.isEmpty() && (attributePathVariables == null)));

	PathPattern pathPattern = matchingPattern(request);
	String pattern = pathPattern != null ? pathPattern.getPatternString() : "";
	Flux<String> responseBody;
	if (!pattern.isEmpty()) {
		responseBody = Flux.just(pattern, "\n", pathVariables.toString());
	}
	else {
		responseBody = Flux.just(pathVariables.toString());
	}
	return ServerResponse.ok().body(responseBody, String.class);
}
 
Example #8
Source File: PatternsRequestCondition.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Compare the two conditions based on the URL patterns they contain.
 * Patterns are compared one at a time, from top to bottom. If all compared
 * patterns match equally, but one instance has more patterns, it is
 * considered a closer match.
 * <p>It is assumed that both instances have been obtained via
 * {@link #getMatchingCondition(ServerWebExchange)} to ensure they
 * contain only patterns that match the request and are sorted with
 * the best matches on top.
 */
@Override
public int compareTo(PatternsRequestCondition other, ServerWebExchange exchange) {
	Iterator<PathPattern> iterator = this.patterns.iterator();
	Iterator<PathPattern> iteratorOther = other.getPatterns().iterator();
	while (iterator.hasNext() && iteratorOther.hasNext()) {
		int result = PathPattern.SPECIFICITY_COMPARATOR.compare(iterator.next(), iteratorOther.next());
		if (result != 0) {
			return result;
		}
	}
	if (iterator.hasNext()) {
		return -1;
	}
	else if (iteratorOther.hasNext()) {
		return 1;
	}
	else {
		return 0;
	}
}
 
Example #9
Source File: AbstractUrlHandlerMapping.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Look up a handler instance for the given URL lookup path.
 * <p>Supports direct matches, e.g. a registered "/test" matches "/test",
 * and various path pattern matches, e.g. a registered "/t*" matches
 * both "/test" and "/team". For details, see the PathPattern class.
 * @param lookupPath the URL the handler is mapped to
 * @param exchange the current exchange
 * @return the associated handler instance, or {@code null} if not found
 * @see org.springframework.web.util.pattern.PathPattern
 */
@Nullable
protected Object lookupHandler(PathContainer lookupPath, ServerWebExchange exchange) throws Exception {

	List<PathPattern> matches = this.handlerMap.keySet().stream()
			.filter(key -> key.matches(lookupPath))
			.collect(Collectors.toList());

	if (matches.isEmpty()) {
		return null;
	}

	if (matches.size() > 1) {
		matches.sort(PathPattern.SPECIFICITY_COMPARATOR);
		if (logger.isTraceEnabled()) {
			logger.debug(exchange.getLogPrefix() + "Matching patterns " + matches);
		}
	}

	PathPattern pattern = matches.get(0);
	PathContainer pathWithinMapping = pattern.extractPathWithinPattern(lookupPath);
	return handleMatch(this.handlerMap.get(pattern), pattern, pathWithinMapping, exchange);
}
 
Example #10
Source File: RouterFunctionMapping.java    From java-technology-stack with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void setAttributes(Map<String, Object> attributes, ServerRequest serverRequest,
		HandlerFunction<?> handlerFunction) {

	attributes.put(RouterFunctions.REQUEST_ATTRIBUTE, serverRequest);
	attributes.put(BEST_MATCHING_HANDLER_ATTRIBUTE, handlerFunction);

	PathPattern matchingPattern =
			(PathPattern) attributes.get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
	if (matchingPattern != null) {
		attributes.put(BEST_MATCHING_PATTERN_ATTRIBUTE, matchingPattern);
	}
	Map<String, String> uriVariables =
			(Map<String, String>) attributes
					.get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
	if (uriVariables != null) {
		attributes.put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables);
	}
}
 
Example #11
Source File: AbstractUrlHandlerMapping.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private Object handleMatch(Object handler, PathPattern bestMatch, PathContainer pathWithinMapping,
		ServerWebExchange exchange) {

	// Bean name or resolved handler?
	if (handler instanceof String) {
		String handlerName = (String) handler;
		handler = obtainApplicationContext().getBean(handlerName);
	}

	validateHandler(handler, exchange);

	exchange.getAttributes().put(BEST_MATCHING_HANDLER_ATTRIBUTE, handler);
	exchange.getAttributes().put(BEST_MATCHING_PATTERN_ATTRIBUTE, bestMatch);
	exchange.getAttributes().put(PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, pathWithinMapping);

	return handler;
}
 
Example #12
Source File: ResourceUrlProvider.java    From java-technology-stack with MIT License 6 votes vote down vote up
private Mono<String> resolveResourceUrl(ServerWebExchange exchange, PathContainer lookupPath) {
	return this.handlerMap.entrySet().stream()
			.filter(entry -> entry.getKey().matches(lookupPath))
			.min((entry1, entry2) ->
					PathPattern.SPECIFICITY_COMPARATOR.compare(entry1.getKey(), entry2.getKey()))
			.map(entry -> {
				PathContainer path = entry.getKey().extractPathWithinPattern(lookupPath);
				int endIndex = lookupPath.elements().size() - path.elements().size();
				PathContainer mapping = lookupPath.subPath(0, endIndex);
				ResourceWebHandler handler = entry.getValue();
				List<ResourceResolver> resolvers = handler.getResourceResolvers();
				ResourceResolverChain chain = new DefaultResourceResolverChain(resolvers);
				return chain.resolveUrlPath(path.value(), handler.getLocations())
						.map(resolvedPath -> mapping.value() + resolvedPath);
			})
			.orElseGet(() ->{
				if (logger.isTraceEnabled()) {
					logger.trace(exchange.getLogPrefix() + "No match for \"" + lookupPath + "\"");
				}
				return Mono.empty();
			});
}
 
Example #13
Source File: RequestMappingHandlerMappingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path,
		RequestMethod requestMethod) throws Exception {

	Class<?> clazz = ComposedAnnotationController.class;
	Method method = ClassUtils.getMethod(clazz, methodName, (Class<?>[]) null);
	RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, clazz);

	assertNotNull(info);

	Set<PathPattern> paths = info.getPatternsCondition().getPatterns();
	assertEquals(1, paths.size());
	assertEquals(path, paths.iterator().next().getPatternString());

	Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
	assertEquals(1, methods.size());
	assertEquals(requestMethod, methods.iterator().next());

	return info;
}
 
Example #14
Source File: OpenApiResource.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate path.
 *
 * @param restControllers the rest controllers
 * @param map the map
 */
protected void calculatePath(Map<String, Object> restControllers, Map<RequestMappingInfo, HandlerMethod> map) {
	for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : map.entrySet()) {
		RequestMappingInfo requestMappingInfo = entry.getKey();
		HandlerMethod handlerMethod = entry.getValue();
		PatternsRequestCondition patternsRequestCondition = requestMappingInfo.getPatternsCondition();
		Set<PathPattern> patterns = patternsRequestCondition.getPatterns();
		for (PathPattern pathPattern : patterns) {
			String operationPath = pathPattern.getPatternString();
			Map<String, String> regexMap = new LinkedHashMap<>();
			operationPath = PathUtils.parsePath(operationPath, regexMap);
			if (operationPath.startsWith(DEFAULT_PATH_SEPARATOR)
					&& (restControllers.containsKey(handlerMethod.getBean().toString()) || actuatorProvider.isPresent())
					&& isPackageToScan(handlerMethod.getBeanType().getPackage()) && isPathToMatch(operationPath)) {
				Set<RequestMethod> requestMethods = requestMappingInfo.getMethodsCondition().getMethods();
				// default allowed requestmethods
				if (requestMethods.isEmpty())
					requestMethods = this.getDefaultAllowedHttpMethods();
				calculatePath(handlerMethod, operationPath, requestMethods);
			}
		}
	}
}
 
Example #15
Source File: RequestMappingHandlerMappingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path,
		RequestMethod requestMethod) throws Exception {

	Class<?> clazz = ComposedAnnotationController.class;
	Method method = clazz.getMethod(methodName);
	RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, clazz);

	assertNotNull(info);

	Set<PathPattern> paths = info.getPatternsCondition().getPatterns();
	assertEquals(1, paths.size());
	assertEquals(path, paths.iterator().next().getPatternString());

	Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
	assertEquals(1, methods.size());
	assertEquals(requestMethod, methods.iterator().next());

	return info;
}
 
Example #16
Source File: RouterFunctionMapping.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void setAttributes(Map<String, Object> attributes, ServerRequest serverRequest,
		HandlerFunction<?> handlerFunction) {

	attributes.put(RouterFunctions.REQUEST_ATTRIBUTE, serverRequest);
	attributes.put(BEST_MATCHING_HANDLER_ATTRIBUTE, handlerFunction);

	PathPattern matchingPattern =
			(PathPattern) attributes.get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE);
	if (matchingPattern != null) {
		attributes.put(BEST_MATCHING_PATTERN_ATTRIBUTE, matchingPattern);
	}
	Map<String, String> uriVariables =
			(Map<String, String>) attributes
					.get(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
	if (uriVariables != null) {
		attributes.put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables);
	}
}
 
Example #17
Source File: ResourceUrlProvider.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private Mono<String> resolveResourceUrl(ServerWebExchange exchange, PathContainer lookupPath) {
	return this.handlerMap.entrySet().stream()
			.filter(entry -> entry.getKey().matches(lookupPath))
			.min((entry1, entry2) ->
					PathPattern.SPECIFICITY_COMPARATOR.compare(entry1.getKey(), entry2.getKey()))
			.map(entry -> {
				PathContainer path = entry.getKey().extractPathWithinPattern(lookupPath);
				int endIndex = lookupPath.elements().size() - path.elements().size();
				PathContainer mapping = lookupPath.subPath(0, endIndex);
				ResourceWebHandler handler = entry.getValue();
				List<ResourceResolver> resolvers = handler.getResourceResolvers();
				ResourceResolverChain chain = new DefaultResourceResolverChain(resolvers);
				return chain.resolveUrlPath(path.value(), handler.getLocations())
						.map(resolvedPath -> mapping.value() + resolvedPath);
			})
			.orElseGet(() ->{
				if (logger.isTraceEnabled()) {
					logger.trace(exchange.getLogPrefix() + "No match for \"" + lookupPath + "\"");
				}
				return Mono.empty();
			});
}
 
Example #18
Source File: RequestPredicates.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean test(ServerRequest request) {
	PathContainer pathContainer = request.pathContainer();
	PathPattern.PathMatchInfo info = this.pattern.matchAndExtract(pathContainer);
	traceMatch("Pattern", this.pattern.getPatternString(), request.path(), info != null);
	if (info != null) {
		mergeAttributes(request, info.getUriVariables(), this.pattern);
		return true;
	}
	else {
		return false;
	}
}
 
Example #19
Source File: RequestMappingInfoTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void prependPatternWithSlash() {
	RequestMappingInfo actual = paths("foo").build();
	List<PathPattern> patterns = new ArrayList<>(actual.getPatternsCondition().getPatterns());
	assertEquals(1, patterns.size());
	assertEquals("/foo", patterns.get(0).getPatternString());
}
 
Example #20
Source File: ApiVersionWebFilter.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Process the web request and validate the API version in the header. If the API version does not match, then set
 * an HTTP 412 status and write the error message to the response.
 *
 * @param exchange {@inheritDoc}
 * @param chain {@inheritDoc}
 * @return {@inheritDoc}
 */
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
	PathPattern p = new PathPatternParser().parse(V2_API_PATH_PATTERN);
	Mono<Void> filterMono = chain.filter(exchange);
	if (p.matches(exchange.getRequest().getPath()) && version != null && !anyVersionAllowed()) {
		String apiVersion = exchange.getRequest().getHeaders().getFirst(version.getBrokerApiVersionHeader());
		ServerHttpResponse response = exchange.getResponse();
		String message = null;
		if (apiVersion == null) {
			response.setStatusCode(HttpStatus.BAD_REQUEST);
			message = ServiceBrokerApiVersionErrorMessage.from(version.getApiVersion(), "null").toString();
		}
		else if (!version.getApiVersion().equals(apiVersion)) {
			response.setStatusCode(HttpStatus.PRECONDITION_FAILED);
			message = ServiceBrokerApiVersionErrorMessage.from(version.getApiVersion(), apiVersion)
					.toString();
		}
		if (message != null) {
			String json;
			try {
				json = new ObjectMapper().writeValueAsString(new ErrorMessage(message));
			}
			catch (JsonProcessingException e) {
				json = "{}";
			}
			Flux<DataBuffer> responseBody =
					Flux.just(json)
							.map(s -> toDataBuffer(s, response.bufferFactory()));
			filterMono = response.writeWith(responseBody);
		}
	}
	return filterMono;
}
 
Example #21
Source File: SentryConfiguration.java    From hesperides with GNU General Public License v3.0 5 votes vote down vote up
private static String getMatchingPattern(HttpServletRequest request) {
    PathPattern dataRestPathPattern = (PathPattern) request
            .getAttribute(DATA_REST_PATH_PATTERN_ATTRIBUTE);
    if (dataRestPathPattern != null) {
        return dataRestPathPattern.getPatternString();
    }
    return (String) request
            .getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
}
 
Example #22
Source File: PatternsRequestConditionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void equallyMatchingPatternsAreBothPresent() throws Exception {
	PatternsRequestCondition c = createPatternsCondition("/a", "/b");
	assertEquals(2, c.getPatterns().size());
	Iterator<PathPattern> itr = c.getPatterns().iterator();
	assertEquals("/a", itr.next().getPatternString());
	assertEquals("/b", itr.next().getPatternString());
}
 
Example #23
Source File: ResourceUrlProviderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public boolean matches(Object item) {
	if (item != null && item instanceof PathPattern) {
		return ((PathPattern) item).getPatternString().equals(pattern);
	}
	return false;
}
 
Example #24
Source File: RequestPredicates.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static void mergeAttributes(ServerRequest request, Map<String, String> variables,
		PathPattern pattern) {
	Map<String, String> pathVariables = mergePathVariables(request.pathVariables(), variables);
	request.attributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE,
				Collections.unmodifiableMap(pathVariables));

	pattern = mergePatterns(
			(PathPattern) request.attributes().get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE),
			pattern);
	request.attributes().put(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE, pattern);
}
 
Example #25
Source File: RequestPredicates.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public boolean test(ServerRequest request) {
	PathContainer pathContainer = request.pathContainer();
	PathPattern.PathMatchInfo info = this.pattern.matchAndExtract(pathContainer);
	traceMatch("Pattern", this.pattern.getPatternString(), request.path(), info != null);
	if (info != null) {
		mergeAttributes(request, info.getUriVariables(), this.pattern);
		return true;
	}
	else {
		return false;
	}
}
 
Example #26
Source File: RequestPredicates.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static PathPattern mergePatterns(@Nullable PathPattern oldPattern, PathPattern newPattern) {
	if (oldPattern != null) {
		return oldPattern.combine(newPattern);
	}
	else {
		return newPattern;
	}

}
 
Example #27
Source File: ResourceUrlProvider.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Manually configure resource handler mappings.
 * <p><strong>Note:</strong> by default resource mappings are auto-detected
 * from the Spring {@code ApplicationContext}. If this property is used,
 * auto-detection is turned off.
 */
public void registerHandlers(Map<String, ResourceWebHandler> handlerMap) {
	this.handlerMap.clear();
	handlerMap.forEach((rawPattern, resourceWebHandler) -> {
		rawPattern = prependLeadingSlash(rawPattern);
		PathPattern pattern = this.patternParser.parse(rawPattern);
		this.handlerMap.put(pattern, resourceWebHandler);
	});
}
 
Example #28
Source File: RequestPredicates.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static Map<String, Object> mergeAttributes(ServerRequest request,
Map<String, String> pathVariables, PathPattern pattern) {
	Map<String, Object> result = new ConcurrentHashMap<>(request.attributes());

	result.put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE,
			mergePathVariables(request.pathVariables(), pathVariables));

	pattern = mergePatterns(
			(PathPattern) request.attributes().get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE),
			pattern);
	result.put(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE, pattern);
	return result;
}
 
Example #29
Source File: RequestPredicates.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static void mergeAttributes(ServerRequest request, Map<String, String> variables,
		PathPattern pattern) {
	Map<String, String> pathVariables = mergePathVariables(request.pathVariables(), variables);
	request.attributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE,
				Collections.unmodifiableMap(pathVariables));

	pattern = mergePatterns(
			(PathPattern) request.attributes().get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE),
			pattern);
	request.attributes().put(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE, pattern);
}
 
Example #30
Source File: ResourceUrlProvider.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Manually configure resource handler mappings.
 * <p><strong>Note:</strong> by default resource mappings are auto-detected
 * from the Spring {@code ApplicationContext}. If this property is used,
 * auto-detection is turned off.
 */
public void registerHandlers(Map<String, ResourceWebHandler> handlerMap) {
	this.handlerMap.clear();
	handlerMap.forEach((rawPattern, resourceWebHandler) -> {
		rawPattern = prependLeadingSlash(rawPattern);
		PathPattern pattern = this.patternParser.parse(rawPattern);
		this.handlerMap.put(pattern, resourceWebHandler);
	});
}