GH-791 Add support for propagating input headers
Resolves #791 polishing merge
This commit is contained in:
@@ -170,6 +170,8 @@ public class FunctionProperties implements EnvironmentAware, ApplicationContextA
|
||||
|
||||
private Map<String, Object> outputHeaderMappingExpression;
|
||||
|
||||
private boolean copyInputHeaders;
|
||||
|
||||
public Map<String, Object> getInputHeaderMappingExpression() {
|
||||
return inputHeaderMappingExpression;
|
||||
}
|
||||
@@ -187,5 +189,13 @@ public class FunctionProperties implements EnvironmentAware, ApplicationContextA
|
||||
this.outputHeaderMappingExpression = outputHeaderMappingExpression;
|
||||
}
|
||||
|
||||
public boolean isCopyInputHeaders() {
|
||||
return copyInputHeaders;
|
||||
}
|
||||
|
||||
public void setCopyInputHeaders(boolean copyInputHeaders) {
|
||||
this.copyInputHeaders = copyInputHeaders;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,6 +401,8 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
||||
|
||||
private boolean isSingleton = true;
|
||||
|
||||
private boolean propagateInputHeaders;
|
||||
|
||||
/*
|
||||
* This is primarily to support Stream's ability to access
|
||||
* un-converted payload (e.g., to evaluate expression on some attribute of a payload)
|
||||
@@ -426,6 +428,15 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
||||
this.outputType = this.normalizeType(outputType);
|
||||
this.functionDefinition = functionDefinition;
|
||||
this.message = this.inputType != null && FunctionTypeUtils.isMessage(this.inputType);
|
||||
if (functionProperties != null) {
|
||||
Map<String, FunctionConfigurationProperties> funcConfiguration = functionProperties.getConfiguration();
|
||||
if (!CollectionUtils.isEmpty(funcConfiguration)) {
|
||||
FunctionConfigurationProperties configuration = funcConfiguration.get(functionDefinition);
|
||||
if (configuration != null) {
|
||||
propagateInputHeaders = configuration.isCopyInputHeaders();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSkipOutputConversion() {
|
||||
@@ -1087,6 +1098,9 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
||||
}
|
||||
|
||||
private boolean isExtractPayload(Message<?> message, Type type) {
|
||||
if (this.propagateInputHeaders) {
|
||||
return false;
|
||||
}
|
||||
if (this.isRoutingFunction()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,9 +48,14 @@ public class SmartCompositeMessageConverter extends CompositeMessageConverter {
|
||||
if (!(message.getPayload() instanceof byte[]) && targetClass.isInstance(message.getPayload()) && !(message.getPayload() instanceof Collection<?>)) {
|
||||
return message.getPayload();
|
||||
}
|
||||
Object result = converter.fromMessage(message, targetClass);
|
||||
if (result != null) {
|
||||
return result;
|
||||
try {
|
||||
Object result = converter.fromMessage(message, targetClass);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user