From b05dc36e02bca0adccba1d7265a9c42f85ea40e4 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti <65240126+fjtirado@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:13:39 +0100 Subject: [PATCH] Fixing ce content type when using binary (#3391) --- .../http/CloudEventHttpOutgoingDecorator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/quarkus/addons/common/reactive-messaging/src/main/java/org/kie/kogito/addon/quarkus/common/reactive/messaging/http/CloudEventHttpOutgoingDecorator.java b/quarkus/addons/common/reactive-messaging/src/main/java/org/kie/kogito/addon/quarkus/common/reactive/messaging/http/CloudEventHttpOutgoingDecorator.java index 2aed1745489..2e068729f4f 100644 --- a/quarkus/addons/common/reactive-messaging/src/main/java/org/kie/kogito/addon/quarkus/common/reactive/messaging/http/CloudEventHttpOutgoingDecorator.java +++ b/quarkus/addons/common/reactive-messaging/src/main/java/org/kie/kogito/addon/quarkus/common/reactive/messaging/http/CloudEventHttpOutgoingDecorator.java @@ -22,8 +22,10 @@ import org.kie.kogito.addon.quarkus.common.reactive.messaging.MessageDecorator; import io.quarkus.reactivemessaging.http.runtime.OutgoingHttpMetadata; +import io.smallrye.reactive.messaging.ce.OutgoingCloudEventMetadata; import jakarta.ws.rs.core.HttpHeaders; +import jakarta.ws.rs.core.MediaType; /** * Decorators for Http CloudEvents outgoing messages @@ -40,6 +42,12 @@ public class CloudEventHttpOutgoingDecorator implements MessageDecorator { static final OutgoingHttpMetadata HTTP_RESPONSE_METADATA = new OutgoingHttpMetadata.Builder().addHeader(HttpHeaders.CONTENT_TYPE, CLOUD_EVENTS_CONTENT_TYPE).build(); + /** + * Metadata to include content-type for binary CloudEvents messages + */ + private static final OutgoingHttpMetadata HTTP_BINARY_RESPONSE_METADATA = + new OutgoingHttpMetadata.Builder().addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build(); + /** * Decorates a given payload with custom metadata needed by Http Outgoing processing * @@ -48,6 +56,6 @@ public class CloudEventHttpOutgoingDecorator implements MessageDecorator { */ @Override public Message decorate(Message message) { - return message.addMetadata(HTTP_RESPONSE_METADATA); + return message.getMetadata(OutgoingCloudEventMetadata.class).isEmpty() ? message.addMetadata(HTTP_RESPONSE_METADATA) : message.addMetadata(HTTP_BINARY_RESPONSE_METADATA); } }