Skip to content

Commit 77555a0

Browse files
committed
GH-1514 Correct the function filtering documentation
The documentation stated that spring.cloud.function.definition can be used to explicitly define which functions are exported by the web module. It does not; every function in the catalog is exported. Document the spring.cloud.function.http.<method-name> properties as the way to restrict invocation and add a test showing that the definition property does not filter. Resolves #1514 Signed-off-by: Oleg Zhurakousky <oleg.zhurakousky@broadcom.com> (cherry picked from commit 38b495b)
1 parent f5fbd01 commit 77555a0

2 files changed

Lines changed: 95 additions & 7 deletions

File tree

‎docs/modules/ROOT/pages/spring-cloud-function/standalone-web-applications.adoc‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,30 @@ of the actual URL, giving user ability to use it for evaluation and computation.
8080
[[function-filtering-rules]]
8181
== Function Filtering rules
8282

83-
In situations where there are more than one function in catalog there may be a need to only export certain functions or function compositions. In that case you can use
84-
the same `spring.cloud.function.definition` property listing functions you intend to export delimited by `;`.
85-
Note that in this case nothing will be mapped to the root path and functions that are not listed (including compositions) are not going to be exported.
83+
In situations where there are more than one function in catalog there may be a need to only export certain functions or function compositions.
84+
The `spring.cloud.function.definition` property can not be used for that. It does not restrict which functions are exported; every function in the catalog
85+
is available under its name (e.g., `localhost:8080/foo`) regardless of its value. The property is only used to map a function or a function composition to the root path
86+
or to a URL that can not be resolved to a function, as described above.
87+
88+
To restrict which functions can be invoked, use the `spring.cloud.function.http.<method-name>` properties described in xref:spring-cloud-function/standalone-web-applications.adoc#crud-rest-with-spring-cloud-function[CRUD REST with Spring Cloud Function].
89+
For each HTTP method they list, delimited by `;`, the functions and function compositions that may be invoked with that method.
90+
A request for a function that is not listed for its method is rejected with `405 Method Not Allowed`.
8691

8792
For example,
8893

8994
----
90-
--spring.cloud.function.definition=foo;bar
95+
spring.cloud.function.http.GET=foo;bar
96+
spring.cloud.function.http.POST=foo;bar
9197
----
9298

93-
This will only export function `foo` and function `bar` regardless how many functions are available in catalog (e.g., `localhost:8080/foo`).
99+
This only allows `foo` and `bar` to be invoked with `GET` and `POST` (e.g., `localhost:8080/foo`) regardless of how many functions are available in catalog.
94100

95101
----
96-
--spring.cloud.function.definition=foo|bar;baz
102+
spring.cloud.function.http.POST=foo|bar;baz
97103
----
98104

99-
This will only export function composition `foo|bar` and function `baz` regardless how many functions are available in catalog (e.g., `localhost:8080/foo,bar`).
105+
This only allows the function composition `foo|bar` and the function `baz` to be invoked with `POST` (e.g., `localhost:8080/foo,bar`).
106+
Methods for which no property is provided are not restricted.
100107

101108
== Http Headers propagation
102109

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2026-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.function.test;
18+
19+
import java.util.function.Function;
20+
21+
import org.junit.jupiter.api.Test;
22+
import reactor.core.publisher.Mono;
23+
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.boot.SpringBootConfiguration;
26+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
27+
import org.springframework.boot.test.context.SpringBootTest;
28+
import org.springframework.boot.webtestclient.autoconfigure.AutoConfigureWebTestClient;
29+
import org.springframework.context.annotation.Bean;
30+
import org.springframework.test.annotation.DirtiesContext;
31+
import org.springframework.test.web.reactive.server.WebTestClient;
32+
33+
/**
34+
* Documents that {@code spring.cloud.function.definition} does not restrict which
35+
* functions are exported by the web module. Restricting is done with
36+
* {@code spring.cloud.function.http.<METHOD>}.
37+
*/
38+
@SpringBootTest({ "spring.main.web-application-type=REACTIVE",
39+
"spring.functional.enabled=false",
40+
"spring.cloud.function.definition=uppercase;reverse" })
41+
@AutoConfigureWebTestClient
42+
@DirtiesContext
43+
public class DefinitionPropertyDoesNotFilterExportsTests {
44+
45+
@Autowired
46+
private WebTestClient client;
47+
48+
@Test
49+
public void functionNotListedInDefinitionIsStillExported() {
50+
this.client.post().uri("/lowercase").body(Mono.just("ABC"), String.class).exchange()
51+
.expectStatus().isOk().expectBody(String.class).isEqualTo("abc");
52+
}
53+
54+
@Test
55+
public void listedFunctionIsExported() {
56+
this.client.post().uri("/uppercase").body(Mono.just("abc"), String.class).exchange()
57+
.expectStatus().isOk().expectBody(String.class).isEqualTo("ABC");
58+
}
59+
60+
@SpringBootConfiguration
61+
@EnableAutoConfiguration
62+
protected static class TestConfiguration {
63+
64+
@Bean
65+
public Function<String, String> uppercase() {
66+
return String::toUpperCase;
67+
}
68+
69+
@Bean
70+
public Function<String, String> reverse() {
71+
return v -> new StringBuilder(v).reverse().toString();
72+
}
73+
74+
@Bean
75+
public Function<String, String> lowercase() {
76+
return String::toLowerCase;
77+
}
78+
79+
}
80+
81+
}

0 commit comments

Comments
 (0)