polishing

This commit is contained in:
markfisher
2017-03-31 11:43:28 -04:00
parent 3b598bd10c
commit 0b49edc2fd
6 changed files with 48 additions and 53 deletions

View File

@@ -201,50 +201,24 @@ public class ContextFunctionCatalogAutoConfiguration {
} }
private boolean isFluxFunction(String name, Function<?, ?> function) { private boolean isFluxFunction(String name, Function<?, ?> function) {
if (this.registry.containsBeanDefinition(name)) { Boolean fluxTypes = this.hasFluxTypes(name, 2);
BeanDefinition beanDefinition = this.registry.getBeanDefinition(name); return (fluxTypes != null) ? fluxTypes
Object source = beanDefinition.getSource(); : FunctionUtils.isFluxFunction(function);
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);
} }
private boolean isFluxConsumer(String name, Consumer<?> function) { private boolean isFluxConsumer(String name, Consumer<?> consumer) {
if (this.registry.containsBeanDefinition(name)) { Boolean fluxTypes = this.hasFluxTypes(name, 1);
BeanDefinition beanDefinition = this.registry.getBeanDefinition(name); return (fluxTypes != null) ? fluxTypes
Object source = beanDefinition.getSource(); : FunctionUtils.isFluxConsumer(consumer);
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 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)) { if (this.registry.containsBeanDefinition(name)) {
BeanDefinition beanDefinition = this.registry.getBeanDefinition(name); BeanDefinition beanDefinition = this.registry.getBeanDefinition(name);
Object source = beanDefinition.getSource(); Object source = beanDefinition.getSource();
@@ -255,14 +229,19 @@ public class ContextFunctionCatalogAutoConfiguration {
if (returnType instanceof ParameterizedType) { if (returnType instanceof ParameterizedType) {
Type[] types = ((ParameterizedType) returnType) Type[] types = ((ParameterizedType) returnType)
.getActualTypeArguments(); .getActualTypeArguments();
if (types != null && types.length == 1) { if (types != null && types.length == numTypes) {
return (types[0].getTypeName() String fluxClassName = Flux.class.getName();
.startsWith(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, private boolean isGenericSupplier(ConfigurableListableBeanFactory factory,

View File

@@ -30,14 +30,14 @@ import reactor.core.publisher.Flux;
*/ */
public class FluxConsumer<T> implements Consumer<Flux<T>> { public class FluxConsumer<T> implements Consumer<Flux<T>> {
private final Consumer<T> function; private final Consumer<T> consumer;
public FluxConsumer(Consumer<T> function) { public FluxConsumer(Consumer<T> consumer) {
this.function = function; this.consumer = consumer;
} }
@Override @Override
public void accept(Flux<T> input) { public void accept(Flux<T> input) {
input.subscribe(t -> function.accept(t)); input.subscribe(t -> consumer.accept(t));
} }
} }

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 * Autoconfiguration for the {@link ProxyExchange} argument handler in Spring MVC
* <code>@RequestMapping</code> methods. * <code>@RequestMapping</code> methods.
* @author Dave Syer
* *
* @author Dave Syer
*/ */
@Configuration @Configuration
@ConditionalOnWebApplication @ConditionalOnWebApplication
@@ -55,7 +55,7 @@ public class ProxyResponseAutoConfiguration extends WebMvcConfigurerAdapter {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public ProxyExchangeArgumentResolver proxyExchangeBuilderArgumentResolver( public ProxyExchangeArgumentResolver proxyExchangeArgumentResolver(
Optional<RestTemplateBuilder> optional, ProxyProperties proxy) { Optional<RestTemplateBuilder> optional, ProxyProperties proxy) {
RestTemplateBuilder builder = optional.orElse(new RestTemplateBuilder()); RestTemplateBuilder builder = optional.orElse(new RestTemplateBuilder());
RestTemplate template = builder.build(); RestTemplate template = builder.build();

View File

@@ -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; package org.springframework.cloud.function.web.gateway;
import java.net.URI; import java.net.URI;