Minor enhancements to the previosu commit

Resolves #448
This commit is contained in:
Oleg Zhurakousky
2020-02-10 20:43:11 +01:00
parent 005d87181f
commit 6c4b5051c3

View File

@@ -88,6 +88,8 @@ import org.springframework.util.StringUtils;
* {@link #register(FunctionRegistration)} operation are stored/cached locally.
*
* @author Oleg Zhurakousky
* @author Eric Botard
*
* @since 3.0
*/
public class BeanFactoryAwareFunctionRegistry
@@ -596,12 +598,12 @@ public class BeanFactoryAwareFunctionRegistry
}
else {
result = this.invokeFunction(this.composed ? input
: this.convertInputValueIfNecessary(input, FunctionTypeUtils.getInputType(this.functionType, 0)));
: (input == null ? input : this.convertInputValueIfNecessary(input, FunctionTypeUtils.getInputType(this.functionType, 0))));
}
}
// Outputs will be converted only if we're told how (via acceptedOutputMimeTypes), otherwise output returned as is.
if (!ObjectUtils.isEmpty(this.acceptedOutputMimeTypes)) {
if (result != null && !ObjectUtils.isEmpty(this.acceptedOutputMimeTypes)) {
result = result instanceof Publisher
? this.convertOutputPublisherIfNecessary((Publisher<?>) result, enricher, this.acceptedOutputMimeTypes)
: this.convertOutputValueIfNecessary(result, enricher, this.acceptedOutputMimeTypes);
@@ -634,9 +636,12 @@ public class BeanFactoryAwareFunctionRegistry
}
convertedValue = Tuples.fromArray(convertedInputArray);
}
else if (value != null) {
else {
List<MimeType> acceptedContentTypes = MimeTypeUtils.parseMimeTypes(acceptedOutputMimeTypes[0].toString());
if (CollectionUtils.isEmpty(acceptedContentTypes)) {
convertedValue = value;
}
else {
for (int i = 0; i < acceptedContentTypes.size() && convertedValue == null; i++) {
MimeType acceptedContentType = acceptedContentTypes.get(i);
if (value instanceof Message) {
@@ -666,11 +671,13 @@ public class BeanFactoryAwareFunctionRegistry
}
}
}
}
if (convertedValue == null) {
throw new MessageConversionException(COULD_NOT_CONVERT_OUTPUT);
}
return convertedValue;
}
@SuppressWarnings("rawtypes")