Add skipInput/Output conversion attributes to FunctionInvocationWrapper

This commit is contained in:
Oleg Zhurakousky
2020-10-23 17:19:32 +02:00
parent 388cd6674b
commit 908b1c49c0
2 changed files with 15 additions and 30 deletions

View File

@@ -34,21 +34,11 @@ public class FunctionProperties {
/** /**
* Name of the header to be used to instruct function catalog to skip input type conversion. * Name of the header to be used to instruct function catalog to skip input type conversion.
* @deprecated since 3.1. Use #SKIP_INPUT_CONVERSION_HEADER * @deprecated since 3.1. Not used anymore
*/ */
@Deprecated @Deprecated
public final static String SKIP_CONVERSION_HEADER = "skip-input-type-conversion"; public final static String SKIP_CONVERSION_HEADER = "skip-input-type-conversion";
/**
* Name of the header to be used to instruct function catalog to skip input type conversion.
*/
public final static String SKIP_INPUT_CONVERSION_HEADER = "skip-input-type-conversion";
/**
* Name of the header to be used to instruct function catalog to skip output type conversion.
*/
public final static String SKIP_OUTPUT_CONVERSION_HEADER = "skip-output-type-conversion";
/** /**
* Name of the header to be used to instruct function to apply this content type for output conversion. * Name of the header to be used to instruct function to apply this content type for output conversion.
*/ */

View File

@@ -275,6 +275,10 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
private String[] expectedOutputContentType; private String[] expectedOutputContentType;
private boolean skipInputConversion;
private boolean skipOutputConversion;
/* /*
* This is primarily to support Stream's ability to access * This is primarily to support Stream's ability to access
* un-converted payload (e.g., to evaluate expression on some attribute of a payload) * un-converted payload (e.g., to evaluate expression on some attribute of a payload)
@@ -292,6 +296,14 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
this.message = this.inputType != null && FunctionTypeUtils.isMessage(this.inputType); this.message = this.inputType != null && FunctionTypeUtils.isMessage(this.inputType);
} }
public void setSkipInputConversion(boolean skipInputConversion) {
this.skipInputConversion = skipInputConversion;
}
public void setSkipOutputConversion(boolean skipOutputConversion) {
this.skipOutputConversion = skipOutputConversion;
}
public Object getTarget() { public Object getTarget() {
return target; return target;
} }
@@ -684,7 +696,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
+ this.functionDefinition + "' since it's input type is Void and as such it is treated as Supplier."); + this.functionDefinition + "' since it's input type is Void and as such it is treated as Supplier.");
input = null; input = null;
} }
if (this.isSkipConversionHeaderSet(input, true)) { if (this.skipInputConversion && !(input instanceof Publisher)) {
if (!FunctionTypeUtils.isMessage(type)) { if (!FunctionTypeUtils.isMessage(type)) {
input = this.isFunction() input = this.isFunction()
? new OriginalMessageHolder(((Message) input).getPayload(), (Message<?>) input) ? new OriginalMessageHolder(((Message) input).getPayload(), (Message<?>) input)
@@ -733,7 +745,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
* set as a header in a message or explicitly provided as part of the lookup. * set as a header in a message or explicitly provided as part of the lookup.
*/ */
private Object convertOutputIfNecessary(Object output, Type type, String[] contentType) { private Object convertOutputIfNecessary(Object output, Type type, String[] contentType) {
if (this.isSkipConversionHeaderSet(output, false)) { if (this.skipOutputConversion) {
return output; return output;
} }
if (output instanceof Message && !this.containsRetainMessageSignalInHeaders((Message) output)) { if (output instanceof Message && !this.containsRetainMessageSignalInHeaders((Message) output)) {
@@ -769,23 +781,6 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
return convertedOutput; return convertedOutput;
} }
/*
* This header may be set by a framework that uses s-c-function but does not want to rely on type
* conversion mechanism provided by s-c-function
*/
private boolean isSkipConversionHeaderSet(Object value, boolean input) {
if (value instanceof Message) {
Message message = (Message) value;
String headerName = input ? FunctionProperties.SKIP_INPUT_CONVERSION_HEADER : FunctionProperties.SKIP_OUTPUT_CONVERSION_HEADER;
if (message.getHeaders().containsKey(headerName)) {
Object skipValue = message.getHeaders().get(headerName);
boolean skip = skipValue instanceof Boolean ? (boolean) skipValue : Boolean.parseBoolean((String) skipValue);
return skip;
}
}
return false;
}
/** /**
* Will check if message contains any of the headers that are considered to serve as * Will check if message contains any of the headers that are considered to serve as
* signals to retain output as Message (regardless of the output type of function). * signals to retain output as Message (regardless of the output type of function).