davsclaus commented on code in PR #28365:
URL: https://github.com/apache/camel/pull/28365#discussion_r4366205666


##########
components/camel-aws/camel-aws2-eventbridge/src/main/java/org/apache/camel/component/aws2/eventbridge/EventbridgeProducer.java:
##########
@@ -410,28 +417,50 @@ private void putEvent(EventBridgeClient 
eventbridgeClient, Exchange exchange) th
                     PutEventsRequestEntry.Builder entryBuilder = 
PutEventsRequestEntry.builder();
                     String resourcesArn = getRequiredHeader(exchange, 
EventbridgeConstants.EVENT_RESOURCES_ARN, String.class,
                             "At least one resource ARN must be specified");
-                    
entryBuilder.resources(Stream.of(resourcesArn.split(",")).toList());
+                    entryBuilder.resources(Stream.of(resourcesArn.split(","))
+                            .map(String::trim)
+                            .filter(ObjectHelper::isNotEmpty)
+                            .toList());
                     String detailType = getRequiredHeader(exchange, 
EventbridgeConstants.EVENT_DETAIL_TYPE, String.class,
                             "Detail Type must be specified");
                     entryBuilder.detailType(detailType);
                     String source = getRequiredHeader(exchange, 
EventbridgeConstants.EVENT_SOURCE, String.class,
                             "Source must be specified");
                     entryBuilder.source(source);
                     
entryBuilder.eventBusName(getConfiguration().getEventbusName());
-                    try {
-                        
entryBuilder.detail(exchange.getMessage().getMandatoryBody(String.class));
-                    } catch (InvalidPayloadException e) {
-                        throw new RuntimeException(e);
-                    }
+                    
entryBuilder.detail(exchange.getMessage().getMandatoryBody(String.class));
                     builder.entries(entryBuilder.build());
                     return eventbridgeClient.putEvents(builder.build());
                 },
                 "Put Events",
                 (PutEventsResponse response, Message message) -> {
                     message.setHeader(EventbridgeConstants.FAILED_ENTRY_COUNT, 
response.failedEntryCount());
+                    failOnRejectedEvents(response);
                 });
     }
 
+    private static void failOnRejectedEvents(PutEventsResponse response) {
+        Integer failedEntryCount = response.failedEntryCount();
+        if (failedEntryCount == null || failedEntryCount == 0) {
+            return;
+        }
+        // the result entries are in the order of the request entries, and a 
rejected one has an error code
+        String errors = response.entries().stream()
+                .filter(entry -> ObjectHelper.isNotEmpty(entry.errorCode()))
+                .map(EventbridgeProducer::describeError)
+                .collect(Collectors.joining("; "));
+        String what = response.entries().size() > 1
+                ? failedEntryCount + " of " + response.entries().size() + " 
events"
+                : "the event";
+        throw new IllegalStateException("EventBridge rejected " + what + ": " 
+ errors);
+    }

Review Comment:
   Agreed, fixed in eace52eb9eec: a rejected event now fails with a 
`CamelExecutionException` that carries the exchange (the exchange is passed 
into `failOnRejectedEvents`). The test and the upgrade guide say so too.
   
   _Claude Code on behalf of davsclaus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to