Fix function eligibility filtering
This commit is contained in:
@@ -121,6 +121,9 @@ public class BeanFactoryAwareFunctionRegistry extends SimpleFunctionRegistry imp
|
||||
+ "use 'spring.cloud.function.definition' property to explicitly define it.");
|
||||
return null;
|
||||
}
|
||||
if (!isFunctionDefinitionEligible(functionDefinition)) {
|
||||
return null;
|
||||
}
|
||||
FunctionInvocationWrapper function = this.doLookup(type, functionDefinition, expectedOutputMimeTypes);
|
||||
Object syncInstance = functionDefinition == null ? this : functionDefinition;
|
||||
synchronized (syncInstance) {
|
||||
@@ -139,6 +142,9 @@ public class BeanFactoryAwareFunctionRegistry extends SimpleFunctionRegistry imp
|
||||
if (functionCandidate instanceof FunctionRegistration) {
|
||||
functionRegistration = (FunctionRegistration) functionCandidate;
|
||||
}
|
||||
else if (functionCandidate instanceof BiFunction || functionCandidate instanceof BiConsumer) {
|
||||
functionRegistration = this.registerMessagingBiFunction(functionCandidate, functionName);
|
||||
}
|
||||
else if (this.isFunctionPojo(functionCandidate, functionName)) {
|
||||
Method functionalMethod = FunctionTypeUtils.discoverFunctionalMethod(functionCandidate.getClass());
|
||||
functionCandidate = this.proxyTarget(functionCandidate, functionalMethod);
|
||||
@@ -148,9 +154,6 @@ public class BeanFactoryAwareFunctionRegistry extends SimpleFunctionRegistry imp
|
||||
functionRegistration = this.applicationContext
|
||||
.getBean(functionName + FunctionRegistration.REGISTRATION_NAME_SUFFIX, FunctionRegistration.class);
|
||||
}
|
||||
else if (functionCandidate instanceof BiFunction || functionCandidate instanceof BiConsumer) {
|
||||
functionRegistration = this.registerMessagingBiFunction(functionCandidate, functionName);
|
||||
}
|
||||
else {
|
||||
functionType = FunctionTypeUtils.discoverFunctionType(functionCandidate, functionName, this.applicationContext);
|
||||
}
|
||||
|
||||
@@ -188,6 +188,17 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean isFunctionDefinitionEligible(String functionDefinition) {
|
||||
if (this.functionProperties != null) {
|
||||
for (String definition : this.functionProperties.getIneligibleDefinitions()) {
|
||||
if (functionDefinition.contains(definition)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----
|
||||
|
||||
@Override
|
||||
@@ -217,8 +228,10 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
function = this.compose(type, functionDefinition);
|
||||
}
|
||||
|
||||
if (function != null && !ObjectUtils.isEmpty(expectedOutputMimeTypes)) {
|
||||
function.expectedOutputContentType = expectedOutputMimeTypes;
|
||||
if (function != null) {
|
||||
if (!ObjectUtils.isEmpty(expectedOutputMimeTypes)) {
|
||||
function.expectedOutputContentType = expectedOutputMimeTypes;
|
||||
}
|
||||
}
|
||||
else if (logger.isDebugEnabled()) {
|
||||
logger.debug("Function '" + functionDefinition + "' is not found in cache");
|
||||
@@ -243,8 +256,9 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
? functionDefinition.replaceAll(",", "|")
|
||||
: System.getProperty(FunctionProperties.FUNCTION_DEFINITION, "");
|
||||
|
||||
if (!this.getNames(null).contains(functionDefinition)) {
|
||||
List<String> eligibleFunction = this.getNames(null).stream()
|
||||
Set<String> names = this.getNames(null);
|
||||
if (!names.contains(functionDefinition)) {
|
||||
List<String> eligibleFunction = names.stream()
|
||||
.filter(name -> !RoutingFunction.FUNCTION_NAME.equals(name))
|
||||
.collect(Collectors.toList());
|
||||
if (eligibleFunction.size() == 1
|
||||
|
||||
@@ -114,7 +114,7 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
for (String beanName : context.getBeanDefinitionNames()) {
|
||||
try {
|
||||
FunctionInvocationWrapper function = catalog.lookup(beanName);
|
||||
if (function != null) {
|
||||
if (function != null && function.getFunctionDefinition().equals(beanName)) {
|
||||
registeredFunction.add(function);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user