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/23 08:35:45 UTC

[camel-kamelets-examples] branch main updated: Add example with DSL transform from xml to yaml

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 bd7cad8  Add example with DSL transform from xml to yaml
bd7cad8 is described below

commit bd7cad8492b8541d6c4e2c6b96a3c81d9ebd73b9
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 23 09:34:46 2023 +0200

    Add example with DSL transform from xml to yaml
---
 jbang/xml-to-yaml/.gitignore             |  1 +
 jbang/xml-to-yaml/OrderService.java      | 19 ++++++++++
 jbang/xml-to-yaml/README.adoc            | 61 ++++++++++++++++++++++++++++++++
 jbang/xml-to-yaml/application.properties |  5 +++
 jbang/xml-to-yaml/order.xml              | 18 ++++++++++
 5 files changed, 104 insertions(+)

diff --git a/jbang/xml-to-yaml/.gitignore b/jbang/xml-to-yaml/.gitignore
new file mode 100644
index 0000000..11c58b7
--- /dev/null
+++ b/jbang/xml-to-yaml/.gitignore
@@ -0,0 +1 @@
+dump
\ No newline at end of file
diff --git a/jbang/xml-to-yaml/OrderService.java b/jbang/xml-to-yaml/OrderService.java
new file mode 100644
index 0000000..17935ac
--- /dev/null
+++ b/jbang/xml-to-yaml/OrderService.java
@@ -0,0 +1,19 @@
+package com.foo;
+
+public class OrderService {
+
+   private String customer;
+
+   public void setCustomer(String customer) {
+       this.customer = customer;
+   }
+
+   public String getCustomer() {
+   	   return customer;
+   }
+
+   public String processorOrder(String id) {
+       return "Order " + id + " ordered by " + customer;
+   }
+
+}
\ No newline at end of file
diff --git a/jbang/xml-to-yaml/README.adoc b/jbang/xml-to-yaml/README.adoc
new file mode 100644
index 0000000..976d9ea
--- /dev/null
+++ b/jbang/xml-to-yaml/README.adoc
@@ -0,0 +1,61 @@
+== XML to YAML
+
+This example shows XML DSL with both bean and routes using the new <camel> root tag.
+
+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 --directory=my-dump
+----
+
+This will transform the Camel XML DSL into YAML 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/xml-to-yaml/application.properties b/jbang/xml-to-yaml/application.properties
new file mode 100644
index 0000000..4c10dbe
--- /dev/null
+++ b/jbang/xml-to-yaml/application.properties
@@ -0,0 +1,5 @@
+# dump routes to YAML in dump folder
+camel.main.dump-routes=yaml
+camel.main.dump-routes-include=all
+camel.main.dump-routes-directory=dump
+camel.main.dump-routes-uri-as-parameters=true
\ No newline at end of file
diff --git a/jbang/xml-to-yaml/order.xml b/jbang/xml-to-yaml/order.xml
new file mode 100644
index 0000000..1ef2c07
--- /dev/null
+++ b/jbang/xml-to-yaml/order.xml
@@ -0,0 +1,18 @@
+<camel>
+
+    <bean name="orderService" type="com.foo.OrderService">
+        <properties>
+            <property key="customer" value="Acme"/>
+        </properties>
+    </bean>
+
+    <route>
+        <from uri="timer:xml?period={{time:1000}}"/>
+        <setBody>
+            <simple>${random(1000)}</simple>
+        </setBody>
+        <bean ref="orderService"/>
+        <log message="${body}"/>
+    </route>
+
+</camel>