camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r1381135 - in /camel/trunk: components/camel-cdi/src/main/java/org/apache/camel/cdi/ components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/ examples/camel-example-cdi/ parent/ tests/ tests/camel-itest-cdi/ tests/camel-i...
Date Wed, 05 Sep 2012 10:53:52 GMT
Author: jstrachan
Date: Wed Sep  5 10:53:51 2012
New Revision: 1381135

URL: http://svn.apache.org/viewvc?rev=1381135&view=rev
Log:
added integration test to ensure the camel injections allow us to specify different camel contexts; plus we can default the camel context to use from the @CamelStart annotation on a RouteBuilder to make things more DRY

Added:
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextMap.java   (with props)
    camel/trunk/tests/camel-itest-cdi/
    camel/trunk/tests/camel-itest-cdi/pom.xml   (with props)
    camel/trunk/tests/camel-itest-cdi/src/
    camel/trunk/tests/camel-itest-cdi/src/data/
    camel/trunk/tests/camel-itest-cdi/src/data/message1.xml   (with props)
    camel/trunk/tests/camel-itest-cdi/src/data/message2.xml   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/
    camel/trunk/tests/camel-itest-cdi/src/main/java/
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Constants.java   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextA.java   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextB.java   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextC.java   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextD.java   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/resources/
    camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/
    camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/LICENSE.txt   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/NOTICE.txt   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/beans.xml   (with props)
    camel/trunk/tests/camel-itest-cdi/src/main/resources/log4j.properties   (with props)
    camel/trunk/tests/camel-itest-cdi/src/test/
    camel/trunk/tests/camel-itest-cdi/src/test/java/
    camel/trunk/tests/camel-itest-cdi/src/test/java/org/
    camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/
    camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/
    camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/
    camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/
    camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/IntegrationTest.java   (with props)
