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/12/04 10:54:40 UTC
[camel] 01/04: CAMEL-17272: camel-spring-xml - Classic Spring XML add support for external route configuration XML files
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 da71cccd1648276e6e0d995f68e3366b751ff0f1
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Dec 4 10:52:32 2021 +0100
CAMEL-17272: camel-spring-xml - Classic Spring XML add support for external route configuration XML files
---
.../org/apache/camel/spring/xml/jaxb.index | 1 +
.../spring/xml/routeConfigurationContext.json | 17 ++++++
.../CamelRouteConfigurationContextFactoryBean.java | 67 ++++++++++++++++++++++
.../spring/xml/handler/CamelNamespaceHandler.java | 33 +++++++++++
4 files changed, 118 insertions(+)
diff --git a/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/jaxb.index b/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/jaxb.index
index f7926d6..ee308b7 100644
--- a/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/jaxb.index
+++ b/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/jaxb.index
@@ -7,6 +7,7 @@ CamelFluentProducerTemplateFactoryBean
CamelProducerTemplateFactoryBean
CamelRedeliveryPolicyFactoryBean
CamelRestContextFactoryBean
+CamelRouteConfigurationContextFactoryBean
CamelRouteContextFactoryBean
CamelRouteTemplateContextFactoryBean
CamelThreadPoolFactoryBean
diff --git a/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/routeConfigurationContext.json b/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/routeConfigurationContext.json
new file mode 100644
index 0000000..a858ab4
--- /dev/null
+++ b/components/camel-spring-xml/src/generated/resources/org/apache/camel/spring/xml/routeConfigurationContext.json
@@ -0,0 +1,17 @@
+{
+ "model": {
+ "kind": "model",
+ "name": "routeConfigurationContext",
+ "title": "Route Configuration Context",
+ "description": "Configuration of route configurations using XML",
+ "deprecated": false,
+ "label": "spring,configuration,routing",
+ "javaType": "org.apache.camel.spring.xml.CamelRouteConfigurationContextFactoryBean",
+ "input": false,
+ "output": false
+ },
+ "properties": {
+ "routeConfiguration": { "kind": "element", "displayName": "Route Configuration", "required": false, "type": "array", "javaType": "java.util.List<org.apache.camel.model.RouteConfigurationDefinition>", "deprecated": false, "autowired": false, "secret": false, "description": "Route Configurations" },
+ "id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "The id of this node" }
+ }
+}
diff --git a/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/CamelRouteConfigurationContextFactoryBean.java b/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/CamelRouteConfigurationContextFactoryBean.java
new file mode 100644
index 0000000..0e10ef1
--- /dev/null
+++ b/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/CamelRouteConfigurationContextFactoryBean.java
@@ -0,0 +1,67 @@
+/*
+ * 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.spring.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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 org.apache.camel.model.IdentifiedType;
+import org.apache.camel.model.RouteConfigurationDefinition;
+import org.apache.camel.spi.Metadata;
+import org.springframework.beans.factory.FactoryBean;
+
+/**
+ * Configuration of route configurations using XML
+ */
+@Metadata(label = "spring,configuration,routing")
+@XmlRootElement(name = "routeConfigurationContext")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelRouteConfigurationContextFactoryBean extends IdentifiedType
+ implements FactoryBean<List<RouteConfigurationDefinition>> {
+
+ @XmlElement(name = "routeConfiguration", required = true)
+ @Metadata(description = "Route Configurations")
+ private List<RouteConfigurationDefinition> routeConfigurations = new ArrayList<>();
+
+ @Override
+ public List<RouteConfigurationDefinition> getObject() throws Exception {
+ return routeConfigurations;
+ }
+
+ @Override
+ public Class<?> getObjectType() {
+ return routeConfigurations.getClass();
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public List<RouteConfigurationDefinition> getRouteConfigurations() {
+ return routeConfigurations;
+ }
+
+ public void setRouteConfigurations(List<RouteConfigurationDefinition> routeConfigurations) {
+ this.routeConfigurations = routeConfigurations;
+ }
+}
diff --git a/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/handler/CamelNamespaceHandler.java b/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/handler/CamelNamespaceHandler.java
index fed1bba..d525e8d 100644
--- a/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/handler/CamelNamespaceHandler.java
@@ -47,6 +47,7 @@ import org.apache.camel.spring.xml.CamelFluentProducerTemplateFactoryBean;
import org.apache.camel.spring.xml.CamelProducerTemplateFactoryBean;
import org.apache.camel.spring.xml.CamelRedeliveryPolicyFactoryBean;
import org.apache.camel.spring.xml.CamelRestContextFactoryBean;
+import org.apache.camel.spring.xml.CamelRouteConfigurationContextFactoryBean;
import org.apache.camel.spring.xml.CamelRouteContextFactoryBean;
import org.apache.camel.spring.xml.CamelRouteTemplateContextFactoryBean;
import org.apache.camel.spring.xml.CamelThreadPoolFactoryBean;
@@ -126,6 +127,8 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
@Override
public void init() {
+ // register routeContext parser
+ registerParser("routeConfigurationContext", new RouteConfigurationContextDefinitionParser());
// register routeTemplateContext parser
registerParser("routeTemplateContext", new RouteTemplateContextDefinitionParser());
// register restContext parser
@@ -263,6 +266,36 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
}
}
+ protected class RouteConfigurationContextDefinitionParser extends BeanDefinitionParser {
+
+ public RouteConfigurationContextDefinitionParser() {
+ super(CamelRouteConfigurationContextFactoryBean.class, false);
+ }
+
+ @Override
+ protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
+ doBeforeParse(element);
+ super.doParse(element, parserContext, builder);
+
+ // now lets parse the routes with JAXB
+ Binder<Node> binder;
+ try {
+ binder = getJaxbContext().createBinder();
+ } catch (JAXBException e) {
+ throw new BeanDefinitionStoreException("Failed to create the JAXB binder", e);
+ }
+ Object value = parseUsingJaxb(element, parserContext, binder);
+
+ if (value instanceof CamelRouteConfigurationContextFactoryBean) {
+ CamelRouteConfigurationContextFactoryBean factoryBean = (CamelRouteConfigurationContextFactoryBean) value;
+ builder.addPropertyValue("routeConfigurations", factoryBean.getRouteConfigurations());
+ }
+
+ // lets inject the namespaces into any namespace aware POJOs
+ injectNamespaces(element, binder);
+ }
+ }
+
protected class RouteTemplateContextDefinitionParser extends BeanDefinitionParser {
public RouteTemplateContextDefinitionParser() {