CAMEL-23521: camel-core - XML route dumping is missing target element closing tags#23305
Conversation
… closing tags The doDumpXml() method in DefaultDumpRoutesStrategy was stripping the outer container element (routes, rests, routeTemplates) using simple string matching. The opening tag removal only matched bare `<routes>` but the LwModelToXMLDumper (the default xml-io based dumper) always emits a namespace attribute: `<routes xmlns="http://camel.apache.org/schema/xml-io">`. This caused the opening container tag to remain in the output while the closing tag was correctly removed, producing malformed XML in both logged and file output. Fix: use a regex that matches the opening container tag with or without any namespace/xmlns attributes, so both opening and closing tags are consistently stripped regardless of which dumper is in use. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Claus Ibsen <claus.ibsen@gmail.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
| assertTrue(xml.contains("<camel>"), "Expected <camel> root wrapper"); | ||
| assertTrue(xml.contains("</camel>"), "Expected </camel> root wrapper closing tag"); | ||
|
|
||
| // outer container tags must be stripped entirely (both opening and closing) - CAMEL-23521 | ||
| assertFalse(xml.contains("<routes"), "Outer <routes> wrapper must be stripped"); | ||
| assertFalse(xml.contains("<routeTemplates"), "Outer <routeTemplates> wrapper must be stripped"); | ||
|
|
||
| // individual route elements must be present and properly closed | ||
| assertTrue(xml.contains("<route "), "Expected individual <route> elements"); | ||
| assertTrue(xml.contains("</route>"), "Expected </route> closing tag"); | ||
| assertTrue(xml.contains("<routeTemplate "), "Expected individual <routeTemplate> elements"); | ||
| assertTrue(xml.contains("</routeTemplate>"), "Expected </routeTemplate> closing tag"); |
There was a problem hiding this comment.
using AssertJ/XMLUnit, it would help to have better readability when the test is failing. For instance to show what is current content of xml
There was a problem hiding this comment.
Done — switched all assertions to AssertJ assertThat(...).as("...\nActual xml:\n%s", xml).contains(...) / doesNotContain(...). When a check fails, the full dumped XML is now included in the failure message, which makes debugging much easier. Committed in d6c7492.
Claude Code on behalf of Claus Ibsen
|
🧪 CI tested the following changed modules:
Build reactor — dependencies compiled but only changed modules were tested (2 modules)
|
Switch assertions in DefaultDumpRoutesStrategyXmlTest from JUnit assertTrue/assertFalse to AssertJ assertThat, so that the actual XML content is included in the failure message when an assertion fails. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Fixes CAMEL-23521: When XML route dumping is performed via
DefaultDumpRoutesStrategy, the output contains the opening<routes>,<rests>, or<routeTemplates>tag with its namespace attribute but is missing the corresponding closing tag, producing malformed XML.Root cause:
doDumpXml()strips the outer container element by matching its opening and closing tags via simple string replacement. The old JAXB/Spring dumper emittedxmlns="http://camel.apache.org/schema/spring", which was explicitly stripped first to produce a bare<routes>. The lightweight xml-io dumper (LwModelToXMLDumper, the current default) usesxmlns="http://camel.apache.org/schema/xml-io"instead. Because only the Spring namespace was handled, the regex<routes>never matched the opening tag (which still had the xml-io namespace attribute), but</routes>(no attributes) was correctly matched and removed — leaving an orphaned opening tag.Fix: Replace the exact
<routes>string match with a regex<routes(?:\s[^>]*)?>that matches the opening tag with or without any namespace/xmlns attributes. This handles both dumpers (xml-io and Spring/JAXB) and any future dumpers regardless of their namespace conventions.Changes
core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java— fix indoDumpXml(): use regex to match outer container opening tag with optional attributescore/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java— new test verifying that dumped XML has correct structure (outer containers stripped, individual elements properly closed,<camel>wrapper present)Test plan
DefaultDumpRoutesStrategyXmlTest.testDumpXmlHasCorrectStructureverifies that routes and routeTemplates dump files are well-structured (outer container stripped, individual elements present and closed,<camel>wrapper intact)DumpModel*tests passmvn clean install -DskipTests) passesClaude Code on behalf of Claus Ibsen