RouterFunction honors PathPatternParser in config

This commit introduces a way to change the PathPatternParser used in
PathPredicates, by way of a ChangePathPatternParserVisitor. This
visitor is used by both WebFluxConfigurationSupport and
WebMvcConfigurationSupport to make sure the configured parser is used.

Closes gh-23236
This commit is contained in:
Arjen Poutsma
2020-05-01 14:00:16 +02:00
parent 671d4519b2
commit e9d9de5f99
12 changed files with 454 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import reactor.test.StepVerifier;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
@@ -67,4 +68,26 @@ public class RouterFunctionMappingTests {
.verify();
}
@Test
public void changeParser() throws Exception {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route()
.GET("/foo", handlerFunction)
.POST("/bar", handlerFunction)
.build();
RouterFunctionMapping mapping = new RouterFunctionMapping(routerFunction);
mapping.setMessageReaders(this.codecConfigurer.getReaders());
mapping.setUseCaseSensitiveMatch(false);
mapping.afterPropertiesSet();
ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("https://example.com/FOO"));
Mono<Object> result = mapping.getHandler(exchange);
StepVerifier.create(result)
.expectNext(handlerFunction)
.verifyComplete();
}
}