You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/03/24 09:36:57 UTC

[camel] branch main updated (d753d10cded -> ac9b1939f39)

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

davsclaus pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


    from d753d10cded CAMEL-15105: move handling of internal services to a separate class
     new 56a454c5bc7 CAMEL-19156: XML routes loader (jaxb) should load routes-configurations
     new ac9b1939f39 CAMEL-19156: XML routes loader (jaxb) should load routes-configurations

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../java/org/apache/camel/xml/jaxb/JaxbHelper.java | 62 ++++++++++++++++++++++
 .../ROOT/pages/camel-3x-upgrade-guide-3_21.adoc    | 38 +++++++------
 .../ROOT/pages/camel-4-migration-guide.adoc        |  6 +++
 .../dsl/xml/jaxb/JaxbXmlRoutesBuilderLoader.java   | 21 +++++++-
 4 files changed, 110 insertions(+), 17 deletions(-)


[camel] 02/02: CAMEL-19156: XML routes loader (jaxb) should load routes-configurations

Posted by da...@apache.org.
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

commit ac9b1939f3981f9bc12bf7da7e9e602887d56880
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Mar 24 10:36:30 2023 +0100

    CAMEL-19156: XML routes loader (jaxb) should load routes-configurations
---
 .../ROOT/pages/camel-3x-upgrade-guide-3_21.adoc    | 38 +++++++++++++---------
 .../ROOT/pages/camel-4-migration-guide.adoc        |  6 ++++
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
index 2985b69ddf2..9bbdbb18e8a 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
@@ -112,6 +112,28 @@ The `certificatePath` parameter can now be specified as resource: for user point
 
 The deprecated option `componentName` was removed. Please use either `producerComponentName` or `consumerComponentName`.
 
+=== Deprecated Components
+
+The following components that had been marked as deprecated, were removed in this release:
+
+* camel-dozer
+* camel-cmis
+
+== Backlog Tracing
+
+The option `backlogTracing=true` now automatic enabled the tracer on startup. The previous behavior
+was _surprisingly_ that the tracer was only made available, and had to be manually enabled afterwards.
+The old behavior can be archived by setting `backlogTracingStandby=true`.
+
+Move the following class from `org.apache.camel.api.management.mbean.BacklogTracerEventMessage` in `camel-management-api` JAR
+to `org.apache.camel.spi.BacklogTracerEventMessage` in `camel-api` JAR.
+
+
+== Camel Spring Boot
+
+The `camel-spring-boot` dependency no longer includes `camel-spring-xml`. To use legacy Spring XML files `<beans>`
+with Camel on Spring Boot, then include the `camel-spring-boot-xml-starter` dependency.
+
 === camel-micrometer-starter
 
 The `uri` tags are now static instead of dynamic (by default), as potential too many tags generated due to URI with dynamic values.
@@ -134,19 +156,3 @@ Then calling _myservice_ would before require to include the context-path, such
 Now the context-path is not in use, and the endpoint can be called with `http://localhost:8080/myservice`.
 
 NOTE: The `platform-http-starter` can also be used with Rest DSL.
-
-=== Deprecated Components
-
-The following components that had been marked as deprecated, were removed in this release:
-
-* camel-dozer
-* camel-cmis
-
-== Backlog Tracing
-
-The option `backlogTracing=true` now automatic enabled the tracer on startup. The previous behavior
-was _surprisingly_ that the tracer was only made available, and had to be manually enabled afterwards.
-The old behavior can be archived by setting `backlogTracingStandby=true`.
-
-Move the following class from `org.apache.camel.api.management.mbean.BacklogTracerEventMessage` in `camel-management-api` JAR
-to `org.apache.camel.spi.BacklogTracerEventMessage` in `camel-api` JAR.
diff --git a/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc b/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
index 550d378d66d..856730757a4 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4-migration-guide.adoc
@@ -172,6 +172,12 @@ The API in `org.apache.camel.http.common.HttpBinding` has changed slightly to be
 The `parseBody` method now takes in `HttpServletRequest` as input parameter. And all `HttpMessage`
 has been changed to generic `Message` types.
 
+
+== Camel Spring Boot
+
+The `camel-spring-boot` dependency no longer includes `camel-spring-xml`. To use legacy Spring XML files `<beans>`
+with Camel on Spring Boot, then include the `camel-spring-boot-xml-starter` dependency.
+
 === camel-micrometer-starter
 
 The `uri` tags are now static instead of dynamic (by default), as potential too many tags generated due to URI with dynamic values.


[camel] 01/02: CAMEL-19156: XML routes loader (jaxb) should load routes-configurations

Posted by da...@apache.org.
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

commit 56a454c5bc73decf7fe460d89097b9de804ad653
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Mar 24 10:31:59 2023 +0100

    CAMEL-19156: XML routes loader (jaxb) should load routes-configurations
---
 .../java/org/apache/camel/xml/jaxb/JaxbHelper.java | 62 ++++++++++++++++++++++
 .../dsl/xml/jaxb/JaxbXmlRoutesBuilderLoader.java   | 21 +++++++-
 2 files changed, 82 insertions(+), 1 deletion(-)

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 7d3fa490313..843c4fe0f81 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
@@ -18,6 +18,7 @@ package org.apache.camel.xml.jaxb;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -41,6 +42,9 @@ import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.model.ExpressionNode;
 import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.OptionalIdentifiedDefinition;
+import org.apache.camel.model.OutputDefinition;
+import org.apache.camel.model.RouteConfigurationDefinition;
+import org.apache.camel.model.RouteConfigurationsDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RouteTemplateDefinition;
 import org.apache.camel.model.RouteTemplatesDefinition;
@@ -198,6 +202,24 @@ public final class JaxbHelper {
         }
     }
 
