This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new c70e46cba4d8 CAMEL-23521: camel-core - XML route dumping is missing
target element closing tags (#23305)
c70e46cba4d8 is described below
commit c70e46cba4d872cb2eb5a64b4c188ecf37d92ae6
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue May 19 10:45:27 2026 +0200
CAMEL-23521: camel-core - XML route dumping is missing target element
closing tags (#23305)
* CAMEL-23521: camel-core - XML route dumping is missing target element
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 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
* CAMEL-23521: Use AssertJ in test for better failure diagnostics
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 <[email protected]>
* CAMEL-23521: chain AssertJ assertions for clearer failure output
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
---------
Signed-off-by: Claus Ibsen <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../camel/impl/DefaultDumpRoutesStrategy.java | 6 +-
.../impl/DefaultDumpRoutesStrategyXmlTest.java | 86 ++++++++++++++++++++++
2 files changed, 88 insertions(+), 4 deletions(-)
diff --git
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
index cf5e5c38db59..52683d13291a 100644
---
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
+++
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultDumpRoutesStrategy.java
@@ -741,12 +741,10 @@ public class DefaultDumpRoutesStrategy extends
ServiceSupport implements DumpRou
ModelToXMLDumper dumper, String replace, String kind,
StringBuilder sbLocal, StringBuilder sbLog) {
try {
String xml = dumper.dumpModelAsXml(camelContext, def,
resolvePlaceholders, generatedIds, false);
- // remove spring schema xmlns that camel-jaxb dumper includes
- xml = StringHelper.replaceFirst(xml, "
xmlns=\"http://camel.apache.org/schema/spring\">", ">");
xml = xml.replace("</" + replace + ">", "</" + replace + ">\n");
- // remove outer tag (routes, rests, etc)
+ // remove outer tag (routes, rests, etc) including any xmlns
attributes
replace = replace + "s";
- xml = StringHelper.replaceFirst(xml, "<" + replace + ">", "");
+ xml = xml.replaceFirst("<" + replace + "(?:\\s[^>]*)?>", "");
xml = StringHelper.replaceFirst(xml, "</" + replace + ">", "");
sbLocal.append(xml);
diff --git
a/core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java
b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java
new file mode 100644
index 000000000000..9a553f9e0f6d
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/impl/DefaultDumpRoutesStrategyXmlTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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();
+
+ assertThat(xml)
+ .as("XML dump structure check.\nActual xml:\n%s", xml)
+ // the dump wraps output in <camel> and strips the outer
container elements
+ .contains("<camel>", "</camel>")
+ // outer container tags must be stripped entirely (both
opening and closing) - CAMEL-23521
+ .doesNotContain("<routes", "<routeTemplates")
+ // individual route elements must be present and properly
closed
+ .contains("<route ", "</route>", "<routeTemplate ",
"</routeTemplate>");
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ routeTemplate("myTemplate")
+ .templateParameter("greeting")
+ .from("direct:template")
+ .setBody().simple("{{greeting}} ${body}");
+
+ from("direct:greet").routeId("greet")
+ .setBody().constant("Hello World");
+ }
+ };
+ }
+}