You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "davsclaus (via GitHub)" <gi...@apache.org> on 2026/05/18 16:58:15 UTC

[PR] CAMEL-23521: camel-core - XML route dumping is missing target element closing tags [camel]

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

   ## 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 emitted `xmlns="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) uses `xmlns="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 in `doDumpXml()`: use regex to match outer container opening tag with optional attributes
   - `core/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
   
   - [x] New test `DefaultDumpRoutesStrategyXmlTest.testDumpXmlHasCorrectStructure` verifies that routes and routeTemplates dump files are well-structured (outer container stripped, individual elements present and closed, `<camel>` wrapper intact)
   - [x] All existing `DumpModel*` tests pass
   - [x] Full root build (`mvn clean install -DskipTests`) passes
   
   _Claude Code on behalf of Claus Ibsen_


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23521: camel-core - XML route dumping is missing target element closing tags [camel]

Posted by "apupier (via GitHub)" <gi...@apache.org>.
apupier commented on code in PR #23305:
URL: https://github.com/apache/camel/pull/23305#discussion_r3264458978


##########
core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.IOHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultDumpRoutesStrategyXmlTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.setDumpRoutes("xml");
+
+        DefaultDumpRoutesStrategy drd = new DefaultDumpRoutesStrategy();
+        drd.setInclude("routes,routeTemplates");
+        drd.setLog(false);
+        drd.setOutput(testDirectory().toString());
+        drd.setResolvePlaceholders(false);
+        context.addService(drd);
+
+        return context;
+    }
+
+    @Test
+    public void testDumpXmlHasCorrectStructure() throws Exception {
+        File dir = testDirectory().toFile();
+        File[] files = dir.listFiles();
+        assertThat(files).as("Expected dump files in %s", dir).isNotNull().isNotEmpty();
+
+        StringBuilder all = new StringBuilder();
+        for (File f : files) {
+            if (f.getName().endsWith(".xml")) {
+                all.append(IOHelper.loadText(new FileInputStream(f)));
+            }
+        }
+        String xml = all.toString();
+
+        // the dump wraps output in <camel> and strips the outer container elements
+        assertThat(xml).as("Expected <camel> root wrapper\nActual xml:\n%s", xml)
+                .contains("<camel>", "</camel>");
+
+        // outer container tags must be stripped entirely (both opening and closing) - CAMEL-23521
+        assertThat(xml).as("Outer <routes> wrapper must be stripped\nActual xml:\n%s", xml)
+                .doesNotContain("<routes");
+        assertThat(xml).as("Outer <routeTemplates> wrapper must be stripped\nActual xml:\n%s", xml)
+                .doesNotContain("<routeTemplates");
+
+        // individual route elements must be present and properly closed
+        assertThat(xml).as("Expected individual <route> elements\nActual xml:\n%s", xml)
+                .contains("<route ", "</route>");
+        assertThat(xml).as("Expected individual <routeTemplate> elements\nActual xml:\n%s", xml)
+                .contains("<routeTemplate ", "</routeTemplate>");
+    }

Review Comment:
   the assertion could be chained so that it gives an overview of all the part which are failing in a single time



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23521: camel-core - XML route dumping is missing target element closing tags [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus merged PR #23305:
URL: https://github.com/apache/camel/pull/23305


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23521: camel-core - XML route dumping is missing target element closing tags [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #23305:
URL: https://github.com/apache/camel/pull/23305#discussion_r3261695568


##########
core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.IOHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class DefaultDumpRoutesStrategyXmlTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.setDumpRoutes("xml");
+
+        DefaultDumpRoutesStrategy drd = new DefaultDumpRoutesStrategy();
+        drd.setInclude("routes,routeTemplates");
+        drd.setLog(false);
+        drd.setOutput(testDirectory().toString());
+        drd.setResolvePlaceholders(false);
+        context.addService(drd);
+
+        return context;
+    }
+
+    @Test
+    public void testDumpXmlHasCorrectStructure() throws Exception {
+        File dir = testDirectory().toFile();
+        File[] files = dir.listFiles();
+        assertNotNull(files, "Expected dump files in " + dir);
+
+        StringBuilder all = new StringBuilder();
+        for (File f : files) {
+            if (f.getName().endsWith(".xml")) {
+                all.append(IOHelper.loadText(new FileInputStream(f)));
+            }
+        }
+        String xml = all.toString();
+
+        // the dump wraps output in <camel> and strips the outer container elements
+        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");

Review 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 d6c7492b4a42.
   
   _Claude Code on behalf of Claus Ibsen_



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23521: camel-core - XML route dumping is missing target element closing tags [camel]

Posted by "apupier (via GitHub)" <gi...@apache.org>.
apupier commented on code in PR #23305:
URL: https://github.com/apache/camel/pull/23305#discussion_r3261434924


##########
core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.IOHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class DefaultDumpRoutesStrategyXmlTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.setDumpRoutes("xml");
+
+        DefaultDumpRoutesStrategy drd = new DefaultDumpRoutesStrategy();
+        drd.setInclude("routes,routeTemplates");
+        drd.setLog(false);
+        drd.setOutput(testDirectory().toString());
+        drd.setResolvePlaceholders(false);
+        context.addService(drd);
+
+        return context;
+    }
+
+    @Test
+    public void testDumpXmlHasCorrectStructure() throws Exception {
+        File dir = testDirectory().toFile();
+        File[] files = dir.listFiles();
+        assertNotNull(files, "Expected dump files in " + dir);
+
+        StringBuilder all = new StringBuilder();
+        for (File f : files) {
+            if (f.getName().endsWith(".xml")) {
+                all.append(IOHelper.loadText(new FileInputStream(f)));
+            }
+        }
+        String xml = all.toString();
+
+        // the dump wraps output in <camel> and strips the outer container elements
+        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");

Review 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`



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23521: camel-core - XML route dumping is missing target element closing tags [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23305:
URL: https://github.com/apache/camel/pull/23305#issuecomment-4481108293

   <!-- ci-tested-modules -->
   :test_tube: **CI tested the following changed modules:**
   
   - `core/camel-core-engine`
   - `core/camel-core`
   
   > :information_source: Dependent modules were not tested because the total number of affected modules exceeded the threshold (50). Use the `test-dependents` label to force testing all dependents.
   
   :warning: **Some tests are disabled on GitHub Actions** (`@DisabledIfSystemProperty(named = "ci.env.name")`) and require manual verification:
   
   - `core/camel-core`: 2 test(s) disabled on GitHub Actions
   
   <details><summary>Build reactor — dependencies compiled but only changed modules were tested (2 modules)</summary>
   
   - Camel :: Core
   - Camel :: Core Engine
   
   </details>
   
   ---
   :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/26047896141)


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23521: camel-core - XML route dumping is missing target element closing tags [camel]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #23305:
URL: https://github.com/apache/camel/pull/23305#discussion_r3264596293


