|
17 | 17 | package org.springframework.cloud.function.context.config; |
18 | 18 |
|
19 | 19 | import java.util.Map; |
| 20 | +import java.util.Map.Entry; |
20 | 21 | import java.util.function.Function; |
21 | 22 |
|
22 | 23 | import org.apache.commons.logging.Log; |
@@ -133,14 +134,8 @@ private Object route(Object input, boolean originalInputIsPublisher) { |
133 | 134 | } |
134 | 135 | } |
135 | 136 | if (function == null) { |
136 | | - if (StringUtils.hasText((String) message.getHeaders().get(FunctionProperties.FUNCTION_DEFINITION))) { |
137 | | - function = functionFromDefinition((String) message.getHeaders().get(FunctionProperties.FUNCTION_DEFINITION)); |
138 | | - if (function.isInputTypePublisher()) { |
139 | | - this.assertOriginalInputIsNotPublisher(originalInputIsPublisher); |
140 | | - } |
141 | | - } |
142 | | - else if (StringUtils.hasText((String) message.getHeaders().get(FunctionProperties.ROUTING_EXPRESSION))) { |
143 | | - function = this.functionFromExpression((String) message.getHeaders().get(FunctionProperties.ROUTING_EXPRESSION), message, true); |
| 137 | + function = this.locateFunctionFromDefinitionOrExpression(message); |
| 138 | + if (function != null) { |
144 | 139 | if (function.isInputTypePublisher()) { |
145 | 140 | this.assertOriginalInputIsNotPublisher(originalInputIsPublisher); |
146 | 141 | } |
@@ -196,6 +191,18 @@ else if (StringUtils.hasText(functionProperties.getRoutingExpression())) { |
196 | 191 | return function.apply(input); |
197 | 192 | } |
198 | 193 |
|
| 194 | + private FunctionInvocationWrapper locateFunctionFromDefinitionOrExpression(Message<?> message) { |
| 195 | + for (Entry<String, Object> headerEntry : message.getHeaders().entrySet()) { |
| 196 | + if (headerEntry.getKey().equalsIgnoreCase(FunctionProperties.FUNCTION_DEFINITION)) { |
| 197 | + return functionFromDefinition((String) headerEntry.getValue()); |
| 198 | + } |
| 199 | + else if (headerEntry.getKey().equalsIgnoreCase(FunctionProperties.ROUTING_EXPRESSION)) { |
| 200 | + return this.functionFromExpression((String) headerEntry.getValue(), message, true); |
| 201 | + } |
| 202 | + } |
| 203 | + return null; |
| 204 | + } |
| 205 | + |
199 | 206 | private void assertOriginalInputIsNotPublisher(boolean originalInputIsPublisher) { |
200 | 207 | Assert.isTrue(!originalInputIsPublisher, "Routing input of type Publisher is not supported per individual " |
201 | 208 | + "values (e.g., message header or POJO). Instead you should use 'spring.cloud.function.definition' or " |
|
0 commit comments