org.springframework.cloud.function.context.catalog.FunctionInspector Java Examples

The following examples show how to use org.springframework.cloud.function.context.catalog.FunctionInspector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FunctionConfiguration.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
private boolean determineFunctionName(FunctionCatalog catalog, Environment environment) {
	String definition = streamFunctionProperties.getDefinition();
	if (!StringUtils.hasText(definition)) {
		definition = environment.getProperty("spring.cloud.function.definition");
	}

	if (StringUtils.hasText(definition)) {
		streamFunctionProperties.setDefinition(definition);
	}
	else if (Boolean.parseBoolean(environment.getProperty("spring.cloud.stream.function.routing.enabled", "false"))
			|| environment.containsProperty("spring.cloud.function.routing-expression")) {
		streamFunctionProperties.setDefinition(RoutingFunction.FUNCTION_NAME);
	}
	else {
		streamFunctionProperties.setDefinition(((FunctionInspector) functionCatalog).getName(functionCatalog.lookup("")));
	}
	return StringUtils.hasText(streamFunctionProperties.getDefinition());
}
 
Example #2
Source File: FunctionInvoker.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
private void start() {
	ConfigurableApplicationContext context = SpringApplication.run(FunctionClassUtils.getStartClass());
	Environment environment = context.getEnvironment();
	String functionName = environment.getProperty("spring.cloud.function.definition");
	FunctionCatalog functionCatalog = context.getBean(FunctionCatalog.class);
	this.mapper = context.getBean(ObjectMapper.class);
	this.configureObjectMapper();

	if (logger.isInfoEnabled()) {
		logger.info("Locating function: '" + functionName + "'");
	}

	this.function = functionCatalog.lookup(functionName, "application/json");
	Assert.notNull(this.function, "Failed to lookup function " + functionName);

	if (!StringUtils.hasText(functionName)) {
		FunctionInspector inspector = context.getBean(FunctionInspector.class);
		functionName = inspector.getRegistration(this.function).getNames().toString();
	}

	if (logger.isInfoEnabled()) {
		logger.info("Located function: '" + functionName + "'");
	}
}
 
Example #3
Source File: ContextFunctionCatalogInitializerTests.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
private void create(ApplicationContextInitializer<GenericApplicationContext>[] types,
		String... props) {
	this.context = new GenericApplicationContext();
	Map<String, Object> map = new HashMap<>();
	for (String prop : props) {
		String[] array = StringUtils.delimitedListToStringArray(prop, "=");
		String key = array[0];
		String value = array.length > 1 ? array[1] : "";
		map.put(key, value);
	}
	if (!map.isEmpty()) {
		this.context.getEnvironment().getPropertySources()
				.addFirst(new MapPropertySource("testProperties", map));
	}
	for (ApplicationContextInitializer<GenericApplicationContext> type : types) {
		type.initialize(this.context);
	}
	new ContextFunctionCatalogInitializer.ContextFunctionCatalogBeanRegistrar(
			this.context).postProcessBeanDefinitionRegistry(this.context);
	this.context.refresh();
	this.catalog = this.context.getBean(FunctionCatalog.class);
	this.inspector = this.context.getBean(FunctionInspector.class);
}
 
Example #4
Source File: ReactorAutoConfigurationInitializer.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private void registerEndpoint(GenericApplicationContext context) {
	context.registerBean(StringConverter.class,
			() -> new BasicStringConverter(context.getBean(FunctionInspector.class), context.getBeanFactory()));
	context.registerBean(RequestProcessor.class,
			() -> new RequestProcessor(context.getBean(FunctionInspector.class),
					context.getBean(FunctionCatalog.class), context.getBeanProvider(JsonMapper.class),
					context.getBean(StringConverter.class), context.getBeanProvider(ServerCodecConfigurer.class)));
	context.registerBean(PublicFunctionEndpointFactory.class,
			() -> new PublicFunctionEndpointFactory(context.getBean(FunctionCatalog.class),
					context.getBean(FunctionInspector.class), context.getBean(RequestProcessor.class),
					context.getEnvironment()));
	context.registerBean(RouterFunction.class,
			() -> context.getBean(PublicFunctionEndpointFactory.class).functionEndpoints());
}
 
Example #5
Source File: FunctionConfiguration.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Bean
public InitializingBean functionInitializer(FunctionCatalog functionCatalog, FunctionInspector functionInspector,
		StreamFunctionProperties functionProperties, @Nullable BindableProxyFactory[] bindableProxyFactories,
		BindingServiceProperties serviceProperties, ConfigurableApplicationContext applicationContext,
		FunctionBindingRegistrar bindingHolder, StreamBridge streamBridge) {

	boolean shouldCreateInitializer = applicationContext.containsBean("output")
			|| ObjectUtils.isEmpty(applicationContext.getBeanNamesForAnnotation(EnableBinding.class));

	return shouldCreateInitializer
			? new FunctionToDestinationBinder(functionCatalog, functionProperties,
					serviceProperties, streamBridge)
					: null;
}
 