##########
core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.util.IOHelper;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DefaultDumpRoutesStrategyXmlTest extends ContextTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.setDumpRoutes("xml");
+
+        DefaultDumpRoutesStrategy drd = new DefaultDumpRoutesStrategy();
+        drd.setInclude("routes,routeTemplates");
+        drd.setLog(false);
+        drd.setOutput(testDirectory().toString());
+        drd.setResolvePlaceholders(false);
+        context.addService(drd);
+
+        return context;
+    }
+
+    @Test
+    public void testDumpXmlHasCorrectStructure() throws Exception {
+        File dir = testDirectory().toFile();
+        File[] files = dir.listFiles();
+        assertThat(files).as("Expected dump files in %s", dir).isNotNull().isNotEmpty();
+
+        StringBuilder all = new StringBuilder();
+        for (File f : files) {
+            if (f.getName().endsWith(".xml")) {
+                all.append(IOHelper.loadText(new FileInputStream(f)));
+            }
+        }
+        String xml = all.toString();
+
+        // the dump wraps output in <camel> and strips the outer container elements
+        assertThat(xml).as("Expected <camel> root wrapper\nActual xml:\n%s", xml)
+                .contains("<camel>", "</camel>");
+
+        // outer container tags must be stripped entirely (both opening and closing) - CAMEL-23521
+        assertThat(xml).as("Outer <routes> wrapper must be stripped\nActual xml:\n%s", xml)
+                .doesNotContain("<routes");
+        assertThat(xml).as("Outer <routeTemplates> wrapper must be stripped\nActual xml:\n%s", xml)
+                .doesNotContain("<routeTemplates");
+
+        // individual route elements must be present and properly closed
+        assertThat(xml).as("Expected individual <route> elements\nActual xml:\n%s", xml)
+                .contains("<route ", "</route>");
+        assertThat(xml).as("Expected individual <routeTemplate> elements\nActual xml:\n%s", xml)
+                .contains("<routeTemplate ", "</routeTemplate>");
+    }

Review Comment:
   Done — chained all assertions into a single `assertThat(xml).as("...", xml).contains(...).doesNotContain(...).contains(...)` call. The full XML context is now shown once in the `as()` description and all conditions are visible together in one invocation. Committed in 37b7454.
   
   _Claude Code on behalf of Claus Ibsen_



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-23521: camel-core - XML route dumping is missing target element closing tags [camel]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #23305:
URL: https://github.com/apache/camel/pull/23305#issuecomment-4481092913

   :star2: Thank you for your contribution to the Apache Camel project! :star2:
     :robot: CI automation will test this PR automatically.
   
     :camel: Apache Camel Committers, please review the following items:
   
     * First-time contributors **require MANUAL approval** for the GitHub Actions to run
     * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI.
     * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR.
     * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary.
     
     :warning: Be careful when sharing logs. Review their contents before sharing them publicly.


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org