Skip to content

Commit

Permalink
Fixing ce content type when using binary (apache#3391)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtirado authored and rgdoliveira committed Feb 6, 2024
1 parent 320fc96 commit b05dc36
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*
Expand All @@ -48,6 +56,6 @@ public class CloudEventHttpOutgoingDecorator implements MessageDecorator {
*/
@Override
public <T> Message<T> decorate(Message<T> message) {
return message.addMetadata(HTTP_RESPONSE_METADATA);
return message.getMetadata(OutgoingCloudEventMetadata.class).isEmpty() ? message.addMetadata(HTTP_RESPONSE_METADATA) : message.addMetadata(HTTP_BINARY_RESPONSE_METADATA);
}
}

0 comments on commit b05dc36

Please sign in to comment.