GH-708 Initial refactoring and consolidation of s-c-function-web MVC part.
This commit is contained in:
@@ -720,7 +720,25 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private Object fluxifyInputIfNecessary(Object input) {
|
||||
if (!(input instanceof Publisher) && this.isTypePublisher(this.inputType) && !FunctionTypeUtils.isMultipleArgumentType(this.inputType)) {
|
||||
if (FunctionTypeUtils.isMultipleArgumentType(this.inputType)) {
|
||||
return input;
|
||||
}
|
||||
|
||||
if (!this.isRoutingFunction() && !(input instanceof Publisher)) {
|
||||
Object payload = input;
|
||||
if (input instanceof Message) {
|
||||
payload = ((Message) input).getPayload();
|
||||
}
|
||||
if (JsonMapper.isJsonStringRepresentsCollection(payload) && !FunctionTypeUtils.isTypeCollection(this.inputType)) {
|
||||
payload = jsonMapper.fromJson(payload, List.class);
|
||||
MessageHeaders headers = ((Message) input).getHeaders();
|
||||
input = ((List) payload).stream()
|
||||
.map(p -> MessageBuilder.withPayload(p).copyHeaders(headers).build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
if (this.isTypePublisher(this.inputType) && !(input instanceof Publisher)) {
|
||||
if (input == null) {
|
||||
input = FunctionTypeUtils.isMono(this.inputType) ? Mono.empty() : Flux.empty();
|
||||
}
|
||||
@@ -740,6 +758,9 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
input = FunctionTypeUtils.isMono(this.inputType) ? Mono.just(input) : Flux.just(input);
|
||||
}
|
||||
}
|
||||
else if (input instanceof Iterable && !FunctionTypeUtils.isTypeCollection(this.inputType)) {
|
||||
input = Flux.fromIterable((Iterable) input);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -946,7 +967,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
}
|
||||
}
|
||||
else {
|
||||
convertedInput = this.convertNonMessageInputIfNecessary(type, input, JsonMapper.isJsonString(input));
|
||||
convertedInput = this.convertNonMessageInputIfNecessary(type, input, JsonMapper.isJsonString(input) || input instanceof Map);
|
||||
if (convertedInput != null && logger.isDebugEnabled()) {
|
||||
logger.debug("Converted input: " + input + " to: " + convertedInput);
|
||||
}
|
||||
|
||||
@@ -547,6 +547,29 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat(result.getHeaders().get("after")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testEachElementInFluxIsProcessed() {
|
||||
FunctionCatalog catalog = this.configureCatalog(SampleFunctionConfiguration.class);
|
||||
Function f = catalog.lookup("uppercasePerson");
|
||||
|
||||
Flux flux = Flux.just("{\"id\":1, \"name\":\"oleg\"}", "{\"id\":2, \"name\":\"seva\"}");
|
||||
Flux result = (Flux) f.apply(flux);
|
||||
|
||||
List<Person> list = (List) result.collectList().block();
|
||||
assertThat(list.size()).isEqualTo(2);
|
||||
assertThat(list.get(0).name).isEqualTo("OLEG");
|
||||
assertThat(list.get(1).name).isEqualTo("SEVA");
|
||||
|
||||
|
||||
|
||||
result = (Flux) f.apply(new GenericMessage<String>("[{\"id\":1, \"name\":\"oleg\"}, {\"id\":2, \"name\":\"seva\"}]"));
|
||||
list = (List) result.collectList().block();
|
||||
assertThat(list.size()).isEqualTo(2);
|
||||
assertThat(list.get(0).name).isEqualTo("OLEG");
|
||||
assertThat(list.get(1).name).isEqualTo("SEVA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGH_608() {
|
||||
ApplicationContext context = new SpringApplicationBuilder(SampleFunctionConfiguration.class)
|
||||
|
||||
Reference in New Issue
Block a user