diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionAroundWrapper.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionAroundWrapper.java index 5cc22cf1c..eff1e8c8d 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionAroundWrapper.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/catalog/FunctionAroundWrapper.java @@ -40,8 +40,9 @@ public abstract class FunctionAroundWrapper implements BiFunction) input, targetFunction); + + if (input instanceof Message || targetFunction.isOutputTypePublisher()) { + return this.doApply(input, targetFunction); } else if (targetFunction.isSupplier() && !targetFunction.isOutputTypePublisher()) { result = this.doApply(null, targetFunction); @@ -53,5 +54,5 @@ public abstract class FunctionAroundWrapper implements BiFunction input, FunctionInvocationWrapper targetFunction); + protected abstract Object doApply(Object input, FunctionInvocationWrapper targetFunction); } diff --git a/spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/MarcinSleuthTests.java b/spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/MarcinSleuthTests.java deleted file mode 100644 index 59a07004c..000000000 --- a/spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/MarcinSleuthTests.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2021-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.cloud.function.context.catalog; - -import java.util.function.Function; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.cloud.function.context.FunctionCatalog; -import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.messaging.Message; -import org.springframework.messaging.support.MessageBuilder; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Oleg Zhurakousky - */ -public class MarcinSleuthTests { - - private ApplicationContext context; - - private FunctionCatalog configureCatalog(Class... configClass) { - this.context = new SpringApplicationBuilder(configClass) - .run("--logging.level.org.springframework.cloud.function=DEBUG", - "--spring.main.lazy-initialization=true"); - FunctionCatalog catalog = context.getBean(FunctionCatalog.class); - return catalog; - } - - @BeforeEach - public void before() { - System.clearProperty("spring.cloud.function.definition"); - } - - @Test - public void testMarcinHeaderInjection() { - FunctionCatalog catalog = this.configureCatalog(SampleFunctionConfiguration.class); - - FunctionInvocationWrapper function = catalog.lookup("echo", "application/json"); - Message result = (Message) function.apply(MessageBuilder.withPayload("hello").build()); - assertThat(result.getHeaders().get("his-name")).isEqualTo("marcin"); - } - - @EnableAutoConfiguration - @Configuration - protected static class SampleFunctionConfiguration { - - @Bean - public Function, Message> echo() { - return m -> m; - } - - @Bean - public FunctionAroundWrapper aroundWrapper() { - return new FunctionAroundWrapper() { - - @Override - protected Object doApply(Message input, - FunctionInvocationWrapper targetFunction) { - return targetFunction.apply(MessageBuilder.fromMessage(input).setHeader("his-name", "marcin").build()); - } - }; - } - } -}