+    public static void applyNamespaces(RouteConfigurationDefinition config, Map<String, String> namespaces) {
+        List<OutputDefinition<?>> defs = new ArrayList<>();
+        defs.addAll(config.getIntercepts());
+        defs.addAll(config.getInterceptFroms());
+        defs.addAll(config.getInterceptSendTos());
+        defs.addAll(config.getOnCompletions());
+        defs.addAll(config.getOnExceptions());
+        for (OutputDefinition<?> def : defs) {
+            Collection<ExpressionNode> col = filterTypeInOutputs(def.getOutputs(), ExpressionNode.class);
+            for (ExpressionNode en : col) {
+                NamespaceAware na = getNamespaceAwareFromExpression(en);
+                if (na != null) {
+                    na.setNamespaces(namespaces);
+                }
+            }
+        }
+    }
+
     public static <T extends NamedNode> T modelToXml(CamelContext context, String xml, Class<T> type) throws Exception {
         JAXBContext jaxbContext = getJAXBContext(context);
 
@@ -283,6 +305,46 @@ public final class JaxbHelper {
         return answer;
     }
 
+    public static RouteConfigurationsDefinition loadRouteConfigurationsDefinition(CamelContext context, InputStream inputStream)
+            throws Exception {
+        XmlConverter xmlConverter = newXmlConverter(context);
+        Document dom = xmlConverter.toDOMDocument(inputStream, null);
+
+        JAXBContext jaxbContext = getJAXBContext(context);
+
+        Map<String, String> namespaces = new LinkedHashMap<>();
+        extractNamespaces(dom, namespaces);
+        if (!namespaces.containsValue(CAMEL_NS)) {
+            addNamespaceToDom(dom);
+        }
+
+        Binder<Node> binder = jaxbContext.createBinder();
+        Object result = binder.unmarshal(dom);
+
+        if (result == null) {
+            throw new JAXBException("Cannot unmarshal to RouteConfigurationsDefinition using JAXB");
+        }
+
+        // can either be routes or a single route
+        RouteConfigurationsDefinition answer;
+        if (result instanceof RouteConfigurationDefinition) {
+            RouteConfigurationDefinition config = (RouteConfigurationDefinition) result;
+            answer = new RouteConfigurationsDefinition();
+            applyNamespaces(config, namespaces);
+            answer.getRouteConfigurations().add(config);
+        } else if (result instanceof RouteConfigurationsDefinition) {
+            answer = (RouteConfigurationsDefinition) result;
+            for (RouteConfigurationDefinition config : answer.getRouteConfigurations()) {
+                applyNamespaces(config, namespaces);
+            }
+        } else {
+            // ignore not supported type
+            return null;
+        }
+
+        return answer;
+    }
+
     public static RouteTemplatesDefinition loadRouteTemplatesDefinition(CamelContext context, InputStream inputStream)
             throws Exception {
         XmlConverter xmlConverter = newXmlConverter(context);
diff --git a/dsl/camel-xml-jaxb-dsl/src/main/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlRoutesBuilderLoader.java b/dsl/camel-xml-jaxb-dsl/src/main/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlRoutesBuilderLoader.java
index 48e3453d84d..544c7b179ac 100644
--- a/dsl/camel-xml-jaxb-dsl/src/main/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlRoutesBuilderLoader.java
+++ b/dsl/camel-xml-jaxb-dsl/src/main/java/org/apache/camel/dsl/xml/jaxb/JaxbXmlRoutesBuilderLoader.java
@@ -21,7 +21,11 @@ import java.io.InputStream;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.builder.RouteConfigurationBuilder;
 import org.apache.camel.dsl.support.RouteBuilderLoaderSupport;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.RouteConfigurationDefinition;
+import org.apache.camel.model.RouteConfigurationsDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RouteTemplatesDefinition;
 import org.apache.camel.model.RoutesDefinition;
@@ -31,6 +35,7 @@ import org.apache.camel.spi.Resource;
 import org.apache.camel.spi.annotations.RoutesLoader;
 
 import static org.apache.camel.xml.jaxb.JaxbHelper.loadRestsDefinition;
+import static org.apache.camel.xml.jaxb.JaxbHelper.loadRouteConfigurationsDefinition;
 import static org.apache.camel.xml.jaxb.JaxbHelper.loadRouteTemplatesDefinition;
 import static org.apache.camel.xml.jaxb.JaxbHelper.loadRoutesDefinition;
 import static org.apache.camel.xml.jaxb.JaxbHelper.loadTemplatedRoutesDefinition;
@@ -46,7 +51,7 @@ public class JaxbXmlRoutesBuilderLoader extends RouteBuilderLoaderSupport {
 
     @Override
     public RouteBuilder doLoadRouteBuilder(Resource resource) throws Exception {
-        return new RouteBuilder() {
+        return new RouteConfigurationBuilder() {
             @Override
             public void configure() throws Exception {
                 // we use configure to load the routes
@@ -83,6 +88,20 @@ public class JaxbXmlRoutesBuilderLoader extends RouteBuilderLoaderSupport {
                     }
                 }
             }
+
+            @Override
+            public void configuration() throws Exception {
+                try (InputStream is = resourceInputStream(resource)) {
+                    RouteConfigurationsDefinition configurations = loadRouteConfigurationsDefinition(getCamelContext(), is);
+                    if (configurations != null) {
+                        for (RouteConfigurationDefinition config : configurations.getRouteConfigurations()) {
+                            CamelContextAware.trySetCamelContext(config, getCamelContext());
+                            ((ModelCamelContext) getCamelContext()).addRouteConfiguration(config);
+                        }
+                    }
+                }
+            }
+
         };
     }
 }