camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astefanu...@apache.org
Subject [3/6] camel git commit: CAMEL-9882: Support importing Camel XML configuration files in Camel CDI
Date Tue, 19 Apr 2016 12:58:55 GMT
http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlErrorHandlerFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlErrorHandlerFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlErrorHandlerFactoryBean.java
new file mode 100644
index 0000000..9966030
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlErrorHandlerFactoryBean.java
@@ -0,0 +1,139 @@
+/**
+ * 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.cdi;
+
+import java.util.function.Function;
+
+import static java.util.Objects.nonNull;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.CreationException;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.camel.Processor;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
+import org.apache.camel.builder.ErrorHandlerBuilder;
+import org.apache.camel.builder.LoggingErrorHandlerBuilder;
+import org.apache.camel.cdi.xml.ErrorHandlerDefinition;
+import org.apache.camel.cdi.xml.RedeliveryPolicyFactoryBean;
+import org.apache.camel.processor.RedeliveryPolicy;
+
+import static org.apache.camel.cdi.BeanManagerHelper.getReferenceByName;
+import static org.apache.camel.util.ObjectHelper.isNotEmpty;
+
+final class XmlErrorHandlerFactoryBean extends SyntheticBean<ErrorHandlerBuilder> {
+
+    private final BeanManager manager;
+
+    private final ErrorHandlerDefinition handler;
+
+    XmlErrorHandlerFactoryBean(BeanManager manager, SyntheticAnnotated annotated, Class<?> type, Function<Bean<ErrorHandlerBuilder>, String> toString, ErrorHandlerDefinition handler) {
+        super(manager, annotated, type, null, toString);
+        this.manager = manager;
+        this.handler = handler;
+    }
+
+    @Override
+    public ErrorHandlerBuilder create(CreationalContext<ErrorHandlerBuilder> creationalContext) {
+        try {
+            ErrorHandlerBuilder builder = handler.getType().getTypeAsClass().newInstance();
+
+            switch (handler.getType()) {
+            case DefaultErrorHandler:
+            case DeadLetterChannel:
+                setProperties((DefaultErrorHandlerBuilder) builder);
+                break;
+            case LoggingErrorHandler:
+                setProperties((LoggingErrorHandlerBuilder) builder);
+                break;
+            case NoErrorHandler:
+                // No configuration required
+                break;
+            case TransactionErrorHandler:
+                break;
+            default:
+                break;
+            }
+
+            return builder;
+        } catch (Exception cause) {
+            throw new CreationException("Error while creating instance for " + this, cause);
+        }
+    }
+
+    @Override
+    public void destroy(ErrorHandlerBuilder instance, CreationalContext<ErrorHandlerBuilder> creationalContext) {
+        // NOOP
+    }
+
+    private void setProperties(DefaultErrorHandlerBuilder builder) throws Exception {
+        if (nonNull(handler.getDeadLetterHandleNewException())) {
+            builder.setDeadLetterHandleNewException(handler.getDeadLetterHandleNewException());
+        }
+        builder.setDeadLetterUri(handler.getDeadLetterUri());
+        builder.setExecutorServiceRef(handler.getExecutorServiceRef());
+        builder.setRetryWhileRef(handler.getRetryWhileRef());
+        if (nonNull(handler.getUseOriginalMessage())) {
+            builder.setUseOriginalMessage(handler.getUseOriginalMessage());
+        }
+
+        if (isNotEmpty(handler.getOnExceptionOccurredRef())) {
+            Processor processor = getReferenceByName(manager, handler.getOnExceptionOccurredRef(), Processor.class)
+                .orElseThrow(() -> new UnsatisfiedResolutionException(
+                    String.format("No bean with name [%s] to satisfy attribute [%s]",
+                        handler.getOnPrepareFailureRef(), "onExceptionOccurredRef")));
+            builder.setOnExceptionOccurred(processor);
+        }
+
+        if (isNotEmpty(handler.getOnPrepareFailureRef())) {
+            Processor processor = getReferenceByName(manager, handler.getOnPrepareFailureRef(), Processor.class)
+                .orElseThrow(() -> new UnsatisfiedResolutionException(
+                    String.format("No bean with name [%s] to satisfy attribute [%s]",
+                        handler.getOnPrepareFailureRef(), "onPrepareFailureRef")));
+            builder.setOnPrepareFailure(processor);
+        }
+
+        if (isNotEmpty(handler.getOnRedeliveryRef())) {
+            Processor processor = getReferenceByName(manager, handler.getOnRedeliveryRef(), Processor.class)
+                .orElseThrow(() -> new UnsatisfiedResolutionException(
+                    String.format("No bean with name [%s] to satisfy attribute [%s]",
+                        handler.getOnPrepareFailureRef(), "onRedeliveryRef")));
+            builder.setOnRedelivery(processor);
+        }
+
+        if (nonNull(handler.getRedeliveryPolicy())) {
+            RedeliveryPolicyFactoryBean policy = handler.getRedeliveryPolicy();
+            policy.setBeanManager(manager);
+            builder.setRedeliveryPolicy(policy.getObject());
+        }
+
+        if (isNotEmpty(handler.getRedeliveryPolicyRef())) {
+            RedeliveryPolicy policy = getReferenceByName(manager, handler.getRedeliveryPolicyRef(), RedeliveryPolicy.class)
+                .orElseThrow(() -> new UnsatisfiedResolutionException(
+                    String.format("No bean with name [%s] to satisfy attribute [%s]",
+                        handler.getRedeliveryPolicyRef(), "redeliveryPolicyRef")));
+            builder.setRedeliveryPolicy(policy);
+        }
+    }
+
+    private void setProperties(LoggingErrorHandlerBuilder builder) {
+        builder.setLevel(handler.getLevel());
+        builder.setLogName(handler.getLogName());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlFactoryBeanInjectionTarget.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlFactoryBeanInjectionTarget.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlFactoryBeanInjectionTarget.java
new file mode 100644
index 0000000..234b653
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlFactoryBeanInjectionTarget.java
@@ -0,0 +1,56 @@
+/**
+ * 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.cdi;
+
+import javax.enterprise.inject.CreationException;
+import javax.enterprise.inject.InjectionException;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.core.xml.AbstractCamelFactoryBean;
+import org.apache.camel.util.ObjectHelper;
+
+import static org.apache.camel.cdi.BeanManagerHelper.getReference;
+
+final class XmlFactoryBeanInjectionTarget<T> extends SyntheticInjectionTarget<T> {
+
+    XmlFactoryBeanInjectionTarget(BeanManager manager, AbstractCamelFactoryBean<T> factory, Bean<?> context) {
+        super(
+            () -> {
+                try {
+                    if (ObjectHelper.isEmpty(factory.getCamelContextId()) && context != null) {
+                        factory.setCamelContext(getReference(manager, CamelContext.class, context));
+                    }
+                    factory.afterPropertiesSet();
+                    return factory.getObject();
+                } catch (Exception cause) {
+                    throw new CreationException(cause);
+                }
+            },
+            i -> {
+            },
+            i -> {
+                try {
+                    factory.destroy();
+                } catch (Exception cause) {
+                    throw new InjectionException(cause);
+                }
+            }
+        );
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlProxyFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlProxyFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlProxyFactoryBean.java
new file mode 100644
index 0000000..d7540c4
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlProxyFactoryBean.java
@@ -0,0 +1,103 @@
+/**
+ * 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.cdi;
+
+import java.util.function.Function;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.CreationException;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.FailedToCreateProducerException;
+import org.apache.camel.Producer;
+import org.apache.camel.cdi.xml.ProxyFactoryDefinition;
+import org.apache.camel.component.bean.ProxyHelper;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
+
+import static org.apache.camel.cdi.BeanManagerHelper.getReference;
+import static org.apache.camel.cdi.BeanManagerHelper.getReferenceByName;
+import static org.apache.camel.util.ObjectHelper.isNotEmpty;
+
+final class XmlProxyFactoryBean<T> extends SyntheticBean<T> {
+
+    private final BeanManager manager;
+
+    private final Bean<?> context;
+
+    private final ProxyFactoryDefinition proxy;
+
+    XmlProxyFactoryBean(BeanManager manager, SyntheticAnnotated annotated, Class<?> type, Function<Bean<T>, String> toString, Bean<?> context, ProxyFactoryDefinition proxy) {
+        super(manager, annotated, type, null, toString);
+        this.manager = manager;
+        this.context = context;
+        this.proxy = proxy;
+    }
+
+    @Override
+    public T create(CreationalContext<T> creationalContext) {
+        try {
+            CamelContext context = isNotEmpty(proxy.getCamelContextId())
+                ? getReferenceByName(manager, proxy.getCamelContextId(), CamelContext.class).get()
+                : getReference(manager, CamelContext.class, this.context);
+
+            Endpoint endpoint;
+            if (ObjectHelper.isNotEmpty(proxy.getServiceRef())) {
+                endpoint = context.getRegistry().lookupByNameAndType(proxy.getServiceRef(), Endpoint.class);
+            } else {
+                if (ObjectHelper.isNotEmpty(proxy.getServiceUrl())) {
+                    endpoint = context.getEndpoint(proxy.getServiceUrl());
+                } else {
+                    throw new IllegalStateException("serviceUrl or serviceRef must not be empty!");
+                }
+            }
+
+            if (endpoint == null) {
+                throw new UnsatisfiedResolutionException("Could not resolve endpoint: "
+                    + (ObjectHelper.isNotEmpty(proxy.getServiceRef())
+                    ? proxy.getServiceRef()
+                    : proxy.getServiceUrl()));
+            }
+
+            // binding is enabled by default
+            boolean bind = proxy.getBinding() != null ? proxy.getBinding() : true;
+
+            try {
+                // Start the endpoint before we create the producer
+                ServiceHelper.startService(endpoint);
+                Producer producer = endpoint.createProducer();
+                // Add and start the producer
+                context.addService(producer, true, true);
+                return ProxyHelper.createProxy(endpoint, bind, producer, (Class<T>) proxy.getServiceInterface());
+            } catch (Exception cause) {
+                throw new FailedToCreateProducerException(endpoint, cause);
+            }
+        } catch (Exception cause) {
+            throw new CreationException("Error while creating instance for " + this, cause);
+        }
+    }
+
+    @Override
+    public void destroy(T instance, CreationalContext<T> creationalContext) {
+        // We let the Camel context manage the lifecycle of the consumer and
+        // shut it down when Camel stops.
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlServiceExporterBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlServiceExporterBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlServiceExporterBean.java
new file mode 100644
index 0000000..1a5d819
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/XmlServiceExporterBean.java
@@ -0,0 +1,95 @@
+/**
+ * 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.cdi;
+
+import java.util.function.Function;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.CreationException;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.FailedToCreateConsumerException;
+import org.apache.camel.cdi.xml.ServiceExporterDefinition;
+import org.apache.camel.component.bean.BeanProcessor;
+import org.apache.camel.util.ServiceHelper;
+
+import static org.apache.camel.cdi.BeanManagerHelper.getReference;
+import static org.apache.camel.cdi.BeanManagerHelper.getReferenceByName;
+import static org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint;
+import static org.apache.camel.util.ObjectHelper.isNotEmpty;
+
+final class XmlServiceExporterBean<T> extends SyntheticBean<T> {
+
+    private final BeanManager manager;
+
+    private final Bean<?> context;
+
+    private final ServiceExporterDefinition exporter;
+
+    private final Class<?> type;
+
+    XmlServiceExporterBean(BeanManager manager, SyntheticAnnotated annotated, Class<?> type, Function<Bean<T>, String> toString, Bean<?> context, ServiceExporterDefinition exporter) {
+        super(manager, annotated, type, null, toString);
+        this.manager = manager;
+        this.context = context;
+        this.exporter = exporter;
+        this.type = type;
+    }
+
+    @Override
+    public T create(CreationalContext<T> creationalContext) {
+        try {
+            CamelContext context = isNotEmpty(exporter.getCamelContextId())
+                ? getReferenceByName(manager, exporter.getCamelContextId(), CamelContext.class).get()
+                : getReference(manager, CamelContext.class, this.context);
+
+            Bean<?> bean = manager.resolve(manager.getBeans(exporter.getServiceRef()));
+            if (bean == null) {
+                throw new UnsatisfiedResolutionException("No bean with name [" + exporter.getServiceRef() + "] is deployed!");
+            }
+
+            @SuppressWarnings("unchecked")
+            T service = (T) manager.getReference(bean, type, manager.createCreationalContext(bean));
+
+            Endpoint endpoint = getMandatoryEndpoint(context, exporter.getUri());
+            try {
+                // need to start endpoint before we create consumer
+                ServiceHelper.startService(endpoint);
+                Consumer consumer = endpoint.createConsumer(new BeanProcessor(service, context));
+                // add and start consumer
+                context.addService(consumer, true, true);
+            } catch (Exception cause) {
+                throw new FailedToCreateConsumerException(endpoint, cause);
+            }
+
+            return service;
+        } catch (Exception cause) {
+            throw new CreationException("Error while creating instance for " + this, cause);
+        }
+    }
+
+    @Override
+    public void destroy(T instance, CreationalContext<T> creationalContext) {
+        // We let the Camel context manage the lifecycle of the consumer and
+        // shut it down when Camel stops.
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ApplicationContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ApplicationContextFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ApplicationContextFactoryBean.java
new file mode 100644
index 0000000..d8cc54e
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ApplicationContextFactoryBean.java
@@ -0,0 +1,105 @@
+/**
+ * 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.cdi.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.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.core.xml.AbstractCamelFactoryBean;
+
+@XmlRootElement(name = "beans", namespace = "http://www.springframework.org/schema/beans")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ApplicationContextFactoryBean {
+
+    @XmlElement(name = "camelContext")
+    private List<CamelContextFactoryBean> contexts = new ArrayList<>();
+
+    @XmlElement(name = "errorHandler")
+    private List<ErrorHandlerDefinition> errorHandlers = new ArrayList<>();
+
+    @XmlElement(name = "import")
+    private List<ImportDefinition> imports = new ArrayList<>();
+
+    @XmlElement(name = "restContext")
+    private List<RestContextDefinition> restContexts = new ArrayList<>();
+
+    @XmlElement(name = "routeContext")
+    private List<RouteContextDefinition> routeContexts = new ArrayList<>();
+
+    @XmlElements({
+        @XmlElement(name = "consumerTemplate", type = ConsumerTemplateFactoryBean.class),
+        @XmlElement(name = "endpoint", type = EndpointFactoryBean.class),
+        @XmlElement(name = "redeliveryPolicyProfile", type = RedeliveryPolicyFactoryBean.class),
+        @XmlElement(name = "template", type = ProducerTemplateFactoryBean.class),
+        @XmlElement(name = "threadPool", type = ThreadPoolFactoryBean.class)
+    })
+    private List<AbstractCamelFactoryBean<?>> beans = new ArrayList<>();
+
+    public List<CamelContextFactoryBean> getContexts() {
+        return contexts;
+    }
+
+    public void setContexts(List<CamelContextFactoryBean> contexts) {
+        this.contexts = contexts;
+    }
+
+    public List<ErrorHandlerDefinition> getErrorHandlers() {
+        return errorHandlers;
+    }
+
+    public void setErrorHandlers(List<ErrorHandlerDefinition> errorHandlers) {
+        this.errorHandlers = errorHandlers;
+    }
+
+    public List<ImportDefinition> getImports() {
+        return imports;
+    }
+
+    public void setImports(List<ImportDefinition> imports) {
+        this.imports = imports;
+    }
+
+    public List<RestContextDefinition> getRestContexts() {
+        return restContexts;
+    }
+
+    public void setRestContexts(List<RestContextDefinition> restContexts) {
+        this.restContexts = restContexts;
+    }
+
+    public List<RouteContextDefinition> getRouteContexts() {
+        return routeContexts;
+    }
+
+    public void setRouteContexts(List<RouteContextDefinition> routeContexts) {
+        this.routeContexts = routeContexts;
+    }
+
+    public List<AbstractCamelFactoryBean<?>> getBeans() {
+        return beans;
+    }
+
+    public void setBeans(List<AbstractCamelFactoryBean<?>> beans) {
+        this.beans = beans;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/BeanManagerAware.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/BeanManagerAware.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/BeanManagerAware.java
new file mode 100644
index 0000000..2154877
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/BeanManagerAware.java
@@ -0,0 +1,25 @@
+/**
+ * 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.cdi.xml;
+
+import javax.enterprise.inject.spi.BeanManager;
+
+public interface BeanManagerAware {
+
+    void setBeanManager(BeanManager manager);
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/BeanManagerHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/BeanManagerHelper.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/BeanManagerHelper.java
new file mode 100644
index 0000000..4fad1c1
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/BeanManagerHelper.java
@@ -0,0 +1,38 @@
+/**
+ * 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.cdi.xml;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.camel.CamelContext;
+
+final class BeanManagerHelper {
+
+    private BeanManagerHelper() {
+    }
+
+    static CamelContext getCamelContextById(BeanManager manager, String camelContextId) {
+        Bean<?> bean = manager.resolve(manager.getBeans(camelContextId));
+        return (CamelContext) manager.getReference(bean, CamelContext.class, manager.createCreationalContext(bean));
+    }
+
+    static CamelContext getDefaultCamelContext(BeanManager manager) {
+        Bean<?> bean = manager.resolve(manager.getBeans(CamelContext.class));
+        return (CamelContext) manager.getReference(bean, CamelContext.class, manager.createCreationalContext(bean));
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java
new file mode 100644
index 0000000..a5f8e49
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/CamelContextFactoryBean.java
@@ -0,0 +1,719 @@
+/**
+ * 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.cdi.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.ShutdownRoute;
+import org.apache.camel.ShutdownRunningTask;
+import org.apache.camel.TypeConverterExists;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.core.xml.AbstractCamelContextFactoryBean;
+import org.apache.camel.core.xml.AbstractCamelFactoryBean;
+import org.apache.camel.core.xml.CamelJMXAgentDefinition;
+import org.apache.camel.core.xml.CamelPropertyPlaceholderDefinition;
+import org.apache.camel.core.xml.CamelStreamCachingStrategyDefinition;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.model.ContextScanDefinition;
+import org.apache.camel.model.InterceptDefinition;
+import org.apache.camel.model.InterceptFromDefinition;
+import org.apache.camel.model.InterceptSendToEndpointDefinition;
+import org.apache.camel.model.OnCompletionDefinition;
+import org.apache.camel.model.OnExceptionDefinition;
+import org.apache.camel.model.PackageScanDefinition;
+import org.apache.camel.model.PropertiesDefinition;
+import org.apache.camel.model.RestContextRefDefinition;
+import org.apache.camel.model.RouteBuilderDefinition;
+import org.apache.camel.model.RouteContextRefDefinition;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.ThreadPoolProfileDefinition;
+import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.rest.RestConfigurationDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.spi.PackageScanFilter;
+
+@XmlRootElement(name = "camelContext")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<DefaultCamelContext> implements BeanManagerAware {
+
+    @XmlAttribute(name = "depends-on")
+    private String dependsOn;
+
+    @XmlAttribute
+    private String trace;
+
+    @XmlAttribute
+    private String messageHistory;
+
+    @XmlAttribute
+    private String logExhaustedMessageBody;
+
+    @XmlAttribute
+    private String streamCache;
+
+    @XmlAttribute
+    private String delayer;
+
+    @XmlAttribute
+    private String handleFault;
+
+    @XmlAttribute
+    private String errorHandlerRef;
+
+    @XmlAttribute
+    private String autoStartup;
+
+    @XmlAttribute
+    private String shutdownEager;
+
+    @XmlAttribute
+    private String useMDCLogging;
+
+    @XmlAttribute
+    private String useBreadcrumb;
+
+    @XmlAttribute
+    private String allowUseOriginalMessage;
+
+    @XmlAttribute
+    private String runtimeEndpointRegistryEnabled;
+
+    @XmlAttribute
+    private String managementNamePattern;
+
+    @XmlAttribute
+    private String threadNamePattern;
+
+    @XmlAttribute
+    private ShutdownRoute shutdownRoute;
+
+    @XmlAttribute
+    private ShutdownRunningTask shutdownRunningTask;
+
+    @Deprecated
+    @XmlAttribute
+    private Boolean lazyLoadTypeConverters;
+
+    @XmlAttribute
+    private Boolean typeConverterStatisticsEnabled;
+
+    @XmlAttribute
+    private TypeConverterExists typeConverterExists;
+
+    @XmlAttribute
+    private LoggingLevel typeConverterExistsLoggingLevel;
+
+    @XmlElement(name = "properties")
+    private PropertiesDefinition properties;
+
+    @XmlElement(name = "propertyPlaceholder", type = CamelPropertyPlaceholderDefinition.class)
+    private CamelPropertyPlaceholderDefinition camelPropertyPlaceholder;
+
+    @XmlElement(name = "package")
+    private String[] packages = {};
+
+    @XmlElement(name = "packageScan", type = PackageScanDefinition.class)
+    private PackageScanDefinition packageScan;
+
+    @XmlElement(name = "contextScan", type = ContextScanDefinition.class)
+    private ContextScanDefinition contextScan;
+
+    @XmlElement(name = "streamCaching", type = CamelStreamCachingStrategyDefinition.class)
+    private CamelStreamCachingStrategyDefinition camelStreamCachingStrategy;
+
+    @XmlElement(name = "jmxAgent", type = CamelJMXAgentDefinition.class)
+    private CamelJMXAgentDefinition camelJMXAgent;
+
+    @XmlElements({
+        @XmlElement(name = "consumerTemplate", type = ConsumerTemplateFactoryBean.class),
+        @XmlElement(name = "redeliveryPolicyProfile", type = RedeliveryPolicyFactoryBean.class),
+        @XmlElement(name = "template", type = ProducerTemplateFactoryBean.class),
+        @XmlElement(name = "threadPool", type = ThreadPoolFactoryBean.class)
+    })
+    private List<AbstractCamelFactoryBean<?>> beans;
+
+    @XmlElement(name = "errorHandler", type = ErrorHandlerDefinition.class)
+    private List<ErrorHandlerDefinition> errorHandlers;
+
+    @XmlElement(name = "export", type = ServiceExporterDefinition.class)
+    private List<ServiceExporterDefinition> exports;
+
+    @XmlElement(name = "proxy")
+    private List<ProxyFactoryDefinition> proxies;
+
+    @XmlElement(name = "routeBuilder")
+    private List<RouteBuilderDefinition> builderRefs = new ArrayList<>();
+
+    @XmlElement(name = "routeContextRef")
+    private List<RouteContextRefDefinition> routeRefs = new ArrayList<>();
+
+    @XmlElement(name = "restContextRef")
+    private List<RestContextRefDefinition> restRefs = new ArrayList<>();
+
+    @XmlElement(name = "threadPoolProfile")
+    private List<ThreadPoolProfileDefinition> threadPoolProfiles;
+
+    @XmlElement(name = "endpoint")
+    private List<EndpointFactoryBean> endpoints;
+
+    @XmlElement(name = "dataFormats")
+    private DataFormatsDefinition dataFormats;
+
+    @XmlElement(name = "redeliveryPolicyProfile")
+    private List<RedeliveryPolicyFactoryBean> redeliveryPolicies;
+
+    @XmlElement(name = "onException")
+    private List<OnExceptionDefinition> onExceptions = new ArrayList<>();
+
+    @XmlElement(name = "onCompletion")
+    private List<OnCompletionDefinition> onCompletions = new ArrayList<>();
+
+    @XmlElement(name = "intercept")
+    private List<InterceptDefinition> intercepts = new ArrayList<>();
+
+    @XmlElement(name = "interceptFrom")
+    private List<InterceptFromDefinition> interceptFroms = new ArrayList<>();
+
+    @XmlElement(name = "interceptSendToEndpoint")
+    private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<>();
+
+    @XmlElement(name = "restConfiguration")
+    private RestConfigurationDefinition restConfiguration;
+
+    @XmlElement(name = "rest")
+    private List<RestDefinition> rests = new ArrayList<>();
+
+    @XmlElement(name = "route")
+    private List<RouteDefinition> routes = new ArrayList<>();
+
+    @XmlTransient
+    private DefaultCamelContext context;
+
+    @XmlTransient
+    private BeanManager manager;
+
+    @XmlTransient
+    private boolean implicitId;
+
+    @Override
+    public Class<DefaultCamelContext> getObjectType() {
+        return DefaultCamelContext.class;
+    }
+
+    @Override
+    public void setBeanManager(BeanManager manager) {
+        this.manager = manager;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected <S> S getBeanForType(Class<S> clazz) {
+        Bean<?> bean = manager.resolve(manager.getBeans(clazz));
+        if (bean == null) {
+            return null;
+        }
+
+        return (S) manager.getReference(bean, clazz, manager.createCreationalContext(bean));
+    }
+
+    @Override
+    protected void findRouteBuildersByPackageScan(String[] packages, PackageScanFilter filter, List<RoutesBuilder> builders) throws Exception {
+        // add filter to class resolver which then will filter
+        getContext().getPackageScanClassResolver().addFilter(filter);
+
+        PackageScanRouteBuilderFinder finder = new PackageScanRouteBuilderFinder(getContext(), packages, getContextClassLoaderOnStart(), getContext().getPackageScanClassResolver());
+        finder.appendBuilders(builders);
+
+        // and remove the filter
+        getContext().getPackageScanClassResolver().removeFilter(filter);
+    }
+
+    @Override
+    protected void findRouteBuildersByContextScan(PackageScanFilter filter, boolean includeNonSingletons, List<RoutesBuilder> builders) throws Exception {
+        ContextScanRouteBuilderFinder finder = new ContextScanRouteBuilderFinder(manager, filter, includeNonSingletons);
+        finder.appendBuilders(builders);
+    }
+
+    @Override
+    protected void initBeanPostProcessor(DefaultCamelContext context) {
+        // Already done by Camel CDI injection target
+    }
+
+    @Override
+    protected void postProcessBeforeInit(RouteBuilder builder) {
+        // Already done by Camel CDI injection target
+    }
+
+    @Override
+    protected void initCustomRegistry(DefaultCamelContext context) {
+        // Already done by Camel CDI injection target
+    }
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        super.afterPropertiesSet();
+        setupRoutes();
+    }
+
+    @Override
+    public DefaultCamelContext getContext() {
+        return context;
+    }
+
+    public void setContext(DefaultCamelContext context) {
+        this.context = context;
+    }
+
+    @Override
+    public DefaultCamelContext getContext(boolean create) {
+        return context;
+    }
+
+    public List<AbstractCamelFactoryBean<?>> getBeans() {
+        return beans;
+    }
+
+    public void setBeans(List<AbstractCamelFactoryBean<?>> beans) {
+        this.beans = beans;
+    }
+
+    public List<RouteDefinition> getRoutes() {
+        return routes;
+    }
+
+    public void setRoutes(List<RouteDefinition> routes) {
+        this.routes = routes;
+    }
+
+    public List<RestDefinition> getRests() {
+        return rests;
+    }
+
+    public void setRests(List<RestDefinition> rests) {
+        this.rests = rests;
+    }
+
+    public RestConfigurationDefinition getRestConfiguration() {
+        return restConfiguration;
+    }
+
+    public void setRestConfiguration(RestConfigurationDefinition restConfiguration) {
+        this.restConfiguration = restConfiguration;
+    }
+
+    public List<EndpointFactoryBean> getEndpoints() {
+        return endpoints;
+    }
+
+    public void setEndpoints(List<EndpointFactoryBean> endpoints) {
+        this.endpoints = endpoints;
+    }
+
+    public List<RedeliveryPolicyFactoryBean> getRedeliveryPolicies() {
+        return redeliveryPolicies;
+    }
+
+    public void setRedeliveryPolicies(List<RedeliveryPolicyFactoryBean> redeliveryPolicies) {
+        this.redeliveryPolicies = redeliveryPolicies;
+    }
+
+    public List<InterceptDefinition> getIntercepts() {
+        return intercepts;
+    }
+
+    public void setIntercepts(List<InterceptDefinition> intercepts) {
+        this.intercepts = intercepts;
+    }
+
+    public List<InterceptFromDefinition> getInterceptFroms() {
+        return interceptFroms;
+    }
+
+    public void setInterceptFroms(List<InterceptFromDefinition> interceptFroms) {
+        this.interceptFroms = interceptFroms;
+    }
+
+    public List<InterceptSendToEndpointDefinition> getInterceptSendToEndpoints() {
+        return interceptSendToEndpoints;
+    }
+
+    public void setInterceptSendToEndpoints(List<InterceptSendToEndpointDefinition> interceptSendToEndpoints) {
+        this.interceptSendToEndpoints = interceptSendToEndpoints;
+    }
+
+    public PropertiesDefinition getProperties() {
+        return properties;
+    }
+
+    public void setProperties(PropertiesDefinition properties) {
+        this.properties = properties;
+    }
+
+    public String[] getPackages() {
+        return packages;
+    }
+
+    /**
+     * Sets the package names to be recursively searched for Java classes which
+     * extend {@link org.apache.camel.builder.RouteBuilder} to be auto-wired up to the
+     * {@link CamelContext} as a route. Note that classes are excluded if
+     * they are specifically configured in the deployment.
+     * <p/>
+     * A more advanced configuration can be done using {@link #setPackageScan(org.apache.camel.model.PackageScanDefinition)}
+     *
+     * @param packages the package names which are recursively searched
+     * @see #setPackageScan(org.apache.camel.model.PackageScanDefinition)
+     */
+    public void setPackages(String[] packages) {
+        this.packages = packages;
+    }
+
+    public PackageScanDefinition getPackageScan() {
+        return packageScan;
+    }
+
+    /**
+     * Sets the package scanning information. Package scanning allows for the
+     * automatic discovery of certain camel classes at runtime for inclusion
+     * e.g. {@link org.apache.camel.builder.RouteBuilder} implementations
+     *
+     * @param packageScan the package scan
+     */
+    public void setPackageScan(PackageScanDefinition packageScan) {
+        this.packageScan = packageScan;
+    }
+
+    public ContextScanDefinition getContextScan() {
+        return contextScan;
+    }
+
+    /**
+     * Sets the context scanning information.
+     * Context scanning allows for the automatic discovery of Camel routes runtime for inclusion
+     * e.g. {@link org.apache.camel.builder.RouteBuilder} implementations
+     *
+     * @param contextScan the context scan
+     */
+    public void setContextScan(ContextScanDefinition contextScan) {
+        this.contextScan = contextScan;
+    }
+
+    public CamelPropertyPlaceholderDefinition getCamelPropertyPlaceholder() {
+        return camelPropertyPlaceholder;
+    }
+
+    public void setCamelPropertyPlaceholder(CamelPropertyPlaceholderDefinition camelPropertyPlaceholder) {
+        this.camelPropertyPlaceholder = camelPropertyPlaceholder;
+    }
+
+    public CamelStreamCachingStrategyDefinition getCamelStreamCachingStrategy() {
+        return camelStreamCachingStrategy;
+    }
+
+    public void setCamelStreamCachingStrategy(CamelStreamCachingStrategyDefinition camelStreamCachingStrategy) {
+        this.camelStreamCachingStrategy = camelStreamCachingStrategy;
+    }
+
+    public String getTrace() {
+        return trace;
+    }
+
+    public void setTrace(String trace) {
+        this.trace = trace;
+    }
+
+    public String getMessageHistory() {
+        return messageHistory;
+    }
+
+    public void setMessageHistory(String messageHistory) {
+        this.messageHistory = messageHistory;
+    }
+
+    @Override
+    public String getLogExhaustedMessageBody() {
+        return logExhaustedMessageBody;
+    }
+
+    public void setLogExhaustedMessageBody(String logExhaustedMessageBody) {
+        this.logExhaustedMessageBody = logExhaustedMessageBody;
+    }
+
+    public String getStreamCache() {
+        return streamCache;
+    }
+
+    public void setStreamCache(String streamCache) {
+        this.streamCache = streamCache;
+    }
+
+    public String getDelayer() {
+        return delayer;
+    }
+
+    public void setDelayer(String delayer) {
+        this.delayer = delayer;
+    }
+
+    public String getHandleFault() {
+        return handleFault;
+    }
+
+    public void setHandleFault(String handleFault) {
+        this.handleFault = handleFault;
+    }
+
+    public String getAutoStartup() {
+        return autoStartup;
+    }
+
+    public void setAutoStartup(String autoStartup) {
+        this.autoStartup = autoStartup;
+    }
+
+    public String getShutdownEager() {
+        return shutdownEager;
+    }
+
+    public void setShutdownEager(String shutdownEager) {
+        this.shutdownEager = shutdownEager;
+    }
+
+    public String getUseMDCLogging() {
+        return useMDCLogging;
+    }
+
+    public void setUseMDCLogging(String useMDCLogging) {
+        this.useMDCLogging = useMDCLogging;
+    }
+
+    public String getUseBreadcrumb() {
+        return useBreadcrumb;
+    }
+
+    public void setUseBreadcrumb(String useBreadcrumb) {
+        this.useBreadcrumb = useBreadcrumb;
+    }
+
+    public String getAllowUseOriginalMessage() {
+        return allowUseOriginalMessage;
+    }
+
+    public void setAllowUseOriginalMessage(String allowUseOriginalMessage) {
+        this.allowUseOriginalMessage = allowUseOriginalMessage;
+    }
+
+    public String getRuntimeEndpointRegistryEnabled() {
+        return runtimeEndpointRegistryEnabled;
+    }
+
+    public void setRuntimeEndpointRegistryEnabled(String runtimeEndpointRegistryEnabled) {
+        this.runtimeEndpointRegistryEnabled = runtimeEndpointRegistryEnabled;
+    }
+
+    public String getManagementNamePattern() {
+        return managementNamePattern;
+    }
+
+    public void setManagementNamePattern(String managementNamePattern) {
+        this.managementNamePattern = managementNamePattern;
+    }
+
+    public String getThreadNamePattern() {
+        return threadNamePattern;
+    }
+
+    public void setThreadNamePattern(String threadNamePattern) {
+        this.threadNamePattern = threadNamePattern;
+    }
+
+    @Deprecated
+    public Boolean getLazyLoadTypeConverters() {
+        return lazyLoadTypeConverters;
+    }
+
+    @Deprecated
+    public void setLazyLoadTypeConverters(Boolean lazyLoadTypeConverters) {
+        this.lazyLoadTypeConverters = lazyLoadTypeConverters;
+    }
+
+    public Boolean getTypeConverterStatisticsEnabled() {
+        return typeConverterStatisticsEnabled;
+    }
+
+    public void setTypeConverterStatisticsEnabled(Boolean typeConverterStatisticsEnabled) {
+        this.typeConverterStatisticsEnabled = typeConverterStatisticsEnabled;
+    }
+
+    public TypeConverterExists getTypeConverterExists() {
+        return typeConverterExists;
+    }
+
+    public void setTypeConverterExists(TypeConverterExists typeConverterExists) {
+        this.typeConverterExists = typeConverterExists;
+    }
+
+    public LoggingLevel getTypeConverterExistsLoggingLevel() {
+        return typeConverterExistsLoggingLevel;
+    }
+
+    public void setTypeConverterExistsLoggingLevel(LoggingLevel typeConverterExistsLoggingLevel) {
+        this.typeConverterExistsLoggingLevel = typeConverterExistsLoggingLevel;
+    }
+
+    public CamelJMXAgentDefinition getCamelJMXAgent() {
+        return camelJMXAgent;
+    }
+
+    public void setCamelJMXAgent(CamelJMXAgentDefinition agent) {
+        camelJMXAgent = agent;
+    }
+
+    public List<RouteBuilderDefinition> getBuilderRefs() {
+        return builderRefs;
+    }
+
+    public void setBuilderRefs(List<RouteBuilderDefinition> builderRefs) {
+        this.builderRefs = builderRefs;
+    }
+
+    public List<RouteContextRefDefinition> getRouteRefs() {
+        return routeRefs;
+    }
+
+    public void setRouteRefs(List<RouteContextRefDefinition> routeRefs) {
+        this.routeRefs = routeRefs;
+    }
+
+    public List<RestContextRefDefinition> getRestRefs() {
+        return restRefs;
+    }
+
+    public void setRestRefs(List<RestContextRefDefinition> restRefs) {
+        this.restRefs = restRefs;
+    }
+
+    public String getErrorHandlerRef() {
+        return errorHandlerRef;
+    }
+
+    public void setErrorHandlerRef(String errorHandlerRef) {
+        this.errorHandlerRef = errorHandlerRef;
+    }
+
+    public DataFormatsDefinition getDataFormats() {
+        return dataFormats;
+    }
+
+    public void setDataFormats(DataFormatsDefinition dataFormats) {
+        this.dataFormats = dataFormats;
+    }
+
+    public List<OnExceptionDefinition> getOnExceptions() {
+        return onExceptions;
+    }
+
+    public void setOnExceptions(List<OnExceptionDefinition> onExceptions) {
+        this.onExceptions = onExceptions;
+    }
+
+    public List<OnCompletionDefinition> getOnCompletions() {
+        return onCompletions;
+    }
+
+    public void setOnCompletions(List<OnCompletionDefinition> onCompletions) {
+        this.onCompletions = onCompletions;
+    }
+
+    public ShutdownRoute getShutdownRoute() {
+        return shutdownRoute;
+    }
+
+    public void setShutdownRoute(ShutdownRoute shutdownRoute) {
+        this.shutdownRoute = shutdownRoute;
+    }
+
+    public ShutdownRunningTask getShutdownRunningTask() {
+        return shutdownRunningTask;
+    }
+
+    public void setShutdownRunningTask(ShutdownRunningTask shutdownRunningTask) {
+        this.shutdownRunningTask = shutdownRunningTask;
+    }
+
+    public List<ThreadPoolProfileDefinition> getThreadPoolProfiles() {
+        return threadPoolProfiles;
+    }
+
+    public void setThreadPoolProfiles(List<ThreadPoolProfileDefinition> threadPoolProfiles) {
+        this.threadPoolProfiles = threadPoolProfiles;
+    }
+
+    public String getDependsOn() {
+        return dependsOn;
+    }
+
+    public void setDependsOn(String dependsOn) {
+        this.dependsOn = dependsOn;
+    }
+
+    public List<ProxyFactoryDefinition> getProxies() {
+        return proxies;
+    }
+
+    public void setProxies(List<ProxyFactoryDefinition> proxies) {
+        this.proxies = proxies;
+    }
+
+    public List<ServiceExporterDefinition> getExports() {
+        return exports;
+    }
+
+    public void setExports(List<ServiceExporterDefinition> exports) {
+        this.exports = exports;
+    }
+
+    public boolean isImplicitId() {
+        return implicitId;
+    }
+
+    public void setImplicitId(boolean implicitId) {
+        this.implicitId = implicitId;
+    }
+
+    public List<ErrorHandlerDefinition> getErrorHandlers() {
+        return errorHandlers;
+    }
+
+    public void setErrorHandlers(List<ErrorHandlerDefinition> errorHandlers) {
+        this.errorHandlers = errorHandlers;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ConsumerTemplateFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ConsumerTemplateFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ConsumerTemplateFactoryBean.java
new file mode 100644
index 0000000..d718235
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ConsumerTemplateFactoryBean.java
@@ -0,0 +1,53 @@
+/**
+ * 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.cdi.xml;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.core.xml.AbstractCamelConsumerTemplateFactoryBean;
+
+/**
+ * A factory for creating a new {@link org.apache.camel.ConsumerTemplate}
+ * instance with a minimum of XML
+ */
+@XmlRootElement(name = "consumerTemplate")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ConsumerTemplateFactoryBean extends AbstractCamelConsumerTemplateFactoryBean implements BeanManagerAware {
+
+    @XmlTransient
+    private BeanManager manager;
+
+    @Override
+    public void setBeanManager(BeanManager manager) {
+        this.manager = manager;
+    }
+
+    @Override
+    protected CamelContext getCamelContextWithId(String camelContextId) {
+        return BeanManagerHelper.getCamelContextById(manager, camelContextId);
+    }
+
+    @Override
+    protected CamelContext discoverDefaultCamelContext() {
+        return BeanManagerHelper.getDefaultCamelContext(manager);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ContextScanRouteBuilderFinder.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ContextScanRouteBuilderFinder.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ContextScanRouteBuilderFinder.java
new file mode 100644
index 0000000..19ac7db
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ContextScanRouteBuilderFinder.java
@@ -0,0 +1,86 @@
+/**
+ * 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.cdi.xml;
+
+import java.util.List;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Any;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.spi.PackageScanFilter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A helper class which will find all {@link org.apache.camel.builder.RouteBuilder} beans
+ * in the {@link BeanManager}.
+ */
+final class ContextScanRouteBuilderFinder {
+
+    private static final AnnotationLiteral<Any> ANY = new AnnotationLiteral<Any>() {
+    };
+
+    private final Logger logger = LoggerFactory.getLogger(ContextScanRouteBuilderFinder.class);
+
+    private final BeanManager manager;
+
+    private final PackageScanFilter filter;
+
+    private final boolean includeNonSingletons;
+
+    ContextScanRouteBuilderFinder(BeanManager manager, PackageScanFilter filter, boolean includeNonSingletons) {
+        this.manager = manager;
+        this.filter = filter;
+        this.includeNonSingletons = includeNonSingletons;
+    }
+
+    /**
+     * Appends all the {@link org.apache.camel.builder.RouteBuilder} bean instances that can be found in the manager.
+     */
+    void appendBuilders(List<RoutesBuilder> list) {
+        for (Bean<?> bean : manager.getBeans(RoutesBuilder.class, ANY)) {
+            logger.trace("Found RouteBuilder bean {}", bean);
+
+            // certain beans should be ignored
+            if (shouldIgnoreBean(bean)) {
+                logger.debug("Ignoring RouteBuilder {}", bean);
+                continue;
+            }
+
+            if (!isFilteredClass(bean)) {
+                logger.debug("Ignoring filtered RouteBuilder {}", bean);
+                continue;
+            }
+
+            logger.debug("Adding instantiated RouteBuilder {}", bean);
+            Object instance = manager.getReference(bean, RoutesBuilder.class, manager.createCreationalContext(bean));
+            list.add((RoutesBuilder) instance);
+        }
+    }
+
+    private boolean shouldIgnoreBean(Bean<?> bean) {
+        return !includeNonSingletons && !ApplicationScoped.class.equals(bean.getScope());
+    }
+
+    private boolean isFilteredClass(Bean<?> bean) {
+        return filter != null && filter.matches(bean.getBeanClass());
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/EndpointFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/EndpointFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/EndpointFactoryBean.java
new file mode 100644
index 0000000..3c649277
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/EndpointFactoryBean.java
@@ -0,0 +1,53 @@
+/**
+ * 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.cdi.xml;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.core.xml.AbstractCamelEndpointFactoryBean;
+
+/**
+ * A factory which instantiates {@link Endpoint} objects
+ */
+@XmlRootElement(name = "endpoint")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class EndpointFactoryBean extends AbstractCamelEndpointFactoryBean implements BeanManagerAware {
+
+    @XmlTransient
+    private BeanManager manager;
+
+    @Override
+    public void setBeanManager(BeanManager manager) {
+        this.manager = manager;
+    }
+
+    @Override
+    protected CamelContext getCamelContextWithId(String camelContextId) {
+        return BeanManagerHelper.getCamelContextById(manager, camelContextId);
+    }
+
+    @Override
+    protected CamelContext discoverDefaultCamelContext() {
+        return BeanManagerHelper.getDefaultCamelContext(manager);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ErrorHandlerDefinition.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ErrorHandlerDefinition.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ErrorHandlerDefinition.java
new file mode 100644
index 0000000..939a07b
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ErrorHandlerDefinition.java
@@ -0,0 +1,210 @@
+/**
+ * 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.cdi.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The &lt;errorHandler&gt; tag element.
+ */
+@XmlRootElement(name = "errorHandler")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ErrorHandlerDefinition extends IdentifiedType {
+
+    @XmlAttribute
+    private ErrorHandlerType type = ErrorHandlerType.DefaultErrorHandler;
+
+    @XmlAttribute
+    private String deadLetterUri;
+
+    @XmlAttribute
+    private Boolean deadLetterHandleNewException;
+
+    @XmlAttribute
+    private LoggingLevel level;
+
+    @XmlAttribute
+    private LoggingLevel rollbackLoggingLevel;
+
+    @XmlAttribute
+    private String logName;
+
+    @XmlAttribute
+    private Boolean useOriginalMessage;
+
+    @XmlAttribute
+    private String transactionTemplateRef;
+
+    @XmlAttribute
+    private String transactionManagerRef;
+
+    @XmlAttribute
+    private String onRedeliveryRef;
+
+    @XmlAttribute
+    private String onExceptionOccurredRef;
+
+    @XmlAttribute
+    private String onPrepareFailureRef;
+
+    @XmlAttribute
+    private String retryWhileRef;
+
+    @XmlAttribute
+    private String redeliveryPolicyRef;
+
+    @XmlAttribute
+    private String executorServiceRef;
+
+    @XmlElement
+    private RedeliveryPolicyFactoryBean redeliveryPolicy;
+
+    public ErrorHandlerType getType() {
+        return type;
+    }
+
+    public void setType(ErrorHandlerType type) {
+        this.type = type;
+    }
+
+    public String getDeadLetterUri() {
+        return deadLetterUri;
+    }
+
+    public void setDeadLetterUri(String deadLetterUri) {
+        this.deadLetterUri = deadLetterUri;
+    }
+
+    public Boolean getDeadLetterHandleNewException() {
+        return deadLetterHandleNewException;
+    }
+
+    public void setDeadLetterHandleNewException(Boolean deadLetterHandleNewException) {
+        this.deadLetterHandleNewException = deadLetterHandleNewException;
+    }
+
+    public LoggingLevel getLevel() {
+        return level;
+    }
+
+    public void setLevel(LoggingLevel level) {
+        this.level = level;
+    }
+
+    public LoggingLevel getRollbackLoggingLevel() {
+        return rollbackLoggingLevel;
+    }
+
+    public void setRollbackLoggingLevel(LoggingLevel rollbackLoggingLevel) {
+        this.rollbackLoggingLevel = rollbackLoggingLevel;
+    }
+
+    public String getLogName() {
+        return logName;
+    }
+
+    public void setLogName(String logName) {
+        this.logName = logName;
+    }
+
+    public Boolean getUseOriginalMessage() {
+        return useOriginalMessage;
+    }
+
+    public void setUseOriginalMessage(Boolean useOriginalMessage) {
+        this.useOriginalMessage = useOriginalMessage;
+    }
+
+    public String getTransactionTemplateRef() {
+        return transactionTemplateRef;
+    }
+
+    public void setTransactionTemplateRef(String transactionTemplateRef) {
+        this.transactionTemplateRef = transactionTemplateRef;
+    }
+
+    public String getTransactionManagerRef() {
+        return transactionManagerRef;
+    }
+
+    public void setTransactionManagerRef(String transactionManagerRef) {
+        this.transactionManagerRef = transactionManagerRef;
+    }
+
+    public String getOnRedeliveryRef() {
+        return onRedeliveryRef;
+    }
+
+    public void setOnRedeliveryRef(String onRedeliveryRef) {
+        this.onRedeliveryRef = onRedeliveryRef;
+    }
+
+    public String getOnExceptionOccurredRef() {
+        return onExceptionOccurredRef;
+    }
+
+    public void setOnExceptionOccurredRef(String onExceptionOccurredRef) {
+        this.onExceptionOccurredRef = onExceptionOccurredRef;
+    }
+
+    public String getOnPrepareFailureRef() {
+        return onPrepareFailureRef;
+    }
+
+    public void setOnPrepareFailureRef(String onPrepareFailureRef) {
+        this.onPrepareFailureRef = onPrepareFailureRef;
+    }
+
+    public String getRetryWhileRef() {
+        return retryWhileRef;
+    }
+
+    public void setRetryWhileRef(String retryWhileRef) {
+        this.retryWhileRef = retryWhileRef;
+    }
+
+    public String getRedeliveryPolicyRef() {
+        return redeliveryPolicyRef;
+    }
+
+    public void setRedeliveryPolicyRef(String redeliveryPolicyRef) {
+        this.redeliveryPolicyRef = redeliveryPolicyRef;
+    }
+
+    public String getExecutorServiceRef() {
+        return executorServiceRef;
+    }
+
+    public void setExecutorServiceRef(String executorServiceRef) {
+        this.executorServiceRef = executorServiceRef;
+    }
+
+    public RedeliveryPolicyFactoryBean getRedeliveryPolicy() {
+        return redeliveryPolicy;
+    }
+
+    public void setRedeliveryPolicy(RedeliveryPolicyFactoryBean redeliveryPolicy) {
+        this.redeliveryPolicy = redeliveryPolicy;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ErrorHandlerType.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ErrorHandlerType.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ErrorHandlerType.java
new file mode 100644
index 0000000..57b0860
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ErrorHandlerType.java
@@ -0,0 +1,62 @@
+/**
+ * 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.cdi.xml;
+
+import javax.xml.bind.annotation.XmlEnum;
+import javax.xml.bind.annotation.XmlType;
+
+import org.apache.camel.builder.DeadLetterChannelBuilder;
+import org.apache.camel.builder.DefaultErrorHandlerBuilder;
+import org.apache.camel.builder.ErrorHandlerBuilder;
+import org.apache.camel.builder.LoggingErrorHandlerBuilder;
+import org.apache.camel.builder.NoErrorHandlerBuilder;
+
+/**
+ * Used to configure the errorHandler type
+ */
+@XmlType
+@XmlEnum(String.class)
+public enum ErrorHandlerType {
+
+    DefaultErrorHandler,
+    DeadLetterChannel,
+    LoggingErrorHandler,
+    NoErrorHandler,
+    TransactionErrorHandler;
+
+    /**
+     * Get the type as class.
+     *
+     * @return the class which represents the selected type.
+     */
+    public Class<? extends ErrorHandlerBuilder> getTypeAsClass() {
+        switch (this) {
+        case DefaultErrorHandler:
+            return DefaultErrorHandlerBuilder.class;
+        case DeadLetterChannel:
+            return DeadLetterChannelBuilder.class;
+        case LoggingErrorHandler:
+            return LoggingErrorHandlerBuilder.class;
+        case NoErrorHandler:
+            return NoErrorHandlerBuilder.class;
+        case TransactionErrorHandler:
+            throw new UnsupportedOperationException("Unsupported error handler: " + this);
+        default:
+            throw new IllegalArgumentException("Unknown error handler: " + this);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ImportDefinition.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ImportDefinition.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ImportDefinition.java
new file mode 100644
index 0000000..3be6ca2
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ImportDefinition.java
@@ -0,0 +1,42 @@
+/**
+ * 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.cdi.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * The &lt;import&gt; tag element.
+ *
+*/
+@XmlRootElement(name = "import")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ImportDefinition {
+
+    @XmlAttribute(required = true)
+    private String resource;
+
+    public String getResource() {
+        return resource;
+    }
+
+    public void setResource(String resource) {
+        this.resource = resource;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/PackageScanRouteBuilderFinder.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/PackageScanRouteBuilderFinder.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/PackageScanRouteBuilderFinder.java
new file mode 100644
index 0000000..4d689ec
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/PackageScanRouteBuilderFinder.java
@@ -0,0 +1,92 @@
+/**
+ * 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.cdi.xml;
+
+import java.lang.reflect.Modifier;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.spi.PackageScanClassResolver;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A helper class which will find all {@link org.apache.camel.builder.RouteBuilder} instances on the classpath.
+ */
+final class PackageScanRouteBuilderFinder {
+
+    private final Logger logger = LoggerFactory.getLogger(PackageScanRouteBuilderFinder.class);
+
+    private final CamelContext camelContext;
+
+    private final String[] packages;
+
+    private final PackageScanClassResolver resolver;
+
+    PackageScanRouteBuilderFinder(CamelContext camelContext, String[] packages, ClassLoader classLoader, PackageScanClassResolver resolver) {
+        this.camelContext = camelContext;
+        this.packages = packages;
+        this.resolver = resolver;
+        resolver.addClassLoader(classLoader);
+    }
+
+    /**
+     * Appends all the {@link org.apache.camel.builder.RouteBuilder} instances that can be found on the classpath
+     */
+    void appendBuilders(List<RoutesBuilder> list) throws IllegalAccessException, InstantiationException {
+        Set<Class<?>> classes = resolver.findImplementations(RoutesBuilder.class, packages);
+        for (Class<?> aClass : classes) {
+            logger.trace("Found RouteBuilder class: {}", aClass);
+
+            // certain beans should be ignored
+            if (shouldIgnoreBean(aClass)) {
+                logger.debug("Ignoring RouteBuilder class: {}", aClass);
+                continue;
+            }
+
+            if (!isValidClass(aClass)) {
+                logger.debug("Ignoring invalid RouteBuilder class: {}", aClass);
+                continue;
+            }
+
+            // type is valid so create and instantiate the builder
+            @SuppressWarnings("unchecked")
+            RoutesBuilder builder = instantiateBuilder((Class<? extends RoutesBuilder>) aClass);
+
+            logger.debug("Adding instantiated RouteBuilder: {}", builder);
+            list.add(builder);
+        }
+    }
+
+    private boolean shouldIgnoreBean(Class<?> type) {
+        Map<String, ?> beans = camelContext.getRegistry().findByTypeWithName(type);
+        return !(beans == null || beans.isEmpty());
+    }
+
+    private boolean isValidClass(Class<?> type) {
+        return Modifier.isPublic(type.getModifiers())
+            && !Modifier.isAbstract(type.getModifiers())
+            && !type.isInterface();
+    }
+
+    private RoutesBuilder instantiateBuilder(Class<? extends RoutesBuilder> type) {
+        return camelContext.getInjector().newInstance(type);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ProducerTemplateFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ProducerTemplateFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ProducerTemplateFactoryBean.java
new file mode 100644
index 0000000..9867686
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ProducerTemplateFactoryBean.java
@@ -0,0 +1,62 @@
+/**
+ * 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.cdi.xml;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.core.xml.AbstractCamelProducerTemplateFactoryBean;
+
+/**
+ * A factory for creating a new {@link org.apache.camel.ProducerTemplate}
+ * instance with a minimum of XML
+ */
+@XmlRootElement(name = "template")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class ProducerTemplateFactoryBean extends AbstractCamelProducerTemplateFactoryBean implements BeanManagerAware {
+
+    @XmlTransient
+    private BeanManager manager;
+
+    @Override
+    public void setBeanManager(BeanManager manager) {
+        this.manager = manager;
+    }
+
+    @Override
+    protected CamelContext getCamelContextWithId(String camelContextId) {
+        return BeanManagerHelper.getCamelContextById(manager, camelContextId);
+    }
+
+    @Override
+    protected CamelContext discoverDefaultCamelContext() {
+        return BeanManagerHelper.getDefaultCamelContext(manager);
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    // Work-around as DefaultProducerTemplate does not have a default no-args constructor
+    // which leads to OpenWebBeans being unable to create proxies for the corresponding bean
+    public Class getObjectType() {
+        return ProducerTemplate.class;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ProxyFactoryDefinition.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ProxyFactoryDefinition.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ProxyFactoryDefinition.java
new file mode 100644
index 0000000..2c0a2bc
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/ProxyFactoryDefinition.java
@@ -0,0 +1,87 @@
+/**
+ * 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.cdi.xml;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The &lt;proxy&gt; tag element.
+ *
+*/
+// FIXME: to remove when getters are added to org.apache.camel.core.xml.CamelProxyFactoryDefinition
+@XmlRootElement(name = "proxy")
+public class ProxyFactoryDefinition extends IdentifiedType {
+
+    @XmlAttribute
+    private String serviceUrl;
+
+    @XmlAttribute
+    private String serviceRef;
+
+    @XmlAttribute
+    private Class<?> serviceInterface;
+
+    @XmlAttribute
+    private String camelContextId;
+
+    @XmlAttribute
+    private Boolean binding;
+
+
+    public String getServiceUrl() {
+        return serviceUrl;
+    }
+
+    public void setServiceUrl(String serviceUrl) {
+        this.serviceUrl = serviceUrl;
+    }
+
+    public String getServiceRef() {
+        return serviceRef;
+    }
+
+    public void setServiceRef(String serviceRef) {
+        this.serviceRef = serviceRef;
+    }
+
+    public Class<?> getServiceInterface() {
+        return serviceInterface;
+    }
+
+    public void setServiceInterface(Class<?> serviceInterface) {
+        this.serviceInterface = serviceInterface;
+    }
+
+    public String getCamelContextId() {
+        return camelContextId;
+    }
+
+    public void setCamelContextId(String camelContextId) {
+        this.camelContextId = camelContextId;
+    }
+
+    public Boolean getBinding() {
+        return binding;
+    }
+
+    public void setBinding(Boolean binding) {
+        this.binding = binding;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RedeliveryPolicyFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RedeliveryPolicyFactoryBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RedeliveryPolicyFactoryBean.java
new file mode 100644
index 0000000..8672fab
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RedeliveryPolicyFactoryBean.java
@@ -0,0 +1,52 @@
+/**
+ * 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.cdi.xml;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.core.xml.AbstractCamelRedeliveryPolicyFactoryBean;
+
+/**
+ * A factory which instantiates {@link org.apache.camel.processor.RedeliveryPolicy} objects
+ */
+@XmlRootElement(name = "redeliveryPolicyProfile")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class RedeliveryPolicyFactoryBean extends AbstractCamelRedeliveryPolicyFactoryBean implements BeanManagerAware {
+
+    @XmlTransient
+    private BeanManager manager;
+
+    @Override
+    public void setBeanManager(BeanManager manager) {
+        this.manager = manager;
+    }
+
+    @Override
+    protected CamelContext getCamelContextWithId(String camelContextId) {
+        return BeanManagerHelper.getCamelContextById(manager, camelContextId);
+    }
+
+    @Override
+    protected CamelContext discoverDefaultCamelContext() {
+        return BeanManagerHelper.getDefaultCamelContext(manager);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RestContextDefinition.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RestContextDefinition.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RestContextDefinition.java
new file mode 100644
index 0000000..a6b1120
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RestContextDefinition.java
@@ -0,0 +1,44 @@
+/**
+ * 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.cdi.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.rest.RestDefinition;
+
+@XmlRootElement(name = "restContext")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class RestContextDefinition extends IdentifiedType {
+
+    @XmlElement(name = "rest", required = true)
+    private List<RestDefinition> rests = new ArrayList<>();
+
+    public List<RestDefinition> getRests() {
+        return rests;
+    }
+
+    public void setRests(List<RestDefinition> rests) {
+        this.rests = rests;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ba1172ad/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RouteContextDefinition.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RouteContextDefinition.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RouteContextDefinition.java
new file mode 100644
index 0000000..43cf80d
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/xml/RouteContextDefinition.java
@@ -0,0 +1,44 @@
+/**
+ * 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.cdi.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.RouteDefinition;
+
+@XmlRootElement(name = "routeContext")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class RouteContextDefinition extends IdentifiedType {
+
+    @XmlElement(name = "route", required = true)
+    private List<RouteDefinition> routes = new ArrayList<>();
+
+    public List<RouteDefinition> getRoutes() {
+        return routes;
+    }
+
+    public void setRoutes(List<RouteDefinition> routes) {
+        this.routes = routes;
+    }
+}


Mime
View raw message