If I set path prefixes dynamically using PrefixPathGatewayFilterFactory, and one of them happens to be an empty string, I get an exception
Caused by: java.lang.IllegalArgumentException: 'uriTemplate' must not be null
It's because its apply() method calls the UriTemplate constructor
@Override
public GatewayFilter apply(Config config) {
return new GatewayFilter() {
final UriTemplate uriTemplate = new UriTemplate(config.prefix);
which in turn checks the prefix for emptiness (not just nullness, as the exception message suggests)
public UriTemplate(String uriTemplate) {
Assert.hasText(uriTemplate, "'uriTemplate' must not be null");
It's super-easy to fix: simply replace
Assert.hasText(uriTemplate, "'uriTemplate' must not be null");
with
Assert.notNull(uriTemplate, "'uriTemplate' must not be null");
I want to point out that RewritePathGatewayFilterFactory does support empty replacements, for example
My Spring Cloud version is 2023.0.0, Spring Boot is at 3.2.1
If I set path prefixes dynamically using
PrefixPathGatewayFilterFactory, and one of them happens to be an empty string, I get an exceptionIt's because its
apply()method calls theUriTemplateconstructorwhich in turn checks the prefix for emptiness (not just nullness, as the exception message suggests)
It's super-easy to fix: simply replace
with
I want to point out that
RewritePathGatewayFilterFactorydoes support empty replacements, for exampleMy Spring Cloud version is 2023.0.0, Spring Boot is at 3.2.1