Disconnect FunctionInspector from adapter request handlers and Kotlin module
This commit is contained in:
@@ -28,7 +28,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -50,9 +49,6 @@ public class SpringBootApiGatewayRequestHandler extends
|
||||
@Autowired
|
||||
private ObjectMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private FunctionInspector inspector;
|
||||
|
||||
public SpringBootApiGatewayRequestHandler(Class<?> configurationClass) {
|
||||
super(configurationClass);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class AzureSpringBootRequestHandler<I, O> extends AbstractSpringFunctionA
|
||||
if (!(input instanceof Collection)) {
|
||||
return true;
|
||||
}
|
||||
if (getInspector() != null) {
|
||||
if (function != null) {
|
||||
return Collection.class
|
||||
.isAssignableFrom(((FunctionInvocationWrapper) function).getRawInputType());
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class AzureSpringBootRequestHandler<I, O> extends AbstractSpringFunctionA
|
||||
if (!(output instanceof Collection)) {
|
||||
return true;
|
||||
}
|
||||
if (getInspector() != null) {
|
||||
if (function != null) {
|
||||
Class<?> outputType = FunctionTypeUtils.getRawType(FunctionTypeUtils.getGenericType(((FunctionInvocationWrapper) function).getOutputType()));
|
||||
return Collection.class.isAssignableFrom(outputType);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import reactor.core.publisher.Mono;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionTypeUtils;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.cloud.function.context.config.FunctionContextUtils;
|
||||
@@ -55,7 +54,10 @@ import org.springframework.util.CollectionUtils;
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.1
|
||||
*
|
||||
* @deprecated since 3.1 in favor of individual implementations of invokers
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractSpringFunctionAdapterInitializer<C> implements Closeable {
|
||||
|
||||
private static Log logger = LogFactory.getLog(AbstractSpringFunctionAdapterInitializer.class);
|
||||
@@ -77,9 +79,6 @@ public abstract class AbstractSpringFunctionAdapterInitializer<C> implements Clo
|
||||
|
||||
private AtomicBoolean initialized = new AtomicBoolean();
|
||||
|
||||
@Autowired(required = false)
|
||||
private FunctionInspector inspector;
|
||||
|
||||
@Autowired(required = false)
|
||||
protected FunctionCatalog catalog;
|
||||
|
||||
@@ -140,11 +139,6 @@ public abstract class AbstractSpringFunctionAdapterInitializer<C> implements Clo
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected FunctionInspector getInspector() {
|
||||
return inspector;
|
||||
}
|
||||
|
||||
protected Class<?> getInputType() {
|
||||
|
||||
Object func = function();
|
||||
@@ -240,7 +234,8 @@ public abstract class AbstractSpringFunctionAdapterInitializer<C> implements Clo
|
||||
if (!(input instanceof Collection)) {
|
||||
return true;
|
||||
}
|
||||
if (getInspector() != null) {
|
||||
|
||||
if (function != null) {
|
||||
return Collection.class
|
||||
.isAssignableFrom(((FunctionInvocationWrapper) function).getRawInputType());
|
||||
}
|
||||
@@ -251,7 +246,7 @@ public abstract class AbstractSpringFunctionAdapterInitializer<C> implements Clo
|
||||
if (!(output instanceof Collection)) {
|
||||
return true;
|
||||
}
|
||||
if (getInspector() != null) {
|
||||
if (function != null) {
|
||||
Class<?> outputType = FunctionTypeUtils.getRawType(FunctionTypeUtils.getGenericType(((FunctionInvocationWrapper) function).getOutputType()));
|
||||
return Collection.class.isAssignableFrom(outputType);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspector {
|
||||
public class SimpleFunctionRegistry implements FunctionRegistry {
|
||||
protected Log logger = LogFactory.getLog(this.getClass());
|
||||
/*
|
||||
* - do we care about FunctionRegistration after it's been registered? What additional value does it bring?
|
||||
@@ -122,11 +122,6 @@ public class SimpleFunctionRegistry implements FunctionRegistry, FunctionInspect
|
||||
return (T) function;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionRegistration<?> getRegistration(Object function) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void register(FunctionRegistration<T> registration) {
|
||||
this.functionRegistrations.add(registration);
|
||||
|
||||
@@ -27,7 +27,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionTypeUtils;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -43,8 +44,6 @@ public class ContextFunctionCatalogAutoConfigurationKotlinTests {
|
||||
|
||||
private FunctionCatalog catalog;
|
||||
|
||||
private FunctionInspector inspector;
|
||||
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
@@ -58,35 +57,26 @@ public class ContextFunctionCatalogAutoConfigurationKotlinTests {
|
||||
SimpleConfiguration.class });
|
||||
|
||||
assertThat(this.context.getBean("kotlinFunction")).isInstanceOf(Function1.class);
|
||||
assertThat((Function<?, ?>) this.catalog.lookup(Function.class, "kotlinFunction"))
|
||||
.isInstanceOf(Function.class);
|
||||
assertThat(this.inspector
|
||||
.getInputType(this.catalog.lookup(Function.class, "kotlinFunction")))
|
||||
.isAssignableFrom(String.class);
|
||||
assertThat(this.inspector
|
||||
.getOutputType(this.catalog.lookup(Function.class, "kotlinFunction")))
|
||||
.isAssignableFrom(String.class);
|
||||
FunctionInvocationWrapper function = this.catalog.lookup(Function.class, "kotlinFunction");
|
||||
assertThat(function).isInstanceOf(Function.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getGenericType(function.getInputType()))).isAssignableFrom(String.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getGenericType(function.getOutputType()))).isAssignableFrom(String.class);
|
||||
|
||||
|
||||
function = this.catalog.lookup(Function.class, "kotlinConsumer");
|
||||
assertThat(this.context.getBean("kotlinConsumer")).isInstanceOf(Function1.class);
|
||||
assertThat((Function<?, ?>) this.catalog.lookup(Function.class, "kotlinConsumer"))
|
||||
.isInstanceOf(Function.class);
|
||||
assertThat(this.inspector
|
||||
.getInputType(this.catalog.lookup(Function.class, "kotlinConsumer")))
|
||||
.isAssignableFrom(String.class);
|
||||
assertThat(function).isInstanceOf(Function.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getGenericType(function.getInputType()))).isAssignableFrom(String.class);
|
||||
|
||||
|
||||
assertThat(this.context.getBean("kotlinSupplier")).isInstanceOf(Function0.class);
|
||||
Supplier<String> supplier = this.catalog.lookup(Supplier.class, "kotlinSupplier");
|
||||
FunctionInvocationWrapper supplier = this.catalog.lookup(Function.class, "kotlinSupplier");
|
||||
assertThat(supplier).isInstanceOf(Supplier.class);
|
||||
assertThat(supplier.get()).isEqualTo("Hello");
|
||||
assertThat((Supplier<?>) this.catalog.lookup(Supplier.class, "kotlinSupplier"))
|
||||
.isInstanceOf(Supplier.class);
|
||||
assertThat(this.inspector
|
||||
.getOutputType(this.catalog.lookup(Supplier.class, "kotlinSupplier")))
|
||||
.isAssignableFrom(String.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getGenericType(supplier.getOutputType()))).isAssignableFrom(String.class);
|
||||
|
||||
Function<String, String> function = this.catalog
|
||||
.lookup(Function.class, "kotlinFunction|function2");
|
||||
assertThat(function.apply("Hello"))
|
||||
.isEqualTo("HELLOfunction2");
|
||||
function = this.catalog.lookup(Function.class, "kotlinFunction|function2");
|
||||
assertThat(function.apply("Hello")).isEqualTo("HELLOfunction2");
|
||||
|
||||
Function<String, String> javaFunction = this.catalog
|
||||
.lookup(Function.class, "javaFunction");
|
||||
@@ -97,7 +87,6 @@ public class ContextFunctionCatalogAutoConfigurationKotlinTests {
|
||||
private void create(Class<?>[] types, String... props) {
|
||||
this.context = new SpringApplicationBuilder(types).properties(props).run();
|
||||
this.catalog = this.context.getBean(FunctionCatalog.class);
|
||||
this.inspector = this.context.getBean(FunctionInspector.class);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
Reference in New Issue
Block a user