Java Code Examples for org.springframework.web.util.pattern.PathPatternParser#parse()

The following examples show how to use org.springframework.web.util.pattern.PathPatternParser#parse() . 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: PatternsRequestConditionTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void matchTrailingSlash() throws Exception {
	MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));

	PatternsRequestCondition condition = createPatternsCondition("/foo");
	PatternsRequestCondition match = condition.getMatchingCondition(exchange);

	assertNotNull(match);
	assertEquals("Should match by default", "/foo",
			match.getPatterns().iterator().next().getPatternString());

	condition = createPatternsCondition("/foo");
	match = condition.getMatchingCondition(exchange);

	assertNotNull(match);
	assertEquals("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)",
			"/foo", match.getPatterns().iterator().next().getPatternString());

	PathPatternParser parser = new PathPatternParser();
	parser.setMatchOptionalTrailingSeparator(false);
	condition = new PatternsRequestCondition(parser.parse("/foo"));
	match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/")));

	assertNull(match);
}
 
Example 2
Source File: PatternsRequestConditionTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void matchTrailingSlash() throws Exception {
	MockServerWebExchange exchange = MockServerWebExchange.from(get("/foo/"));

	PatternsRequestCondition condition = createPatternsCondition("/foo");
	PatternsRequestCondition match = condition.getMatchingCondition(exchange);

	assertNotNull(match);
	assertEquals("Should match by default", "/foo",
			match.getPatterns().iterator().next().getPatternString());

	condition = createPatternsCondition("/foo");
	match = condition.getMatchingCondition(exchange);

	assertNotNull(match);
	assertEquals("Trailing slash should be insensitive to useSuffixPatternMatch settings (SPR-6164, SPR-5636)",
			"/foo", match.getPatterns().iterator().next().getPatternString());

	PathPatternParser parser = new PathPatternParser();
	parser.setMatchOptionalTrailingSeparator(false);
	condition = new PatternsRequestCondition(parser.parse("/foo"));
	match = condition.getMatchingCondition(MockServerWebExchange.from(get("/foo/")));

	assertNull(match);
}
 
Example 3
Source File: RequestPredicates.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Return a function that creates new path-matching {@code RequestPredicates}
 * from pattern Strings using the given {@link PathPatternParser}.
 * <p>This method can be used to specify a non-default, customized
 * {@code PathPatternParser} when resolving path patterns.
 * @param patternParser the parser used to parse patterns given to the returned function
 * @return a function that resolves a pattern String into a path-matching
 * {@code RequestPredicates} instance
 */
public static Function<String, RequestPredicate> pathPredicates(PathPatternParser patternParser) {
	Assert.notNull(patternParser, "PathPatternParser must not be null");
	return pattern -> new PathPatternPredicate(patternParser.parse(pattern));
}
 
Example 4
Source File: RequestPredicates.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Return a function that creates new path-matching {@code RequestPredicates}
 * from pattern Strings using the given {@link PathPatternParser}.
 * <p>This method can be used to specify a non-default, customized
 * {@code PathPatternParser} when resolving path patterns.
 * @param patternParser the parser used to parse patterns given to the returned function
 * @return a function that resolves a pattern String into a path-matching
 * {@code RequestPredicates} instance
 */
public static Function<String, RequestPredicate> pathPredicates(PathPatternParser patternParser) {
	Assert.notNull(patternParser, "PathPatternParser must not be null");
	return pattern -> new PathPatternPredicate(patternParser.parse(pattern));
}
 
Example 5
Source File: RequestPredicates.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Return a function that creates new path-matching {@code RequestPredicates}
 * from pattern Strings using the given {@link PathPatternParser}.
 * <p>This method can be used to specify a non-default, customized
 * {@code PathPatternParser} when resolving path patterns.
 * @param patternParser the parser used to parse patterns given to the returned function
 * @return a function that resolves a pattern String into a path-matching
 * {@code RequestPredicates} instance
 */
public static Function<String, RequestPredicate> pathPredicates(PathPatternParser patternParser) {
	Assert.notNull(patternParser, "PathPatternParser must not be null");
	return pattern -> new PathPatternPredicate(patternParser.parse(pattern));
}