Java Code Examples for org.springframework.web.util.pattern.PathPattern#PathMatchInfo

The following examples show how to use org.springframework.web.util.pattern.PathPattern#PathMatchInfo . These examples are extracted from open source projects. 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 Project: spring-analysis-note   File: RequestPredicates.java    License: 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 2
/**
 * Expose URI template variables, matrix variables, and producible media types in the request.
 * @see HandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE
 * @see HandlerMapping#MATRIX_VARIABLES_ATTRIBUTE
 * @see HandlerMapping#PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
 */
@Override
protected void handleMatch(RequestMappingInfo info, HandlerMethod handlerMethod,
		ServerWebExchange exchange) {

	super.handleMatch(info, handlerMethod, exchange);

	PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();

	PathPattern bestPattern;
	Map<String, String> uriVariables;
	Map<String, MultiValueMap<String, String>> matrixVariables;

	Set<PathPattern> patterns = info.getPatternsCondition().getPatterns();
	if (patterns.isEmpty()) {
		bestPattern = getPathPatternParser().parse(lookupPath.value());
		uriVariables = Collections.emptyMap();
		matrixVariables = Collections.emptyMap();
	}
	else {
		bestPattern = patterns.iterator().next();
		PathPattern.PathMatchInfo result = bestPattern.matchAndExtract(lookupPath);
		Assert.notNull(result, () ->
				"Expected bestPattern: " + bestPattern + " to match lookupPath " + lookupPath);
		uriVariables = result.getUriVariables();
		matrixVariables = result.getMatrixVariables();
	}

	exchange.getAttributes().put(BEST_MATCHING_HANDLER_ATTRIBUTE, handlerMethod);
	exchange.getAttributes().put(BEST_MATCHING_PATTERN_ATTRIBUTE, bestPattern);
	exchange.getAttributes().put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables);
	exchange.getAttributes().put(MATRIX_VARIABLES_ATTRIBUTE, matrixVariables);

	if (!info.getProducesCondition().getProducibleMediaTypes().isEmpty()) {
		Set<MediaType> mediaTypes = info.getProducesCondition().getProducibleMediaTypes();
		exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes);
	}
}
 
Example 3
Source Project: spring-analysis-note   File: RequestPredicates.java    License: 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 4
@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 5
/**
 * Expose URI template variables, matrix variables, and producible media types in the request.
 * @see HandlerMapping#URI_TEMPLATE_VARIABLES_ATTRIBUTE
 * @see HandlerMapping#MATRIX_VARIABLES_ATTRIBUTE
 * @see HandlerMapping#PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE
 */
@Override
protected void handleMatch(RequestMappingInfo info, HandlerMethod handlerMethod,
		ServerWebExchange exchange) {

	super.handleMatch(info, handlerMethod, exchange);

	PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication();

	PathPattern bestPattern;
	Map<String, String> uriVariables;
	Map<String, MultiValueMap<String, String>> matrixVariables;

	Set<PathPattern> patterns = info.getPatternsCondition().getPatterns();
	if (patterns.isEmpty()) {
		bestPattern = getPathPatternParser().parse(lookupPath.value());
		uriVariables = Collections.emptyMap();
		matrixVariables = Collections.emptyMap();
	}
	else {
		bestPattern = patterns.iterator().next();
		PathPattern.PathMatchInfo result = bestPattern.matchAndExtract(lookupPath);
		Assert.notNull(result, () ->
				"Expected bestPattern: " + bestPattern + " to match lookupPath " + lookupPath);
		uriVariables = result.getUriVariables();
		matrixVariables = result.getMatrixVariables();
	}

	exchange.getAttributes().put(BEST_MATCHING_HANDLER_ATTRIBUTE, handlerMethod);
	exchange.getAttributes().put(BEST_MATCHING_PATTERN_ATTRIBUTE, bestPattern);
	exchange.getAttributes().put(URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriVariables);
	exchange.getAttributes().put(MATRIX_VARIABLES_ATTRIBUTE, matrixVariables);

	if (!info.getProducesCondition().getProducibleMediaTypes().isEmpty()) {
		Set<MediaType> mediaTypes = info.getProducesCondition().getProducibleMediaTypes();
		exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, mediaTypes);
	}
}