You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/01/15 14:44:17 UTC
[9/9] camel git commit: CAMEL-9201: Improved Camel CDI component
CAMEL-9201: Improved Camel CDI component
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0421c24d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0421c24d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0421c24d
Branch: refs/heads/master
Commit: 0421c24dfcf992f3296ed746469771e3800200e3
Parents: d3d75d2
Author: Antonin Stefanutti <an...@stefanutti.fr>
Authored: Mon Aug 3 17:54:34 2015 +0200
Committer: Antonin Stefanutti <an...@stefanutti.fr>
Committed: Fri Jan 15 14:04:26 2016 +0100
----------------------------------------------------------------------
components/camel-cdi/pom.xml | 320 ++++++++++++++---
.../org/apache/camel/cdi/AnnotatedDelegate.java | 85 +++++
.../camel/cdi/AnnotatedMemberDelegate.java | 48 +++
.../camel/cdi/AnnotatedMethodDelegate.java | 44 +++
.../apache/camel/cdi/AnnotatedTypeDelegate.java | 59 ++++
.../org/apache/camel/cdi/AnnotatedWrapper.java | 84 +++++
.../java/org/apache/camel/cdi/AnyLiteral.java | 31 ++
.../java/org/apache/camel/cdi/BeanDelegate.java | 92 +++++
.../org/apache/camel/cdi/BeanManagerHelper.java | 58 ++++
.../camel/cdi/CamelBeanInjectionTarget.java | 47 +++
.../camel/cdi/CamelContextDefaultProducer.java | 57 ++++
.../camel/cdi/CamelContextInjectionTarget.java | 35 ++
.../camel/cdi/CamelContextOsgiProducer.java | 62 ++++
.../apache/camel/cdi/CamelContextProducer.java | 129 +++++++
.../apache/camel/cdi/CdiBeanManagerHelper.java | 73 ----
.../org/apache/camel/cdi/CdiBeanRegistry.java | 119 -------
.../camel/cdi/CdiCamelBeanPostProcessor.java | 120 +++++++
.../org/apache/camel/cdi/CdiCamelContext.java | 80 +----
.../apache/camel/cdi/CdiCamelContextBean.java | 120 +++++++
.../camel/cdi/CdiCamelContextNameStrategy.java | 45 +++
.../apache/camel/cdi/CdiCamelEnvironment.java | 66 ++++
.../org/apache/camel/cdi/CdiCamelExtension.java | 328 ++++++++++++++++++
.../org/apache/camel/cdi/CdiCamelFactory.java | 211 ++++++++++++
.../org/apache/camel/cdi/CdiCamelInjector.java | 48 +++
.../org/apache/camel/cdi/CdiCamelRegistry.java | 98 ++++++
.../org/apache/camel/cdi/CdiEventComponent.java | 53 +++
.../org/apache/camel/cdi/CdiEventConsumer.java | 71 ++++
.../org/apache/camel/cdi/CdiEventEndpoint.java | 127 +++++++
.../org/apache/camel/cdi/CdiEventNotifier.java | 47 +++
.../org/apache/camel/cdi/CdiEventProducer.java | 47 +++
.../java/org/apache/camel/cdi/CdiInjector.java | 62 ----
.../java/org/apache/camel/cdi/CdiSpiHelper.java | 143 ++++++++
.../camel/cdi/CdiTypeConverterLoader.java | 33 ++
.../java/org/apache/camel/cdi/ContextName.java | 131 ++++---
.../org/apache/camel/cdi/DefaultLiteral.java | 31 ++
.../camel/cdi/DelegateInjectionTarget.java | 51 +++
.../org/apache/camel/cdi/DelegateProducer.java | 51 +++
.../java/org/apache/camel/cdi/Excluded.java | 40 +++
.../camel/cdi/ForwardingObserverMethod.java | 78 +++++
.../main/java/org/apache/camel/cdi/Main.java | 65 ++--
.../main/java/org/apache/camel/cdi/Mock.java | 14 +-
.../java/org/apache/camel/cdi/RoutesXml.java | 2 +-
.../src/main/java/org/apache/camel/cdi/Uri.java | 43 +--
.../main/java/org/apache/camel/cdi/Vetoed.java | 32 ++
.../properties/CdiPropertiesComponent.java | 33 --
.../properties/CdiPropertiesParser.java | 47 ---
.../apache/camel/cdi/internal/BeanAdapter.java | 133 --------
.../camel/cdi/internal/CamelContextBean.java | 138 --------
.../camel/cdi/internal/CamelContextConfig.java | 89 -----
.../camel/cdi/internal/CamelContextMap.java | 82 -----
.../camel/cdi/internal/CamelExtension.java | 342 -------------------
.../apache/camel/cdi/internal/CamelFactory.java | 86 -----
.../cdi/internal/DelegateInjectionTarget.java | 63 ----
.../src/main/resources/META-INF/LICENSE.txt | 203 -----------
.../src/main/resources/META-INF/NOTICE.txt | 11 -
.../src/main/resources/META-INF/beans.xml | 32 +-
.../javax.enterprise.inject.spi.Extension | 3 +-
.../apache/camel/cdi/CamelContextAwareTest.java | 38 ---
.../camel/cdi/CamelEndpointInjectTest.java | 46 ---
.../apache/camel/cdi/CamelExtensionTest.java | 39 ---
.../apache/camel/cdi/CdiContextTestSupport.java | 79 -----
.../org/apache/camel/cdi/CdiTestSupport.java | 62 ----
.../camel/cdi/ConsumeStubbedEndpointTest.java | 55 ---
.../java/org/apache/camel/cdi/ConsumeTest.java | 54 ---
.../EndpointDefinedUsingConfigPropertyTest.java | 79 -----
.../apache/camel/cdi/EndpointInjectTest.java | 43 ---
.../camel/cdi/EndpointNamedInjectTest.java | 39 ---
.../camel/cdi/EndpointPropertyInjectTest.java | 43 ---
.../apache/camel/cdi/EndpointUriInjectTest.java | 47 ---
.../camel/cdi/InjectCamelAnnotationsTest.java | 78 -----
.../camel/cdi/MockEndpointInjectTest.java | 45 ---
.../org/apache/camel/cdi/ProduceInjectTest.java | 45 ---
.../cdi/RegistryLookupAndInjectorTest.java | 94 -----
.../camel/cdi/XmlRoutesFromClassPathTest.java | 60 ----
.../apache/camel/cdi/XmlRoutesFromURLTest.java | 44 ---
.../apache/camel/cdi/bean/BeanInjectBean.java | 47 +++
.../camel/cdi/bean/CamelContextAwareBean.java | 38 +++
.../cdi/bean/CamelContextProducerMethod.java | 40 +++
.../camel/cdi/bean/ConsumeMethodBean.java | 38 +++
.../cdi/bean/CustomLifecycleCamelContext.java | 52 +++
.../cdi/bean/CustomPropertiesCamelContext.java | 32 ++
.../camel/cdi/bean/DefaultCamelContextBean.java | 28 ++
.../camel/cdi/bean/EndpointInjectRoute.java | 35 ++
.../bean/EndpointInjectWrongContextRoute.java | 36 ++
.../camel/cdi/bean/EventConsumingRoute.java | 65 ++++
.../cdi/bean/EventConsumingRouteCdi10.java | 66 ++++
.../camel/cdi/bean/EventProducingRoute.java | 65 ++++
.../cdi/bean/EventProducingRouteCdi10.java | 66 ++++
.../camel/cdi/bean/FirstCamelContextBean.java | 28 ++
.../FirstCamelContextEndpointInjectRoute.java | 34 ++
.../FirstCamelContextEventConsumingRoute.java | 38 +++
.../FirstCamelContextEventProducingRoute.java | 38 +++
.../FirstCamelContextProduceTemplateBean.java | 30 ++
.../FirstCamelContextPropertyInjectBean.java | 38 +++
.../camel/cdi/bean/FirstCamelContextRoute.java | 29 ++
.../cdi/bean/FirstNamedCamelContextBean.java | 29 ++
.../cdi/bean/FirstNamedCamelContextRoute.java | 29 ++
.../camel/cdi/bean/InjectedEndpointRoute.java | 35 ++
.../cdi/bean/InjectedTypeConverterRoute.java | 28 ++
.../apache/camel/cdi/bean/ManualCamelRoute.java | 29 ++
.../cdi/bean/ManualStartupCamelContext.java | 37 ++
.../camel/cdi/bean/MockAnnotationRoute.java | 41 +++
.../apache/camel/cdi/bean/NamedCamelBean.java | 27 ++
.../camel/cdi/bean/ProduceTemplateBean.java | 30 ++
.../camel/cdi/bean/PropertyEndpointRoute.java | 30 ++
.../camel/cdi/bean/PropertyInjectBean.java | 38 +++
.../camel/cdi/bean/RecipientListMethodBean.java | 34 ++
.../camel/cdi/bean/SecondCamelContextBean.java | 33 ++
.../SecondCamelContextEndpointInjectRoute.java | 34 ++
.../SecondCamelContextEventConsumingRoute.java | 38 +++
.../SecondCamelContextEventProducingRoute.java | 38 +++
.../SecondCamelContextProduceTemplateBean.java | 30 ++
.../SecondCamelContextPropertyInjectBean.java | 38 +++
.../cdi/bean/SecondNamedCamelContextBean.java | 29 ++
.../cdi/bean/SecondNamedCamelContextRoute.java | 29 ++
.../apache/camel/cdi/bean/SimpleCamelRoute.java | 40 +++
.../apache/camel/cdi/bean/UriEndpointRoute.java | 30 ++
.../properties/PropertiesComponentTest.java | 53 ---
.../cdi/converter/InjectedTypeConverter.java | 42 +++
.../cdi/expression/ExchangeExpression.java | 37 ++
.../org/apache/camel/cdi/pojo/EventPayload.java | 47 +++
.../camel/cdi/pojo/EventPayloadInteger.java | 24 ++
.../camel/cdi/pojo/EventPayloadString.java | 24 ++
.../camel/cdi/pojo/TypeConverterInput.java | 30 ++
.../camel/cdi/pojo/TypeConverterOutput.java | 30 ++
.../camel/cdi/qualifier/BarQualifier.java | 38 +++
.../camel/cdi/qualifier/FooQualifier.java | 38 +++
.../org/apache/camel/cdi/qualifier/Manual.java | 34 ++
.../cdi/rule/ExpectedDeploymentException.java | 105 ++++++
.../org/apache/camel/cdi/rule/LogVerifier.java | 75 ++++
.../java/org/apache/camel/cdi/store/Item.java | 85 -----
.../org/apache/camel/cdi/store/Products.java | 56 ---
.../apache/camel/cdi/store/ShoppingBean.java | 58 ----
.../cdi/support/CamelEndpointInjectedBean.java | 38 ---
.../apache/camel/cdi/support/CdiConfigFile.java | 39 ---
.../cdi/support/CheeseComponentFactory.java | 35 --
.../camel/cdi/support/ContextAwareBean.java | 39 ---
.../camel/cdi/support/EndpointInjectedBean.java | 36 --
.../cdi/support/EndpointUriInjectedBean.java | 49 ---
.../EndpointUriPropertyInjectedBean.java | 40 ---
.../cdi/support/MockEndpointInjectedBean.java | 39 ---
.../camel/cdi/support/NamedEndpointBean.java | 33 --
.../camel/cdi/support/ProduceInjectedBean.java | 40 ---
.../test/AdvisedMockEndpointProducerTest.java | 96 ++++++
.../apache/camel/cdi/test/AdvisedRouteTest.java | 105 ++++++
.../cdi/test/AmbiguousCamelContextTest.java | 55 +++
.../apache/camel/cdi/test/BeanInjectTest.java | 88 +++++
.../camel/cdi/test/CamelContextAwareTest.java | 57 ++++
.../cdi/test/CamelContextProducerFieldTest.java | 97 ++++++
.../test/CamelContextProducerMethodTest.java | 89 +++++
.../camel/cdi/test/CamelEventEndpointTest.java | 143 ++++++++
.../camel/cdi/test/CamelEventNotifierTest.java | 151 ++++++++
.../camel/cdi/test/ConsumeMethodTest.java | 69 ++++
.../camel/cdi/test/ContextComponentTest.java | 92 +++++
.../camel/cdi/test/CustomCamelContextTest.java | 90 +++++
.../camel/cdi/test/DefaultCamelContextTest.java | 69 ++++
.../camel/cdi/test/EndpointInjectTest.java | 69 ++++
.../camel/cdi/test/EventComponentTest.java | 91 +++++
.../camel/cdi/test/EventEndpointCdi12Test.java | 277 +++++++++++++++
.../camel/cdi/test/EventEndpointTest.java | 282 +++++++++++++++
.../camel/cdi/test/InjectedEndpointTest.java | 68 ++++
.../cdi/test/InjectedTypeConverterTest.java | 103 ++++++
.../camel/cdi/test/ManualCamelContextTest.java | 117 +++++++
.../apache/camel/cdi/test/MockEndpointTest.java | 84 +++++
.../cdi/test/MultiCamelContextProducerTest.java | 168 +++++++++
.../camel/cdi/test/MultiCamelContextTest.java | 159 +++++++++
.../test/MultiContextEndpointInjectTest.java | 137 ++++++++
.../cdi/test/MultiContextEventEndpointTest.java | 190 +++++++++++
.../cdi/test/MultiContextEventNotifierTest.java | 300 ++++++++++++++++
.../test/MultiContextProduceTemplateTest.java | 157 +++++++++
.../test/MultiContextPropertyInjectTest.java | 193 +++++++++++
.../camel/cdi/test/NamedCamelBeanTest.java | 75 ++++
.../camel/cdi/test/NamedCamelContextTest.java | 114 +++++++
.../camel/cdi/test/ProduceTemplateTest.java | 76 +++++
.../camel/cdi/test/PropertiesLocationTest.java | 102 ++++++
.../test/PropertiesMultipleLocationTest.java | 55 +++
.../camel/cdi/test/PropertyEndpointTest.java | 88 +++++
.../camel/cdi/test/PropertyInjectTest.java | 101 ++++++
.../cdi/test/QualifiedCamelContextTest.java | 100 ++++++
.../test/QualifiedMultiCamelContextTest.java | 173 ++++++++++
.../camel/cdi/test/RawEventEndpointTest.java | 110 ++++++
.../camel/cdi/test/RecipientListMethodTest.java | 77 +++++
.../cdi/test/RouteDefinitionsFromXmlTest.java | 78 +++++
.../camel/cdi/test/UndefinedPropertyTest.java | 83 +++++
...UnsatisfiedContextForEndpointInjectTest.java | 58 ++++
.../cdi/test/UnstoppedCamelContextBeanTest.java | 87 +++++
.../UnstoppedCamelContextProducerFieldTest.java | 82 +++++
...UnstoppedCamelContextProducerMethodTest.java | 88 +++++
.../apache/camel/cdi/test/UriEndpointTest.java | 69 ++++
.../cdi/test/UriQualifierWithContextTest.java | 90 +++++
.../camel/cdi/test/UriWithWrongContextTest.java | 78 +++++
.../src/test/resources/META-INF/beans.xml | 18 -
.../test/resources/META-INF/camel.properties | 1 -
.../camel-cdi/src/test/resources/bar.properties | 18 +
.../camel-cdi/src/test/resources/foo.properties | 18 +
.../src/test/resources/log4j.properties | 23 +-
.../src/test/resources/logging.properties | 50 +++
.../src/test/resources/placeholder.properties | 18 +
.../camel-cdi/src/test/resources/routes.xml | 28 +-
components/camel-sjms/pom.xml | 2 +-
examples/camel-example-cdi/pom.xml | 13 +-
.../org/apache/camel/example/cdi/MyRoutes.java | 4 +-
parent/pom.xml | 16 +-
.../features/src/main/resources/features.xml | 4 +-
tests/camel-itest-cdi/pom.xml | 34 +-
.../apache/camel/itest/cdi/CamelContextA.java | 28 ++
.../apache/camel/itest/cdi/CamelContextB.java | 28 ++
.../apache/camel/itest/cdi/CamelContextC.java | 28 ++
.../apache/camel/itest/cdi/CamelContextD.java | 28 ++
.../apache/camel/itest/cdi/RoutesContextA.java | 22 +-
.../apache/camel/itest/cdi/RoutesContextB.java | 20 +-
.../apache/camel/itest/cdi/RoutesContextC.java | 17 +-
.../apache/camel/itest/cdi/RoutesContextD.java | 19 +-
.../itest/cdi/properties/Camel1Config.java | 38 ---
.../itest/cdi/properties/Camel2Config.java | 38 ---
.../apache/camel/itest/cdi/CamelCdiTest.java | 60 ++--
.../itest/cdi/PropertiesConfigurationTest.java | 75 ++++
.../properties/PropertiesConfigurationTest.java | 69 ----
.../META-INF/maven/archetype-metadata.xml | 4 +-
.../main/resources/archetype-resources/pom.xml | 11 +-
.../src/main/java/MyRoutes.java | 3 +-
221 files changed, 11054 insertions(+), 3626 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-cdi/pom.xml b/components/camel-cdi/pom.xml
index 74b8635..648670d 100644
--- a/components/camel-cdi/pom.xml
+++ b/components/camel-cdi/pom.xml
@@ -26,136 +26,354 @@
<artifactId>camel-cdi</artifactId>
<packaging>bundle</packaging>
- <name>Camel :: CDI</name>
- <description>Camel Contexts and Dependency Injection (JSR-299) support</description>
+ <name>Camel :: CDI Component</name>
+ <description>Camel Contexts and Dependency Injection Support</description>
<properties>
<camel.osgi.import>
!org.apache.camel.cdi.*,
!org.apache.deltaspike.cdise.api.*,
- org.apache.deltaspike.core.api.*;resolution:=optional,
${camel.osgi.import.defaults},
*
</camel.osgi.import>
<camel.osgi.export.pkg>
- org.apache.camel.cdi;${camel.osgi.version},
- org.apache.camel.cdi.internal;${camel.osgi.version},
- org.apache.camel.cdi.component.*;${camel.osgi.version}
+ org.apache.camel.cdi;${camel.osgi.version}
</camel.osgi.export.pkg>
<camel.osgi.provide.capability>
org.ops4j.pax.cdi.extension; extension=camel-cdi-extension
</camel.osgi.provide.capability>
- <camel.osgi.require.capability>
- osgi.extender;filter:="(osgi.extender=pax.cdi)",
- org.ops4j.pax.cdi.extension;filter:="(extension=deltaspike-core-api)"
- </camel.osgi.require.capability>
</properties>
+ <dependencyManagement>
+ <dependencies>
+
+ <!-- test dependencies -->
+
+ <dependency>
+ <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+ <artifactId>shrinkwrap-descriptors-bom</artifactId>
+ <version>${shrinkwrap-descriptors-version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-bom</artifactId>
+ <version>${arquillian-version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
+ <!-- compile dependencies -->
+
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
- <!-- cdi api -->
- <dependency>
- <groupId>javax.enterprise</groupId>
- <artifactId>cdi-api</artifactId>
- <version>${cdi-api-version}</version>
- <scope>provided</scope>
- </dependency>
-
- <!-- DeltaSpike -->
+ <!-- DeltaSpike is only used to provide Main support thus optional -->
<dependency>
<groupId>org.apache.deltaspike.core</groupId>
<artifactId>deltaspike-core-api</artifactId>
<version>${deltaspike-version}</version>
+ <optional>true</optional>
</dependency>
<dependency>
- <groupId>org.apache.deltaspike.core</groupId>
- <artifactId>deltaspike-core-impl</artifactId>
+ <groupId>org.apache.deltaspike.cdictrl</groupId>
+ <artifactId>deltaspike-cdictrl-api</artifactId>
<version>${deltaspike-version}</version>
- <scope>runtime</scope>
+ <optional>true</optional>
</dependency>
- <!-- only required for the Main -->
+ <!-- provided dependencies -->
+
<dependency>
- <groupId>org.apache.deltaspike.cdictrl</groupId>
- <artifactId>deltaspike-cdictrl-api</artifactId>
- <version>${deltaspike-version}</version>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-osgi</artifactId>
+ <version>${project.version}</version>
+ <scope>provided</scope>
<optional>true</optional>
</dependency>
- <!-- logging -->
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi-version}</version>
+ <scope>provided</scope>
+ <optional>true</optional>
</dependency>
+
+ <!-- test dependencies -->
+
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
+ <artifactId>camel-context</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>${hamcrest-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j-version}</version>
<scope>test</scope>
</dependency>
- </dependencies>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <version>${arquillian-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+ <artifactId>shrinkwrap-descriptors-depchain</artifactId>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
<profiles>
<profile>
- <id>owb</id>
+ <id>weld-1.0</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/*Cdi12Test.java</exclude>
+ <!-- Weld does not resolve observer method based on the runtime type of the event object, e.g. @Observe Long for a Long object fired with Event<Object> -->
+ <exclude>**/RawEventEndpointTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<dependencies>
+
+ <!-- provided dependencies -->
+
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-servlet_3.0_spec</artifactId>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>${cdi-api-1.0-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>javax.el-api</artifactId>
+ <version>${javax.el-api-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- test dependencies -->
+
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core</artifactId>
+ <version>${weld1-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-se-embedded-1.1</artifactId>
+ <version>${arquillian-weld-se-embedded-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>weld-1.2</id>
+
+ <dependencies>
+
+ <!-- provided dependencies -->
+
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>${cdi-api-1.2-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- test dependencies -->
+
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core-impl</artifactId>
+ <version>${weld2-version}</version>
<scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.apache.deltaspike.cdictrl</groupId>
- <artifactId>deltaspike-cdictrl-owb</artifactId>
- <version>${deltaspike-version}</version>
+ <groupId>org.jboss.arquillian.container</groupId>
+ <artifactId>arquillian-weld-se-embedded-1.1</artifactId>
+ <version>${arquillian-weld-se-embedded-version}</version>
<scope>test</scope>
</dependency>
+
+ </dependencies>
+ </profile>
+
+ <profile>
+ <id>owb-1.0</id>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/*Cdi12Test.java</exclude>
+ <!-- OWB does not call the InjectionTarget#preDestroy method -->
+ <exclude>**/UnstoppedCamelContext*Test.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <!-- provided dependencies -->
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_1.0_spec</artifactId>
+ <version>${geronimo-jcdi-1.0-spec-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
- <groupId>org.apache.openwebbeans</groupId>
- <artifactId>openwebbeans-impl</artifactId>
- <version>${openwebbeans-version}</version>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>${geronimo-atinject-1.0-spec-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.1_spec</artifactId>
+ <version>${geronimo-interceptor-1.1-spec-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- test dependencies -->
+
+ <dependency>
+ <groupId>org.apache.openwebbeans.arquillian</groupId>
+ <artifactId>owb-arquillian-standalone</artifactId>
+ <version>${openwebbeans1-version}</version>
<scope>test</scope>
</dependency>
+
<dependency>
<groupId>org.apache.openwebbeans</groupId>
- <artifactId>openwebbeans-spi</artifactId>
- <version>${openwebbeans-version}</version>
+ <artifactId>openwebbeans-impl</artifactId>
+ <version>${openwebbeans1-version}</version>
<scope>test</scope>
</dependency>
+
</dependencies>
</profile>
<profile>
- <id>weld2</id>
+ <id>owb-1.2</id>
+
<dependencies>
+
+ <!-- provided dependencies -->
+
<dependency>
- <groupId>org.apache.deltaspike.cdictrl</groupId>
- <artifactId>deltaspike-cdictrl-weld</artifactId>
- <version>${deltaspike-version}</version>
- <scope>test</scope>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+ <version>${geronimo-jcdi-1.1-spec-version}</version>
+ <scope>provided</scope>
</dependency>
+
<dependency>
- <groupId>org.jboss.weld.se</groupId>
- <artifactId>weld-se-core</artifactId>
- <version>${weld2-version}</version>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-atinject_1.0_spec</artifactId>
+ <version>${geronimo-atinject-1.0-spec-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.2_spec</artifactId>
+ <version>${geronimo-annotation-1.2-spec-version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-interceptor_1.2_spec</artifactId>
+ <version>${geronimo-interceptor-1.2-spec-version}</version>
<scope>provided</scope>
</dependency>
+
+ <!-- test dependencies -->
+
+ <dependency>
+ <groupId>org.apache.openwebbeans.arquillian</groupId>
+ <artifactId>owb-arquillian-standalone</artifactId>
+ <version>${openwebbeans-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.openwebbeans</groupId>
+ <artifactId>openwebbeans-impl</artifactId>
+ <version>${openwebbeans-version}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</profile>
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java
new file mode 100644
index 0000000..ccd4989
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedDelegate.java
@@ -0,0 +1,85 @@
+/**
+ * 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.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+import javax.enterprise.inject.spi.Annotated;
+
+class AnnotatedDelegate implements Annotated {
+
+ private final Annotated delegate;
+
+ private final Set<Annotation> annotations;
+
+ AnnotatedDelegate(Annotated delegate, Set<Annotation> annotations) {
+ this.delegate = delegate;
+ this.annotations = new HashSet<>(annotations);
+ }
+
+ AnnotatedDelegate(Annotated delegate) {
+ this.delegate = delegate;
+ this.annotations = delegate.getAnnotations();
+ }
+
+ @Override
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
+ for (Annotation annotation : annotations) {
+ if (annotation.annotationType().equals(annotationType)) {
+ return annotationType.cast(annotation);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Set<Annotation> getAnnotations() {
+ return annotations;
+ }
+
+ @Override
+ public Type getBaseType() {
+ return delegate.getBaseType();
+ }
+
+ @Override
+ public Set<Type> getTypeClosure() {
+ return delegate.getTypeClosure();
+ }
+
+ @Override
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
+ return getAnnotation(annotationType) != null;
+ }
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ return delegate.equals(object);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedMemberDelegate.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedMemberDelegate.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedMemberDelegate.java
new file mode 100644
index 0000000..d33732c
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedMemberDelegate.java
@@ -0,0 +1,48 @@
+/**
+ * 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.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.util.Set;
+import javax.enterprise.inject.spi.AnnotatedMember;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+class AnnotatedMemberDelegate<T> extends AnnotatedDelegate implements AnnotatedMember<T> {
+
+ private final AnnotatedMember<T> delegate;
+
+ AnnotatedMemberDelegate(AnnotatedMember<T> delegate, Set<Annotation> annotations) {
+ super(delegate, annotations);
+ this.delegate = delegate;
+ }
+
+ @Override
+ public AnnotatedType<T> getDeclaringType() {
+ return delegate.getDeclaringType();
+ }
+
+ @Override
+ public Member getJavaMember() {
+ return delegate.getJavaMember();
+ }
+
+ @Override
+ public boolean isStatic() {
+ return delegate.isStatic();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedMethodDelegate.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedMethodDelegate.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedMethodDelegate.java
new file mode 100644
index 0000000..6e0b5df
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedMethodDelegate.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;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Set;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
+
+final class AnnotatedMethodDelegate<T> extends AnnotatedMemberDelegate<T> implements AnnotatedMethod<T> {
+
+ private final AnnotatedMethod<T> delegate;
+
+ AnnotatedMethodDelegate(AnnotatedMethod<T> delegate, Set<Annotation> annotations) {
+ super(delegate, annotations);
+ this.delegate = delegate;
+ }
+
+ @Override
+ public List<AnnotatedParameter<T>> getParameters() {
+ return delegate.getParameters();
+ }
+
+ @Override
+ public Method getJavaMember() {
+ return delegate.getJavaMember();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedTypeDelegate.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedTypeDelegate.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedTypeDelegate.java
new file mode 100644
index 0000000..8d43662
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedTypeDelegate.java
@@ -0,0 +1,59 @@
+/**
+ * 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.HashSet;
+import java.util.Set;
+import javax.enterprise.inject.spi.AnnotatedConstructor;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+
+final class AnnotatedTypeDelegate<T> extends AnnotatedDelegate implements AnnotatedType<T> {
+
+ private final Set<AnnotatedMethod<? super T>> methods;
+
+ private final AnnotatedType<T> delegate;
+
+ AnnotatedTypeDelegate(AnnotatedType<T> delegate, Set<AnnotatedMethod<? super T>> methods) {
+ super(delegate);
+ this.delegate = delegate;
+ this.methods = new HashSet<>(delegate.getMethods());
+ this.methods.removeAll(methods);
+ this.methods.addAll(methods);
+ }
+
+ @Override
+ public Set<AnnotatedConstructor<T>> getConstructors() {
+ return delegate.getConstructors();
+ }
+
+ @Override
+ public Set<AnnotatedField<? super T>> getFields() {
+ return delegate.getFields();
+ }
+
+ @Override
+ public Class<T> getJavaClass() {
+ return delegate.getJavaClass();
+ }
+
+ @Override
+ public Set<AnnotatedMethod<? super T>> getMethods() {
+ return methods;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedWrapper.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedWrapper.java
new file mode 100644
index 0000000..013738a
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnnotatedWrapper.java
@@ -0,0 +1,84 @@
+/**
+ * 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.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+import javax.enterprise.inject.spi.Annotated;
+
+// This class is used as a work-around to OWB-1099
+final class AnnotatedWrapper implements Annotated {
+
+ private final Annotated delegate;
+
+ AnnotatedWrapper(Annotated delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public Type getBaseType() {
+ return delegate.getBaseType();
+ }
+
+ @Override
+ public Set<Type> getTypeClosure() {
+ return delegate.getTypeClosure();
+ }
+
+ @Override
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
+ return delegate.getAnnotation(annotationType);
+ }
+
+ @Override
+ public Set<Annotation> getAnnotations() {
+ return delegate.getAnnotations();
+ }
+
+ @Override
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
+ return delegate.isAnnotationPresent(annotationType);
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+ if (object == null || getClass() != object.getClass()) {
+ return false;
+ }
+
+ AnnotatedWrapper that = (AnnotatedWrapper) object;
+
+ if (!getBaseType().equals(that.getBaseType())) {
+ return false;
+ } else if (!getTypeClosure().equals(that.getTypeClosure())) {
+ return false;
+ }
+ return getAnnotations().equals(that.getAnnotations());
+ }
+
+ @Override
+ public int hashCode() {
+ int result = getBaseType() != null ? getBaseType().hashCode() : 0;
+ result = 31 * result + (getTypeClosure() != null ? getTypeClosure().hashCode() : 0);
+ result = 31 * result + (getAnnotations() != null ? getAnnotations().hashCode() : 0);
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java
new file mode 100755
index 0000000..decff53
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/AnyLiteral.java
@@ -0,0 +1,31 @@
+/**
+ * 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.Any;
+import javax.enterprise.util.AnnotationLiteral;
+
+@Vetoed
+final class AnyLiteral extends AnnotationLiteral<Any> implements Any {
+
+ static final Any INSTANCE = new AnyLiteral();
+
+ private static final long serialVersionUID = 1L;
+
+ private AnyLiteral() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/BeanDelegate.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/BeanDelegate.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/BeanDelegate.java
new file mode 100644
index 0000000..c1592cd
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/BeanDelegate.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;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Set;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+final class BeanDelegate<T> implements Bean<T> {
+
+ private final Bean<T> delegate;
+
+ private final Set<Annotation> qualifiers;
+
+ BeanDelegate(Bean<T> delegate, Set<? extends Annotation> qualifiers) {
+ this.delegate = delegate;
+ this.qualifiers = Collections.unmodifiableSet(qualifiers);
+ }
+
+ @Override
+ public Set<Type> getTypes() {
+ return delegate.getTypes();
+ }
+
+ @Override
+ public Set<Annotation> getQualifiers() {
+ return qualifiers;
+ }
+
+ @Override
+ public Class<? extends Annotation> getScope() {
+ return delegate.getScope();
+ }
+
+ @Override
+ public String getName() {
+ return delegate.getName();
+ }
+
+ @Override
+ public Set<Class<? extends Annotation>> getStereotypes() {
+ return delegate.getStereotypes();
+ }
+
+ @Override
+ public boolean isAlternative() {
+ return delegate.isAlternative();
+ }
+
+ @Override
+ public Class<?> getBeanClass() {
+ return delegate.getBeanClass();
+ }
+
+ @Override
+ public Set<InjectionPoint> getInjectionPoints() {
+ return delegate.getInjectionPoints();
+ }
+
+ @Override
+ public boolean isNullable() {
+ return delegate.isNullable();
+ }
+
+ @Override
+ public T create(CreationalContext<T> creationalContext) {
+ return delegate.create(creationalContext);
+ }
+
+ @Override
+ public void destroy(T instance, CreationalContext<T> creationalContext) {
+ delegate.destroy(instance, creationalContext);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/BeanManagerHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/BeanManagerHelper.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/BeanManagerHelper.java
new file mode 100644
index 0000000..47118bf
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/BeanManagerHelper.java
@@ -0,0 +1,58 @@
+/**
+ * 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.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+@Vetoed
+final class BeanManagerHelper {
+
+ private BeanManagerHelper() {
+ }
+
+ static <T> Set<T> getReferencesByType(BeanManager manager, Class<T> type, Annotation... qualifiers) {
+ Set<T> references = new HashSet<>();
+ for (Bean<?> bean : manager.getBeans(type, qualifiers)) {
+ references.add(getReference(manager, type, bean));
+ }
+ return references;
+ }
+
+ static <T> T getReferenceByName(BeanManager manager, String name, Class<T> type) {
+ Set<Bean<?>> beans = manager.getBeans(name);
+ if (beans == null || beans.isEmpty()) {
+ return null;
+ }
+ return getReference(manager, type, manager.resolve(beans));
+ }
+
+ static <T> T getReferenceByType(BeanManager manager, Class<T> type, Annotation... qualifiers) {
+ Set<Bean<?>> beans = manager.getBeans(type, qualifiers);
+ if (beans == null || beans.isEmpty()) {
+ return null;
+ }
+ return getReference(manager, type, manager.resolve(beans));
+ }
+
+ static <T> T getReference(BeanManager manager, Class<T> type, Bean<?> bean) {
+ return type.cast(manager.getReference(bean, type, manager.createCreationalContext(bean)));
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelBeanInjectionTarget.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelBeanInjectionTarget.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelBeanInjectionTarget.java
new file mode 100644
index 0000000..9a78e61
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelBeanInjectionTarget.java
@@ -0,0 +1,47 @@
+/**
+ * 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.context.spi.CreationalContext;
+import javax.enterprise.inject.InjectionException;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+final class CamelBeanInjectionTarget<T> extends DelegateInjectionTarget<T> implements InjectionTarget<T> {
+
+ private final InjectionTarget<T> delegate;
+
+ private final CdiCamelBeanPostProcessor processor;
+
+ CamelBeanInjectionTarget(InjectionTarget<T> delegate, BeanManager manager) {
+ super(delegate);
+ this.delegate = delegate;
+ this.processor = new CdiCamelBeanPostProcessor(manager);
+ }
+
+ @Override
+ public void inject(T instance, CreationalContext<T> ctx) {
+ super.inject(instance, ctx);
+ try {
+ // TODO: see how to retrieve the bean name
+ processor.postProcessBeforeInitialization(instance, instance.getClass().getName());
+ processor.postProcessAfterInitialization(instance, instance.getClass().getName());
+ } catch (Exception cause) {
+ throw new InjectionException("Camel annotations post processing of [" + delegate + "] failed!", cause);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextDefaultProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextDefaultProducer.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextDefaultProducer.java
new file mode 100644
index 0000000..4af15e7
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextDefaultProducer.java
@@ -0,0 +1,57 @@
+/**
+ * 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.Collections;
+import java.util.Set;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+import org.apache.camel.impl.DefaultCamelContext;
+
+@Vetoed
+final class CamelContextDefaultProducer implements InjectionTarget<DefaultCamelContext> {
+
+ @Override
+ public DefaultCamelContext produce(CreationalContext<DefaultCamelContext> ctx) {
+ DefaultCamelContext context = new DefaultCamelContext();
+ context.setNameStrategy(new CdiCamelContextNameStrategy());
+ return context;
+ }
+
+ @Override
+ public void inject(DefaultCamelContext instance, CreationalContext<DefaultCamelContext> ctx) {
+ }
+
+ @Override
+ public void postConstruct(DefaultCamelContext instance) {
+ }
+
+ @Override
+ public void preDestroy(DefaultCamelContext instance) {
+ }
+
+ @Override
+ public void dispose(DefaultCamelContext instance) {
+ }
+
+ @Override
+ public Set<InjectionPoint> getInjectionPoints() {
+ return Collections.emptySet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextInjectionTarget.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextInjectionTarget.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextInjectionTarget.java
new file mode 100644
index 0000000..4b84eed
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextInjectionTarget.java
@@ -0,0 +1,35 @@
+/**
+ * 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.spi.InjectionTarget;
+import javax.enterprise.inject.spi.Producer;
+
+import org.apache.camel.CamelContext;
+
+final class CamelContextInjectionTarget<T extends CamelContext> extends DelegateInjectionTarget<T> implements InjectionTarget<T> {
+
+ CamelContextInjectionTarget(InjectionTarget<T> target, Producer<T> producer) {
+ super(target, producer);
+ }
+
+ @Override
+ public void preDestroy(T instance) {
+ super.preDestroy(instance);
+ super.dispose(instance);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextOsgiProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextOsgiProducer.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextOsgiProducer.java
new file mode 100644
index 0000000..d780255
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextOsgiProducer.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;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.InjectionException;
+import javax.enterprise.inject.spi.Producer;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.core.osgi.OsgiCamelContextHelper;
+import org.apache.camel.core.osgi.OsgiCamelContextPublisher;
+import org.apache.camel.core.osgi.utils.BundleContextUtils;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultCamelContextNameStrategy;
+import org.apache.camel.spi.CamelContextNameStrategy;
+import org.osgi.framework.BundleContext;
+
+final class CamelContextOsgiProducer<T extends CamelContext> extends DelegateProducer<T> {
+
+ CamelContextOsgiProducer(Producer<T> delegate) {
+ super(delegate);
+ }
+
+ @Override
+ public T produce(CreationalContext<T> ctx) {
+ T context = super.produce(ctx);
+
+ // Register the context in the OSGi registry
+ BundleContext bundle = BundleContextUtils.getBundleContext(getClass());
+ context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle));
+
+ if (!(context instanceof DefaultCamelContext)) {
+ // Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface
+ throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
+ }
+
+ DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
+ adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle));
+ CamelContextNameStrategy strategy = context.getNameStrategy();
+ OsgiCamelContextHelper.osgiUpdate(adapted, bundle);
+ // FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely
+ if (!(strategy instanceof DefaultCamelContextNameStrategy)) {
+ context.setNameStrategy(strategy);
+ }
+
+ return context;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java
new file mode 100644
index 0000000..ebf80eb
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CamelContextProducer.java
@@ -0,0 +1,129 @@
+/**
+ * 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.beans.Introspector;
+import java.lang.annotation.Annotation;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.InjectionException;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedField;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Producer;
+import javax.inject.Named;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.DefaultCamelContextNameStrategy;
+import org.apache.camel.impl.ExplicitCamelContextNameStrategy;
+import org.apache.camel.spi.CamelContextNameStrategy;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+final class CamelContextProducer<T extends CamelContext> extends DelegateProducer<T> {
+
+ private final Logger logger = LoggerFactory.getLogger(getClass());
+
+ private final Annotated annotated;
+
+ private final BeanManager manager;
+
+ private final CdiCamelExtension extension;
+
+ CamelContextProducer(Producer<T> delegate, Annotated annotated, BeanManager manager, CdiCamelExtension extension) {
+ super(delegate);
+ this.annotated = annotated;
+ this.manager = manager;
+ this.extension = extension;
+ }
+
+ @Override
+ public T produce(CreationalContext<T> ctx) {
+ T context = super.produce(ctx);
+
+ // Do not override the name if it's been already set (in the bean constructor for example)
+ if (annotated != null && context.getNameStrategy() instanceof DefaultCamelContextNameStrategy) {
+ context.setNameStrategy(nameStrategy(annotated));
+ }
+
+ // Add bean registry and Camel injector
+ if (context instanceof DefaultCamelContext) {
+ DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
+ adapted.setRegistry(new CdiCamelRegistry(manager));
+ adapted.setInjector(new CdiCamelInjector(context.getInjector(), manager));
+ } else {
+ // Fail fast for the time being to avoid side effects by the time these two methods get declared on the CamelContext interface
+ throw new InjectionException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
+ }
+
+ // Add event notifier if at least one observer is present
+ Set<Annotation> events = new HashSet<>(extension.getObserverEvents());
+ // Annotated must be wrapped because of OWB-1099
+ Collection<Annotation> qualifiers = annotated != null ? extension.getContextBean(new AnnotatedWrapper(annotated)).getQualifiers() : Arrays.asList(AnyLiteral.INSTANCE, DefaultLiteral.INSTANCE);
+ events.retainAll(qualifiers);
+ if (!events.isEmpty()) {
+ context.getManagementStrategy().addEventNotifier(new CdiEventNotifier(manager, qualifiers));
+ }
+
+ return context;
+ }
+
+ @Override
+ public void dispose(T context) {
+ super.dispose(context);
+
+ if (!context.getStatus().isStopped()) {
+ logger.info("Camel CDI is stopping Camel context [{}]", context.getName());
+ try {
+ context.stop();
+ } catch (Exception cause) {
+ throw ObjectHelper.wrapRuntimeCamelException(cause);
+ }
+ }
+ }
+
+ private static CamelContextNameStrategy nameStrategy(Annotated annotated) {
+ if (annotated.isAnnotationPresent(ContextName.class)) {
+ return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value());
+ } else if (annotated.isAnnotationPresent(Named.class)) {
+ // TODO: support stereotype with empty @Named annotation
+ String name = annotated.getAnnotation(Named.class).value();
+ if (name.isEmpty()) {
+ if (annotated instanceof AnnotatedField) {
+ name = ((AnnotatedField) annotated).getJavaMember().getName();
+ } else if (annotated instanceof AnnotatedMethod) {
+ name = ((AnnotatedMethod) annotated).getJavaMember().getName();
+ if (name.startsWith("get")) {
+ name = Introspector.decapitalize(name.substring(3));
+ }
+ } else {
+ name = Introspector.decapitalize(CdiSpiHelper.getRawType(annotated.getBaseType()).getSimpleName());
+ }
+ }
+ return new ExplicitCamelContextNameStrategy(name);
+ } else {
+ // Use a specific naming strategy for Camel CDI as the default one increments the suffix for each CDI proxy created
+ return new CdiCamelContextNameStrategy();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiBeanManagerHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiBeanManagerHelper.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiBeanManagerHelper.java
deleted file mode 100644
index 91ecbd3..0000000
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiBeanManagerHelper.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/**
- * 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.Set;
-import javax.enterprise.context.spi.CreationalContext;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-
-/**
- * To make looking up beans in CDI easier
- */
-public final class CdiBeanManagerHelper {
-
- private CdiBeanManagerHelper() {
- }
-
- /**
- * To lookup a bean by a type
- */
- public static <T> T lookupBeanByType(BeanManager beanManager, Class<T> type) {
- Set<Bean<?>> beans = beanManager.getBeans(type);
- if (!beans.isEmpty()) {
- Bean<?> bean = beanManager.resolve(beans);
- CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
- Object result = beanManager.getReference(bean, type, creationalContext);
- if (result != null) {
- return type.cast(result);
- }
- }
-
- return null;
- }
-
- /**
- * To lookup a bean by a name
- */
- public static Object lookupBeanByName(BeanManager beanManager, String name) {
- return lookupBeanByNameAndType(beanManager, name, Object.class);
- }
-
- /**
- * To lookup a bean by name and type
- */
- public static <T> T lookupBeanByNameAndType(BeanManager beanManager, String name, Class<T> type) {
- Set<Bean<?>> beans = beanManager.getBeans(name);
- if (!beans.isEmpty()) {
- Bean<?> bean = beanManager.resolve(beans);
- CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
- Object result = beanManager.getReference(bean, type, creationalContext);
- if (result != null) {
- return type.cast(result);
- }
- }
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiBeanRegistry.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiBeanRegistry.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiBeanRegistry.java
deleted file mode 100644
index 4d131a9..0000000
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiBeanRegistry.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * 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.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import javax.enterprise.inject.spi.Bean;
-import javax.enterprise.inject.spi.BeanManager;
-
-import org.apache.camel.spi.Registry;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * CdiBeanRegistry used by Camel to perform lookup into the CDI {@link javax.enterprise.inject.spi.BeanManager}.
- */
-public class CdiBeanRegistry implements Registry {
- private static final Logger LOG = LoggerFactory.getLogger(CdiBeanRegistry.class);
-
- private final BeanManager beanManager;
-
- public CdiBeanRegistry(BeanManager beanManager) {
- this.beanManager = beanManager;
- }
-
- @Override
- public Object lookupByName(final String name) {
- ObjectHelper.notEmpty(name, "name");
- LOG.trace("Looking up bean with name {}", name);
-
- return CdiBeanManagerHelper.lookupBeanByName(beanManager, name);
- }
-
- @Override
- public <T> T lookupByNameAndType(final String name, final Class<T> type) {
- ObjectHelper.notEmpty(name, "name");
- ObjectHelper.notNull(type, "type");
-
- LOG.trace("Looking up bean with name {} of type {}", name, type);
- return CdiBeanManagerHelper.lookupBeanByNameAndType(beanManager, name, type);
- }
-
- @Override
- public <T> Map<String, T> findByTypeWithName(final Class<T> type) {
- ObjectHelper.notNull(type, "type");
-
- LOG.trace("Lookups based of type {}", type);
- Map<String, T> beans = new HashMap<String, T>();
- Set<Bean<?>> definitions = beanManager.getBeans(type);
-
- if (definitions == null) {
- return beans;
- }
- for (Bean<?> bean : definitions) {
- if (bean.getName() != null) {
- T obj = CdiBeanManagerHelper.lookupBeanByNameAndType(beanManager, bean.getName(), type);
- beans.put(bean.getName(), obj);
- }
- }
- return beans;
- }
-
- @Override
- public <T> Set<T> findByType(Class<T> type) {
- ObjectHelper.notNull(type, "type");
-
- LOG.trace("Lookups based of type {}", type);
- Set<T> beans = new HashSet<T>();
- Set<Bean<?>> definitions = beanManager.getBeans(type);
-
- if (definitions == null) {
- return beans;
- }
- for (Bean<?> bean : definitions) {
- if (bean.getName() != null) {
- T obj = CdiBeanManagerHelper.lookupBeanByNameAndType(beanManager, bean.getName(), type);
- beans.add(obj);
- }
- }
- return beans;
- }
-
- @Override
- public Object lookup(String name) {
- return lookupByName(name);
- }
-
- @Override
- public <T> T lookup(String name, Class<T> type) {
- return lookupByNameAndType(name, type);
- }
-
- @Override
- public <T> Map<String, T> lookupByType(Class<T> type) {
- return findByTypeWithName(type);
- }
-
- @Override
- public String toString() {
- return "CdiRegistry[" + System.identityHashCode(this) + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java
new file mode 100644
index 0000000..85284fc
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelBeanPostProcessor.java
@@ -0,0 +1,120 @@
+/**
+ * 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.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+import javax.enterprise.inject.InjectionException;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.apache.camel.BeanInject;
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.PropertyInject;
+import org.apache.camel.impl.CamelPostProcessorHelper;
+import org.apache.camel.impl.DefaultCamelBeanPostProcessor;
+import org.apache.camel.util.ReflectionHelper;
+
+@Vetoed
+final class CdiCamelBeanPostProcessor extends DefaultCamelBeanPostProcessor {
+
+ private final BeanManager manager;
+
+ private final Map<String, CamelPostProcessorHelper> postProcessorHelpers = new HashMap<>();
+
+ // TODO: proper support for multi Camel contexts and custom context qualifiers
+ CdiCamelBeanPostProcessor(BeanManager manager) {
+ this.manager = manager;
+ }
+
+ protected void injectFields(final Object bean, final String beanName) {
+ ReflectionHelper.doWithFields(bean.getClass(), new ReflectionHelper.FieldCallback() {
+ public void doWith(Field field) throws IllegalAccessException {
+ PropertyInject propertyInject = field.getAnnotation(PropertyInject.class);
+ if (propertyInject != null) {
+ try {
+ injectFieldProperty(field, propertyInject.value(), propertyInject.defaultValue(), propertyInject.context(), bean, beanName);
+ } catch (Exception cause) {
+ throw new InjectionException("Injection of [" + propertyInject + "] for field [" + field + "] failed!", cause);
+ }
+ }
+
+ BeanInject beanInject = field.getAnnotation(BeanInject.class);
+ // TODO: proper support for multi Camel contexts
+ if (beanInject != null && getPostProcessorHelper().matchContext(beanInject.context())) {
+ try {
+ injectFieldBean(field, beanInject.value(), bean, beanName);
+ } catch (Exception cause) {
+ throw new InjectionException("Injection of [" + beanInject + "] for field [" + field + "] failed!", cause);
+ }
+ }
+
+ EndpointInject endpointInject = field.getAnnotation(EndpointInject.class);
+ if (endpointInject != null) {
+ try {
+ injectField(field, endpointInject.uri(), endpointInject.ref(), endpointInject.property(), endpointInject.context(), bean, beanName);
+ } catch (Exception cause) {
+ throw new InjectionException("Injection of [" + endpointInject + "] for field [" + field + "] failed!", cause);
+ }
+ }
+
+ Produce produce = field.getAnnotation(Produce.class);
+ if (produce != null) {
+ try {
+ injectField(field, produce.uri(), produce.ref(), produce.property(), produce.context(), bean, beanName);
+ } catch (Exception cause) {
+ throw new InjectionException("Injection of [" + produce + "] for field [" + field + "] failed!", cause);
+ }
+ }
+ }
+ });
+ }
+
+ private void injectField(Field field, String uri, String ref, String property, String context, Object bean, String beanName) {
+ ReflectionHelper.setField(field, bean, getPostProcessorHelper(context).getInjectionValue(field.getType(), uri, ref, property, field.getName(), bean, beanName));
+ }
+
+ private void injectFieldProperty(Field field, String property, String defaultValue, String context, Object bean, String beanName) {
+ ReflectionHelper.setField(field, bean, getPostProcessorHelper(context).getInjectionPropertyValue(field.getType(), property, defaultValue, field.getName(), bean, beanName));
+ }
+
+ private CamelPostProcessorHelper getPostProcessorHelper(String contextName) {
+ CamelPostProcessorHelper helper = postProcessorHelpers.get(contextName);
+ if (helper == null) {
+ CamelContext context = getOrLookupCamelContext(contextName);
+ if (context == null) {
+ throw new UnsatisfiedResolutionException("No Camel context with name [" + contextName + "] is deployed!");
+ }
+ helper = new CamelPostProcessorHelper(context);
+ postProcessorHelpers.put(contextName, helper);
+ }
+ return helper;
+ }
+
+ private CamelContext getOrLookupCamelContext(String contextName) {
+ // TODO: proper support for custom context qualifiers
+ return BeanManagerHelper.getReferenceByType(manager, CamelContext.class, contextName.isEmpty() ? DefaultLiteral.INSTANCE : new ContextName.Literal(contextName));
+ }
+
+ @Override
+ public CamelContext getOrLookupCamelContext() {
+ return BeanManagerHelper.getReferenceByType(manager, CamelContext.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java
old mode 100644
new mode 100755
index df603c7..f5f775d
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContext.java
@@ -16,77 +16,23 @@
*/
package org.apache.camel.cdi;
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.enterprise.inject.Instance;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-
import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.spi.Injector;
-import org.apache.camel.spi.Registry;
-import org.apache.camel.util.ObjectHelper;
/**
- * CDI {@link org.apache.camel.CamelContext} class.
+ * CDI {@link org.apache.camel.CamelContext} class that can be extended
+ * to declare custom Camel context beans. Camel CDI is capable of managing
+ * any bean that implements {@code org.apache.camel.CamelContext},
+ * so that directly extending {@link org.apache.camel.impl.DefaultCamelContext}
+ * is an option to avoid having to depend on Camel CDI specific API, e.g.:
+ *
+ * <pre><code>
+ * {@literal @}ApplicationScoped
+ * {@literal @}ContextName("foo")
+ * public class FooCamelContext extends DefaultCamelContext {
+ * }
+ * </code></pre>
*/
+@Vetoed
public class CdiCamelContext extends DefaultCamelContext {
- private BeanManager beanManager;
-
- public CdiCamelContext() {
- }
-
- @Inject
- public void setBeanManager(Instance<BeanManager> beanManager) {
- this.beanManager = beanManager.get();
- }
-
- @Inject
- public void setRegistry(Instance<Registry> instance) {
- if (isSingular(instance)) {
- setRegistry(instance.get());
- }
- }
-
- @Inject
- public void setInjector(Instance<Injector> instance) {
- if (isSingular(instance)) {
- setInjector(instance.get());
- }
- }
-
- private <T> boolean isSingular(Instance<T> instance) {
- return !instance.isUnsatisfied() && !instance.isAmbiguous();
- }
-
- @PostConstruct
- @Override
- public void start() {
- // make sure to use cdi capable bean registry and injector
- if (!(getRegistry() instanceof CdiBeanRegistry)) {
- setRegistry(new CdiBeanRegistry(beanManager));
- }
-
- if (!(getInjector() instanceof CdiInjector)) {
- setInjector(new CdiInjector(getInjector()));
- }
-
- try {
- super.start();
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
- }
-
- @PreDestroy
- @Override
- public void stop() {
- try {
- super.stop();
- } catch (Exception e) {
- throw ObjectHelper.wrapRuntimeCamelException(e);
- }
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/0421c24d/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContextBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContextBean.java b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContextBean.java
new file mode 100644
index 0000000..08338a2
--- /dev/null
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/CdiCamelContextBean.java
@@ -0,0 +1,120 @@
+/**
+ * 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.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.PassivationCapable;
+
+import org.apache.camel.impl.DefaultCamelContext;
+
+final class CdiCamelContextBean implements Bean<DefaultCamelContext>, PassivationCapable {
+
+ private final Set<Annotation> qualifiers;
+
+ private final Set<Type> types;
+
+ private final InjectionTarget<DefaultCamelContext> target;
+
+ CdiCamelContextBean(BeanManager manager, InjectionTarget<DefaultCamelContext> target) {
+ this.qualifiers = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(AnyLiteral.INSTANCE, DefaultLiteral.INSTANCE)));
+ this.types = Collections.unmodifiableSet(manager.createAnnotatedType(DefaultCamelContext.class).getTypeClosure());
+ this.target = target;
+ }
+
+ @Override
+ public Class<? extends Annotation> getScope() {
+ return ApplicationScoped.class;
+ }
+
+ @Override
+ public Set<Annotation> getQualifiers() {
+ return qualifiers;
+ }
+
+ @Override
+ public DefaultCamelContext create(CreationalContext<DefaultCamelContext> creational) {
+ DefaultCamelContext context = target.produce(creational);
+ target.inject(context, creational);
+ target.postConstruct(context);
+ creational.push(context);
+ return context;
+ }
+
+ @Override
+ public void destroy(DefaultCamelContext instance, CreationalContext<DefaultCamelContext> creational) {
+ target.preDestroy(instance);
+ target.dispose(instance);
+ creational.release();
+ }
+
+ @Override
+ public Class<DefaultCamelContext> getBeanClass() {
+ return DefaultCamelContext.class;
+ }
+
+ @Override
+ public Set<InjectionPoint> getInjectionPoints() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public String getName() {
+ // Not called as this is not a named bean
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return "Default CDI Camel Context";
+ }
+
+ @Override
+ public Set<Class<? extends Annotation>> getStereotypes() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<Type> getTypes() {
+ return types;
+ }
+
+ @Override
+ public boolean isAlternative() {
+ return false;
+ }
+
+ @Override
+ public boolean isNullable() {
+ return false;
+ }
+
+ @Override
+ public String getId() {
+ return getClass().getName();
+ }
+}