diff --git a/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/handler/HandlerFunctions.java b/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/handler/HandlerFunctions.java index 4b35cc44..04cfc1a0 100644 --- a/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/handler/HandlerFunctions.java +++ b/spring-cloud-gateway-server-mvc/src/main/java/org/springframework/cloud/gateway/server/mvc/handler/HandlerFunctions.java @@ -61,7 +61,7 @@ public abstract class HandlerFunctions { FunctionInvocationWrapper function = functionCatalog.lookup(expandedFunctionName, request.headers().accept().stream().map(MimeType::toString).toArray(String[]::new)); if (function != null) { - Object body = request.body(function.getRawInputType()); + Object body = function.isSupplier() ? null : request.body(function.getRawInputType()); return processRequest(request, function, body, false, Collections.emptyList(), Collections.emptyList()); } return ServerResponse.notFound().build(); diff --git a/spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/handler/FunctionHandlerTests.java b/spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/handler/FunctionHandlerTests.java index 28d17153..73de8492 100644 --- a/spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/handler/FunctionHandlerTests.java +++ b/spring-cloud-gateway-server-mvc/src/test/java/org/springframework/cloud/gateway/server/mvc/handler/FunctionHandlerTests.java @@ -18,7 +18,9 @@ package org.springframework.cloud.gateway.server.mvc.handler; import java.util.Locale; import java.util.function.Function; +import java.util.function.Supplier; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -66,6 +68,19 @@ public class FunctionHandlerTests { .isEqualTo("HELLO"); } + @Disabled + @Test + public void testSupplierFunctionWorks() { + restClient.get() + .uri("/supplierfunction") + .accept(MediaType.TEXT_PLAIN) + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("hello"); + } + @SpringBootConfiguration @EnableAutoConfiguration protected static class TestConfiguration { @@ -75,6 +90,11 @@ public class FunctionHandlerTests { return s -> s.toUpperCase(Locale.ROOT); } + @Bean + Supplier hello() { + return () -> "hello"; + } + @Bean public RouterFunction gatewayRouterFunctionsSimpleFunction() { // @formatter:off @@ -83,6 +103,9 @@ public class FunctionHandlerTests { .build() .and(route("testtemplatedfunction") .POST("/templatedfunction/{fnName}", fn("{fnName}")) + .build()) + .and(route("testsupplierfunction") + .POST("/supplierfunction", fn("hello")) .build()); // @formatter:on }