@@ -208,20 +208,26 @@ public final class StreamBridge implements SmartInitializingSingleton {
|
||||
@SuppressWarnings({ "unchecked"})
|
||||
public boolean send(String bindingName, @Nullable String binderName, Object data, MimeType outputContentType) {
|
||||
|
||||
if (data instanceof Message) {
|
||||
data = MessageBuilder.fromMessage((Message) data).setHeader(MessageUtils.TARGET_PROTOCOL, "streamBridge").build();
|
||||
}
|
||||
else {
|
||||
data = new GenericMessage<>(data, Collections.singletonMap(MessageUtils.TARGET_PROTOCOL, "streamBridge"));
|
||||
}
|
||||
|
||||
|
||||
ProducerProperties producerProperties = this.bindingServiceProperties.getProducerProperties(bindingName);
|
||||
MessageChannel messageChannel = this.resolveDestination(bindingName, producerProperties, binderName);
|
||||
|
||||
Function functionToInvoke = this.getStreamBridgeFunction(outputContentType.toString(), producerProperties);
|
||||
|
||||
if (producerProperties != null && producerProperties.isPartitioned()) {
|
||||
functionToInvoke = new PartitionAwareFunctionWrapper(functionToInvoke, this.applicationContext, producerProperties);
|
||||
}
|
||||
Message<byte[]> resultMessage = (Message<byte[]>) functionToInvoke.apply(data);
|
||||
|
||||
|
||||
Message<?> messageToSend = data instanceof Message
|
||||
? MessageBuilder.fromMessage((Message) data).setHeader(MessageUtils.TARGET_PROTOCOL, "streamBridge").build()
|
||||
: new GenericMessage<>(data, Collections.singletonMap(MessageUtils.TARGET_PROTOCOL, "streamBridge"));
|
||||
|
||||
Message<?> resultMessage;
|
||||
synchronized (this) {
|
||||
resultMessage = (Message<byte[]>) functionToInvoke.apply(messageToSend);
|
||||
}
|
||||
|
||||
return messageChannel.send(resultMessage);
|
||||
}
|
||||
|
||||
@@ -267,10 +267,11 @@ public class ContentTypeTckTests {
|
||||
.setHeader("contentType", new MimeType("text", "plain")).build());
|
||||
|
||||
Message<byte[]> outputMessage = target.receive();
|
||||
System.out.println(new String(outputMessage.getPayload()));
|
||||
assertThat(outputMessage.getHeaders().get(MessageHeaders.CONTENT_TYPE))
|
||||
.isEqualTo(MimeTypeUtils.TEXT_PLAIN_VALUE);
|
||||
assertThat(new String(outputMessage.getPayload(), StandardCharsets.UTF_8))
|
||||
.isEqualTo(jsonPayload);
|
||||
assertThat(outputMessage.getPayload())
|
||||
.isEqualTo(jsonPayload.getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user