Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudEventMessageBuilder creates URI with surrounding quotes #1089

Open
kschlesselmann opened this issue Nov 6, 2023 · 2 comments
Open

CloudEventMessageBuilder creates URI with surrounding quotes #1089

kschlesselmann opened this issue Nov 6, 2023 · 2 comments

Comments

@kschlesselmann
Copy link

Currently we're migrating some of our messages to Cloud Events. If we use

CloudEventMessageBuilder.withData(this)
        .setId(UUID.randomUUID().toString())
        .setSource("/my/source")
        .setSpecVersion("1.0")
        .setType("my.type")
        .setHeader(KafkaHeaders.KEY, myId)
        .build(CloudEventMessageUtils.KAFKA_ATTR_PREFIX)

the resulting message apparently has a header ce_source="/my/source" and other clients which validate the incoming messages fail with "/my/source" not being a valid URI.

If I just set the header myself using .setHeader(CloudEventMessageUtils.SOURCE, "/my/source") everything seems fine.

@olegz
Copy link
Contributor

olegz commented Jun 24, 2024

I m not sure i follow. CloudEventMessageBuilder.setSource(..) does the same thing

public CloudEventMessageBuilder<T> setSource(String uri) {
	this.headers.put(CloudEventMessageUtils.SOURCE, URI.create(uri));
	return this;
}

and results is ce-source=ce-source=/my/source (is what I see while interrogating the final Message)
. . . which is the same if I set source explicitly - ce-source=/my/source

Can you please clarify or provide. way to reproduce?

@kschlesselmann
Copy link
Author

kschlesselmann commented Jun 25, 2024

@olegz If I remember correctly the problem was, that Spring created the header ce_source with some value that only Spring could read itself. I'm not sure if it was that the header value had the quotes included resulting in something like

URI.create("\"/foo/bar\"");

on the client consumer side. I'd have te reproduce the issue again on our side.

The fix on our side added a test like

        val message = CloudEventMessageBuilder
            .withData(Instant.now())
            //.setSource("/foo")
            .setHeader(CloudEventMessageUtils.SOURCE, "/foo")
            .build(CloudEventMessageUtils.KAFKA_ATTR_PREFIX)

        assertThat(message.headers)
            .containsEntry("ce_source", "/foo")

as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants