Consolidate isMessage() operation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -29,6 +29,7 @@ import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
@@ -39,7 +40,10 @@ import org.springframework.messaging.support.GenericMessage;
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Semyon Fishman
|
||||
* @author Markus Gulden
|
||||
*
|
||||
* @deprecated since 3.1 in favor of {@link FunctionInvoker}
|
||||
*/
|
||||
@Deprecated
|
||||
public class SpringBootApiGatewayRequestHandler extends
|
||||
SpringBootRequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
||||
|
||||
@@ -66,7 +70,7 @@ public class SpringBootApiGatewayRequestHandler extends
|
||||
}
|
||||
|
||||
private boolean functionAcceptsMessage() {
|
||||
return this.inspector.isMessage(function());
|
||||
return ((FunctionInvocationWrapper) function()).isInputTypeMessage();
|
||||
}
|
||||
|
||||
private Object deserializeBody(APIGatewayProxyRequestEvent event) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
@@ -26,6 +26,7 @@ import com.amazonaws.services.lambda.runtime.events.KinesisEvent;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
@@ -37,7 +38,10 @@ import static java.util.stream.Collectors.toList;
|
||||
* @author Mark Fisher
|
||||
* @author Halvdan Hoem Grelland
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
* @deprecated since 3.1 in favor of {@link FunctionInvoker}
|
||||
*/
|
||||
@Deprecated
|
||||
public class SpringBootKinesisEventHandler<E, O>
|
||||
extends SpringBootRequestHandler<KinesisEvent, O> {
|
||||
|
||||
@@ -62,7 +66,7 @@ public class SpringBootKinesisEventHandler<E, O>
|
||||
protected Object convertEvent(KinesisEvent event) {
|
||||
List<E> payloads = deserializePayloads(event.getRecords());
|
||||
|
||||
if (getInspector().isMessage(function())) {
|
||||
if (((FunctionInvocationWrapper) function()).isInputTypeMessage()) {
|
||||
return wrapInMessages(payloads);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.microsoft.azure.functions.HttpRequestMessage;
|
||||
import com.microsoft.azure.functions.HttpResponseMessage;
|
||||
import com.microsoft.azure.functions.HttpResponseMessage.Builder;
|
||||
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
@@ -74,7 +75,7 @@ public class AzureSpringBootHttpRequestHandler<I> extends
|
||||
|
||||
protected boolean functionAcceptsMessage() {
|
||||
|
||||
return this.getInspector().isMessage(function());
|
||||
return ((FunctionInvocationWrapper) function()).isInputTypeMessage();
|
||||
}
|
||||
|
||||
private MessageHeaders getHeaders(HttpRequestMessage<I> event) {
|
||||
|
||||
@@ -36,6 +36,11 @@ public interface FunctionInspector {
|
||||
|
||||
FunctionRegistration<?> getRegistration(Object function);
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated since 3.1 no longer used by the framework
|
||||
*/
|
||||
@Deprecated
|
||||
default boolean isMessage(Object function) {
|
||||
if (function == null) {
|
||||
return false;
|
||||
|
||||
@@ -191,9 +191,6 @@ public final class FunctionTypeUtils {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Type getInputType(Type functionType) {
|
||||
assertSupportedTypes(functionType);
|
||||
// if (isSupplier(functionType)) {
|
||||
// return getOutputType(functionType, index);
|
||||
// }
|
||||
if (functionType instanceof Class) {
|
||||
Class<?> functionClass = (Class<?>) functionType;
|
||||
if (Function.class.isAssignableFrom(functionClass)) {
|
||||
@@ -205,9 +202,6 @@ public final class FunctionTypeUtils {
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
// else if (Supplier.class.isAssignableFrom(functionClass)) {
|
||||
// functionType = TypeResolver.reify(Supplier.class, (Class<Supplier<?>>) functionClass);
|
||||
// }
|
||||
}
|
||||
|
||||
Type inputType = Object.class;
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.cloud.function.inject.FooConfiguration;
|
||||
import org.springframework.cloud.function.scan.ScannedFunction;
|
||||
import org.springframework.cloud.function.test.GenericFunction;
|
||||
@@ -378,8 +379,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
assertThat(this.inspector
|
||||
.getInputWrapper(this.catalog.lookup(Function.class, "function")))
|
||||
.isAssignableFrom(Integer.class);
|
||||
assertThat(
|
||||
this.inspector.isMessage(this.catalog.lookup(Function.class, "function")))
|
||||
assertThat(((FunctionInvocationWrapper) this.catalog.lookup(Function.class, "function")).isInputTypeMessage())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -244,7 +244,8 @@ public class RequestProcessor {
|
||||
+ "`");
|
||||
}
|
||||
|
||||
if (this.inspector.isMessage(function)) {
|
||||
|
||||
if (function != null && ((FunctionInvocationWrapper) function).isInputTypeMessage()) {
|
||||
flux = messages(wrapper, function, flux);
|
||||
}
|
||||
Mono<ResponseEntity<?>> responseEntityMono = null;
|
||||
@@ -324,7 +325,7 @@ public class RequestProcessor {
|
||||
|
||||
private Mono<ResponseEntity<?>> stream(FunctionWrapper request, Publisher<?> result) {
|
||||
BodyBuilder builder = ResponseEntity.ok();
|
||||
if (this.inspector.isMessage(request.handler())) {
|
||||
if (((FunctionInvocationWrapper) request.handler()).isInputTypeMessage()) {
|
||||
result = Flux.from(result)
|
||||
.doOnNext(value -> addHeaders(builder, (Message<?>) value))
|
||||
.map(message -> MessageUtils.unpack(request.handler(), message)
|
||||
@@ -453,7 +454,7 @@ public class RequestProcessor {
|
||||
private Publisher<?> value(FunctionWrapper wrapper) {
|
||||
Flux<?> input = Flux.from(wrapper.argument)
|
||||
.map(body -> this.converter.convert(wrapper.function, body));
|
||||
if (this.inspector.isMessage(wrapper.function)) {
|
||||
if (((FunctionInvocationWrapper) (Object) wrapper.function).isInputTypeMessage()) {
|
||||
input = messages(wrapper, wrapper.function, input);
|
||||
}
|
||||
return Mono.from(wrapper.function.apply(input));
|
||||
|
||||
Reference in New Issue
Block a user