This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.11.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 97a4f07ea03b06d852a6ed85db91f458fef091a4
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri Sep 3 17:27:06 2021 +0200

    CAMEL-16920: routes built with endpoint-dsl does not output uri when 
dumping routes.
---
 .../java/org/apache/camel/xml/jaxb/JaxbHelper.java | 30 ++++++++++++++++++++++
 .../camel/xml/jaxb/JaxbModelToXMLDumper.java       |  5 ++++
 2 files changed, 35 insertions(+)

diff --git 
a/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java 
b/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
index f8b4789..2adc14f 100644
--- 
a/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
+++ 
b/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbHelper.java
@@ -40,10 +40,13 @@ import org.apache.camel.NamedNode;
 import org.apache.camel.TypeConversionException;
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.model.ExpressionNode;
+import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RouteTemplateDefinition;
 import org.apache.camel.model.RouteTemplatesDefinition;
 import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.SendDefinition;
+import org.apache.camel.model.ToDynamicDefinition;
 import org.apache.camel.model.language.ExpressionDefinition;
 import org.apache.camel.model.rest.RestDefinition;
 import org.apache.camel.model.rest.RestsDefinition;
@@ -80,6 +83,33 @@ public final class JaxbHelper {
         }
     }
 
+    /**
+     * If the route has been built with endpoint-dsl, then the model will not 
have uri set which then cannot be included
+     * in the JAXB model dump
+     */
+    @SuppressWarnings("unchecked")
+    public static void resolveEndpointDslUris(RouteDefinition route) {
+        FromDefinition from = route.getInput();
+        if (from != null && from.getEndpointConsumerBuilder() != null) {
+            String uri = from.getEndpointConsumerBuilder().getUri();
+            from.setUri(uri);
+        }
+        Collection<SendDefinition> col = 
filterTypeInOutputs(route.getOutputs(), SendDefinition.class);
+        for (SendDefinition<?> to : col) {
+            if (to.getEndpointProducerBuilder() != null) {
+                String uri = to.getEndpointProducerBuilder().getUri();
+                to.setUri(uri);
+            }
+        }
+        Collection<ToDynamicDefinition> col2 = 
filterTypeInOutputs(route.getOutputs(), ToDynamicDefinition.class);
+        for (ToDynamicDefinition to : col2) {
+            if (to.getEndpointProducerBuilder() != null) {
+                String uri = to.getEndpointProducerBuilder().getUri();
+                to.setUri(uri);
+            }
+        }
+    }
+
     public static NamespaceAware 
getNamespaceAwareFromExpression(ExpressionNode expressionNode) {
         ExpressionDefinition ed = expressionNode.getExpression();
 
diff --git 
a/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbModelToXMLDumper.java
 
b/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbModelToXMLDumper.java
index f21fc98..21b650d 100644
--- 
a/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbModelToXMLDumper.java
+++ 
b/core/camel-xml-jaxb/src/main/java/org/apache/camel/xml/jaxb/JaxbModelToXMLDumper.java
@@ -55,6 +55,7 @@ import static 
org.apache.camel.xml.jaxb.JaxbHelper.extractNamespaces;
 import static org.apache.camel.xml.jaxb.JaxbHelper.getJAXBContext;
 import static org.apache.camel.xml.jaxb.JaxbHelper.modelToXml;
 import static org.apache.camel.xml.jaxb.JaxbHelper.newXmlConverter;
+import static org.apache.camel.xml.jaxb.JaxbHelper.resolveEndpointDslUris;
 
 /**
  * JAXB based {@link ModelToXMLDumper}.
@@ -73,18 +74,22 @@ public class JaxbModelToXMLDumper implements 
ModelToXMLDumper {
             List<RouteTemplateDefinition> templates = 
((RouteTemplatesDefinition) definition).getRouteTemplates();
             for (RouteTemplateDefinition route : templates) {
                 extractNamespaces(route.getRoute(), namespaces);
+                resolveEndpointDslUris(route.getRoute());
             }
         } else if (definition instanceof RouteTemplateDefinition) {
             RouteTemplateDefinition template = (RouteTemplateDefinition) 
definition;
             extractNamespaces(template.getRoute(), namespaces);
+            resolveEndpointDslUris(template.getRoute());
         } else if (definition instanceof RoutesDefinition) {
             List<RouteDefinition> routes = ((RoutesDefinition) 
definition).getRoutes();
             for (RouteDefinition route : routes) {
                 extractNamespaces(route, namespaces);
+                resolveEndpointDslUris(route);
             }
         } else if (definition instanceof RouteDefinition) {
             RouteDefinition route = (RouteDefinition) definition;
             extractNamespaces(route, namespaces);
+            resolveEndpointDslUris(route);
         }
 
         Marshaller marshaller = jaxbContext.createMarshaller();

Reply via email to