Initial support for Supplier functions in server-webmvc
See gh-3646
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user