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-jbang-examples.git
The following commit(s) were added to refs/heads/main by this push:
new 41b4f06 Add an example that shows how to use groovy expression with
extra dep… (#56)
41b4f06 is described below
commit 41b4f068855109fc5640c0204ff1b8b3da7bd477
Author: Federico Mariani <[email protected]>
AuthorDate: Fri Feb 13 12:56:06 2026 +0100
Add an example that shows how to use groovy expression with extra dep… (#56)
* Add an example that shows how to use groovy expression with extra
dependencies
* Fix mosquitto test
* Add an example that shows how to use groovy expression with extra
dependencies
---
groovy/README.adoc | 76 +++++++++++++++++++++++++++++++++++++++++++
groovy/application.properties | 1 +
groovy/groovy.camel.yaml | 32 ++++++++++++++++++
mqtt/infra/mosquitto.conf | 2 +-
4 files changed, 110 insertions(+), 1 deletion(-)
diff --git a/groovy/README.adoc b/groovy/README.adoc
new file mode 100644
index 0000000..d6910f5
--- /dev/null
+++ b/groovy/README.adoc
@@ -0,0 +1,76 @@
+== Groovy
+
+This example shows how to use Groovy with extra dependencies in Camel JBang.
+
+The route uses `EmailValidator` from
https://commons.apache.org/proper/commons-validator/[Apache Commons Validator]
+to validate an email address and route the message accordingly using
content-based routing.
+
+The extra dependency is declared in `application.properties` using the
+`camel.jbang.dependencies` property:
+
+[source,properties]
+----
+camel.jbang.dependencies=commons-validator:commons-validator:1.10.1
+----
+
+=== 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 Camel JBang with `camel` as shown below.
+
+=== How to run
+
+You can run this example using:
+
+[source,sh]
+----
+$ camel run *
+----
+
+To see the invalid email branch, edit `groovy.camel.yaml` and change the
`contactEmail` header in the `once` URI to an invalid value:
+
+[source,yaml]
+----
+uri: once:validate?header.contactEmail=not-a-valid-email
+----
+
+You can also declare dependencies as a modeline comment at the top of the YAML
route file:
+
+[source,yaml]
+----
+#//DEPS commons-validator:commons-validator:1.10.1
+----
+
+Or pass the dependency on the command line:
+
+[source,sh]
+----
+$ camel run groovy.camel.yaml --dep=commons-validator:commons-validator:1.10.1
+----
+
+=== 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/groovy/application.properties b/groovy/application.properties
new file mode 100644
index 0000000..e4a4b82
--- /dev/null
+++ b/groovy/application.properties
@@ -0,0 +1 @@
+camel.jbang.dependencies=commons-validator:commons-validator:1.10.1
diff --git a/groovy/groovy.camel.yaml b/groovy/groovy.camel.yaml
new file mode 100644
index 0000000..99e062c
--- /dev/null
+++ b/groovy/groovy.camel.yaml
@@ -0,0 +1,32 @@
+- route:
+ id: route-1681
+ from:
+ id: from-1133
+ uri: once
+ parameters:
+ name: validate
+ steps:
+ - setHeader:
+ id: setHeader-4262
+ constant:
+ expression: [email protected]
+ name: contactEmail
+ - choice:
+ id: choice-1178
+ otherwise:
+ id: otherwise-1234
+ steps:
+ - log:
+ id: log-3646
+ message: "Invalid email: ${header.contactEmail}"
+ when:
+ - id: when-1441
+ steps:
+ - log:
+ id: log-2349
+ message: "Valid contact: ${header.contactEmail}"
+ groovy:
+ expression: >-
+ import org.apache.commons.validator.routines.EmailValidator
+
+
EmailValidator.getInstance().isValid(request.headers['contactEmail'])
diff --git a/mqtt/infra/mosquitto.conf b/mqtt/infra/mosquitto.conf
index 6d3b993..05c4845 100644
--- a/mqtt/infra/mosquitto.conf
+++ b/mqtt/infra/mosquitto.conf
@@ -1,4 +1,4 @@
-protocol mqtt
listener 1883
+protocol mqtt
allow_anonymous true
socket_domain ipv4
\ No newline at end of file