davsclaus opened a new pull request, #26624: URL: https://github.com/apache/camel/pull/26624
## Description A YAML route with a `rest-openapi` producer and no `componentName`, run with `camel run`, failed at startup with ``` Failed to start route ... because: java.lang.NullPointerException: Cannot invoke "io.vertx.core.Vertx.createHttpClient(...)" because "vertx" is null ``` The Jira guessed a missing dependency. The jar is there: the CLI downloads camel-vertx-http for rest-openapi. The cause is lifecycle: 1. the rest-openapi producer picks its HTTP client when its own producer is created, at route start; with no `componentName` the rest component takes the first of the default producer components, `vertx-http`; 2. a component resolved during route startup is built and initialized, not started; `VertxHttpComponent` created its Vert.x in `doStart` only, and `doInit` only looks for a Vert.x bean in the registry; 3. the vertx-http endpoint creates its WebClient in its own `doStart`, with the component's Vert.x, still null. Any path that resolves the vertx-http component late hits the same NPE. The fix is in the component: `getVertx()` creates the managed Vert.x on first use while the component is new, initialized, starting or started (double-checked on a volatile field); `doStart` keeps creating it when nothing asked earlier, `doStop` keeps closing it, a configured Vert.x is kept as before, and once stopped no new instance is created. Verified with the openapi-client example of camel-jbang-examples with its `componentName: http` line removed, against the openapi-server example: the reservations and the 409 are logged, through vertx-http. Not changed here: which producer component is the default (`vertx-http`, then `http`, `undertow`, `netty-http` in `RestEndpoint.DEFAULT_REST_PRODUCER_COMPONENTS`, and the CLI's rule that downloads camel-vertx-http for rest-openapi). That is a separate decision. ## Tests - `VertxHttpComponentLazyVertxTest`: a Vert.x before start, the same instance after start, none after stop; a configured Vert.x kept. - camel-vertx-http suite 93 green. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01Bp3538HRBPMQkb5ta9xRaj -- 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]
