diff --git a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/ContextFunctionCatalogAutoConfiguration.java b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/ContextFunctionCatalogAutoConfiguration.java index af264fe2b..9b1f503a6 100644 --- a/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/ContextFunctionCatalogAutoConfiguration.java +++ b/spring-cloud-function-context/src/main/java/org/springframework/cloud/function/context/ContextFunctionCatalogAutoConfiguration.java @@ -201,50 +201,24 @@ public class ContextFunctionCatalogAutoConfiguration { } private boolean isFluxFunction(String name, Function function) { - if (this.registry.containsBeanDefinition(name)) { - BeanDefinition beanDefinition = this.registry.getBeanDefinition(name); - Object source = beanDefinition.getSource(); - if (source instanceof StandardMethodMetadata) { - StandardMethodMetadata metadata = (StandardMethodMetadata) source; - Type returnType = metadata.getIntrospectedMethod() - .getGenericReturnType(); - if (returnType instanceof ParameterizedType) { - Type[] types = ((ParameterizedType) returnType) - .getActualTypeArguments(); - if (types != null && types.length == 2) { - return (types[0].getTypeName() - .startsWith(Flux.class.getName()) - && types[1].getTypeName() - .startsWith(Flux.class.getName())); - } - } - } - } - return FunctionUtils.isFluxFunction(function); + Boolean fluxTypes = this.hasFluxTypes(name, 2); + return (fluxTypes != null) ? fluxTypes + : FunctionUtils.isFluxFunction(function); } - private boolean isFluxConsumer(String name, Consumer function) { - if (this.registry.containsBeanDefinition(name)) { - BeanDefinition beanDefinition = this.registry.getBeanDefinition(name); - Object source = beanDefinition.getSource(); - if (source instanceof StandardMethodMetadata) { - StandardMethodMetadata metadata = (StandardMethodMetadata) source; - Type returnType = metadata.getIntrospectedMethod() - .getGenericReturnType(); - if (returnType instanceof ParameterizedType) { - Type[] types = ((ParameterizedType) returnType) - .getActualTypeArguments(); - if (types != null && types.length == 1) { - return (types[0].getTypeName() - .startsWith(Flux.class.getName())); - } - } - } - } - return FunctionUtils.isFluxConsumer(function); + private boolean isFluxConsumer(String name, Consumer consumer) { + Boolean fluxTypes = this.hasFluxTypes(name, 1); + return (fluxTypes != null) ? fluxTypes + : FunctionUtils.isFluxConsumer(consumer); } - private boolean isFluxSupplier(String name, Supplier function) { + private boolean isFluxSupplier(String name, Supplier supplier) { + Boolean fluxTypes = this.hasFluxTypes(name, 1); + return (fluxTypes != null) ? fluxTypes + : FunctionUtils.isFluxSupplier(supplier); + } + + private Boolean hasFluxTypes(String name, int numTypes) { if (this.registry.containsBeanDefinition(name)) { BeanDefinition beanDefinition = this.registry.getBeanDefinition(name); Object source = beanDefinition.getSource(); @@ -255,14 +229,19 @@ public class ContextFunctionCatalogAutoConfiguration { if (returnType instanceof ParameterizedType) { Type[] types = ((ParameterizedType) returnType) .getActualTypeArguments(); - if (types != null && types.length == 1) { - return (types[0].getTypeName() - .startsWith(Flux.class.getName())); + if (types != null && types.length == numTypes) { + String fluxClassName = Flux.class.getName(); + for (Type t : types) { + if (!(t.getTypeName().startsWith(fluxClassName))) { + return false; + } + } + return true; } } } } - return FunctionUtils.isFluxSupplier(function); + return null; } private boolean isGenericSupplier(ConfigurableListableBeanFactory factory, diff --git a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/support/FluxConsumer.java b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/support/FluxConsumer.java index a9a928999..ac8b5c300 100644 --- a/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/support/FluxConsumer.java +++ b/spring-cloud-function-core/src/main/java/org/springframework/cloud/function/support/FluxConsumer.java @@ -30,14 +30,14 @@ import reactor.core.publisher.Flux; */ public class FluxConsumer implements Consumer> { - private final Consumer function; + private final Consumer consumer; - public FluxConsumer(Consumer function) { - this.function = function; + public FluxConsumer(Consumer consumer) { + this.consumer = consumer; } @Override public void accept(Flux input) { - input.subscribe(t -> function.accept(t)); + input.subscribe(t -> consumer.accept(t)); } } diff --git a/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyExchangeArgumentResolver.java b/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyExchangeArgumentResolver.java index 4e84e4f25..bc9e143be 100644 --- a/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyExchangeArgumentResolver.java +++ b/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyExchangeArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2016-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. diff --git a/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyProperties.java b/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyProperties.java index 8f98807c3..01419f35d 100644 --- a/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyProperties.java +++ b/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2016-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. diff --git a/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyResponseAutoConfiguration.java b/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyResponseAutoConfiguration.java index c02c68e93..ddfd07676 100644 --- a/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyResponseAutoConfiguration.java +++ b/spring-cloud-function-gateway/src/main/java/org/springframework/cloud/function/gateway/config/ProxyResponseAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2016-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. @@ -41,8 +41,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter /** * Autoconfiguration for the {@link ProxyExchange} argument handler in Spring MVC * @RequestMapping methods. - * @author Dave Syer * + * @author Dave Syer */ @Configuration @ConditionalOnWebApplication @@ -55,7 +55,7 @@ public class ProxyResponseAutoConfiguration extends WebMvcConfigurerAdapter { @Bean @ConditionalOnMissingBean - public ProxyExchangeArgumentResolver proxyExchangeBuilderArgumentResolver( + public ProxyExchangeArgumentResolver proxyExchangeArgumentResolver( Optional optional, ProxyProperties proxy) { RestTemplateBuilder builder = optional.orElse(new RestTemplateBuilder()); RestTemplate template = builder.build(); diff --git a/spring-cloud-function-gateway/src/test/java/org/springframework/cloud/function/web/gateway/ProductionConfigurationTests.java b/spring-cloud-function-gateway/src/test/java/org/springframework/cloud/function/web/gateway/ProductionConfigurationTests.java index 718fe933d..0edfd95cf 100644 --- a/spring-cloud-function-gateway/src/test/java/org/springframework/cloud/function/web/gateway/ProductionConfigurationTests.java +++ b/spring-cloud-function-gateway/src/test/java/org/springframework/cloud/function/web/gateway/ProductionConfigurationTests.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016-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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.cloud.function.web.gateway; import java.net.URI;