GH-587 Add support for inferring 'accept' content type for simple types
This fix also introduces new Function property 'accept' with no default value which implicitely would default to application/json unless the output type of the function is String at which point it would default to text/plain. However, if it was explicitely set in FunctionProperties it will be used regardless of the function output type. Resolves #587
This commit is contained in:
@@ -44,10 +44,7 @@ public class FunctionProperties {
|
||||
private String definition;
|
||||
|
||||
|
||||
private String contentType = "application/json";
|
||||
|
||||
|
||||
private String accept = "application/json";
|
||||
private String accept;
|
||||
|
||||
/**
|
||||
* SpEL expression which should result in function definition (e.g., function name or composition instruction).
|
||||
@@ -71,14 +68,6 @@ public class FunctionProperties {
|
||||
this.routingExpression = routingExpression;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getAccept() {
|
||||
return accept;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.type.StandardMethodMetadata;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.converter.CompositeMessageConverter;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -85,20 +84,19 @@ public class BeanFactoryAwareFunctionRegistry extends SimpleFunctionRegistry imp
|
||||
this.applicationContext.getBeanNamesForType(Consumer.class).length;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Set<String> getNames(Class<?> type) {
|
||||
Set<String> registeredNames = super.getNames(type);
|
||||
if (type == null) {
|
||||
registeredNames
|
||||
.addAll(CollectionUtils.arrayToList(this.applicationContext.getBeanNamesForType(Function.class)));
|
||||
.addAll(Arrays.asList(this.applicationContext.getBeanNamesForType(Function.class)));
|
||||
registeredNames
|
||||
.addAll(CollectionUtils.arrayToList(this.applicationContext.getBeanNamesForType(Supplier.class)));
|
||||
.addAll(Arrays.asList(this.applicationContext.getBeanNamesForType(Supplier.class)));
|
||||
registeredNames
|
||||
.addAll(CollectionUtils.arrayToList(this.applicationContext.getBeanNamesForType(Consumer.class)));
|
||||
.addAll(Arrays.asList(this.applicationContext.getBeanNamesForType(Consumer.class)));
|
||||
}
|
||||
else {
|
||||
registeredNames.addAll(CollectionUtils.arrayToList(this.applicationContext.getBeanNamesForType(type)));
|
||||
registeredNames.addAll(Arrays.asList(this.applicationContext.getBeanNamesForType(type)));
|
||||
}
|
||||
return registeredNames;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user