|
56 | 56 | import org.springframework.cloud.function.context.FunctionRegistration; |
57 | 57 | import org.springframework.cloud.function.context.FunctionRegistry; |
58 | 58 | import org.springframework.cloud.function.context.PostProcessingFunction; |
| 59 | +import org.springframework.cloud.function.context.config.KotlinLambdaToFunctionAutoConfiguration; |
59 | 60 | import org.springframework.cloud.function.context.config.RoutingFunction; |
60 | 61 | import org.springframework.cloud.function.core.FunctionInvocationHelper; |
61 | 62 | import org.springframework.cloud.function.json.JsonMapper; |
|
72 | 73 | import org.springframework.messaging.converter.MessageConverter; |
73 | 74 | import org.springframework.messaging.support.MessageBuilder; |
74 | 75 | import org.springframework.util.Assert; |
| 76 | +import org.springframework.util.ClassUtils; |
75 | 77 | import org.springframework.util.CollectionUtils; |
76 | 78 | import org.springframework.util.MimeTypeUtils; |
77 | 79 | import org.springframework.util.ObjectUtils; |
78 | 80 | import org.springframework.util.StringUtils; |
79 | 81 |
|
80 | 82 |
|
| 83 | + |
| 84 | + |
81 | 85 | /** |
82 | 86 | * Implementation of {@link FunctionCatalog} and {@link FunctionRegistry} which |
83 | 87 | * does not depend on Spring's {@link BeanFactory}. |
@@ -443,6 +447,11 @@ public class FunctionInvocationWrapper implements Function<Object, Object>, Cons |
443 | 447 | if (target instanceof PostProcessingFunction) { |
444 | 448 | this.postProcessor = (PostProcessingFunction) target; |
445 | 449 | } |
| 450 | + if (ClassUtils.isPresent("kotlin.jvm.functions.Function0", ClassUtils.getDefaultClassLoader()) |
| 451 | + && target instanceof KotlinLambdaToFunctionAutoConfiguration.KotlinFunctionWrapper kotlinFunction |
| 452 | + && kotlinFunction.getKotlinLambdaTarget() instanceof PostProcessingFunction) { |
| 453 | + this.postProcessor = (PostProcessingFunction) kotlinFunction.getKotlinLambdaTarget(); |
| 454 | + } |
446 | 455 | this.target = target; |
447 | 456 | this.inputType = this.normalizeType(inputType); |
448 | 457 | this.outputType = this.normalizeType(outputType); |
@@ -770,6 +779,9 @@ else if (this.isConsumer()) { |
770 | 779 | } |
771 | 780 |
|
772 | 781 | if (this.postProcessor != null) { |
| 782 | + if (!(result instanceof Message)) { |
| 783 | + result = MessageBuilder.withPayload(result).build(); |
| 784 | + } |
773 | 785 | this.unconvertedResult.set((Message<Object>) result); |
774 | 786 | } |
775 | 787 |
|
|
0 commit comments