This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new fe8f4ef8bd63 CAMEL-26300: camel-google-calendar - the CloudEvent 
transformer fails with a clear message on a body that is not an Event (#29217)
fe8f4ef8bd63 is described below

commit fe8f4ef8bd63ef65a1bf0aba1c8661c44b7fcd5c
Author: Andrea Cosentino <[email protected]>
AuthorDate: Thu Nov 5 13:03:55 2026 +0100

    CAMEL-26300: camel-google-calendar - the CloudEvent transformer fails with 
a clear message on a body that is not an Event (#29217)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 ...alendarStreamCloudEventDataTypeTransformer.java | 14 +++++++--
 ...darStreamCloudEventDataTypeTransformerTest.java | 33 +++++++++++++++++++++-
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  7 +++++
 3 files changed, 51 insertions(+), 3 deletions(-)

diff --git 
a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/transform/GoogleCalendarStreamCloudEventDataTypeTransformer.java
 
b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/transform/GoogleCalendarStreamCloudEventDataTypeTransformer.java
index df677639863e..350f3222a0b6 100644
--- 
a/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/transform/GoogleCalendarStreamCloudEventDataTypeTransformer.java
+++ 
b/components/camel-google/camel-google-calendar/src/main/java/org/apache/camel/component/google/calendar/transform/GoogleCalendarStreamCloudEventDataTypeTransformer.java
@@ -20,6 +20,7 @@ package org.apache.camel.component.google.calendar.transform;
 import java.util.Map;
 
 import com.google.api.services.calendar.model.Event;
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Message;
 import org.apache.camel.cloudevents.CloudEvent;
 import org.apache.camel.cloudevents.CloudEvents;
@@ -44,6 +45,16 @@ public class 
GoogleCalendarStreamCloudEventDataTypeTransformer extends Transform
 
     @Override
     public void transform(Message message, DataType fromType, DataType toType) 
{
+        Event event = message.getBody(Event.class);
+        if (event == null) {
+            Object body = message.getBody();
+            throw new CamelExecutionException(
+                    "The body must be a Google Calendar Event, such as the 
body of the google-calendar-stream consumer,"
+                                              + " to read the CloudEvent 
subject from, but was: "
+                                              + (body != null ? 
body.getClass().getName() : "null"),
+                    message.getExchange());
+        }
+
         final Map<String, Object> headers = message.getHeaders();
 
         CloudEvent cloudEvent = CloudEvents.v1_0;
@@ -56,8 +67,7 @@ public class 
GoogleCalendarStreamCloudEventDataTypeTransformer extends Transform
                     "google.calendar.stream." + 
message.getHeader(GoogleCalendarStreamConstants.EVENT_ID, String.class));
         }
 
-        headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SUBJECT,
-                message.getBody(Event.class).getEventType());
+        headers.put(CloudEvent.CAMEL_CLOUD_EVENT_SUBJECT, 
event.getEventType());
         headers.put(CloudEvent.CAMEL_CLOUD_EVENT_TIME, 
cloudEvent.getEventTime(message.getExchange()));
         headers.put(CloudEvent.CAMEL_CLOUD_EVENT_CONTENT_TYPE, 
CloudEvent.APPLICATION_OCTET_STREAM_MIME_TYPE);
     }
diff --git 
a/components/camel-google/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/transform/GoogleCalendarStreamCloudEventDataTypeTransformerTest.java
 
b/components/camel-google/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/transform/GoogleCalendarStreamCloudEventDataTypeTransformerTest.java
index a311f61fba0a..f0ff37944040 100644
--- 
a/components/camel-google/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/transform/GoogleCalendarStreamCloudEventDataTypeTransformerTest.java
+++ 
b/components/camel-google/camel-google-calendar/src/test/java/org/apache/camel/component/google/calendar/transform/GoogleCalendarStreamCloudEventDataTypeTransformerTest.java
@@ -16,7 +16,11 @@
  */
 package org.apache.camel.component.google.calendar.transform;
 
+import java.util.Arrays;
+import java.util.Map;
+
 import com.google.api.services.calendar.model.Event;
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Exchange;
 import org.apache.camel.cloudevents.CloudEvent;
 import 
org.apache.camel.component.google.calendar.stream.GoogleCalendarStreamConstants;
@@ -30,9 +34,12 @@ import org.apache.camel.support.DefaultExchange;
 import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 class GoogleCalendarStreamCloudEventDataTypeTransformerTest {
 
@@ -84,7 +91,31 @@ class GoogleCalendarStreamCloudEventDataTypeTransformerTest {
         // another body is no Event to read the subject from
         Exchange other = new DefaultExchange(camelContext);
         other.getMessage().setBody("Test");
-        assertThrows(NullPointerException.class,
+        assertThrows(CamelExecutionException.class,
                 () -> transformer.transform(other.getMessage(), DataType.ANY, 
DataType.ANY));
     }
+
+    @Test
+    void anotherBodyFailsWithAClearMessage() {
+        // CAMEL-26300: a body that is no Event failed with a 
NullPointerException
+        for (Object body : Arrays.asList("secret text", Map.of("eventType", 
"secret value"), null)) {
+            Exchange exchange = new DefaultExchange(camelContext);
+            
exchange.getMessage().setHeader(GoogleCalendarStreamConstants.EVENT_ID, 
"event1");
+            exchange.getMessage().setBody(body);
+
+            CamelExecutionException e = 
assertThrows(CamelExecutionException.class,
+                    () -> transformer.transform(exchange.getMessage(), 
DataType.ANY, DataType.ANY), String.valueOf(body));
+
+            String type = body != null ? body.getClass().getName() : "null";
+            assertTrue(e.getMessage().startsWith("The body must be a Google 
Calendar Event, such as the body of the"
+                                                 + " google-calendar-stream 
consumer, to read the CloudEvent subject from,"
+                                                 + " but was: " + type),
+                    e.getMessage());
+            assertFalse(e.getMessage().contains("secret"), e.getMessage());
+            assertSame(exchange, e.getExchange());
+            // no CloudEvent header is set on a message that fails
+            
assertNull(exchange.getMessage().getHeader(CloudEvent.CAMEL_CLOUD_EVENT_TYPE));
+            
assertNull(exchange.getMessage().getHeader(CloudEvent.CAMEL_CLOUD_EVENT_SOURCE));
+        }
+    }
 }
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index c5120c17c7b1..12c60876e8f3 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -6060,6 +6060,13 @@ The `pinecone:rag` data type transformer now reads the 
`QueryResponseWithUnsigne
   `NullPointerException`. A `byte[]` or an `InputStream` body is sent as its 
bytes, and another body as text in UTF-8
   (previously in the default charset of the JVM).
 
+=== camel-google-calendar - the CloudEvent transformer on a body that is not 
an Event
+
+The `google-calendar-stream:application-cloudevents` data type transformer now 
fails with a `CamelExecutionException`
+that says the body must be a Google Calendar `Event` when the body is not one, 
and it sets no CloudEvent header then.
+Before, it failed with a `NullPointerException`. The body of the 
`google-calendar-stream` consumer is always an
+`Event`, so routes that use the transformer after that consumer are not 
affected.
+
 === camel-aws2-eventbridge - putEvent fails when the event is rejected
 
 When EventBridge rejects the event, for example with `MalformedDetail` for a 
detail that is not a JSON object, the

Reply via email to