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 2023/08/30 11:58:49 UTC

[camel-kamelets-examples] branch main updated: camel-jbang - Allow to load OSGi with embedded

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new 93bd84c  camel-jbang - Allow to load OSGi <blueprint> with embedded <camelContext>
93bd84c is described below

commit 93bd84c9a8980978b405dd8701e737fc62f9ac15
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 30 07:41:57 2023 +0200

    camel-jbang - Allow to load OSGi <blueprint> with embedded <camelContext>
---
 jbang/blueprint-to-yaml/.gitignore             |  2 +
 jbang/blueprint-to-yaml/Address.java           | 24 ++++++++++
 jbang/blueprint-to-yaml/OrderService.java      | 35 +++++++++++++++
 jbang/blueprint-to-yaml/README.adoc            | 61 ++++++++++++++++++++++++++
 jbang/blueprint-to-yaml/application.properties |  2 +
 jbang/blueprint-to-yaml/order-blueprint.xml    | 32 ++++++++++++++
 6 files changed, 156 insertions(+)

diff --git a/jbang/blueprint-to-yaml/.gitignore b/jbang/blueprint-to-yaml/.gitignore
new file mode 100644
index 0000000..898d599
--- /dev/null
+++ b/jbang/blueprint-to-yaml/.gitignore
@@ -0,0 +1,2 @@
+dump
+my-dump
\ No newline at end of file
diff --git a/jbang/blueprint-to-yaml/Address.java b/jbang/blueprint-to-yaml/Address.java
new file mode 100644
index 0000000..c251979
--- /dev/null
+++ b/jbang/blueprint-to-yaml/Address.java
@@ -0,0 +1,24 @@
+package com.foo;
+
+public class Address {
+
+	private int zip;
+	private String street;
+
+	public int getZip() {
+		return zip;
+	}
+
+	public void setZip(int zip) {
+		this.zip = zip;
+	}
+
+	public String getStreet() {
+		return street;
+	}
+
+	public void setStreet(String street) {
+		this.street = street;
+	}
+
+}
\ No newline at end of file
diff --git a/jbang/blueprint-to-yaml/OrderService.java b/jbang/blueprint-to-yaml/OrderService.java
new file mode 100644
index 0000000..3f2e86c
--- /dev/null
+++ b/jbang/blueprint-to-yaml/OrderService.java
@@ -0,0 +1,35 @@
+package com.foo;
+
+import com.foo.Address;
+
+public class OrderService {
+
+   private String customer;
+   private Address address;
+
+   public OrderService(boolean customer, Address address) {
+       this.customer = customer ? "Acme" : "None";
+       this.address = address;
+   }
+
+   public void setCustomer(String customer) {
+       this.customer = customer;
+   }
+
+   public String getCustomer() {
+   	   return customer;
+   }
+
+   public void setAddress(Address address) {
+       this.address = address;
+   }
+
+   public Address getAddress() {
+       return address;
+   }   
+
+   public String processorOrder(String id) {
+       return "Order2 " + id + " ordered by " + customer + " to " + address.getStreet();
+   }
+
+}
\ No newline at end of file
diff --git a/jbang/blueprint-to-yaml/README.adoc b/jbang/blueprint-to-yaml/README.adoc
new file mode 100644
index 0000000..a2d4bcb
--- /dev/null
+++ b/jbang/blueprint-to-yaml/README.adoc
@@ -0,0 +1,61 @@
+== XML to YAML
+
+This example shows legacy OSGi Blueprint XML file with <blueprint> and <camelContext> with embedded <route>.
+
+The XML can be migrated to YAML DSL using Camel JBang.
+
+=== Install JBang
+
+First install JBang according to https://www.jbang.dev
+
+When JBang is installed then you should be able to run from a shell:
+
+[source,sh]
+----
+$ jbang --version
+----
+
+This will output the version of JBang.
+
+To run this example you can either install Camel on JBang via:
+
+[source,sh]
+----
+$ jbang app install camel@apache/camel
+----
+
+Which allows to run CamelJBang with `camel` as shown below.
+
+=== How to run
+
+Then you can run this example using:
+
+[source,sh]
+----
+$ camel run *
+----
+
+=== Transforming to YAML
+
+The example will on startup transform the source from XML to YAML and save
+this into dump sub directory.
+
+This can also be done explicit from CLI, by executing:
+
+[source,sh]
+----
+$ camel transform * --format=yaml --output=my-dump
+----
+
+This will transform the XML DSL into YAML DSL and store the output in the my-dump directory.
+
+
+=== Help and contributions
+
+If you hit any problem using Camel or have some feedback, then please
+https://camel.apache.org/community/support/[let us know].
+
+We also love contributors, so
+https://camel.apache.org/community/contributing/[get involved] :-)
+
+The Camel riders!
diff --git a/jbang/blueprint-to-yaml/application.properties b/jbang/blueprint-to-yaml/application.properties
new file mode 100644
index 0000000..ef1be51
--- /dev/null
+++ b/jbang/blueprint-to-yaml/application.properties
@@ -0,0 +1,2 @@
+zipCode = 90210
+streetName = Gardenstreet 444
diff --git a/jbang/blueprint-to-yaml/order-blueprint.xml b/jbang/blueprint-to-yaml/order-blueprint.xml
new file mode 100644
index 0000000..b71d868
--- /dev/null
+++ b/jbang/blueprint-to-yaml/order-blueprint.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="
+           http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+   <!-- beans -->
+   <bean id="orderService" class="com.foo.OrderService">
+       <argument index="0" value="true"/>
+       <argument index="1" ref="office"/>
+   </bean> 
+   <!-- uses blueprint property placeholder ${xxx} syntax -->
+   <bean id="office" class="com.foo.Address">
+       <property name="zip" value="${zipCode}"/>
+       <property name="street" value="${streetName}"/>
+   </bean>
+
+  <!-- embed Camel with routes -->
+  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+    <route>
+        <from uri="timer:xml?period={{time:1000}}"/>
+        <setBody>
+            <simple>${random(1000)}</simple>
+        </setBody>
+        <bean ref="orderService"/>
+        <log message="${body}"/>
+    </route>
+
+  </camelContext>
+
+</blueprint>