Modified:
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Mock.java
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextBean.java
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java
    camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelFactory.java
    camel/trunk/examples/camel-example-cdi/pom.xml
    camel/trunk/parent/pom.xml
    camel/trunk/tests/pom.xml

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Mock.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Mock.java?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Mock.java (original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Mock.java Wed Sep  5 10:53:51 2012
@@ -36,4 +36,10 @@ public @interface Mock {
      */
     @Nonbinding
     String value() default "";
+
+    /**
+     * Returns the name of the CamelContext to use to resolve the endpoint for this URI
+     */
+    @Nonbinding
+    String context() default "";
 }

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java (original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/cdi/Uri.java Wed Sep  5 10:53:51 2012
@@ -49,4 +49,10 @@ public @interface Uri {
      */
     @Nonbinding
     String value();
+
+    /**
+     * Returns the name of the CamelContext to use to resolve the endpoint for this URI
+     */
+    @Nonbinding
+    String context() default "";
 }

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java (original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/BeanAdapter.java Wed Sep  5 10:53:51 2012
@@ -24,6 +24,7 @@ import java.util.List;
 import org.apache.camel.Consume;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Produce;
+import org.apache.camel.cdi.CamelStartup;
 import org.apache.camel.impl.DefaultCamelBeanPostProcessor;
 
 /**
@@ -35,6 +36,11 @@ public class BeanAdapter {
     private final List<Method> endpointMethods = new ArrayList<Method>();
     private final List<Field> produceFields = new ArrayList<Field>();
     private final List<Field> endpointFields = new ArrayList<Field>();
+    private final CamelStartup startup;
+
+    public BeanAdapter(CamelStartup startup) {
+        this.startup = startup;
+    }
 
     /**
      * Returns true if this adapter is empty (i.e. has no custom adapter code)
@@ -70,10 +76,11 @@ public class BeanAdapter {
     public void inject(CamelExtension camelExtension, Object reference,
                                 String beanName) {
         for (Method method : consumeMethods) {
-            Consume consume = method.getAnnotation(Consume.class);
-            if (consume != null) {
+            Consume annotation = method.getAnnotation(Consume.class);
+            if (annotation != null) {
+                String contextName = CamelExtension.getCamelContextName(annotation.context(), startup);
                 DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
-                        consume.context());
+                        contextName);
                 if (postProcessor != null) {
                     postProcessor.getPostProcessorHelper().consumerInjection(method, reference, beanName);
                 }
@@ -82,7 +89,7 @@ public class BeanAdapter {
         for (Method method : produceMethods) {
             Produce annotation = method.getAnnotation(Produce.class);
             if (annotation != null) {
-                String contextName = annotation.context();
+                String contextName = CamelExtension.getCamelContextName(annotation.context(), startup);
                 DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
                         contextName);
                 if (postProcessor != null && postProcessor.getPostProcessorHelper().matchContext(contextName)) {
@@ -94,7 +101,7 @@ public class BeanAdapter {
         for (Method method : endpointMethods) {
             EndpointInject annotation = method.getAnnotation(EndpointInject.class);
             if (annotation != null) {
-                String contextName = annotation.context();
+                String contextName = CamelExtension.getCamelContextName(annotation.context(), startup);
                 DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
                         contextName);
                 if (postProcessor != null && postProcessor.getPostProcessorHelper().matchContext(contextName)) {
@@ -107,7 +114,7 @@ public class BeanAdapter {
         for (Field field : produceFields) {
             Produce annotation = field.getAnnotation(Produce.class);
             if (annotation != null) {
-                String contextName = annotation.context();
+                String contextName = CamelExtension.getCamelContextName(annotation.context(), startup);
                 DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
                         contextName);
                 if (postProcessor != null && postProcessor.getPostProcessorHelper().matchContext(contextName)) {
@@ -118,7 +125,7 @@ public class BeanAdapter {
         }
         for (Field field : endpointFields) {
             EndpointInject annotation = field.getAnnotation(EndpointInject.class);
-            String contextName = annotation.context();
+            String contextName = CamelExtension.getCamelContextName(annotation.context(), startup);
             DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
                     contextName);
             if (postProcessor != null && postProcessor.getPostProcessorHelper().matchContext(contextName)) {
@@ -127,4 +134,5 @@ public class BeanAdapter {
             }
         }
     }
+
 }

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextBean.java?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextBean.java (original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextBean.java Wed Sep  5 10:53:51 2012
@@ -23,7 +23,6 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
@@ -67,6 +66,9 @@ public class CamelContextBean implements
     @Override
     public CdiCamelContext create(CreationalContext<CdiCamelContext> context) {
         CdiCamelContext camelContext = target.produce(context);
+        if (ObjectHelper.isNotEmpty(camelContextName)) {
+            camelContext.setName(camelContextName);
+        }
         target.postConstruct(camelContext);
         context.push(camelContext);
         return camelContext;
@@ -128,10 +130,7 @@ public class CamelContextBean implements
         return camelContextName;
     }
 
-    protected void configureCamelContext(CdiCamelContext camelContext) {
-        if (ObjectHelper.isNotEmpty(camelContextName)) {
-            camelContext.setName(camelContextName);
-        }
+    public void configureCamelContext(CdiCamelContext camelContext) {
         for (Bean<?> bean : routeBuilderBeans) {
             CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
             RouteBuilder routeBuilder = (RouteBuilder)beanManager.getReference(bean, RouteBuilder.class, creationalContext);
@@ -142,11 +141,4 @@ public class CamelContextBean implements
             }
         }
     }
-
-    public CdiCamelContext configure() {
-        CreationalContext<CdiCamelContext> creationalContext = beanManager.createCreationalContext(this);
-        CdiCamelContext cdiCamelContext = create(creationalContext);
-        configureCamelContext(cdiCamelContext);
-        return cdiCamelContext;
-    }
 }

Added: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextMap.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextMap.java?rev=1381135&view=auto
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextMap.java (added)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextMap.java Wed Sep  5 10:53:51 2012
@@ -0,0 +1,82 @@
+/**
+ *
+ * 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.component.cdi.internal;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * A helper class to be able to resolve CamelContext instances by their name
+ */
+@ApplicationScoped
+public class CamelContextMap {
+    @Inject
+    private Instance<CamelContext> camelContexts;
+
+    private Map<String, CamelContext> camelContextMap = new HashMap<String, CamelContext>();
+
+    @PostConstruct
+    public void start() {
+        ObjectHelper.notNull(camelContexts, "camelContexts");
+
+        Iterator<CamelContext> iterator = camelContexts.iterator();
+        while (iterator.hasNext()) {
+            CamelContext camelContext = iterator.next();
+            camelContextMap.put(camelContext.getName(), camelContext);
+        }
+    }
+
+    /**
+     * Returns the {@link CamelContext} for the given context name
+     */
+    public CamelContext getCamelContext(String name) {
+        CamelContext answer = camelContextMap.get(name);
+        if (answer == null && ObjectHelper.isEmpty(name)) {
+            // lets return the first one for the default context?
+            Collection<CamelContext> values = camelContextMap.values();
+            for (CamelContext value : values) {
+                answer = value;
+                break;
+            }
+        }
+        return answer;
+
+    }
+
+    /**
+     * Returns the CamelContext for the given name or throw an exception
+     */
+    public CamelContext getMandatoryCamelContext(String contextName) {
+        CamelContext camelContext = getCamelContext(contextName);
+        ObjectHelper.notNull(camelContext, "No CamelContext found for name '" + contextName + "' when available names are " + camelContextMap.keySet());
+        return camelContext;
+    }
+
+    public Map<String, CamelContext> getCamelContextMap() {
+        return camelContextMap;
+    }
+}

Propchange: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelContextMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java (original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelExtension.java Wed Sep  5 10:53:51 2012
@@ -20,6 +20,7 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -46,6 +47,7 @@ import org.apache.camel.builder.RouteBui
 import org.apache.camel.cdi.CamelStartup;
 import org.apache.camel.component.cdi.CdiCamelContext;
 import org.apache.camel.impl.DefaultCamelBeanPostProcessor;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ReflectionHelper;
 import org.apache.deltaspike.core.api.provider.BeanProvider;
 import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
@@ -55,15 +57,26 @@ import org.apache.deltaspike.core.util.m
  */
 public class CamelExtension implements Extension {
 
-    private Map<Bean<?>, BeanAdapter> eagerBeans = new HashMap<Bean<?>, BeanAdapter>();
+    CamelContextMap camelContextMap;
+
+    private Set<Bean<?>> eagerBeans = new HashSet<Bean<?>>();
     private Map<String, List<Bean<?>>> namedCamelContexts = new HashMap<String, List<Bean<?>>>();
     private List<CamelContextBean> camelContextBeans = new ArrayList<CamelContextBean>();
-    private Map<String, CamelContext> camelContexts = new HashMap<String, CamelContext>();
 
     public CamelExtension() {
     }
 
     /**
+     * If no context name is specified then default it to the value from the {@link org.apache.camel.cdi.CamelStartup} annotation
+     */
+    public static String getCamelContextName(String context, CamelStartup annotation) {
+        if (ObjectHelper.isEmpty(context) && annotation != null) {
+            return annotation.contextName();
+        }
+        return context;
+    }
+
+    /**
      * Process camel context aware bean definitions.
      *
      * @param process Annotated type.
@@ -127,7 +140,7 @@ public class CamelExtension implements E
             public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
                 Consume consume = method.getAnnotation(Consume.class);
                 if (consume != null) {
-                    eagerlyCreate(bean);
+                    eagerBeans.add(bean);
                 }
             }
         });
@@ -151,22 +164,19 @@ public class CamelExtension implements E
      * Lets force the CDI container to create all beans annotated with @Consume so that the consumer becomes active
      */
     public void startConsumeBeans(@Observes AfterDeploymentValidation event, BeanManager beanManager) throws Exception {
-        if (camelContextBeans.isEmpty()) {
-            CamelContext camelContext = BeanProvider.getContextualReference(CamelContext.class);
-            camelContexts.put("", camelContext);
-        }
-        for (CamelContextBean camelContextBean : camelContextBeans) {
-            CdiCamelContext context = camelContextBean.configure();
-            camelContexts.put(camelContextBean.getCamelContextName(), context);
+        for (CamelContextBean bean : camelContextBeans) {
+            String name = bean.getCamelContextName();
+            CamelContext context = getCamelContext(name);
+            if (context == null) {
+                throw new IllegalStateException("CamelContext '" + name + "' has not been injected into the CamelContextMap");
+            }
+            bean.configureCamelContext((CdiCamelContext)context);
         }
 
-        Set<Map.Entry<Bean<?>, BeanAdapter>> entries = eagerBeans.entrySet();
-        for (Map.Entry<Bean<?>, BeanAdapter> entry : entries) {
-            Bean<?> bean = entry.getKey();
+        for (Bean<?> bean : eagerBeans) {
+            // force lazy creation to start the consumer
             CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
-
-            // force lazy creation
-            beanManager.getReference(bean, Object.class, creationalContext);
+            beanManager.getReference(bean, bean.getBeanClass(), creationalContext);
         }
     }
 
@@ -177,10 +187,12 @@ public class CamelExtension implements E
     @SuppressWarnings("unchecked")
     public void onInjectionTarget(@Observes ProcessInjectionTarget event) {
         final InjectionTarget injectionTarget = event.getInjectionTarget();
-        final Class beanClass = event.getAnnotatedType().getJavaClass();
+        AnnotatedType annotatedType = event.getAnnotatedType();
+        final Class beanClass = annotatedType.getJavaClass();
         // TODO this is a bit of a hack - what should the bean name be?
-        final String beanName = event.getInjectionTarget().toString();
-        final BeanAdapter adapter = createBeanAdapter(beanClass);
+        final String beanName = injectionTarget.toString();
+        CamelStartup camelStartup = annotatedType.getAnnotation(CamelStartup.class);
+        final BeanAdapter adapter = createBeanAdapter(beanClass, camelStartup);
         if (!adapter.isEmpty()) {
             DelegateInjectionTarget newTarget = new DelegateInjectionTarget(injectionTarget) {
 
@@ -203,7 +215,9 @@ public class CamelExtension implements E
      * of @Produce / @EndpointInject and processing of the @Consume annotations are not performed.
      */
     public void inject(Object bean) {
-        final BeanAdapter adapter = createBeanAdapter(bean.getClass());
+        Class<?> beanClass = bean.getClass();
+        CamelStartup camelStartup = beanClass.getAnnotation(CamelStartup.class);
+        final BeanAdapter adapter = createBeanAdapter(beanClass, camelStartup);
         if (!adapter.isEmpty()) {
             // TODO this is a bit of a hack - what should the bean name be?
             final String beanName = bean.toString();
@@ -211,8 +225,8 @@ public class CamelExtension implements E
         }
     }
 
-    private BeanAdapter createBeanAdapter(Class beanClass) {
-        final BeanAdapter adapter = new BeanAdapter();
+    private BeanAdapter createBeanAdapter(Class beanClass, CamelStartup camelStartup) {
+        final BeanAdapter adapter = new BeanAdapter(camelStartup);
         ReflectionHelper.doWithFields(beanClass, new ReflectionHelper.FieldCallback() {
             @Override
             public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
@@ -247,7 +261,7 @@ public class CamelExtension implements E
     }
 
     protected DefaultCamelBeanPostProcessor getPostProcessor(String context) {
-        CamelContext camelContext = camelContexts.get(context);
+        CamelContext camelContext = getCamelContext(context);
         if (camelContext != null) {
             return new DefaultCamelBeanPostProcessor(camelContext);
         } else {
@@ -255,13 +269,12 @@ public class CamelExtension implements E
         }
     }
 
-    protected BeanAdapter eagerlyCreate(Bean<?> bean) {
-        BeanAdapter beanAdapter = eagerBeans.get(bean);
-        if (beanAdapter == null) {
-            beanAdapter = new BeanAdapter();
-            eagerBeans.put(bean, beanAdapter);
+    protected CamelContext getCamelContext(String context) {
+        if (camelContextMap == null) {
+            camelContextMap = BeanProvider.getContextualReference(CamelContextMap.class);
+            ObjectHelper.notNull(camelContextMap, "Could not resolve CamelContextMap");
         }
-        return beanAdapter;
+        return camelContextMap.getCamelContext(context);
     }
 
     /**

Modified: camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelFactory.java?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelFactory.java (original)
+++ camel/trunk/components/camel-cdi/src/main/java/org/apache/camel/component/cdi/internal/CamelFactory.java Wed Sep  5 10:53:51 2012
@@ -18,13 +18,14 @@ package org.apache.camel.component.cdi.i
 
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.inject.Inject;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.ProducerTemplate;
+import org.apache.camel.cdi.CamelStartup;
 import org.apache.camel.cdi.Mock;
 import org.apache.camel.cdi.Uri;
 import org.apache.camel.component.mock.MockEndpoint;
@@ -35,8 +36,7 @@ import org.apache.camel.util.ObjectHelpe
  * produces {@link Endpoint} and {@link org.apache.camel.ProducerTemplate} instances for injection into beans
  */
 public class CamelFactory {
-    @Inject
-    private CamelContext camelContext;
+    @Inject CamelContextMap camelContextMap;
 
     @Produces
     @Mock
@@ -47,27 +47,40 @@ public class CamelFactory {
         if (ObjectHelper.isEmpty(uri)) {
             uri = "mock:" + point.getMember().getName();
         }
-        return CamelContextHelper.getMandatoryEndpoint(camelContext, uri, MockEndpoint.class);
+        return CamelContextHelper.getMandatoryEndpoint(getCamelContext(point, annotation.context()), uri, MockEndpoint.class);
     }
 
     @Produces
     @Uri("")
-    public Endpoint createEndpoint(InjectionPoint point, BeanManager beanManager) {
+    public Endpoint createEndpoint(InjectionPoint point) {
         Annotated annotated = point.getAnnotated();
         Uri uri = annotated.getAnnotation(Uri.class);
         ObjectHelper.notNull(uri, "Should be annotated with @Uri");
-        return CamelContextHelper.getMandatoryEndpoint(camelContext, uri.value());
+        return CamelContextHelper.getMandatoryEndpoint(getCamelContext(point, uri.context()), uri.value());
     }
 
     @Produces
     @Uri("")
     public ProducerTemplate createProducerTemplate(InjectionPoint point) {
-        ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
         Annotated annotated = point.getAnnotated();
         Uri uri = annotated.getAnnotation(Uri.class);
+        CamelContext camelContext = getCamelContext(point, uri.context());
+        ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
         ObjectHelper.notNull(uri, "Should be annotated with @Uri");
         Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(camelContext, uri.value());
         producerTemplate.setDefaultEndpoint(endpoint);
         return producerTemplate;
     }
+
+    protected CamelContext getCamelContext(InjectionPoint point, String contextName) {
+        CamelStartup startup = point.getAnnotated().getAnnotation(CamelStartup.class);
+        if (startup == null) {
+            Bean<?> bean = point.getBean();
+            if (bean != null) {
+                startup = bean.getBeanClass().getAnnotation(CamelStartup.class);
+            }
+        }
+        String name = CamelExtension.getCamelContextName(contextName, startup);
+        return camelContextMap.getMandatoryCamelContext(name);
+    }
 }

Modified: camel/trunk/examples/camel-example-cdi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cdi/pom.xml?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-cdi/pom.xml (original)
+++ camel/trunk/examples/camel-example-cdi/pom.xml Wed Sep  5 10:53:51 2012
@@ -125,20 +125,20 @@
                 <dependency>
                     <groupId>org.jboss.spec</groupId>
                     <artifactId>jboss-javaee-6.0</artifactId>
-                    <version>1.0.0.Final</version>
+                    <version>${jboss-javaee-6-version}</version>
                     <type>pom</type>
                     <scope>provided</scope>
                 </dependency>
                 <dependency>
                     <groupId>org.jboss.arquillian.container</groupId>
                     <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
-                    <version>1.0.0.CR3</version>
+                    <version>${arquillian-weld-ee-embedded-version}</version>
                     <scope>test</scope>
                 </dependency>
                 <dependency>
                     <groupId>org.jboss.weld</groupId>
                     <artifactId>weld-core</artifactId>
-                    <version>1.1.5.Final</version>
+                  <version>${weld-version}</version>
                     <scope>test</scope>
                 </dependency>
             </dependencies>

Modified: camel/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/parent/pom.xml (original)
+++ camel/trunk/parent/pom.xml Wed Sep  5 10:53:51 2012
@@ -41,6 +41,7 @@
     <apacheds-version>1.5.7</apacheds-version>
     <apache-mime4j-version>0.7.2</apache-mime4j-version>
     <aries-blueprint-version>0.3</aries-blueprint-version>
+    <arquillian-weld-ee-embedded-version>1.0.0.CR3</arquillian-weld-ee-embedded-version>
     <asm-bundle-version>3.3_2</asm-bundle-version>
     <atomikos-transactions-version>3.8.0</atomikos-transactions-version>
     <avro-version>1.6.2</avro-version>
@@ -121,6 +122,7 @@
     <javassist-bundle-version>3.12.1.GA_2</javassist-bundle-version>
     <javax-mail-version>1.4.5</javax-mail-version>
     <jaxen-version>1.1.4</jaxen-version>
+    <jboss-javaee-6-version>1.0.0.Final</jboss-javaee-6-version>
     <jclouds-version>1.4.0</jclouds-version>
     <jclouds-feature-version>1.4.0</jclouds-feature-version>
     <jdom-version>1.1.3</jdom-version>

Added: camel/trunk/tests/camel-itest-cdi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/pom.xml?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/pom.xml (added)
+++ camel/trunk/tests/camel-itest-cdi/pom.xml Wed Sep  5 10:53:51 2012
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements. See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version
+    2.0 (the "License"); you may not use this file except in compliance
+    with the License. You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+    applicable law or agreed to in writing, software distributed under the
+    License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+    CONDITIONS OF ANY KIND, either express or implied. See the License for
+    the specific language governing permissions and limitations under the
+    License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>2.11-SNAPSHOT</version>
+        <relativePath>../../parent</relativePath>
+    </parent>
+
+    <artifactId>camel-itest-cdi</artifactId>
+    <name>Camel :: Integration Tests :: CDI</name>
+    <description>Tests for camel-cdi</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-cdi</artifactId>
+        </dependency>
+
+        <!-- logging -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+
+        <!-- for testing -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit-version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.junit</groupId>
+            <artifactId>arquillian-junit-container</artifactId>
+            <version>1.0.0.CR7</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <profiles>
+        <profile>
+            <id>arquillian-weld-ee-embedded</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.jboss.spec</groupId>
+                    <artifactId>jboss-javaee-6.0</artifactId>
+                    <version>${jboss-javaee-6-version}</version>
+                    <type>pom</type>
+                    <scope>provided</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.jboss.arquillian.container</groupId>
+                    <artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
+                    <version>${arquillian-weld-ee-embedded-version}</version>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>org.jboss.weld</groupId>
+                    <artifactId>weld-core</artifactId>
+                    <version>${weld-version}</version>
+                    <scope>test</scope>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+</project>

Propchange: camel/trunk/tests/camel-itest-cdi/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/data/message1.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/data/message1.xml?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/data/message1.xml (added)
+++ camel/trunk/tests/camel-itest-cdi/src/data/message1.xml Wed Sep  5 10:53:51 2012
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<person user="james">
+  <firstName>James</firstName>
+  <lastName>Strachan</lastName>
+  <city>London</city>
+</person>
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest-cdi/src/data/message1.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/data/message2.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/data/message2.xml?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/data/message2.xml (added)
+++ camel/trunk/tests/camel-itest-cdi/src/data/message2.xml Wed Sep  5 10:53:51 2012
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<person user="hiram">
+  <firstName>Hiram</firstName>
+  <lastName>Chirino</lastName>
+  <city>Tampa</city>
+</person>
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest-cdi/src/data/message2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Constants.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Constants.java?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Constants.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Constants.java Wed Sep  5 10:53:51 2012
@@ -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.itest.cdi;
+
+public class Constants {
+    public static Object[] EXPECTED_BODIES_A = {"messageA1", "messageA2"};
+    public static Object[] EXPECTED_BODIES_B = {"messageB1", "messageB2"};
+    public static Object[] EXPECTED_BODIES_C = {"messageC1", "messageC2"};
+    public static Object[] EXPECTED_BODIES_D = {"messageD1", "messageD2"};
+}

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextA.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextA.java?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextA.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextA.java Wed Sep  5 10:53:51 2012
@@ -0,0 +1,60 @@
+/**
+ *
+ * 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.itest.cdi;
+
+import javax.inject.Inject;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.cdi.CamelStartup;
+import org.apache.camel.cdi.Uri;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Uses contextA with explicit context names on all Camel annotations
+ */
+@CamelStartup(contextName = "contextA")
+public class RoutesContextA extends RouteBuilder {
+    private static final transient Logger LOG = LoggerFactory.getLogger(RoutesContextA.class);
+
+    @Inject @Uri(value = "seda:A.a", context = "contextA")
+    Endpoint a;
+
+    @EndpointInject(uri = "mock:A.b", context = "contextA")
+    public MockEndpoint b;
+
+    @Override
+    public void configure() throws Exception {
+        System.out.println("Adding route from " + a + " to " + b);
+        from(a).to(b);
+    }
+
+    @Inject @Uri(value = "seda:A.a", context = "contextA")
+    ProducerTemplate producer;
+
+    public void sendMessages() {
+        for (Object expectedBody : Constants.EXPECTED_BODIES_A) {
+            LOG.info("Sending " + expectedBody + " to " + producer.getDefaultEndpoint());
+            producer.sendBody(expectedBody);
+        }
+    }
+}

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextA.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextB.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextB.java?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextB.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextB.java Wed Sep  5 10:53:51 2012
@@ -0,0 +1,60 @@
+/**
+ *
+ * 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.itest.cdi;
+
+import javax.inject.Inject;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.cdi.CamelStartup;
+import org.apache.camel.cdi.Uri;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Uses contextB with explicit context names on all Camel annotations
+ */
+@CamelStartup(contextName = "contextB")
+public class RoutesContextB extends RouteBuilder {
+    private static final transient Logger LOG = LoggerFactory.getLogger(RoutesContextB.class);
+
+    @Inject @Uri(value = "seda:B.a", context = "contextB")
+    Endpoint a;
+
+    @EndpointInject(uri = "mock:B.b", context = "contextB")
+    public MockEndpoint b;
+
+    @Override
+    public void configure() throws Exception {
+        System.out.println("Adding route from " + a + " to " + b);
+        from(a).to(b);
+    }
+
+    @Inject @Uri(value = "seda:B.a", context = "contextB")
+    ProducerTemplate producer;
+
+    public void sendMessages() {
+        for (Object expectedBody : Constants.EXPECTED_BODIES_B) {
+            LOG.info("Sending " + expectedBody + " to " + producer.getDefaultEndpoint());
+            producer.sendBody(expectedBody);
+        }
+    }
+}

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextB.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextC.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextC.java?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextC.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextC.java Wed Sep  5 10:53:51 2012
@@ -0,0 +1,60 @@
+/**
+ *
+ * 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.itest.cdi;
+
+import javax.inject.Inject;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.cdi.CamelStartup;
+import org.apache.camel.cdi.Uri;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Uses contextC implicitly using that context for all injection points without
+ * having to mention them on each camel annotation
+ */
+@CamelStartup(contextName = "contextC")
+public class RoutesContextC extends RouteBuilder {
+    private static final transient Logger LOG = LoggerFactory.getLogger(RoutesContextC.class);
+
+    @Inject @Uri("seda:C.a")
+    Endpoint a;
+
+    @EndpointInject(uri = "mock:C.b")
+    MockEndpoint b;
+
+    @Override
+    public void configure() throws Exception {
+        from(a).to(b);
+    }
+
+    @Inject @Uri("seda:C.a")
+    ProducerTemplate producer;
+
+    public void sendMessages() {
+        for (Object expectedBody : Constants.EXPECTED_BODIES_C) {
+            LOG.info("Sending " + expectedBody + " to " + producer.getDefaultEndpoint());
+            producer.sendBody(expectedBody);
+        }
+    }
+}

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextC.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextD.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextD.java?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextD.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextD.java Wed Sep  5 10:53:51 2012
@@ -0,0 +1,60 @@
+/**
+ *
+ * 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.itest.cdi;
+
+import javax.inject.Inject;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.cdi.CamelStartup;
+import org.apache.camel.cdi.Uri;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Uses contextD implicitly using that context for all injection points without
+ * having to mention them on each camel annotation
+ */
+@CamelStartup(contextName = "contextD")
+public class RoutesContextD extends RouteBuilder {
+    private static final transient Logger LOG = LoggerFactory.getLogger(RoutesContextD.class);
+
+    @Inject @Uri("seda:D.a")
+    Endpoint a;
+
+    @EndpointInject(uri = "mock:D.b")
+    MockEndpoint b;
+
+    @Override
+    public void configure() throws Exception {
+        from(a).to(b);
+    }
+
+    @Inject @Uri("seda:D.a")
+    ProducerTemplate producer;
+
+    public void sendMessages() {
+        for (Object expectedBody : Constants.EXPECTED_BODIES_D) {
+            LOG.info("Sending " + expectedBody + " to " + producer.getDefaultEndpoint());
+            producer.sendBody(expectedBody);
+        }
+    }
+}

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/java/org/apache/camel/itest/cdi/RoutesContextD.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/LICENSE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/LICENSE.txt?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/LICENSE.txt (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/LICENSE.txt Wed Sep  5 10:53:51 2012
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/NOTICE.txt
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/NOTICE.txt?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/NOTICE.txt (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/NOTICE.txt Wed Sep  5 10:53:51 2012
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/beans.xml?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/beans.xml (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/beans.xml Wed Sep  5 10:53:51 2012
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<beans/>
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/resources/META-INF/beans.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/main/resources/log4j.properties?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/main/resources/log4j.properties (added)
+++ camel/trunk/tests/camel-itest-cdi/src/main/resources/log4j.properties Wed Sep  5 10:53:51 2012
@@ -0,0 +1,30 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, stdout
+
+# uncomment the next line to debug Camel
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer
\ No newline at end of file

Propchange: camel/trunk/tests/camel-itest-cdi/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/IntegrationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/IntegrationTest.java?rev=1381135&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/IntegrationTest.java (added)
+++ camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/IntegrationTest.java Wed Sep  5 10:53:51 2012
@@ -0,0 +1,121 @@
+/**
+ * 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.itest.cdi;
+
+import java.util.Map;
+import java.util.Set;
+import javax.inject.Inject;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.component.cdi.internal.CamelContextMap;
+import org.apache.camel.component.cdi.internal.CamelExtension;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(Arquillian.class)
+public class IntegrationTest {
+    private static final transient Logger LOG = LoggerFactory.getLogger(IntegrationTest.class);
+
+    @Inject
+    CamelContextMap camelContextMap;
+    @Inject
+    RoutesContextA routesA;
+    @Inject
+    RoutesContextB routesB;
+    @Inject
+    RoutesContextC routesC;
+    @Inject
+    RoutesContextD routesD;
+
+    @Test
+    public void checkContextsHaveCorrectEndpointsAndRoutes() throws Exception {
+        Set<Map.Entry<String,CamelContext>> entries = camelContextMap.getCamelContextMap().entrySet();
+        for (Map.Entry<String, CamelContext> entry : entries) {
+            LOG.info("CamelContext " + entry.getKey() + " has endpoints: " + entry.getValue().getEndpointMap()
+                    .keySet());
+        }
+
+        CamelContext contextA = assertCamelContext("contextA");
+        assertHasEndpoints(contextA, "seda://A.a", "mock://A.b");
+
+        MockEndpoint mockEndpoint = routesA.b;
+        mockEndpoint.expectedBodiesReceived(Constants.EXPECTED_BODIES_A);
+        routesA.sendMessages();
+        mockEndpoint.assertIsSatisfied();
+
+        CamelContext contextB = assertCamelContext("contextB");
+        assertHasEndpoints(contextB, "seda://B.a", "mock://B.b");
+
+        MockEndpoint mockEndpointB = routesB.b;
+        mockEndpointB.expectedBodiesReceived(Constants.EXPECTED_BODIES_B);
+        routesB.sendMessages();
+        mockEndpointB.assertIsSatisfied();
+
+        CamelContext contextC = assertCamelContext("contextC");
+        assertHasEndpoints(contextC, "seda://C.a", "mock://C.b");
+
+        MockEndpoint mockEndpointC = routesC.b;
+        mockEndpointC.expectedBodiesReceived(Constants.EXPECTED_BODIES_C);
+        routesC.sendMessages();
+        mockEndpointC.assertIsSatisfied();
+
+        CamelContext contextD = assertCamelContext("contextD");
+        assertHasEndpoints(contextD, "seda://D.a", "mock://D.b");
+
+        MockEndpoint mockEndpointD = routesD.b;
+        mockEndpointD.expectedBodiesReceived(Constants.EXPECTED_BODIES_D);
+        routesD.sendMessages();
+        mockEndpointD.assertIsSatisfied();
+    }
+
+    public static void assertHasEndpoints(CamelContext context, String... uris) {
+        Map<String, Endpoint> endpointMap = context.getEndpointMap();
+        for (String uri : uris) {
+            Endpoint endpoint = endpointMap.get(uri);
+            assertNotNull(
+                    "CamelContext " + context + " does not have an Endpoint with URI " + uri + " but has "
+                            + endpointMap.keySet(), endpoint);
+        }
+    }
+
+    protected CamelContext assertCamelContext(String contextName) {
+        assertNotNull("camelContextMap not injected!", camelContextMap);
+        CamelContext answer = camelContextMap.getMandatoryCamelContext(contextName);
+        assertTrue("CamelContext '" + contextName + "' is not started", answer.getStatus().isStarted());
+        return answer;
+    }
+
+    @Deployment
+    public static JavaArchive createDeployment() {
+        return ShrinkWrap.create(JavaArchive.class)
+                .addPackage(CamelExtension.class.getPackage())
+                .addPackage(RoutesContextA.class.getPackage())
+                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+    }
+}

Propchange: camel/trunk/tests/camel-itest-cdi/src/test/java/org/apache/camel/itest/cdi/IntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/tests/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/pom.xml?rev=1381135&r1=1381134&r2=1381135&view=diff
==============================================================================
--- camel/trunk/tests/pom.xml (original)
+++ camel/trunk/tests/pom.xml Wed Sep  5 10:53:51 2012
@@ -35,6 +35,7 @@
     <module>test-bundles</module>
     <module>camel-itest-standalone</module>
     <module>camel-itest</module>
+    <module>camel-itest-cdi</module>
     <module>camel-partial-classpath-test</module>
     <module>camel-typeconverterscan-test</module>
     <module>camel-itest-performance</module>



Mime
View raw message