GH-986 Fix regression to NOT attempt output conversion of Message<byte[]>
Resolves #986
This commit is contained in:
@@ -52,6 +52,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.converter.AbstractMessageConverter;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -764,6 +765,24 @@ public class FunctionInvokerTests {
|
||||
assertThat(result.get("body")).isEqualTo("\"Hello from ELB\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLBEventReturningMessage() throws Exception {
|
||||
System.setProperty("MAIN_CLASS", LBConfiguration.class.getName());
|
||||
System.setProperty("spring.cloud.function.definition", "inputOutputLBEventAsMessage");
|
||||
FunctionInvoker invoker = new FunctionInvoker();
|
||||
|
||||
InputStream targetStream = new ByteArrayInputStream(this.sampleLBEvent.getBytes());
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
invoker.handleRequest(targetStream, output, null);
|
||||
|
||||
Map result = mapper.readValue(output.toByteArray(), Map.class);
|
||||
System.out.println("RESULT: " + result);
|
||||
assertThat(result.get("body")).isEqualTo("\"Hello\"");
|
||||
assertThat((boolean) result.get("isBase64Encoded")).isFalse();
|
||||
assertThat(((Map) result.get("headers")).get("foo")).isEqualTo("bar");
|
||||
assertThat(result.get("statusCode")).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLBEventAsMessage() throws Exception {
|
||||
System.setProperty("MAIN_CLASS", LBConfiguration.class.getName());
|
||||
@@ -1298,6 +1317,14 @@ public class FunctionInvokerTests {
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<ApplicationLoadBalancerRequestEvent, Message<byte[]>> inputOutputLBEventAsMessage() {
|
||||
return v -> {
|
||||
Message<byte[]> message = MessageBuilder.withPayload("\"Hello\"".getBytes(StandardCharsets.UTF_8)).setHeader("foo", "bar").build();
|
||||
return message;
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<ApplicationLoadBalancerRequestEvent, ApplicationLoadBalancerResponseEvent> inputOutputLBEvent() {
|
||||
return v -> {
|
||||
|
||||
@@ -1136,7 +1136,7 @@ public class SimpleFunctionRegistry implements FunctionRegistry {
|
||||
}
|
||||
|
||||
if (convertedOutput instanceof Message) {
|
||||
if (((Message) convertedOutput).getPayload() instanceof byte[] && ObjectUtils.isEmpty(contentType)) {
|
||||
if (((Message) convertedOutput).getPayload() instanceof byte[]) {
|
||||
return convertedOutput;
|
||||
}
|
||||
else if (isExtractPayload((Message<?>) convertedOutput, type)) {
|
||||
|
||||
Reference in New Issue
Block a user