This is an automated email from the ASF dual-hosted git repository. bvahdat pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit f03523dc9aea6412f322337eb337f19208ad8054 Author: Babak Vahdat <bvah...@apache.org> AuthorDate: Sun Jun 30 22:23:31 2019 +0200 restore the lost camel-example-cdi-osgi files using the 2.24.1 release --- examples/camel-example-cdi-osgi/README.md | 183 ++++++++++++ examples/camel-example-cdi-osgi/pom.xml | 309 +++++++++++++++++++++ .../org/apache/camel/example/cdi/osgi/Config.java | 35 +++ .../apache/camel/example/cdi/osgi/Consumer.java | 31 +++ .../org/apache/camel/example/cdi/osgi/Jms.java | 41 +++ .../apache/camel/example/cdi/osgi/Producer.java | 30 ++ .../src/main/resources/META-INF/LICENSE.txt | 203 ++++++++++++++ .../src/main/resources/META-INF/NOTICE.txt | 11 + .../src/main/resources/META-INF/beans.xml | 20 ++ .../src/main/resources/jms.properties | 18 ++ .../src/main/resources/log4j2.properties | 23 ++ .../apache/camel/example/cdi/osgi/CdiOsgiIT.java | 4 +- .../camel/example/cdi/osgi/PaxExamOptions.java | 116 ++++++++ 13 files changed, 1022 insertions(+), 2 deletions(-) diff --git a/examples/camel-example-cdi-osgi/README.md b/examples/camel-example-cdi-osgi/README.md new file mode 100644 index 0000000..eec30d4 --- /dev/null +++ b/examples/camel-example-cdi-osgi/README.md @@ -0,0 +1,183 @@ +# OSGi Example - CDI + +### Introduction + +This example illustrates a CDI application that can be executed inside an OSGi container +using PAX CDI. This application can run unchanged as well in Java SE inside a standalone +CDI container. + +The example starts an ActiveMQ in-memory broker and publishes a message when the Camel +context has started. + +The example is implemented in Java with CDI dependency injection. It uses JBoss Weld +as the minimal CDI container to run the application, though you can run the application +in any CDI compliant container. In OSGi, PAX CDI is used to managed the lifecycle of +the CDI container. + +The `camel-core` and `camel-sjms` components are used in this example. + +### Build + +You will need to build this example first: + +```sh +$ mvn install +``` + +### Run + +#### Java SE + +You can run this example using: + +```sh +$ mvn camel:run +``` + +When the Camel application starts, you should see the following message being logged to the console, e.g.: + +``` +2016-02-01 20:13:46,922 [cdi.Main.main()] INFO DefaultCamelContext - Apache Camel 2.17.0 (CamelContext: osgi-example) started in 0.769 seconds +2016-02-01 20:13:47,008 [ Session Task-1] INFO consumer-route - Received message [Sample Message] from [Producer] +``` + +The Camel application can be stopped pressing <kbd>ctrl</kbd>+<kbd>c</kbd> in the shell. + +#### OSGi / Karaf + +This example can be executed within Karaf 4.x. Note that it uses +the `pax-cdi-weld` feature from the PAX CDI version used by Camel and which defines +the Weld version used. For instance, Camel `${version}` depends on PAX CDI `${pax-cdi-version}` +and related `pax-cdi-weld` feature. + +To run the example, from the command line: + +1. In the Karaf install root directory, start Karaf: + + ```sh + $ bin/karaf + ``` + +2. Install the pre-requisites: + + ```sh + karaf@root()> repo-add camel ${version} + karaf@root()> repo-add activemq ${activemq-version} + karaf@root()> feature:install activemq-broker-noweb pax-cdi-weld camel-sjms camel-cdi + ``` + +3. Then install and start the example: + + ```sh + karaf@root()> install -s mvn:org.apache.camel.example/camel-example-cdi-osgi/${version} + ``` + +By tailing the log with: + +```sh +karaf@root()> log:tail +``` + +The following messages should be displayed: + +``` +2016-02-08 12:32:14,395 | INFO | nsole user karaf | CdiCamelExtension | 149 - org.apache.camel.camel-cdi - 2.17.0.SNAPSHOT | Camel CDI is starting Camel context [osgi-example] +2016-02-08 12:32:14,395 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Apache Camel 2.17.0 (CamelContext: osgi-example) is starting +2016-02-08 12:32:14,395 | INFO | nsole user karaf | ManagedManagementStrategy | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | JMX is enabled +2016-02-08 12:32:14,698 | INFO | nsole user karaf | DefaultTypeConverter | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Loaded 182 type converters +2016-02-08 12:32:14,706 | INFO | nsole user karaf | DefaultRuntimeEndpointRegistry | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Runtime endpoint registry is in extended mode gathering usage statistics of all incoming and outgoing endpoints (cache limit: 1000) +2016-02-08 12:32:14,730 | INFO | nsole user karaf | BrokerService | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Using Persistence Adapter: MemoryPersistenceAdapter +2016-02-08 12:32:14,731 | INFO | nsole user karaf | BrokerService | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Apache ActiveMQ 5.12.1 (broker, ID:mbp-2.local-52027-1454930701800-0:3) is starting +2016-02-08 12:32:14,731 | INFO | nsole user karaf | BrokerService | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Apache ActiveMQ 5.12.1 (broker, ID:mbp-2.local-52027-1454930701800-0:3) started +2016-02-08 12:32:14,731 | INFO | nsole user karaf | BrokerService | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | For help or more information please see: http://activemq.apache.org +2016-02-08 12:32:14,731 | WARN | nsole user karaf | BrokerService | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Memory Usage for the Broker (1024 mb) is more than the maximum available for the JVM: 455 mb - resetting to 70% of maximum available: 318 mb +2016-02-08 12:32:14,732 | INFO | nsole user karaf | TransportConnector | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Connector vm://broker started +2016-02-08 12:32:14,755 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance. +2016-02-08 12:32:14,755 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html +2016-02-08 12:32:14,762 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Route: consumer-route started and consuming from: Endpoint[sjms://sample.queue] +2016-02-08 12:32:14,763 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Total 1 routes, of which 1 is started. +2016-02-08 12:32:14,763 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Apache Camel 2.17.0 (CamelContext: osgi-example) started in 0.368 seconds +2016-02-08 12:32:14,774 | INFO | Q Session Task-1 | consumer-route | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Received message [Sample Message] from [Producer] +``` + +Hit <kbd>ctrl</kbd>+<kbd>c</kbd> to exit the log command. + +Camel commands can be used to gain some insights on the CDI Camel +context, e.g.: + +- The `camel:context-list` displays the CDI Camel context: + + ``` + karaf@root()> camel:context-list + Context Status Total # Failed # Inflight # Uptime + ------- ------ ------- -------- ---------- ------ + osgi-example Started 1 0 0 1 minute + ``` + +- The `camel:route-list` command displays the Camel route configured by the `RouteBuilder` bean: + + ``` + karaf@root()> camel:route-list + Context Route Status Total # Failed # Inflight # Uptime + ------- ----- ------ ------- -------- ---------- ------ + osgi-example consumer-route Started 1 0 0 3 minutes + ``` + +- And the `camel:route-info` command displays the exchange completed + when the `CamelContextStartedEvent` CDI event is fired: + + ``` + karaf@root()> camel:route-info consumer-route + Camel Route consumer-route + Camel Context: osgi-example + State: Started + State: Started + + Statistics + Exchanges Total: 1 + Exchanges Completed: 1 + Exchanges Failed: 0 + Exchanges Inflight: 0 + Min Processing Time: 1 ms + Max Processing Time: 1 ms + Mean Processing Time: 1 ms + Total Processing Time: 1 ms + Last Processing Time: 1 ms + Delta Processing Time: 1 ms + Start Statistics Date: 2016-02-08 12:32:14 + Reset Statistics Date: 2016-02-08 12:32:14 + First Exchange Date: 2016-02-08 12:32:14 + Last Exchange Date: 2016-02-08 12:32:14 + ``` + +Finally, you can stop the example with: + +```sh +karaf@root()> uninstall camel-example-cdi-osgi +``` + +And check in the log that the Camel context has been gracefully +shutdown: + +``` +2016-02-08 12:39:34,295 | INFO | nsole user karaf | CamelContextProducer | 149 - org.apache.camel.camel-cdi - 2.17.0.SNAPSHOT | Camel CDI is stopping Camel context [osgi-example] +2016-02-08 12:39:34,295 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Apache Camel 2.17.0 (CamelContext: osgi-example) is shutting down +2016-02-08 12:39:34,297 | INFO | nsole user karaf | DefaultShutdownStrategy | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Starting to graceful shutdown 1 routes (timeout 300 seconds) +2016-02-08 12:39:34,299 | INFO | 1 - ShutdownTask | DefaultShutdownStrategy | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Route: consumer-route shutdown complete, was consuming from: Endpoint[sjms://sample.queue] +2016-02-08 12:39:34,300 | INFO | nsole user karaf | DefaultShutdownStrategy | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Graceful shutdown of 1 routes completed in 0 seconds +2016-02-08 12:39:34,310 | INFO | nsole user karaf | TransportConnector | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Connector vm://broker stopped +2016-02-08 12:39:34,310 | INFO | nsole user karaf | BrokerService | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Apache ActiveMQ 5.12.1 (broker, ID:mbp-2.local-52027-1454930701800-0:3) is shutting down +2016-02-08 12:39:34,311 | INFO | nsole user karaf | BrokerService | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Apache ActiveMQ 5.12.1 (broker, ID:mbp-2.local-52027-1454930701800-0:3) uptime 7 minutes +2016-02-08 12:39:34,311 | INFO | nsole user karaf | BrokerService | 61 - org.apache.activemq.activemq-osgi - 5.12.1 | Apache ActiveMQ 5.12.1 (broker, ID:mbp-2.local-52027-1454930701800-0:3) is shutdown +2016-02-08 12:39:34,313 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Apache Camel 2.17.0 (CamelContext: osgi-example) uptime 7 minutes +2016-02-08 12:39:34,313 | INFO | nsole user karaf | DefaultCamelContext | 151 - org.apache.camel.camel-core - 2.17.0.SNAPSHOT | Apache Camel 2.17.0 (CamelContext: osgi-example) is shutdown in 0.018 seconds +``` + +### Forum, Help, etc + +If you hit an problems please let us know on the Camel Forums +<http://camel.apache.org/discussion-forums.html> + +Please help us make Apache Camel better - we appreciate any feedback you may have. Enjoy! + +The Camel riders! diff --git a/examples/camel-example-cdi-osgi/pom.xml b/examples/camel-example-cdi-osgi/pom.xml new file mode 100644 index 0000000..5197469 --- /dev/null +++ b/examples/camel-example-cdi-osgi/pom.xml @@ -0,0 +1,309 @@ +<?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.example</groupId> + <artifactId>examples</artifactId> + <version>2.24.1</version> + </parent> + + <artifactId>camel-example-cdi-osgi</artifactId> + <name>Camel :: Example :: CDI :: OSGi (deprecated)</name> + <description>PAX CDI example</description> + <packaging>jar</packaging> + + <properties> + <category>OSGi</category> + <title>CDI OSGi</title> + </properties> + + <dependencies> + + <!-- CDI API --> + <dependency> + <groupId>javax.enterprise</groupId> + <artifactId>cdi-api</artifactId> + <version>${cdi-api-1.2-version}</version> + <scope>provided</scope> + </dependency> + + <!-- Camel --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-cdi</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-sjms</artifactId> + </dependency> + + <!-- ActiveMQ --> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>activemq-client</artifactId> + </dependency> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>activemq-broker</artifactId> + <scope>runtime</scope> + </dependency> + + <!-- OSGi API --> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <scope>provided</scope> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>runtime</scope> + </dependency> + + <!-- test --> + + <!-- PAX Exam --> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-spi</artifactId> + <version>${pax-exam-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-junit4</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-container-karaf</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.url</groupId> + <artifactId>pax-url-aether</artifactId> + <version>2.4.5</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.ops4j.pax.tinybundles</groupId> + <artifactId>tinybundles</artifactId> + <version>2.1.1</version> + <scope>test</scope> + </dependency> + + <!-- Karaf & Command Shell --> + <dependency> + <groupId>org.apache.karaf</groupId> + <artifactId>apache-karaf</artifactId> + <version>${karaf4-version}</version> + <type>zip</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.apache.karaf.features</groupId> + <artifactId>framework</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.core</artifactId> + <version>${karaf4-version}</version> + <scope>test</scope> + </dependency> + + <!-- Karaf Camel commands --> + <dependency> + <groupId>org.apache.camel.karaf</groupId> + <artifactId>camel-karaf-commands</artifactId> + <version>${project.version}</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.console</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.karaf</groupId> + <artifactId>org.apache.karaf.util</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-commands-core</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-catalog</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + + <!-- Karaf Features --> + <dependency> + <groupId>org.ops4j.pax.cdi</groupId> + <artifactId>pax-cdi-features</artifactId> + <version>${pax-cdi-version}</version> + <classifier>features</classifier> + <type>xml</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.camel.karaf</groupId> + <artifactId>apache-camel</artifactId> + <version>${project.version}</version> + <classifier>features</classifier> + <type>xml</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.activemq</groupId> + <artifactId>activemq-karaf</artifactId> + <version>${activemq-version}</version> + <classifier>features</classifier> + <type>xml</type> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>*</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> + </dependency> + + </dependencies> + + <build> + <!-- Easier to get the local artifact from the integration tests --> + <finalName>${project.artifactId}</finalName> + + <plugins> + + <!-- Camel plugin to run the example in Java SE --> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-maven-plugin</artifactId> + <version>${project.version}</version> + <dependencies> + <dependency> + <groupId>org.apache.deltaspike.cdictrl</groupId> + <artifactId>deltaspike-cdictrl-weld</artifactId> + <version>${deltaspike-version}</version> + </dependency> + <dependency> + <groupId>org.jboss.weld.se</groupId> + <artifactId>weld-se</artifactId> + <version>${weld2-version}</version> + </dependency> + </dependencies> + </plugin> + + <plugin> + <groupId>org.apache.servicemix.tooling</groupId> + <artifactId>depends-maven-plugin</artifactId> + <executions> + <execution> + <id>generate-depends-file</id> + <goals> + <goal>generate-depends-file</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName> + <Export-Package>org.apache.camel.example.cdi.osgi*</Export-Package> + <Import-Package>*</Import-Package> + <Require-Capability> + osgi.extender; filter:="(osgi.extender=pax.cdi)", + org.ops4j.pax.cdi.extension; filter:="(extension=camel-cdi-extension)" + </Require-Capability> + </instructions> + </configuration> + </plugin> + + </plugins> + </build> + + <profiles> + <profile> + <id>integration</id> + <build> + <plugins> + <!-- Execute in the integration-test phase so that the packaged JAR can be used --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <phase>integration-test</phase> + <goals> + <goal>test</goal> + </goals> + <configuration> + <includes> + <include>**/*IT.java</include> + </includes> + <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + +</project> diff --git a/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Config.java b/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Config.java new file mode 100644 index 0000000..4af90c5 --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Config.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.example.cdi.osgi; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Named; + +import org.apache.camel.component.properties.PropertiesComponent; + +public class Config { + + @Produces + @ApplicationScoped + @Named("properties") + PropertiesComponent properties() { + PropertiesComponent component = new PropertiesComponent(); + component.setLocation("classpath:jms.properties"); + return component; + } +} diff --git a/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Consumer.java b/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Consumer.java new file mode 100644 index 0000000..b524f45 --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Consumer.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.example.cdi.osgi; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.cdi.ContextName; + +@ContextName("osgi-example") +public class Consumer extends RouteBuilder { + + @Override + public void configure() { + from("sjms:sample.queue") + .routeId("consumer-route") + .log("Received message [${body}] from [${header.Sender}]"); + } +} diff --git a/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Jms.java b/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Jms.java new file mode 100644 index 0000000..fe71c42 --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Jms.java @@ -0,0 +1,41 @@ +/** + * 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.example.cdi.osgi; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Produces; +import javax.inject.Named; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.camel.PropertyInject; +import org.apache.camel.component.sjms.SjmsComponent; + +public class Jms { + + @PropertyInject("jms.maxConnections") + int maxConnections; + + @Produces + @Named("sjms") + @ApplicationScoped + SjmsComponent sjms() { + SjmsComponent component = new SjmsComponent(); + component.setConnectionFactory(new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useShutdownHook=false&broker.useJmx=false")); + component.setConnectionCount(maxConnections); + return component; + } +} \ No newline at end of file diff --git a/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Producer.java b/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Producer.java new file mode 100644 index 0000000..dd508cc --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/java/org/apache/camel/example/cdi/osgi/Producer.java @@ -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. + */ +package org.apache.camel.example.cdi.osgi; + +import javax.enterprise.event.Observes; + +import org.apache.camel.ProducerTemplate; +import org.apache.camel.cdi.Uri; +import org.apache.camel.management.event.CamelContextStartedEvent; + +public class Producer { + + void sendMessage(@Observes CamelContextStartedEvent event, @Uri("sjms:sample.queue") ProducerTemplate producer) { + producer.sendBodyAndHeader("Sample Message", "Sender", getClass().getSimpleName()); + } +} diff --git a/examples/camel-example-cdi-osgi/src/main/resources/META-INF/LICENSE.txt b/examples/camel-example-cdi-osgi/src/main/resources/META-INF/LICENSE.txt new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/resources/META-INF/LICENSE.txt @@ -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. + diff --git a/examples/camel-example-cdi-osgi/src/main/resources/META-INF/NOTICE.txt b/examples/camel-example-cdi-osgi/src/main/resources/META-INF/NOTICE.txt new file mode 100644 index 0000000..2e215bf --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/resources/META-INF/NOTICE.txt @@ -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. diff --git a/examples/camel-example-cdi-osgi/src/main/resources/META-INF/beans.xml b/examples/camel-example-cdi-osgi/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..4d1f3eb --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/resources/META-INF/beans.xml @@ -0,0 +1,20 @@ +<?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 diff --git a/examples/camel-example-cdi-osgi/src/main/resources/jms.properties b/examples/camel-example-cdi-osgi/src/main/resources/jms.properties new file mode 100644 index 0000000..645fb22 --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/resources/jms.properties @@ -0,0 +1,18 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +jms.maxConnections=4 diff --git a/examples/camel-example-cdi-osgi/src/main/resources/log4j2.properties b/examples/camel-example-cdi-osgi/src/main/resources/log4j2.properties new file mode 100644 index 0000000..9deb51c --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/main/resources/log4j2.properties @@ -0,0 +1,23 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- + +appender.console.type = Console +appender.console.name = console +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +rootLogger.level = INFO +rootLogger.appenderRef.console.ref = console diff --git a/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java b/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java index bd17736..2d7aaba 100644 --- a/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java +++ b/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/CdiOsgiIT.java @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -83,7 +83,7 @@ public class CdiOsgiIT { @Test public void testRouteStatus() { assertThat("Route status is incorrect!", - context.getRouteController().getRouteStatus("consumer-route"), equalTo(ServiceStatus.Started)); + context.getRouteStatus("consumer-route"), equalTo(ServiceStatus.Started)); } @Test diff --git a/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/PaxExamOptions.java b/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/PaxExamOptions.java new file mode 100644 index 0000000..5d1287c --- /dev/null +++ b/examples/camel-example-cdi-osgi/src/test/java/org/apache/camel/example/cdi/osgi/PaxExamOptions.java @@ -0,0 +1,116 @@ +/** + * 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.example.cdi.osgi; + +import java.io.File; + +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.karaf.options.LogLevelOption; +import org.ops4j.pax.exam.options.DefaultCompositeOption; + +import static org.ops4j.pax.exam.CoreOptions.maven; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.logLevel; + +public enum PaxExamOptions { + + KARAF( + karafDistributionConfiguration() + .frameworkUrl( + maven() + .groupId("org.apache.karaf") + .artifactId("apache-karaf") + .versionAsInProject() + .type("zip")) + .name("Apache Karaf") + .useDeployFolder(false) + .unpackDirectory(new File("target/paxexam/unpack/")), + keepRuntimeFolder(), + // Don't bother with local console output as it just ends up cluttering the logs + configureConsole().ignoreLocalConsole(), + // Force the log level to INFO so we have more details during the test. It defaults to WARN. + logLevel(LogLevelOption.LogLevel.INFO) + ), + CAMEL_COMMANDS( + mavenBundle() + .groupId("org.apache.camel.karaf") + .artifactId("camel-karaf-commands") + .versionAsInProject(), + mavenBundle() + .groupId("org.apache.camel") + .artifactId("camel-commands-core") + .versionAsInProject(), + mavenBundle() + .groupId("org.apache.camel") + .artifactId("camel-catalog") + .versionAsInProject() + ), + PAX_CDI_IMPL( + features( + maven() + .groupId("org.ops4j.pax.cdi") + .artifactId("pax-cdi-features") + .type("xml") + .classifier("features") + .versionAsInProject(), + "pax-cdi-weld") + ), + CAMEL_CDI( + features( + maven() + .groupId("org.apache.camel.karaf") + .artifactId("apache-camel") + .type("xml") + .classifier("features") + .versionAsInProject(), + "camel-cdi") + ), + CAMEL_SJMS( + mavenBundle() + .groupId("org.apache.camel") + .artifactId("camel-sjms") + .versionAsInProject(), + mavenBundle() + .groupId("commons-pool") + .artifactId("commons-pool") + .versionAsInProject() + ), + ACTIVEMQ( + features( + maven() + .groupId("org.apache.activemq") + .artifactId("activemq-karaf") + .type("xml") + .classifier("features") + .versionAsInProject(), + "activemq-broker-noweb") + ); + + private final Option[] options; + + PaxExamOptions(Option... options) { + this.options = options; + } + + public Option option() { + return new DefaultCompositeOption(options); + } +}