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 . 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: 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 2
Source File: RequestMappingInfoHandlerMapping.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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 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 4
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 5
Source File: RequestMappingInfoHandlerMapping.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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);
	}
}