gnodet-bot commented on code in PR #28365:
URL: https://github.com/apache/camel/pull/28365#discussion_r4362410040
##########
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:
💡 **Design note:** `failOnRejectedEvents` throws `IllegalStateException`,
which is not a Camel exception type. The `executeOperation` wrapper catches
`AwsServiceException` and `InvalidPayloadException` but lets
`IllegalStateException` escape unwrapped. This means an explicit
`onException(CamelExecutionException.class)` route won't catch it.
The upgrade guide correctly names this as `IllegalStateException`. But
`CamelExecutionException` would be more consistent with how `batchGetSecret`
handles its failure (which throws `CamelExchangeException`), and would
integrate better with Camel's `onException` routing.
Since `failOnRejectedEvents` is `static` with no exchange access, the fix
belongs at the call site:
```java
// in the response-processor lambda (line ~439):
(PutEventsResponse response, Message message) -> {
message.setHeader(EventbridgeConstants.FAILED_ENTRY_COUNT,
response.failedEntryCount());
if (response.failedEntryCount() != null && response.failedEntryCount() >
0) {
String errors = buildRejectionError(response);
throw new CamelExecutionException("EventBridge rejected " + errors,
exchange);
}
}
```
Or pass the exchange into `failOnRejectedEvents` as a parameter and switch
to `CamelExecutionException(message, exchange)`. Not blocking given the upgrade
guide documents the current behavior.
--
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]