GH-727 Fix Azure's Supplier<Publisher> logic to avoid NPE

Resolves #727
This commit is contained in:
Oleg Zhurakousky
2021-11-18 13:29:07 +01:00
parent 2efb79d470
commit 71f3af825d
2 changed files with 40 additions and 8 deletions

View File

@@ -110,7 +110,11 @@ public class FunctionInvoker<I, O> {
public O handleRequest(I input, ExecutionContext executionContext) {
String functionDefinition = executionContext.getFunctionName();
FunctionInvocationWrapper function = FUNCTION_CATALOG.lookup(functionDefinition);
if (function == null && StringUtils.hasText(functionDefinition) && APPLICATION_CONTEXT.containsBean(functionDefinition)) {
if (function != null && StringUtils.hasText(functionDefinition) && !function.getFunctionDefinition().equals(functionDefinition)) {
this.registerFunction(functionDefinition);
function = FUNCTION_CATALOG.lookup(functionDefinition);
}
else if (function == null && StringUtils.hasText(functionDefinition) && APPLICATION_CONTEXT.containsBean(functionDefinition)) {
this.registerFunction(functionDefinition);
function = FUNCTION_CATALOG.lookup(functionDefinition);
}
@@ -128,7 +132,7 @@ public class FunctionInvoker<I, O> {
resultList.addAll((Collection) resultItem);
}
else {
if (Collection.class.isAssignableFrom(FunctionTypeUtils.getRawType(function.getInputType()))
if (!function.isSupplier() && Collection.class.isAssignableFrom(FunctionTypeUtils.getRawType(function.getInputType()))
&& !Collection.class.isAssignableFrom(FunctionTypeUtils.getRawType(function.getOutputType()))) {
return (O) this.convertOutputIfNecessary(input, resultItem);
}
@@ -145,15 +149,17 @@ public class FunctionInvoker<I, O> {
@SuppressWarnings({ "unchecked", "rawtypes" })
private void registerFunction(String functionDefinition) {
FunctionRegistration functionRegistration =
new FunctionRegistration(APPLICATION_CONTEXT.getBean(functionDefinition), functionDefinition);
if (APPLICATION_CONTEXT.containsBean(functionDefinition)) {
FunctionRegistration functionRegistration =
new FunctionRegistration(APPLICATION_CONTEXT.getBean(functionDefinition), functionDefinition);
Type type = FunctionContextUtils.
findType(functionDefinition, APPLICATION_CONTEXT.getBeanFactory());
Type type = FunctionContextUtils.
findType(functionDefinition, APPLICATION_CONTEXT.getBeanFactory());
functionRegistration = functionRegistration.type(type);
((FunctionRegistry) FUNCTION_CATALOG).register(functionRegistration);
((FunctionRegistry) FUNCTION_CATALOG).register(functionRegistration);
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -186,7 +192,7 @@ public class FunctionInvoker<I, O> {
@SuppressWarnings("unchecked")
private Object convertOutputIfNecessary(Object input, Object output) {
if (input != null && input instanceof HttpRequestMessage) {
if (input instanceof HttpRequestMessage) {
HttpRequestMessage<I> requestMessage = (HttpRequestMessage<I>) input;
Map<String, Object> headers = null;
if (output instanceof Message) {