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

   Fixes [CAMEL-25410](https://issues.apache.org/jira/browse/CAMEL-25410), the 
follow-up of CAMEL-25367 (#27483).
   
   ## Problem
   
   `TryDefinition` kept `doCatch` / `doFinally` in two places: in `outputs` 
(Java DSL, XML, YAML with the clauses inside `steps`), and in the 
`@XmlTransient` fields `catchClauses` / `finallyClause` (YAML with `doCatch` / 
`doFinally` written as properties of `doTry`). `checkInitialized()` copied from 
the outputs into the fields, never the other way. So:
   
   - everything that walks `getOutputs()` missed the property-form clauses: 
`JaxbModelToXMLDumper` still dropped them, the lightweight writers needed a 
special case in three velocity templates (CAMEL-25367), and tooling 
special-cases `getCatchClauses()`;
   - the fields only grew: a catch removed from the outputs (advice-with) 
stayed in the cache and was still reified.
   
   ## Change
   
   The outputs are the single source of truth (public signatures unchanged):
   
   - `setCatchClauses` / `setFinallyClause` fold the clauses into the outputs: 
a doCatch goes before the doFinally, and there is one doFinally.
   - `getCatchClauses()`, `getFinallyClause()` and `getOutputsWithoutCatches()` 
are derived from the outputs on each call, so a clause removed from the outputs 
is gone.
   - The copy constructor no longer copies the clause fields: `super(source)` 
copies the outputs, which hold them. Copying both would give a copy (a route 
template) two instances of each clause.
   - YAML key order: with `doCatch:` above `steps:`, the steps are added after 
the clauses. The ticket suggested sorting in the YAML deserializer. Instead, 
`TryDefinition.addOutput` moves a step that landed in the doTry's own outputs 
after a clause to before the clauses. A step the Java DSL adds while a 
doCatch/doFinally block is open goes to that block, not to the doTry's outputs, 
so it is not moved. The runtime already took the steps from anywhere in the 
outputs, so behaviour does not change; the outputs, and every dump, now read 
steps, doCatch, doFinally. No generator change is needed.
   - The `TryDefinition` special case of `model-writer.vm`, 
`model-yaml-writer.vm` and `model-java-dsl-writer.vm` (CAMEL-25367) is removed, 
and the XML, YAML and Java DSL writers are regenerated.
   - 4.24 upgrade-guide note: `getOutputs()` of a YAML doTry now holds the 
clauses, and the clause getters are derived.
   
   **Not removed:** the doTry special-casing of the tooling 
(`ModelRouteNodeScanner`, `JavaRouteScanner`, `JavaRouteReader` in 
camel-jbang). It is now redundant, because the clauses are in the outputs and 
each walk dedupes with its `seen` set, but I did not run the camel-jbang 
suites, so it stays for a follow-up.
   
   ## Tests
   
   - New `TryDefinitionClausesTest` (camel-core): clauses set as properties are 
in the outputs, in order (steps, doCatch, doFinally); setting them again does 
not duplicate; a clause removed from the outputs is gone; a copy has one 
instance of each clause.
   - New `AdviceWithRemoveDoCatchTest` (camel-core): a doCatch removed with 
advice-with from a started route no longer runs.
   - New `JaxbDumpModelAsXmlTryPropertyClausesTest` (camel-core): the JAXB 
dumper writes property-set clauses.
   - New `TryPropertyClausesTest` (camel-yaml-dsl): YAML with 
`doCatch`/`doFinally` above `steps` gives steps-then-clauses outputs, runs, and 
survives a YAML dump and reload; a route template with property clauses, 
instantiated twice, runs each clause once per exchange.
   - `TryModelWriterTest` (camel-xml-io, camel-yaml-io, camel-java-io):
     - new case: clauses set before the steps are dumped after them;
     - the CAMEL-25367 test asserted `getOutputs().size() == 3`, i.e. that the 
property catch was not in the outputs. It now expects 4, in the order steps, 
doCatch, doFinally.
   - The new camel-core tests fail with the old `TryDefinition` (5 of 5) and 
pass with the change.
   - Runs:
     - camel-xml-io, camel-yaml-io, camel-java-io: full suites.
     - camel-yaml-dsl: full suite, 512 tests.
     - camel-core: the doTry, doCatch, doFinally, advice-with and dump-model 
tests, 310 + 36.
   
   _Claude Code on behalf of davsclaus_
   
   🤖 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