Example #6
Source File: RequestProcessor.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
public RequestProcessor(FunctionInspector inspector,
		FunctionCatalog functionCatalog,
		ObjectProvider<JsonMapper> mapper, StringConverter converter,
		ObjectProvider<ServerCodecConfigurer> codecs) {
	this.mapper = mapper.getIfAvailable();
	this.inspector = inspector;
	this.functionCatalog = functionCatalog;
	this.converter = converter;
	ServerCodecConfigurer source = codecs.getIfAvailable();
	this.messageReaders = source == null ? null : source.getReaders();
}
 
Example #7
Source File: FunctionEndpointInitializer.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
FunctionEndpointFactory(FunctionCatalog functionCatalog, FunctionInspector inspector, RequestProcessor processor,
		Environment environment) {
	String handler = environment.resolvePlaceholders("${function.handler}");
	if (handler.startsWith("$")) {
		handler = null;
	}
	this.processor = processor;
	this.inspector = inspector;
	this.functionCatalog = functionCatalog;
	this.handler = handler;
}
 
Example #8
Source File: FunctionEndpointInitializer.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private void registerEndpoint(GenericApplicationContext context) {
	context.registerBean(StringConverter.class,
			() -> new BasicStringConverter(context.getBean(FunctionInspector.class), context.getBeanFactory()));
	context.registerBean(RequestProcessor.class,
			() -> new RequestProcessor(context.getBean(FunctionInspector.class),
					context.getBean(FunctionCatalog.class),
					context.getBeanProvider(JsonMapper.class), context.getBean(StringConverter.class),
					context.getBeanProvider(ServerCodecConfigurer.class)));
	context.registerBean(FunctionEndpointFactory.class,
			() -> new FunctionEndpointFactory(context.getBean(FunctionCatalog.class),
					context.getBean(FunctionInspector.class), context.getBean(RequestProcessor.class),
					context.getEnvironment()));
	context.registerBean(RouterFunction.class,
			() -> context.getBean(FunctionEndpointFactory.class).functionEndpoints());
}
 
Example #9
Source File: BasicStringConverter.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
public BasicStringConverter(FunctionInspector inspector,
		ConfigurableListableBeanFactory registry) {
	this.inspector = inspector;
	this.registry = registry;
}
 
Example #10
Source File: ReactorAutoConfiguration.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public StringConverter functionStringConverter(FunctionInspector inspector,
		ConfigurableListableBeanFactory beanFactory) {
	return new BasicStringConverter(inspector, beanFactory);
}
 
Example #11
Source File: AbstractSpringFunctionAdapterInitializer.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
protected FunctionInspector getInspector() {
	return inspector;
}
 
Example #12
Source File: RoutingFunction.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
public RoutingFunction(FunctionCatalog functionCatalog, FunctionInspector functionInspector, FunctionProperties functionProperties) {
	this.functionCatalog = functionCatalog;
	this.functionProperties = functionProperties;
	this.functionInspector = functionInspector;
	this.evalContext.addPropertyAccessor(new MapAccessor());
}
 
Example #13
Source File: ContextFunctionCatalogAutoConfiguration.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
@Bean(RoutingFunction.FUNCTION_NAME)
RoutingFunction functionRouter(FunctionCatalog functionCatalog, FunctionInspector functionInspector, FunctionProperties functionProperties) {
	return new RoutingFunction(functionCatalog, functionInspector, functionProperties);
}
 
Example #14
Source File: ContextFunctionCatalogAutoConfigurationTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #15
Source File: ContextFunctionCatalogAutoConfigurationTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
@Bean
public BeanFactoryPostProcessor someBeanFactoryPostProcessor(Environment environment,
	@Nullable FunctionRegistry functionCatalog, @Nullable FunctionInspector inspector) {
	return beanFactory -> { };
}
 
Example #16
Source File: ReactorAutoConfiguration.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public StringConverter functionStringConverter(FunctionInspector inspector,
		ConfigurableListableBeanFactory beanFactory) {
	return new BasicStringConverter(inspector, beanFactory);
}
 
Example #17
Source File: ContextFunctionCatalogAutoConfigurationKotlinTests.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #18
Source File: PublicFunctionEndpointFactory.java    From spring-init with Apache License 2.0 4 votes vote down vote up
public PublicFunctionEndpointFactory(FunctionCatalog functionCatalog, FunctionInspector inspector,
		RequestProcessor processor, Environment environment) {
	super(functionCatalog, inspector, processor, environment);
}