Skip to content

Commit

Permalink
Merge pull request #17 from rgdoliveira/9.99.x-prod_backport
Browse files Browse the repository at this point in the history
[9.99.x-prod] Fixing ce content type when using binary (apache#3391)
  • Loading branch information
rgdoliveira authored Feb 6, 2024
2 parents 65e225f + b05dc36 commit 6213498
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 6213498

Please sign in to comment.