add support for simple (non-Flux) types
add objectToStringHttpMessageConverter CompilerController accepts parameterized types
This commit is contained in:
@@ -18,11 +18,15 @@ package org.springframework.cloud.function.web;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.cloud.function.registry.FunctionCatalog;
|
||||
import org.springframework.cloud.function.support.FluxFunction;
|
||||
import org.springframework.cloud.function.support.FluxSupplier;
|
||||
import org.springframework.cloud.function.support.FunctionUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -54,6 +58,9 @@ public class FunctionController {
|
||||
@RequestBody Flux<String> body) {
|
||||
Function<Object, Object> function = functions.lookupFunction(name);
|
||||
if (function != null) {
|
||||
if (!FunctionUtils.isFluxFunction(function)) {
|
||||
function = new FluxFunction(function);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Flux<String> result = (Flux<String>) function.apply(body);
|
||||
return debug ? result.log() : result;
|
||||
@@ -68,8 +75,11 @@ public class FunctionController {
|
||||
|
||||
@GetMapping(path = "/{name}")
|
||||
public Flux<String> supplier(@PathVariable String name) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Flux<String> result = (Flux<String>) functions.lookupSupplier(name).get();
|
||||
Supplier<Object> supplier = functions.lookupSupplier(name);
|
||||
if (!FunctionUtils.isFluxSupplier(supplier)) {
|
||||
supplier = new FluxSupplier(supplier);
|
||||
}
|
||||
Flux<String> result = (Flux<String>) supplier.get();
|
||||
return debug ? result.log() : result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,8 +22,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.http.converter.ObjectToStringHttpMessageConverter;
|
||||
import org.springframework.web.method.support.AsyncHandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
@@ -32,6 +35,7 @@ import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnWebApplication
|
||||
@@ -39,7 +43,12 @@ import reactor.core.publisher.Flux;
|
||||
public class ReactorAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Autowired
|
||||
private FluxReturnValueHandler returnValueHandler;
|
||||
private ApplicationContext context;
|
||||
|
||||
@Bean
|
||||
public ObjectToStringHttpMessageConverter objectToStringHttpMessageConverter() {
|
||||
return new ObjectToStringHttpMessageConverter(new DefaultConversionService());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FluxReturnValueHandler fluxReturnValueHandler(
|
||||
@@ -49,6 +58,7 @@ public class ReactorAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Configuration
|
||||
protected static class FluxMessageConverterConfiguration {
|
||||
|
||||
@Bean
|
||||
public FluxHttpMessageConverter fluxHttpMessageConverter() {
|
||||
return new FluxHttpMessageConverter();
|
||||
@@ -58,7 +68,6 @@ public class ReactorAutoConfiguration extends WebMvcConfigurerAdapter {
|
||||
@Override
|
||||
public void addReturnValueHandlers(
|
||||
List<HandlerMethodReturnValueHandler> returnValueHandlers) {
|
||||
returnValueHandlers.add(returnValueHandler);
|
||||
returnValueHandlers.add(context.getBean(FluxReturnValueHandler.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user