Initial support for Supplier functions in server-webmvc

See gh-3646
This commit is contained in:
spencergibb
2025-02-05 11:15:37 -05:00
parent adf32f641c
commit 41606b7576
2 changed files with 24 additions and 1 deletions

View File

@@ -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();

View File

@@ -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<String> hello() {
return () -> "hello";
}
@Bean
public RouterFunction<ServerResponse> 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
}