Tweak logic in stream invokers
* If there is only one function, use it unconditionally * If no functions match, ensure that null is not the selector * If a conversion succeeds, check the type of the result
This commit is contained in:
@@ -48,6 +48,8 @@ public class StreamListeningConsumerInvoker implements SmartInitializingSingleto
|
||||
|
||||
private final String[] names;
|
||||
|
||||
private static final String NOENDPOINT = "__NOENDPOINT__";
|
||||
|
||||
public StreamListeningConsumerInvoker(FunctionCatalog functionCatalog,
|
||||
FunctionInspector functionInspector,
|
||||
CompositeMessageConverterFactory converterFactory, String defaultEndpoint,
|
||||
@@ -79,14 +81,23 @@ public class StreamListeningConsumerInvoker implements SmartInitializingSingleto
|
||||
private String select(Message<?> input) {
|
||||
String name = defaultEndpoint;
|
||||
if (name == null) {
|
||||
for (String candidate : names) {
|
||||
Class<?> inputType = functionInspector.getInputType(candidate);
|
||||
if (this.converter.fromMessage(input, inputType) != null) {
|
||||
name = candidate;
|
||||
break;
|
||||
if (names.length == 1) {
|
||||
name = names[0];
|
||||
}
|
||||
else {
|
||||
for (String candidate : names) {
|
||||
Class<?> inputType = functionInspector.getInputType(candidate);
|
||||
Object value = this.converter.fromMessage(input, inputType);
|
||||
if (value != null && inputType.isInstance(value)) {
|
||||
name = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
return NOENDPOINT;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ public class StreamListeningFunctionInvoker implements SmartInitializingSingleto
|
||||
|
||||
private final String[] names;
|
||||
|
||||
private static final String NOENDPOINT = "__NOENDPOINT__";
|
||||
|
||||
public StreamListeningFunctionInvoker(FunctionCatalog functionCatalog,
|
||||
FunctionInspector functionInspector,
|
||||
CompositeMessageConverterFactory converterFactory, String defaultEndpoint,
|
||||
@@ -82,14 +84,23 @@ public class StreamListeningFunctionInvoker implements SmartInitializingSingleto
|
||||
private String select(Message<?> input) {
|
||||
String name = defaultEndpoint;
|
||||
if (name == null) {
|
||||
for (String candidate : names) {
|
||||
Class<?> inputType = functionInspector.getInputType(candidate);
|
||||
if (this.converter.fromMessage(input, inputType) != null) {
|
||||
name = candidate;
|
||||
break;
|
||||
if (names.length == 1) {
|
||||
name = names[0];
|
||||
}
|
||||
else {
|
||||
for (String candidate : names) {
|
||||
Class<?> inputType = functionInspector.getInputType(candidate);
|
||||
Object value = this.converter.fromMessage(input, inputType);
|
||||
if (value != null && inputType.isInstance(value)) {
|
||||
name = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (name == null) {
|
||||
return NOENDPOINT;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user