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

Claus Ibsen commented on CAMEL-25207:
-------------------------------------

Analysis (from reading the code and history, plus runtime checks made for 
CAMEL-25206; nothing built yet):

*Why they are top-level only*
* 2021 (CAMEL-12545): the first YAML routes loader marked onException, 
onCompletion, intercept, interceptFrom and interceptSendToEndpoint with 
{{@YamlIn}} (top-level entries), with a {{//TODO: add an option on Camel's 
definitions to distinguish between IN/OUT types}} in 
GenerateYamlDeserializersMojo that was never done.
* 2021, default since 2023 (CAMEL-16504, CAMEL-19007): flow mode arrived. It 
makes the steps after an EIP with no steps of its own that EIP's children, so 
an empty onException written as a step would swallow the rest of the route.

*What it takes now*
# Schema generator: GenerateYamlSchemaMojo puts a type either among the 
top-level entries ({{@YamlIn}}) or among the steps (processors), never both. 
The five must be both, so they stay valid at the top level and in 
routeConfiguration and become valid as steps. Regenerates camelYamlDsl.json, 
the canonical and model schemas, and the catalog copy.
# Loader: nothing. The generated deserializers already read them as steps into 
the route's outputs (the YAML loads when it is not validated).
# Flow mode: YamlDeserializerSupport.setStepsFlowMode must not make an EIP that 
is taken out of the route ({{isAbstract()}}) take the steps after it. 
transacted and saga are abstract too but wrap the rest of the route 
({{isWrappingEntireOutput()}}), so they keep behaving as today.
# Runtime: nothing. RouteDefinitionHelper already takes route-scoped 
onException, intercepts and onCompletion out of the route's outputs (the XML 
DSL relies on it); nesting them inside a filter or split is already rejected at 
startup ("The output must be added as top-level on the route").
# Validator: the hint in SchemaHints ("'onException' is a top-level entry: 
write it as a list item at the same level as the route, not inside it") would 
fire wrongly for a valid step, so reword or scope it. camel validate could flag 
them nested below the route level, as the schema cannot express "route level 
only" (transacted and saga have the same limitation today).
# Dumper: nothing. It already writes them as steps; that YAML becomes valid, 
and the 5 routes go back into YamlRoundTripTest (CAMEL-25206).
# Docs: a short section in yaml-dsl.adoc on top-level vs route-scoped; YAML 
tabs showing the route-scoped form in the exception clause, onCompletion and 
intercept pages where Java and XML already have one.
# Behaviour change: a YAML file that was never validated with an empty 
onException before other steps: today those steps become the exception handler 
(or the route fails with "no outputs"); afterwards they run normally. A fix, 
but worth a line in the upgrade guide.
# Java parity: Java has route-scoped onException and onCompletion only; the 
intercepts are RouteBuilder-level. YAML would match XML.

*Unit tests in camel-yaml-dsl* (each runs the route, not just loads it)
* onException in a route: handles that route's failures, not those of another 
route in the same file; takes precedence over a top-level onException; with 
only redelivery settings, the steps after it still run.
* onCompletion in a route: runs for that route only, also with onCompleteOnly / 
onFailureOnly.
* intercept, interceptFrom (a matching and a non-matching uri), 
interceptSendToEndpoint in a route: apply to that route only.
* Nested inside a filter: fails at startup with the top-level error.
* Unchanged: the top-level and routeConfiguration forms; flat transacted and 
saga take the rest of the route; the flow-mode tests (AggregateTest, LoopTest, 
SplitTest).
* Schema: the new forms validate, the existing ones still do.
* camel-yaml-dsl-validator: the reworded hint; the 5 corpus routes back in 
YamlRoundTripTest.

Size: moderate (generator branch, one flow-mode condition, a validator hint, 
docs, tests); no runtime change. Best built on top of PR 27157 (CAMEL-25206), 
which has the round-trip test.

_Claude Code on behalf of davsclaus_


> camel-yaml-dsl - Support route scoped onException, onCompletion and 
> interceptors as in the XML and Java DSL
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-25207
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25207
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-yaml-dsl
>            Reporter: Claus Ibsen
>            Priority: Minor
>
> In the XML and Java DSL the cross-cutting EIPs can be scoped to a single 
> route:
> * Java: {{from(...).onException(...)}} and {{from(...).onCompletion()}} 
> inside the route.
> * XML: {{<onException>}}, {{<onCompletion>}}, {{<intercept>}}, 
> {{<interceptFrom>}} and {{<interceptSendToEndpoint>}} inside a {{<route>}}.
> The YAML DSL only has them at the top level (applies to all routes of the 
> file) or in a {{routeConfiguration}}; the schema rejects them as route steps 
> ("'onException' is a top-level entry: write it as a list item at the same 
> level as the route, not inside it").
> The YAML routes loader does accept them as steps when the file is not 
> validated, but flow mode then makes the steps after an {{onException}} with 
> no steps of its own its children, so the route fails to start ("Route has no 
> output processors").
> This also shows in the YAML dumper ({{camel transform route --format yaml}}): 
> an XML or Java route with a route scoped onException, onCompletion or 
> interceptor is written as YAML that {{camel validate}} rejects. Found by the 
> YAML round-trip test of CAMEL-25206 (XML corpus of camel-xml-io: 
> barOnExceptionRoute.xml, onCompletion.xml, barInterceptorRoute.xml, 
> interceptFrom.xml, interceptFromAndSendTo.xml).
> Proposal:
> * Allow onException, onCompletion, intercept, interceptFrom and 
> interceptSendToEndpoint as steps of a route in the YAML DSL (schema and 
> loader), route scoped like in XML.
> * Exclude them from flow mode: the steps after them are never theirs 
> (transacted and saga keep taking the rest of the route).
> * Remove the known entries from the round-trip test of CAMEL-25206.
> _Claude Code on behalf of davsclaus_



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

Reply via email to