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 ca45ec1 Add type converter example ca45ec1 is described below commit ca45ec13fea1f12d78967447fbbb80645590d114 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Fri Oct 28 13:03:04 2022 +0200 Add type converter example --- jbang/type-converter/Cat.java | 16 +++++++++ jbang/type-converter/Dog.java | 16 +++++++++ jbang/type-converter/MyConverter.java | 10 ++++++ jbang/type-converter/MyRoute.java | 17 ++++++++++ jbang/type-converter/README.adoc | 63 +++++++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+) diff --git a/jbang/type-converter/Cat.java b/jbang/type-converter/Cat.java new file mode 100644 index 0000000..d53952a --- /dev/null +++ b/jbang/type-converter/Cat.java @@ -0,0 +1,16 @@ +public class Cat { + + private final String name; + + public Cat(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String say() { + return name + " mjaus"; + } +} \ No newline at end of file diff --git a/jbang/type-converter/Dog.java b/jbang/type-converter/Dog.java new file mode 100644 index 0000000..9841db9 --- /dev/null +++ b/jbang/type-converter/Dog.java @@ -0,0 +1,16 @@ +public class Dog { + + private final String name; + + public Dog(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public String say() { + return name + " barks"; + } +} \ No newline at end of file diff --git a/jbang/type-converter/MyConverter.java b/jbang/type-converter/MyConverter.java new file mode 100644 index 0000000..0407cc4 --- /dev/null +++ b/jbang/type-converter/MyConverter.java @@ -0,0 +1,10 @@ +import org.apache.camel.Converter; + +@Converter +public class MyConverter { + + @Converter + public static Dog catToDog(Cat cat) { + return new Dog(cat.getName()); + } +} \ No newline at end of file diff --git a/jbang/type-converter/MyRoute.java b/jbang/type-converter/MyRoute.java new file mode 100644 index 0000000..0a7c9a3 --- /dev/null +++ b/jbang/type-converter/MyRoute.java @@ -0,0 +1,17 @@ +// camel-k: language=java + +import org.apache.camel.builder.RouteBuilder; + +public class MyRoute extends RouteBuilder { + + @Override + public void configure() throws Exception { + + // Write your routes here, for example: + from("timer:cat2dog?period={{time:5000}}").routeId("cat2dog") + .setBody(e -> new Cat("Snoopy")) + .log("${body.say()}") + .convertBodyTo(Dog.class) + .log("${body.say()}"); + } +} diff --git a/jbang/type-converter/README.adoc b/jbang/type-converter/README.adoc new file mode 100644 index 0000000..37fce1c --- /dev/null +++ b/jbang/type-converter/README.adoc @@ -0,0 +1,63 @@ +== Type Converter + +This example shows how Camel JBang can use custom type converters. + +=== 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 * +---- + +Or run with JBang using the longer command line (without installing camel as app in JBang): + +[source,sh] +---- +$ jbang camel@apache/camel run * +---- + + +=== Live reload + +You can run the example in dev mode which allows you to edit the example, +and hot-reload when the file is saved. + +[source,sh] +---- +$ camel run * --dev +---- + + +=== 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!