CAMEL-17272: camel-spring-xml - Classic Spring XML add support for external route configuration XML files
diff --git a/components/camel-blueprint/src/generated/resources/org/apache/camel/blueprint/jaxb.index b/components/camel-blueprint/src/generated/resources/org/apache/camel/blueprint/jaxb.index
index bab0bd6..55cce40 100644
--- a/components/camel-blueprint/src/generated/resources/org/apache/camel/blueprint/jaxb.index
+++ b/components/camel-blueprint/src/generated/resources/org/apache/camel/blueprint/jaxb.index
@@ -8,6 +8,7 @@
CamelProxyFactoryBean
CamelRedeliveryPolicyFactoryBean
CamelRestContextFactoryBean
+CamelRouteConfigurationContextFactoryBean
CamelRouteContextFactoryBean
CamelRouteTemplateContextFactoryBean
CamelThreadPoolFactoryBean
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 34fec02..982e7ef 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.Resilience4jConfigurationDefinition;
import org.apache.camel.model.RestContextRefDefinition;
import org.apache.camel.model.RouteBuilderDefinition;
+import org.apache.camel.model.RouteConfigurationContextRefDefinition;
import org.apache.camel.model.RouteConfigurationDefinition;
import org.apache.camel.model.RouteContextRefDefinition;
import org.apache.camel.model.RouteDefinition;
@@ -207,6 +208,8 @@
private FaultToleranceConfigurationDefinition defaultFaultToleranceConfiguration;
@XmlElement(name = "faultToleranceConfiguration", type = FaultToleranceConfigurationDefinition.class)
private List<FaultToleranceConfigurationDefinition> faultToleranceConfigurations;
+ @XmlElement(name = "routeConfigurationContextRef")
+ private List<RouteConfigurationContextRefDefinition> routeConfigurationRefs = new ArrayList<>();
@XmlElement(name = "routeTemplateContextRef")
private List<RouteTemplateContextRefDefinition> routeTemplateRefs = new ArrayList<>();
@XmlElement(name = "routeBuilder")
@@ -621,6 +624,15 @@
}
@Override
+ public List<RouteConfigurationContextRefDefinition> getRouteConfigurationRefs() {
+ return routeConfigurationRefs;
+ }
+
+ public void setRouteConfigurationRefs(List<RouteConfigurationContextRefDefinition> routeConfigurationRefs) {
+ this.routeConfigurationRefs = routeConfigurationRefs;
+ }
+
+ @Override
public List<RouteTemplateContextRefDefinition> getRouteTemplateRefs() {
return routeTemplateRefs;
}
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelRouteConfigurationContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelRouteConfigurationContextFactoryBean.java
new file mode 100644
index 0000000..3f44611
--- /dev/null
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelRouteConfigurationContextFactoryBean.java
@@ -0,0 +1,39 @@
+/*
+ * 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.blueprint;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.model.IdentifiedType;
+import org.apache.camel.model.RouteConfigurationDefinition;
+
+@XmlRootElement(name = "routeConfigurationContext")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelRouteConfigurationContextFactoryBean extends IdentifiedType {
+
+ @XmlElement(name = "routeConfiguration", required = true)
+ private List<RouteConfigurationDefinition> routeConfigurations = new ArrayList<>();
+
+ public List<RouteConfigurationDefinition> getRouteConfigurations() {
+ return routeConfigurations;
+ }
+}
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 3111b48..b633cb6 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
@@ -34,6 +34,7 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
+import org.apache.camel.blueprint.CamelRouteConfigurationContextFactoryBean;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
@@ -131,6 +132,7 @@
private static final String CAMEL_CONTEXT = "camelContext";
private static final String ROUTE_CONTEXT = "routeContext";
+ private static final String ROUTE_CONFIGURATION_CONTEXT = "routeConfigurationContext";
private static final String ROUTE_TEMPLATE_CONTEXT = "routeTemplateContext";
private static final String REST_CONTEXT = "restContext";
private static final String ENDPOINT = "endpoint";
@@ -209,6 +211,9 @@
if (element.getLocalName().equals(ROUTE_CONTEXT)) {
return parseRouteContextNode(element, context);
}
+ if (element.getLocalName().equals(ROUTE_CONFIGURATION_CONTEXT)) {
+ return parseRouteConfigurationContextNode(element, context);
+ }
if (element.getLocalName().equals(ROUTE_TEMPLATE_CONTEXT)) {
return parseRouteTemplateContextNode(element, context);
}
@@ -364,8 +369,7 @@
try {
binder = getJaxbContext().createBinder();
} catch (JAXBException e) {
-
- throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
+ throw new ComponentDefinitionException("Failed to create the JAXB binder: " + e, e);
}
Object value = parseUsingJaxb(element, context, binder);
if (!(value instanceof CamelRouteContextFactoryBean)) {
@@ -399,6 +403,47 @@
return ctx;
}
+ private Metadata parseRouteConfigurationContextNode(Element element, ParserContext context) {
+ LOG.trace("Parsing RouteConfigurationContext {}", element);
+ // now parse the routes with JAXB
+ Binder<Node> binder;
+ try {
+ binder = getJaxbContext().createBinder();
+ } catch (JAXBException e) {
+ throw new ComponentDefinitionException("Failed to create the JAXB binder: " + e, e);
+ }
+ Object value = parseUsingJaxb(element, context, binder);
+ if (!(value instanceof CamelRouteConfigurationContextFactoryBean)) {
+ throw new ComponentDefinitionException("Expected an instance of " + CamelRouteConfigurationContextFactoryBean.class);
+ }
+
+ CamelRouteConfigurationContextFactoryBean rcfb = (CamelRouteConfigurationContextFactoryBean) value;
+ String id = rcfb.getId();
+
+ MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class);
+ factory.setId(".camelBlueprint.passThrough." + id);
+ factory.setObject(new PassThroughCallable<Object>(rcfb));
+
+ MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class);
+ factory2.setId(".camelBlueprint.factory." + id);
+ factory2.setFactoryComponent(factory);
+ factory2.setFactoryMethod("call");
+
+ MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class);
+ ctx.setId(id);
+ ctx.setRuntimeClass(List.class);
+ ctx.setFactoryComponent(factory2);
+ ctx.setFactoryMethod("getRouteConfigurations");
+ // must be lazy as we want CamelContext to be activated first
+ ctx.setActivation(ACTIVATION_LAZY);
+
+ // lets inject the namespaces into any namespace aware POJOs
+ injectNamespaces(element, binder);
+
+ LOG.trace("Parsing RouteConfigurationContext {} done, returning {}", element, ctx);
+ return ctx;
+ }
+
private Metadata parseRouteTemplateContextNode(Element element, ParserContext context) {
LOG.trace("Parsing RouteTemplateContext {}", element);
// now parse the routes with JAXB
@@ -406,8 +451,7 @@
try {
binder = getJaxbContext().createBinder();
} catch (JAXBException e) {
-
- throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
+ throw new ComponentDefinitionException("Failed to create the JAXB binder: " + e, e);
}
Object value = parseUsingJaxb(element, context, binder);
if (!(value instanceof CamelRouteTemplateContextFactoryBean)) {
@@ -448,7 +492,7 @@
try {
binder = getJaxbContext().createBinder();
} catch (JAXBException e) {
- throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
+ throw new ComponentDefinitionException("Failed to create the JAXB binder: " + e, e);
}
Object value = parseUsingJaxb(element, context, binder);
if (!(value instanceof CamelRestContextFactoryBean)) {
@@ -489,7 +533,7 @@
try {
binder = getJaxbContext().createBinder();
} catch (JAXBException e) {
- throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
+ throw new ComponentDefinitionException("Failed to create the JAXB binder: " + e, e);
}
Object value = parseUsingJaxb(element, context, binder);
if (!(value instanceof CamelEndpointFactoryBean)) {
@@ -530,7 +574,7 @@
try {
binder = getJaxbContext().createBinder();
} catch (JAXBException e) {
- throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
+ throw new ComponentDefinitionException("Failed to create the JAXB binder: " + e, e);
}
Object value = parseUsingJaxb(element, context, binder);
if (!(value instanceof KeyStoreParametersFactoryBean)) {
@@ -571,7 +615,7 @@
try {
binder = getJaxbContext().createBinder();
} catch (JAXBException e) {
- throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
+ throw new ComponentDefinitionException("Failed to create the JAXB binder: " + e, e);
}
Object value = parseUsingJaxb(element, context, binder);
if (!(value instanceof SecureRandomParametersFactoryBean)) {
@@ -612,7 +656,7 @@
try {
binder = getJaxbContext().createBinder();
} catch (JAXBException e) {
- throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e);
+ throw new ComponentDefinitionException("Failed to create the JAXB binder: " + e, e);
}
Object value = parseUsingJaxb(element, context, binder);
if (!(value instanceof SSLContextParametersFactoryBean)) {