GH-679 Fix output conversion for composed functions
This commit is contained in:
@@ -277,7 +277,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
return null;
|
||||
}
|
||||
Function<?, ?> resultFunction = null;
|
||||
if (this.registrationsByName.containsKey(definition)) {
|
||||
if (this.registrationsByName.containsKey(definition) && ObjectUtils.isEmpty(acceptedOutputTypes)) {
|
||||
Object targetFunction = this.registrationsByName.get(definition).getTarget();
|
||||
Type functionType = this.registrationsByName.get(definition).getType().getType();
|
||||
if (targetFunction instanceof FunctionInvocationWrapper) {
|
||||
@@ -343,7 +343,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
registrationsByName.putIfAbsent(name, registration);
|
||||
}
|
||||
|
||||
function = new FunctionInvocationWrapper(function, currentFunctionType, name, names.length > 1 ? new String[] {} : acceptedOutputTypes);
|
||||
function = new FunctionInvocationWrapper(function, currentFunctionType, name, !names[0].equals("origin") && name.equals(names[names.length - 1]) ? acceptedOutputTypes : new String[] {});
|
||||
|
||||
if (originFunctionType == null) {
|
||||
originFunctionType = currentFunctionType;
|
||||
@@ -723,7 +723,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
}
|
||||
|
||||
if (convertedValue == null) {
|
||||
throw new MessageConversionException(COULD_NOT_CONVERT_OUTPUT);
|
||||
convertedValue = value;
|
||||
}
|
||||
return convertedValue;
|
||||
}
|
||||
|
||||
@@ -244,6 +244,25 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat(function.apply("foo")).isEqualTo("OOF");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompositionWithOutputConversion() {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
Function<Flux<String>, Flux<Message<byte[]>>> fluxFunction = catalog.lookup("uppercase|reverseFlux", "application/json");
|
||||
List<Message<byte[]>> result = fluxFunction.apply(Flux.just("hello", "bye")).collectList().block();
|
||||
assertThat(result.get(0).getPayload()).isEqualTo("\"OLLEH\"".getBytes());
|
||||
assertThat(result.get(1).getPayload()).isEqualTo("\"EYB\"".getBytes());
|
||||
|
||||
fluxFunction = catalog.lookup("uppercase|reverse|reverseFlux", "application/json");
|
||||
result = fluxFunction.apply(Flux.just("hello", "bye")).collectList().block();
|
||||
assertThat(result.get(0).getPayload()).isEqualTo("\"HELLO\"".getBytes());
|
||||
assertThat(result.get(1).getPayload()).isEqualTo("\"BYE\"".getBytes());
|
||||
|
||||
fluxFunction = catalog.lookup("uppercase|reverseFlux|reverse", "application/json");
|
||||
result = fluxFunction.apply(Flux.just("hello", "bye")).collectList().block();
|
||||
assertThat(result.get(0).getPayload()).isEqualTo("\"HELLO\"".getBytes());
|
||||
assertThat(result.get(1).getPayload()).isEqualTo("\"BYE\"".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompositionSupplierAndFunction() {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
|
||||
Reference in New Issue
Block a user