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 82a19a6 CAMEL-20130: camel-yaml-dsl - Allow to use bean builder classes when defining beans 82a19a6 is described below commit 82a19a65774c9c082b3f600d141d24136b9dfa89 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Nov 30 10:17:07 2023 +0100 CAMEL-20130: camel-yaml-dsl - Allow to use bean builder classes when defining beans --- jbang/bean-builder/Customer.java | 36 +++++++++++++++++ jbang/bean-builder/CustomerBuilder.java | 34 ++++++++++++++++ jbang/bean-builder/README.adoc | 69 +++++++++++++++++++++++++++++++++ jbang/bean-builder/myapp.camel.yaml | 18 +++++++++ 4 files changed, 157 insertions(+) diff --git a/jbang/bean-builder/Customer.java b/jbang/bean-builder/Customer.java new file mode 100644 index 0000000..0741bbb --- /dev/null +++ b/jbang/bean-builder/Customer.java @@ -0,0 +1,36 @@ +package com.mycompany; + +public final class Customer { + + private String name; + private String street; + private int zip; + private boolean gold; + + Customer(String name, String street, int zip, boolean gold) { + this.name = name; + this.street = street; + this.zip = zip; + this.gold = gold; + } + + public String getName() { + return name; + } + + public String getStreet() { + return street; + } + + public int getZip() { + return zip; + } + + public boolean isGold() { + return gold; + } + + public String summary() { + return name + " at " + street + " (" + zip + ") is " + (gold ? "gold" : "silver") + " customer"; + } +} \ No newline at end of file diff --git a/jbang/bean-builder/CustomerBuilder.java b/jbang/bean-builder/CustomerBuilder.java new file mode 100644 index 0000000..1e3b3dd --- /dev/null +++ b/jbang/bean-builder/CustomerBuilder.java @@ -0,0 +1,34 @@ +package com.mycompany; + +public final class CustomerBuilder { + + private String name; + private String street; + private int zip; + private boolean gold; + + public CustomerBuilder name(String name) { + this.name = name; + return this; + } + + public CustomerBuilder street(String street) { + this.street = street; + return this; + } + + public CustomerBuilder zip(int zip) { + this.zip = zip; + return this; + } + + public CustomerBuilder gold(boolean gold) { + this.gold = gold; + return this; + } + + public Customer build() { + return new Customer(name, street, zip, gold); + } + +} \ No newline at end of file diff --git a/jbang/bean-builder/README.adoc b/jbang/bean-builder/README.adoc new file mode 100644 index 0000000..385ac02 --- /dev/null +++ b/jbang/bean-builder/README.adoc @@ -0,0 +1,69 @@ +== YAML with configuring Java bean via Builder class + +An example, of using YAML DSL with configuring a Java bean using fluent builder class, +to be used in the Camel route. + +This shows the flexibility of bean configuration in YAML DSL to make it possible +for non Java developers to configure beans that requires using fluent builder class, +with the power of low-code prgramming. + + +=== 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! diff --git a/jbang/bean-builder/myapp.camel.yaml b/jbang/bean-builder/myapp.camel.yaml new file mode 100644 index 0000000..aba4731 --- /dev/null +++ b/jbang/bean-builder/myapp.camel.yaml @@ -0,0 +1,18 @@ +- beans: + - name: myCustomer + type: com.mycompany.Customer + builderClass: com.mycompany.CustomerBuilder + properties: + name: "Acme" + street: "Somestreet 42" + zip: 90210 + gold: true +- from: + uri: "timer:yaml" + parameters: + period: "5000" + steps: + - bean: + ref: myCustomer + method: summary + - log: "${body}"