allthingssecurity opened a new pull request, #30466:
URL: https://github.com/apache/camel/pull/30466

   # Description
   
   [CAMEL-27210](https://issues.apache.org/jira/browse/CAMEL-27210)
   
   The `box:events/listen` consumer listens with the `EventStream` of the Box 
SDK. When a request of the stream's poller thread fails (a network error, or 
Box not reachable for longer than the SDK retries: the long poll, the `OPTIONS 
/events` for a new long poll URL, or the `GET /events` after a change), the 
exception ends the poller thread, and the SDK (`EventStream.notifyException`, 
box-java-sdk 4.16.4) stops the stream before it calls `onException` of the 
listeners. Neither the SDK nor `BoxConsumer.onException` started it again: the 
consumer logged one WARN and received no event any more, while the route stayed 
started. `onNextPosition` ignored the stream position, so there was nothing to 
continue from either.
   
   Fix (`BoxConsumer`):
   - `onNextPosition` keeps the next stream position.
   - `onException` still hands the exception to the exception handler, and then 
schedules a restart: after 1 s, doubled up to 60 s while the stream keeps 
failing, and back to 1 s once events are received again. The restart listens 
with a new `EventStream` from the position after the last events received, or 
from the `startingPosition` of the endpoint when no event was received yet 
(from "now" when the endpoint has none, as at the start).
   - The restart runs on a single-thread scheduled executor of the consumer, 
created in `doStart` and shut down in `doStop`. A lock orders the restart and 
the stop, and a restart that runs after the stop began does nothing 
(`isRunAllowed`). A restart that fails (Box still not reachable when the stream 
starts) schedules the next one.
   
   The same consumer had a second issue, fixed in the same commit as both 
change `BoxConsumer`: it extends `AbstractApiConsumer`, a scheduled poll 
consumer, and did not override `poll()`. Every poll (delay 500 ms by default) 
invoked the `listen` API method again, on the API proxy of the endpoint and 
without the consumer as listener. `BoxEventsManager.listen` logs at DEBUG that 
the listener is missing and returns, and the poll then routed an exchange with 
a `null` body for that `void` result (`ApiConsumerHelper.getResultsProcessed`). 
The route got an empty message twice a second for as long as it ran, besides 
the events. Fix: `BoxConsumer` overrides `poll()`. The events come from the 
event stream, so a poll routes nothing; it marks the consumer ready 
(`forceConsumerAsReady()`), as the poll of the API consumer did.
   
   Not changed: events that happen while the stream is down are read after the 
restart from the stream position, as Box keeps them; a stream that fails before 
its first change and was started at "now" starts at "now" again, so changes 
from that window can be missed (the SDK does not hand out the position it 
started at). Box can deliver an event twice (the SDK only drops duplicates 
within one `EventStream`). A stop that comes while a restart without a position 
asks Box for the "now" position waits for that request, as a start does (the 
Box SDK has no connect or read timeout by default).
   
   Tests: `BoxEventsConsumerTest` runs the real consumer and SDK on a 
`BoxAPIConnection` with a request interceptor (as 
`BoxEventLogsManagerPagingTest` does) that answers like the service: the long 
poll URL for `OPTIONS /events`, `new_change` on the long poll while there are 
events after the stream position, and the events after a stream position with 
the next one. A failing request throws the `BoxAPIException` the SDK throws for 
a network error (`BoxAPIConnection.executeOnClient`). Four tests: without any 
event the route must receive nothing for two seconds (several polls); with one 
event it must receive exactly that event; the first `GET /events` fails, and 
the event must still be routed; the stream fails twice after an event was 
routed, and the next event must be routed, with the stream opened again at the 
position after the first event. Runs: on main all four tests fail; with only 
the `poll()` part the two restart tests still fail (the event after the failure 
is never routed); wi
 th the change all four pass; camel-box-component module unit tests 11 run, 0 
failures (the ITs need a Box account and were not run locally); the test class 
10 times in one JVM: 40 of 40.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it): 
[CAMEL-27210](https://issues.apache.org/jira/browse/CAMEL-27210).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
     (I built the core modules and camel-box (camel-box-api, 
camel-box-component) with the formatter and import-sort plugins. No option or 
doc changed. I did not run the full root build.)
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
     This PR was prepared with Claude Code (Claude Opus 5.5). The commit 
carries a `Co-Authored-By` trailer.
   
   _Claude Code on behalf of allthingssecurity_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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