Claus Ibsen created CAMEL-26299:
-----------------------------------

             Summary: camel-azure-eventgrid - every send fails with a 
NullPointerException: the CloudEvent is built without a data format
                 Key: CAMEL-26299
                 URL: https://issues.apache.org/jira/browse/CAMEL-26299
             Project: Camel
          Issue Type: Bug
          Components: camel-azure
            Reporter: Claus Ibsen
             Fix For: 4.24.0


The producer builds each event with

{code:java}
new CloudEvent("/camel", eventType, BinaryData.fromObject(data), null, null)
{code}

azure-core (1.57.0 on main) requires the format when there is data, so every 
send fails before it reaches Azure:

{noformat}
java.lang.NullPointerException: 'format' cannot be null when 'data' isn't null.
{noformat}

This was checked by building a CloudEvent this way for a String, JSON text, 
byte[], Map, POJO, number, stream and file body: all fail. The call has been 
there since the component was added (CAMEL-20552). The only test of the module, 
EventGridComponentTest, configures endpoints and never sends, so it was not 
seen.

While fixing it, note what BinaryData.fromObject does with the body, as the 
data is the JSON serialization of the object: a Map or a POJO becomes a JSON 
object (what Event Grid expects), but text becomes a JSON string (JSON text is 
sent quoted, not parsed), bytes a base64 string, an InputStream an empty object 
and a File its path. The fix could pick CloudEventDataFormat.JSON for a Map or 
a POJO, send text that is JSON and bytes as they are (BinaryData.fromString / 
fromBytes), and read a stream or a file, plus a test that sends with a mocked 
publisher client.

Found while declaring the catalog body types of the component: 
https://github.com/apache/camel/pull/28446

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to