Skip to content

GH-11635: Keep the data content type in binary mode - #11636

Open
Adrastopoulos wants to merge 3 commits into
spring-projects:mainfrom
Adrastopoulos:GH-11635
Open

Adrastopoulos wants to merge 3 commits into
spring-projects:mainfrom
Adrastopoulos:GH-11635

Conversation

@Adrastopoulos

Copy link
Copy Markdown
Contributor

Fixes #11635

In binary mode, ToCloudEventTransformer now sets contentType to the event's datacontenttype: the input content type, or application/octet-stream when the input has none. That is the value it already writes as ce-datacontenttype. Before, it set application/cloudevents, which the CloudEvents protocol bindings reserve for structured mode, so CloudEventMessageConverter from cloudevents-spring rejected the message as an unknown encoding.

ToCloudEventTransformerTests.convertMessageNoExtensions() now expects text/plain from the input, and noContentType() expects application/octet-stream.

Leaving the input contentType as is would also fix the reported case, but it leaves the header out when the input has none, and the header can hold a MimeType while the attribute is its string form.

Fixes: spring-projects#11635

In binary mode, the `ToCloudEventTransformer` keeps the event data as
the payload, but sets the `contentType` header to
`application/cloudevents`.
The CloudEvents protocol bindings reserve that media type for
structured mode and map `datacontenttype` to the content type in binary
mode.
Consumers such as the `CloudEventMessageConverter` from
`cloudevents-spring` reject such a message as an unknown encoding.

* Map the `datacontenttype` attribute to `contentType` in the
`MessageBuilderMessageWriter`: the input content type,
or `application/octet-stream` if absent
* Adjust `ToCloudEventTransformerTests` for the new header value

Signed-off-by: Gabriel Hall <gabriel.hall@cox.net>
@artembilan

Copy link
Copy Markdown
Member

Im sorry what is wrong with our docs that you have open PR for just created your own issue: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.md#search-github-issues-first-create-one-if-necessary ?

@Adrastopoulos

Adrastopoulos commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

What happened here is that my local clone's CONTRIBUTING.MD predated the change that had that section, and I had made the same oversight in #11636 as well.

@cppwfs cppwfs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

@cppwfs

cppwfs commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@Adrastopoulos Thanks for the feedback. We are in consensus that the PR addresses the issue. Please review my comments on the PR and either address them or reply back. Thank you.

With the `contentType` header now taken from `datacontenttype`, an
input content type such as `application/cloudevents+json` makes a
binary mode message look like a structured mode message.
Readers then parse the raw payload as a full CloudEvent, so its sender
could set the event `id`, `source` and `type`.

* Throw an `IllegalStateException` from the `MessageBuilderMessageWriter`
for a `datacontenttype` that starts with `application/cloudevents`
* Verify the binary mode output with the `CloudEventMessageConverter`
from `cloudevents-spring`
* Document the binary mode `contentType` and the new failure

Signed-off-by: Gabriel Hall <gabriel.hall@cox.net>
…chosen

The `MessageBuilderMessageWriter` checked attribute names to map
`datacontenttype` to `contentType` and to reject structured mode
content types.
That rule is about the mode, and `doTransform()` is where the mode is
chosen.

* Reject `application/cloudevents` content types with `Assert.state()`
in `doTransform()` before the binary mode write
* Pass the content type to the `MessageBuilderMessageWriter` and set
`contentType` in `create()`, where `application/cloudevents` was set
before

Signed-off-by: Gabriel Hall <gabriel.hall@cox.net>
@Adrastopoulos
Adrastopoulos requested a review from cppwfs November 2, 2026 19:48

@cppwfs cppwfs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thank you for your contribution!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToCloudEventTransformer: binary mode sets contentType to application/cloudevents

3 participants