@@ -128,9 +128,9 @@ public final class FunctionTypeUtils {
|
|||||||
for (Type generic : generics) {
|
for (Type generic : generics) {
|
||||||
if (generic instanceof ParameterizedType) {
|
if (generic instanceof ParameterizedType) {
|
||||||
Class<?> rawClsss = (Class<?>) ((ParameterizedType) generic).getRawType();
|
Class<?> rawClsss = (Class<?>) ((ParameterizedType) generic).getRawType();
|
||||||
if (rawClsss.isAssignableFrom(Function.class)
|
if (Function.class.isAssignableFrom(rawClsss)
|
||||||
|| rawClsss.isAssignableFrom(Consumer.class)
|
|| Consumer.class.isAssignableFrom(rawClsss)
|
||||||
|| rawClsss.isAssignableFrom(Supplier.class)) {
|
|| Supplier.class.isAssignableFrom(rawClsss)) {
|
||||||
return generic;
|
return generic;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -145,6 +145,8 @@ public final class FunctionTypeUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static Type discoverFunctionTypeFromFunctionMethod(Method functionMethod) {
|
public static Type discoverFunctionTypeFromFunctionMethod(Method functionMethod) {
|
||||||
Assert.isTrue(
|
Assert.isTrue(
|
||||||
functionMethod.getName().equals("apply") ||
|
functionMethod.getName().equals("apply") ||
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.springframework.cloud.function.context.catalog;
|
|||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.sql.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -132,6 +131,13 @@ public class FunctionTypeUtilsTests {
|
|||||||
assertThat(type.getInputType()).isAssignableFrom(String.class);
|
assertThat(type.getInputType()).isAssignableFrom(String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void foo() {
|
||||||
|
FunctionType type = FunctionType.of(FunctionTypeUtils.discoverFunctionTypeFromClass(ReactiveFunctionImpl.class));
|
||||||
|
assertThat(String.class).isAssignableFrom(type.getInputType());
|
||||||
|
assertThat(Integer.class).isAssignableFrom(type.getOutputType());
|
||||||
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
// public void testInputTypeByIndex() throws Exception {
|
// public void testInputTypeByIndex() throws Exception {
|
||||||
// Type functionType = getReturnType("function");
|
// Type functionType = getReturnType("function");
|
||||||
@@ -208,19 +214,19 @@ public class FunctionTypeUtilsTests {
|
|||||||
|
|
||||||
//============
|
//============
|
||||||
|
|
||||||
private interface MessageFunction<T> extends Function<Message<String>, Message<String>> {
|
private interface MessageFunction extends Function<Message<String>, Message<String>> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface MyMessageFunction extends MessageFunction<Date> {
|
private interface MyMessageFunction extends MessageFunction {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface MessageConsumer<T> extends Consumer<Message<String>> {
|
private interface MessageConsumer extends Consumer<Message<String>> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface MyMessageConsumer extends MessageConsumer<Date> {
|
private interface MyMessageConsumer extends MessageConsumer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,4 +235,17 @@ public class FunctionTypeUtilsTests {
|
|||||||
public void accept(Flux<Message<String>> messageFlux) {
|
public void accept(Flux<Message<String>> messageFlux) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface ReactiveFunction<S, T> extends Function<Flux<S>, Flux<T>> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ReactiveFunctionImpl implements ReactiveFunction<String, Integer> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<Integer> apply(Flux<String> inFlux) {
|
||||||
|
return inFlux.map(v -> Integer.parseInt(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,13 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.cloud.function.context.FunctionProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties("spring.cloud.function.web.export")
|
@ConfigurationProperties(prefix = FunctionProperties.PREFIX + ".web.export")
|
||||||
public class ExporterProperties {
|
public class ExporterProperties {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ public class SupplierExporter implements SmartLifecycle {
|
|||||||
body = message.getPayload();
|
body = message.getPayload();
|
||||||
}
|
}
|
||||||
Mono<ClientResponse> result = this.client.post().uri(uri)
|
Mono<ClientResponse> result = this.client.post().uri(uri)
|
||||||
.headers(headers -> headers(headers, destination, value)).syncBody(body)
|
.headers(headers -> headers(headers, destination, value)).bodyValue(body)
|
||||||
.exchange();
|
.exchange();
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
result = result.log();
|
result = result.log();
|
||||||
|
|||||||
Reference in New Issue
Block a user