This is an automated email from the ASF dual-hosted git repository. jbonofre pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/master by this push: new 6cfd130 Upgrade to Apache Camel 3.4.3 and add camel core example new ed3d6dd Merge pull request #1170 from jbonofre/CAMEL_CORE 6cfd130 is described below commit 6cfd1300fc8d7bbd2615411f2de2f990eb85d1a2 Author: jbonofre <jbono...@apache.org> AuthorDate: Fri Aug 28 21:59:33 2020 +0200 Upgrade to Apache Camel 3.4.3 and add camel core example --- examples/karaf-camel-example/README.md | 6 +- .../main/resources/OSGI-INF/blueprint/route.xml | 16 ++-- .../src/main/feature/feature.xml | 20 ++-- .../karaf-camel-example-java/pom.xml | 12 ++- .../karaf/examples/camel/java/CamelComponent.java | 102 +++++++++++++++++++++ .../camel/java/ExampleCamelRouteBuilder.java | 66 ------------- .../main/resources/OSGI-INF/blueprint/route.xml | 27 ------ examples/karaf-profile-example/pom.xml | 4 + pom.xml | 2 +- 9 files changed, 138 insertions(+), 117 deletions(-) diff --git a/examples/karaf-camel-example/README.md b/examples/karaf-camel-example/README.md index 666c4f9..aae5691 100644 --- a/examples/karaf-camel-example/README.md +++ b/examples/karaf-camel-example/README.md @@ -24,11 +24,11 @@ This example shows how to use Apache Camel in Karaf. Apache Camel is a integrati Apache Camel supports several DSL. This example shows how to use the Camel Java DSL and the Camel Blueprint DSL. -It creates several Camel routes, exposing a HTTP endpoint and using a Content Based Router EIP (Enterprise Integration Pattern). +It creates several Camel routes, exposing HTTP endpoint and using a Content Based Router EIP (Enterprise Integration Pattern). ## Artifacts -* **karaf-camel-example-java** is a bundle containing routes described using the Camel Java DSL. +* **karaf-camel-example-java** is a bundle containing routes described using the Camel Java DSL loaded by SCR. * **karaf-camel-example-blueprint** is just a wrapper containing routes described using Blueprint. Karaf supports deployment of this DSL directly (in the deploy folder for instance) or packaged as a bundle. * **karaf-camel-example-features** provides a Karaf features repository used for the deployment. @@ -60,7 +60,7 @@ karaf@root()> feature:install karaf-camel-example-blueprint ## Usage -Once you have install a Camel feature, the main route is started and bind a HTTP endpoint on `http://localhost:9090/example`. +Once you have installed a Camel feature, the main route started and bind HTTP endpoint on `http://localhost:9090/example`. We can test payloads testing different paths of the content based router. diff --git a/examples/karaf-camel-example/karaf-camel-example-blueprint/src/main/resources/OSGI-INF/blueprint/route.xml b/examples/karaf-camel-example/karaf-camel-example-blueprint/src/main/resources/OSGI-INF/blueprint/route.xml index 00fa7bb..093bcd6 100644 --- a/examples/karaf-camel-example/karaf-camel-example-blueprint/src/main/resources/OSGI-INF/blueprint/route.xml +++ b/examples/karaf-camel-example/karaf-camel-example-blueprint/src/main/resources/OSGI-INF/blueprint/route.xml @@ -26,7 +26,7 @@ <choice> <when> <simple>${headers.CamelHttpMethod} == 'POST'</simple> - <setHeader headerName="type"> + <setHeader name="type"> <jsonpath>$.notification.type</jsonpath> </setHeader> <choice> @@ -34,33 +34,33 @@ <simple>${header.type} == 'email'</simple> <log message="[EXAMPLE INBOUND] Received email notification"/> <to uri="direct:email"/> - <setHeader headerName="Exchange.HTTP_RESPONSE_CODE"><constant>200</constant></setHeader> + <setHeader name="Exchange.HTTP_RESPONSE_CODE"><constant>200</constant></setHeader> </when> <when> <simple>${header.type} == 'http'</simple> <log message="[EXAMPLE INBOUND] Received http notification"/> <to uri="direct:http"/> - <setHeader headerName="Exchange.HTTP_RESPONSE_CODE"><constant>200</constant></setHeader> + <setHeader name="Exchange.HTTP_RESPONSE_CODE"><constant>200</constant></setHeader> </when> <otherwise> <log message="[EXAMPLE INBOUND] Unknown notification"/> <setBody><constant>{ "status": "reject", "type": "unknown" }</constant></setBody> - <setHeader headerName="Exchange.HTTP_RESPONSE_CODE"><constant>400</constant></setHeader> + <setHeader name="Exchange.HTTP_RESPONSE_CODE"><constant>400</constant></setHeader> </otherwise> </choice> </when> <otherwise> <log message="[EXAMPLE INBOUND] only POST is accepted (${headers.CamelHttpMethod})"/> <setBody><constant>{ "error": "only POST is accepted" }</constant></setBody> - <setHeader headerName="Exchange.HTTP_RESPONSE_CODE"><constant>500</constant></setHeader> + <setHeader name="Exchange.HTTP_RESPONSE_CODE"><constant>500</constant></setHeader> </otherwise> </choice> </route> <route id="example-email"> <from uri="direct:email"/> <log message="[EXAMPLE EMAIL] Sending notification email"/> - <setHeader headerName="to"><jsonpath>$.notification.to</jsonpath></setHeader> - <setHeader headerName="subject"><constant>Notification</constant></setHeader> + <setHeader name="to"><jsonpath>$.notification.to</jsonpath></setHeader> + <setHeader name="subject"><constant>Notification</constant></setHeader> <setBody><jsonpath>$.notification.message</jsonpath></setBody> <!-- <to uri="smtp://localhost"/> --> <setBody><simple>{ "status": "email sent", "to": "${header.to}", "subject": "${header.subject}" }</simple></setBody> @@ -68,7 +68,7 @@ <route id="example-http"> <from uri="direct:http"/> <log message="[EXAMPLE HTTP] Sending http notification"/> - <setHeader headerName="service"><jsonpath>$.notification.service</jsonpath></setHeader> + <setHeader name="service"><jsonpath>$.notification.service</jsonpath></setHeader> <!-- <to uri="jetty:..." /> --> <setBody><simple>{ "status": "http requested", "service": "${header.service}" }</simple></setBody> </route> diff --git a/examples/karaf-camel-example/karaf-camel-example-features/src/main/feature/feature.xml b/examples/karaf-camel-example/karaf-camel-example-features/src/main/feature/feature.xml index 92f485c..9073f4b 100644 --- a/examples/karaf-camel-example/karaf-camel-example-features/src/main/feature/feature.xml +++ b/examples/karaf-camel-example/karaf-camel-example-features/src/main/feature/feature.xml @@ -20,7 +20,16 @@ <repository>mvn:org.apache.camel.karaf/apache-camel/${camel.version}/xml/features</repository> - <feature name="karaf-camel-example-common" version="${project.version}"> + <feature name="karaf-camel-example-java" version="${project.version}"> + <feature>scr</feature> + <feature>camel-core</feature> + <feature>camel-jetty</feature> + <feature>camel-jsonpath</feature> + <feature>camel-mail</feature> + <bundle>mvn:org.apache.karaf.examples/karaf-camel-example-core/${project.version}</bundle> + </feature> + + <feature name="karaf-camel-example-blueprint" version="${project.version}"> <feature prerequisite="true">aries-blueprint</feature> <feature>camel-blueprint</feature> <feature>camel-jetty</feature> @@ -29,15 +38,6 @@ <capability> osgi.service;objectClass=org.apache.aries.blueprint.NamespaceHandler;osgi.service.blueprint.namespace=http://camel.apache.org/schema/blueprint;effective:=active; </capability> - </feature> - - <feature name="karaf-camel-example-java" version="${project.version}"> - <feature version="${project.version}">karaf-camel-example-common</feature> - <bundle>mvn:org.apache.karaf.examples/karaf-camel-example-java/${project.version}</bundle> - </feature> - - <feature name="karaf-camel-example-blueprint" version="${project.version}"> - <feature version="${project.version}">karaf-camel-example-common</feature> <bundle>blueprint:mvn:org.apache.karaf.examples/karaf-camel-example-blueprint/${project.version}/xml/route</bundle> </feature> diff --git a/examples/karaf-camel-example/karaf-camel-example-java/pom.xml b/examples/karaf-camel-example/karaf-camel-example-java/pom.xml index c0ff905..cb4999d 100644 --- a/examples/karaf-camel-example/karaf-camel-example-java/pom.xml +++ b/examples/karaf-camel-example/karaf-camel-example-java/pom.xml @@ -34,10 +34,18 @@ <dependencies> <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-core</artifactId> + <groupId>org.apache.camel.karaf</groupId> + <artifactId>camel-core-osgi</artifactId> <version>${camel.version}</version> </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + </dependency> </dependencies> <build> diff --git a/examples/karaf-camel-example/karaf-camel-example-java/src/main/java/org/apache/karaf/examples/camel/java/CamelComponent.java b/examples/karaf-camel-example/karaf-camel-example-java/src/main/java/org/apache/karaf/examples/camel/java/CamelComponent.java new file mode 100644 index 0000000..4fd9556 --- /dev/null +++ b/examples/karaf-camel-example/karaf-camel-example-java/src/main/java/org/apache/karaf/examples/camel/java/CamelComponent.java @@ -0,0 +1,102 @@ +/* + * 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.karaf.examples.camel.java; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.core.osgi.OsgiDefaultCamelContext; +import org.apache.camel.model.ModelCamelContext; +import org.apache.camel.model.RouteDefinition; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; + +import java.util.ArrayList; + +@Component( + name = "karaf-camel-example-java", + immediate = true +) +public class CamelComponent { + + private BundleContext bundleContext; + private ModelCamelContext camelContext; + private ServiceRegistration<CamelContext> serviceRegistration; + + @Activate + public void activate(ComponentContext componentContext) throws Exception { + bundleContext = componentContext.getBundleContext(); + camelContext = new OsgiDefaultCamelContext(bundleContext); + serviceRegistration = bundleContext.registerService(CamelContext.class, camelContext, null); + camelContext.start(); + camelContext.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://0.0.0.0:9090/example") + .id("example-http-inbound") + .convertBodyTo(String.class) + .log("[EXAMPLE INBOUND] Received: ${body}") + .choice() + .when().simple("${headers.CamelHttpMethod} == 'POST'") + .setHeader("type").jsonpath("$.notification.type") + .choice() + .when().simple("${header.type} == 'email'") + .log("[EXAMPLE INBOUND] Received email notification") + .to("direct:email") + .setHeader("Exchange.HTTP_RESPONSE_CODE", constant(200)) + .when().simple("${header.type} == 'http'") + .log("[EXAMPLE INBOUND] Received http notification") + .to("direct:http") + .setHeader("Exchange.HTTP_RESPONSE_CODE", constant(200)) + .otherwise() + .log("[EXAMPLE INBOUND] Unknown notification") + .setBody(constant("{ \"status\": \"reject\", \"type\": \"unknown\" }")) + .setHeader("Exchange.HTTP_RESPONSE_CODE", constant(400)) + .otherwise() + .log("[EXAMPLE INBOUND] only POST is accepted (${headers.CamelHttpMethod})") + .setBody(constant("{ \"error\": \"only POST is accepted\" }")) + .setHeader("Exchange.HTTP_RESPONSE_CODE", constant(500)); + + from("direct:email") + .id("example-email") + .log("[EXAMPLE EMAIL] Sending notification email") + .setHeader("to").jsonpath("$.notification.to") + .setHeader("subject", constant("Notification")) + .setHeader("payload").jsonpath("$.notification.message") + //.to("smtp://localhost"); + .setBody(simple("{ \"status\": \"email sent\", \"to\": \"${header.to}\", \"subject\": \"${header.subject}\" }")); + + from("direct:http") + .id("example-http") + .log("[EXAMPLE HTTP] Sending http notification") + .setHeader("service").jsonpath("$.notification.service") + // send to HTTP service + .setBody(simple("{ \"status\": \"http requested\", \"service\": \"${header.service}\" }")); + } + }); + } + + @Deactivate + public void deactivate() throws Exception { + camelContext.stop(); + camelContext.removeRouteDefinitions(new ArrayList<RouteDefinition>(camelContext.getRouteDefinitions())); + bundleContext.ungetService(serviceRegistration.getReference()); + } + +} diff --git a/examples/karaf-camel-example/karaf-camel-example-java/src/main/java/org/apache/karaf/examples/camel/java/ExampleCamelRouteBuilder.java b/examples/karaf-camel-example/karaf-camel-example-java/src/main/java/org/apache/karaf/examples/camel/java/ExampleCamelRouteBuilder.java deleted file mode 100644 index 9d21e66..0000000 --- a/examples/karaf-camel-example/karaf-camel-example-java/src/main/java/org/apache/karaf/examples/camel/java/ExampleCamelRouteBuilder.java +++ /dev/null @@ -1,66 +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.karaf.examples.camel.java; - -import org.apache.camel.builder.RouteBuilder; - -public class ExampleCamelRouteBuilder extends RouteBuilder { - - @Override - public void configure() throws Exception { - from("jetty:http://0.0.0.0:9090/example") - .id("example-http-inbound") - .convertBodyTo(String.class) - .log("[EXAMPLE INBOUND] Received: ${body}") - .choice() - .when().simple("${headers.CamelHttpMethod} == 'POST'") - .setHeader("type").jsonpath("$.notification.type") - .choice() - .when().simple("${header.type} == 'email'") - .log("[EXAMPLE INBOUND] Received email notification") - .to("direct:email") - .setHeader("Exchange.HTTP_RESPONSE_CODE", constant(200)) - .when().simple("${header.type} == 'http'") - .log("[EXAMPLE INBOUND] Received http notification") - .to("direct:http") - .setHeader("Exchange.HTTP_RESPONSE_CODE", constant(200)) - .otherwise() - .log("[EXAMPLE INBOUND] Unknown notification") - .setBody(constant("{ \"status\": \"reject\", \"type\": \"unknown\" }")) - .setHeader("Exchange.HTTP_RESPONSE_CODE", constant(400)) - .otherwise() - .log("[EXAMPLE INBOUND] only POST is accepted (${headers.CamelHttpMethod})") - .setBody(constant("{ \"error\": \"only POST is accepted\" }")) - .setHeader("Exchange.HTTP_RESPONSE_CODE", constant(500)); - - from("direct:email") - .id("example-email") - .log("[EXAMPLE EMAIL] Sending notification email") - .setHeader("to").jsonpath("$.notification.to") - .setHeader("subject", constant("Notification")) - .setHeader("payload").jsonpath("$.notification.message") - //.to("smtp://localhost"); - .setBody(simple("{ \"status\": \"email sent\", \"to\": \"${header.to}\", \"subject\": \"${header.subject}\" }")); - - from("direct:http") - .id("example-http") - .log("[EXAMPLE HTTP] Sending http notification") - .setHeader("service").jsonpath("$.notification.service") - // send to HTTP service - .setBody(simple("{ \"status\": \"http requested\", \"service\": \"${header.service}\" }")); - } - -} diff --git a/examples/karaf-camel-example/karaf-camel-example-java/src/main/resources/OSGI-INF/blueprint/route.xml b/examples/karaf-camel-example/karaf-camel-example-java/src/main/resources/OSGI-INF/blueprint/route.xml deleted file mode 100644 index 3adb646..0000000 --- a/examples/karaf-camel-example/karaf-camel-example-java/src/main/resources/OSGI-INF/blueprint/route.xml +++ /dev/null @@ -1,27 +0,0 @@ -<?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. ---> -<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> - - <bean id="routeBuilder" class="org.apache.karaf.examples.camel.java.ExampleCamelRouteBuilder"/> - - <camelContext xmlns="http://camel.apache.org/schema/blueprint"> - <routeBuilder ref="routeBuilder"/> - </camelContext> - -</blueprint> \ No newline at end of file diff --git a/examples/karaf-profile-example/pom.xml b/examples/karaf-profile-example/pom.xml index 06ed1e8..9715d9d 100644 --- a/examples/karaf-profile-example/pom.xml +++ b/examples/karaf-profile-example/pom.xml @@ -32,6 +32,10 @@ <name>Apache Karaf :: Examples :: Profile</name> <packaging>pom</packaging> + <properties> + <camel.version>2.24.3</camel.version> + </properties> + <modules> <module>karaf-profile-example-registry</module> <module>karaf-profile-example-dynamic</module> diff --git a/pom.xml b/pom.xml index e025452..68e9af3 100644 --- a/pom.xml +++ b/pom.xml @@ -147,7 +147,7 @@ <javax.annotation.version>1.3.1</javax.annotation.version> <awaitility.version>3.1.6</awaitility.version> <bouncycastle.version>1.62</bouncycastle.version> - <camel.version>2.24.3</camel.version> + <camel.version>3.4.3</camel.version> <cglib.bundle.version>3.2.9_1</cglib.bundle.version> <cxf.version>3.3.5</cxf.version> <jackson.version>2.10.4</jackson.version>