cloudevents / cloudevents/sdk-java

[restful-ws] Allow configuring default writer encoding for CloudEventsProvider

Open
#533 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
446
Forks
172
PR merge metrics
No merged PRs in 30d

Description

The CloudEventsProvider defaults to binary encoding. Only when there is an StructuredEncoding annotation present, this mode will be set. See the logic:

https://github.com/cloudevents/sdk-java/blob/3614a4f5f4982e6ed38332c2cc73b1a558326274/http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/CloudEventsProvider.java#L95-L112

This makes the BinaryEncoding useless, confirmed by no usages in the code.

The default to the binary mode is unfortunate. Some implementations like Quarkus RESTEasy Reactive Server Sent Events (SSE) don't provide the annotations. This is problematic, as the binary mode doesn't make sense in SSE - the headers set by CloudEventsProvider are being dropped.

See the code:

https://github.com/quarkusio/quarkus/blob/247736226a8c8a55fa88a662eda05963803905eb/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/SseUtil.java#L141-L142

See repro: https://github.com/cardil/openshift-knative-showcase/commit/15e00429c459abf655fb483a27f467d598ae173e
Related issue: https://github.com/quarkusio/quarkus/issues/31559

The fact the Quarkus doesn't pass the method annotations, is probably a bug in Quarkus. But, I feel the CloudEvents SDK should allow setting the default mode. Then, the BinaryEncoding could have a meaning, of changing that default encoding per-method.

/kind bug

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/CloudEventsProvider.java, especially the logic around lines 95–112, and review the linked Quarkus SSE behavior. Determine how a configurable default encoding should interact with StructuredEncoding and BinaryEncoding annotations. Done means callers can select the default mode while per-method encoding behavior remains meaningful.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.