[ 
https://issues.apache.org/jira/browse/CAMEL-23553?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18082144#comment-18082144
 ] 

Claus Ibsen commented on CAMEL-23553:
-------------------------------------

Analysis and proposed fix plan (Claude Code on behalf of Claus Ibsen):

h3. Root Cause

{{RestRegistry}} is always registered as a lazy plugin via 
{{lazyAddContextPlugin()}} in {{AbstractCamelContext}} (line 413). However, 
{{isContextPluginInUse()}} in {{DefaultContextPluginManager}} explicitly 
returns {{false}} for lazy plugins (Supplier instances). This means the guard 
condition in {{VertxPlatformHttpConsumer.doInit()}} is always false, and 
{{restRegistry}} is never resolved — even when camel-rest IS on the classpath.

h3. Affected Locations

||File||Issue||
|{{VertxPlatformHttpConsumer.java}} (line 119)|{{isContextPluginInUse}} guard 
always returns false — restRegistry never set, breaks contract-first REST|
|{{MultiRestConsumer.java}} (line 55)|Same broken {{isContextPluginInUse}} 
guard|
|{{RestDevConsole.java}} (lines 41, 87)|Calls {{getRestRegistry()}} directly 
without guard — will throw if camel-rest is not on classpath since the lazy 
supplier calls {{resolveMandatoryBootstrapService}} which throws 
{{NoSuchServiceException}}|

h3. Proposed Fix

Make the lazy resolution return {{null}} gracefully when camel-rest is absent, 
instead of throwing. This avoids try/catch at every call site and lets callers 
use a natural null-check.

*1. {{SimpleCamelContext.createRestRegistryFactory()}}* — change from 
{{resolveMandatoryBootstrapService()}} to {{resolveBootstrapService()}} 
(returns {{Optional}}). Return {{null}} if not found.

*2. {{AbstractCamelContext.createRestRegistry()}}* — null-check the factory, 
return {{null}} if absent.

*3. {{DefaultContextPluginManager.getContextPlugin()}}* — handle {{null}} from 
a lazy supplier (currently it would pass null to {{addContextPlugin}} which 
silently ignores it, leaving the Supplier in place for repeated retries). 
Remove the entry when the supplier returns null.

*4. {{VertxPlatformHttpConsumer.doInit()}}* — drop the {{isContextPluginInUse}} 
guard, resolve via {{PluginHelper.getRestRegistry()}} directly and null-check 
(same pattern RestDevConsole already uses).

*5. {{MultiRestConsumer}} constructor* — same as above.

*6. {{RestDevConsole}}* — already uses null-check, no change needed (it becomes 
correct once the lazy resolution returns null instead of throwing).

> camel-platform-http-vertx: VertxPlatformHttpConsumer fails to resolve 
> RestRegistry
> ----------------------------------------------------------------------------------
>
>                 Key: CAMEL-23553
>                 URL: https://issues.apache.org/jira/browse/CAMEL-23553
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-platform-http-vertx
>            Reporter: James Netherton
>            Priority: Minor
>             Fix For: 4.21.0
>
>
> VertxPlatformHttpConsumer has this logic to resolve the RestRegistry:
> [https://github.com/apache/camel/blob/23db0da261d68bb4ae0175d9b6b07df2f7ee83b6/components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java#L119-L121]
> The if expression always evaluates to false because the RestRegistry is added 
> as a lazy context plugin:
> [https://github.com/apache/camel/blob/23db0da261d68bb4ae0175d9b6b07df2f7ee83b6/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java#L413]
> Lazy plugins are considered as 'not in use' within isContextPluginInUse:
> [https://github.com/apache/camel/blob/23db0da261d68bb4ae0175d9b6b07df2f7ee83b6/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultContextPluginManager.java#L49-L54]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to