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 2021/08/03 14:09:46 UTC

[camel-karaf] branch main updated: CAMEL-16757: Blueprint XML to support routeConfiguration

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-karaf.git


The following commit(s) were added to refs/heads/main by this push:
     new 924d46c  CAMEL-16757: Blueprint XML to support routeConfiguration
924d46c is described below

commit 924d46c17ac7096fb9c4934fc988310e23c219e3
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Aug 3 11:45:58 2021 +0200

    CAMEL-16757: Blueprint XML to support routeConfiguration
---
 .../camel/blueprint/CamelContextFactoryBean.java   | 13 ++++++
 .../blueprint/handler/CamelNamespaceHandler.java   |  2 +-
 ...tRoutesConfigurationBuilderIdOrPatternTest.java | 43 ++++++++++++++++++++
 ...ntRoutesConfigurationBuilderIdOrPatternTest.xml | 46 ++++++++++++++++++++++
 4 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
index a099708..82fd8bb 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
@@ -62,6 +62,7 @@ import org.apache.camel.model.PackageScanDefinition;
 import org.apache.camel.model.Resilience4jConfigurationDefinition;
 import org.apache.camel.model.RestContextRefDefinition;
 import org.apache.camel.model.RouteBuilderDefinition;
+import org.apache.camel.model.RouteConfigurationDefinition;
 import org.apache.camel.model.RouteContextRefDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RouteTemplateContextRefDefinition;
@@ -240,6 +241,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
     private RestConfigurationDefinition restConfiguration;
     @XmlElement(name = "rest")
     private List<RestDefinition> rests = new ArrayList<>();
+    @XmlElement(name = "routeConfiguration")
+    private List<RouteConfigurationDefinition> routeConfigurations = new ArrayList<>();
     @XmlElement(name = "routeTemplate")
     private List<RouteTemplateDefinition> routeTemplates = new ArrayList<>();
     @XmlElement(name = "route")
@@ -1010,6 +1013,16 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
     }
 
     @Override
+    public List<RouteConfigurationDefinition> getRouteConfigurations() {
+        return routeConfigurations;
+    }
+
+    @Override
+    public void setRouteConfigurations(List<RouteConfigurationDefinition> routeConfigurations) {
+        this.routeConfigurations = routeConfigurations;
+    }
+
+    @Override
     public List<RouteTemplateDefinition> getRouteTemplates() {
         return routeTemplates;
     }
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
index dfec0be..3111b48 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
@@ -210,7 +210,7 @@ public class CamelNamespaceHandler implements NamespaceHandler {
                 return parseRouteContextNode(element, context);
             }
             if (element.getLocalName().equals(ROUTE_TEMPLATE_CONTEXT)) {
-                return parseRouteContextNode(element, context);
+                return parseRouteTemplateContextNode(element, context);
             }
             if (element.getLocalName().equals(REST_CONTEXT)) {
                 return parseRestContextNode(element, context);
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintRoutesConfigurationBuilderIdOrPatternTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintRoutesConfigurationBuilderIdOrPatternTest.java
new file mode 100644
index 0000000..d8f8eef
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/BlueprintRoutesConfigurationBuilderIdOrPatternTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.test.blueprint;
+
+import org.junit.Test;
+
+public class BlueprintRoutesConfigurationBuilderIdOrPatternTest extends CamelBlueprintTestSupport {
+
+    @Override
+    protected String getBlueprintDescriptor() {
+        return "org/apache/camel/test/blueprint/blueprintRoutesConfigurationBuilderIdOrPatternTest.xml";
+    }
+
+    @Test
+    public void testRoutesConfigurationOnException() throws Exception {
+        getMockEndpoint("mock:error").expectedBodiesReceived("Bye World");
+
+        try {
+            template.sendBody("direct:start", "Hello World");
+            fail("Should throw exception");
+        } catch (Exception e) {
+            // expected
+        }
+        template.sendBody("direct:start2", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/blueprintRoutesConfigurationBuilderIdOrPatternTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/blueprintRoutesConfigurationBuilderIdOrPatternTest.xml
new file mode 100644
index 0000000..9f053ae
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/blueprintRoutesConfigurationBuilderIdOrPatternTest.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+    <routeConfiguration id="handleError">
+      <onException>
+        <exception>java.lang.Exception</exception>
+        <handled>
+          <constant>true</constant>
+        </handled>
+        <to uri="mock:error"/>
+      </onException>
+    </routeConfiguration>
+
+    <route>
+      <from uri="direct:start"/>
+      <throwException exceptionType="java.lang.IllegalArgumentException" message="Foo"/>
+    </route>
+
+    <route routeConfigurationId="handleError">
+      <from uri="direct:start2"/>
+      <throwException exceptionType="java.lang.IllegalArgumentException" message="Foo2"/>
+    </route>
+
+  </camelContext>
+
+</blueprint>