`ToCloudEventTransformer`: binary mode sets `contentType` to `application/cloudevents`

Aperta Adatta ai principianti
#11,635 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Adrastopoulos ci sta già lavorando.

Dal 28/10/2026.

  • #11636 di @Adrastopoulos — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
86/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java, spring
Ambito
api, backend

Direzione di ricerca

Leggi ToCloudEventTransformer.java intorno alla riga 347 e le asserzioni della modalità binaria in ToCloudEventTransformerTests intorno alle righe 167 e 225. Controlla come il trasformatore imposta contentType quando conserva il payload e scrive gli header ce-*. Aggiorna l’aspettativa della modalità binaria affinché venga mantenuto il content type di input application/json, quindi conferma che il test copra il content type e il payload attesi dei dati CloudEvent.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

in: cloudevents type: bug

Spring Integration 7.1.2, cloudevents-spring 5.1.0.

In binary mode, ToCloudEventTransformer keeps the event data as the payload and writes the attributes as ce-* headers, but it also replaces contentType with application/cloudevents (MessageBuilderMessageWriter#create(…), line 347). The CloudEvents bindings use that media type to mark structured mode; in binary mode the content type is the datacontenttype (HTTP binding §3 and §3.1.1, AMQP binding §3 and §3.1.1). So the CloudEvents SDK can't read the output:

Message<byte[]> input = MessageBuilder.withPayload("{\"order\":42}".getBytes(StandardCharsets.UTF_8))
    .setHeader(MessageHeaders.CONTENT_TYPE, "application/json")
    .build();

Message<?> output = (Message<?>) toCloudEventTransformer.transform(input);
new CloudEventMessageConverter().fromMessage(output, CloudEvent.class);
  • Expected: a CloudEvent with datacontenttype application/json and the payload as its data.
  • Actual: CloudEventRWException: Could not parse. Unknown encoding. Invalid content type or spec version.

With contentType set back to application/json, the same message reads correctly.

Suggested fix: in binary mode, keep the input's contentType, since the payload doesn't change. ToCloudEventTransformerTests asserts the current value at lines 167 and 225.

Lingua principale
Java
Stelle
1.6k
Fork
1.2k
Merge medio
20h 16m
PR unite (30g)
79

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di spring-projects/spring-integration

Tutte le issue di spring-projects/spring-integration

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.