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.git
The following commit(s) were added to refs/heads/main by this push:
new 4447766c0 Fix #3377: new websocket-source and websocket-sink Kamelets,
receive from and send to a WebSocket server (#3379)
4447766c0 is described below
commit 4447766c0901af222d83fd31774a63c0e05a93d5
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 23 16:41:25 2026 +0100
Fix #3377: new websocket-source and websocket-sink Kamelets, receive from
and send to a WebSocket server (#3379)
* Fix #3377: new websocket-source and websocket-sink Kamelets, receive from
and send to a WebSocket server
Both Kamelets are Preview and use camel-vertx-websocket as a client.
websocket-source connects to a
ws:// or wss:// URL (consumeAsClient) and sends on each message the server
pushes, text as text and a
binary message as bytes; it connects again every reconnectInterval after
the connection is lost, up to
maxReconnectAttempts. websocket-sink sends each message to the URL, a text
body as a text message and a
bytes body as a binary message, and connects again on the next message
after the connection is lost.
Options: url (pattern ^wss?://.+), authorization (a credential, sent as the
Authorization header of the
handshake), subProtocols, and for the source reconnectInterval and
maxReconnectAttempts. TLS uses
the certificate authorities of Java, or the global camel.ssl.* settings with
camel.component.vertx-websocket.useGlobalSslContextParameters=true.
The sink removes the CamelVertxWebsocket* headers first: with
CamelVertxWebsocket.sendToAll a message
went to the clients of a vertx-websocket server of the same application
instead of to the URL, and was
lost when there were none.
The component cannot send a first message, such as a subscribe request,
after a client connects, so
the source does not offer it.
The new WebSocketIT tests run against a WebSocket server that is a Camel
route of the test integration:
the source gets the greeting of the server as text, with the query
parameter of the URL, and after the
server restarts it connects again and gets the next greeting as bytes; the
sink's text and bytes
messages reach the server as text and binary messages, with sendToAll and
connectionKey headers set,
which are gone afterwards; and a handshake refused with 401 by a Citrus
HTTP server, which checks the
Authorization header, the subprotocols and the query parameter, fails the
message.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: regenerate the catalog files after merging main
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel-kamelets-catalog-sbom.json | 32 +++++++-
docs/modules/ROOT/nav.adoc | 2 +
kamelets/websocket-sink.kamelet.yaml | 85 +++++++++++++++++++
kamelets/websocket-source.kamelet.yaml | 94 ++++++++++++++++++++++
.../main/resources/META-INF/kamelets-index.json | 20 +++++
.../resources/kamelets/websocket-sink.kamelet.yaml | 85 +++++++++++++++++++
.../kamelets/websocket-source.kamelet.yaml | 94 ++++++++++++++++++++++
.../src/test/java/WebSocketIT.java | 88 ++++++++++++++++++++
.../websocket/websocket-sink-rejected-route.yaml | 47 +++++++++++
.../websocket-sink-rejected.citrus.it.yaml | 75 +++++++++++++++++
.../resources/websocket/websocket-sink-route.yaml | 67 +++++++++++++++
.../websocket/websocket-sink.citrus.it.yaml | 91 +++++++++++++++++++++
.../websocket/websocket-source-route.yaml | 70 ++++++++++++++++
.../websocket/websocket-source.citrus.it.yaml | 78 ++++++++++++++++++
14 files changed, 927 insertions(+), 1 deletion(-)
diff --git a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
index 970d4334d..2231f05bd 100644
--- a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
+++ b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
@@ -1171,6 +1171,16 @@
"type" : "library",
"name" : "webhook-source",
"version" : "4.24.0-SNAPSHOT"
+ }, {
+ "bom-ref" : "kamelet:websocket-sink",
+ "type" : "library",
+ "name" : "websocket-sink",
+ "version" : "4.24.0-SNAPSHOT"
+ }, {
+ "bom-ref" : "kamelet:websocket-source",
+ "type" : "library",
+ "name" : "websocket-source",
+ "version" : "4.24.0-SNAPSHOT"
}, {
"bom-ref" : "kamelet:xj-identity-action",
"type" : "library",
@@ -2441,6 +2451,17 @@
"name" : "camel.apache.org/versioned-by",
"value" : "runtime"
} ]
+ }, {
+ "bom-ref" :
"pkg:maven/org.apache.camel/[email protected]",
+ "type" : "library",
+ "group" : "org.apache.camel",
+ "name" : "camel-vertx-websocket",
+ "version" : "4.24.0-SNAPSHOT",
+ "purl" :
"pkg:maven/org.apache.camel/[email protected]",
+ "properties" : [ {
+ "name" : "camel.apache.org/versioned-by",
+ "value" : "runtime"
+ } ]
}, {
"bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
"type" : "library",
@@ -2516,7 +2537,7 @@
} ],
"dependencies" : [ {
"ref" : "camel-kamelets-catalog",
- "dependsOn" : [ "kamelet:ai-tool-source",
"kamelet:avro-deserialize-action", "kamelet:avro-serialize-action",
"kamelet:aws-bedrock-agent-runtime-sink", "kamelet:aws-bedrock-agent-sink",
"kamelet:aws-bedrock-text-sink", "kamelet:aws-cloudtrail-source",
"kamelet:aws-cloudwatch-sink", "kamelet:aws-comprehend-sink",
"kamelet:aws-ddb-sink", "kamelet:aws-ddb-streams-source",
"kamelet:aws-ec2-sink", "kamelet:aws-eventbridge-sink",
"kamelet:aws-eventbridge-source", "kamelet:aws-kinesis-fireh [...]
+ "dependsOn" : [ "kamelet:ai-tool-source",
"kamelet:avro-deserialize-action", "kamelet:avro-serialize-action",
"kamelet:aws-bedrock-agent-runtime-sink", "kamelet:aws-bedrock-agent-sink",
"kamelet:aws-bedrock-text-sink", "kamelet:aws-cloudtrail-source",
"kamelet:aws-cloudwatch-sink", "kamelet:aws-comprehend-sink",
"kamelet:aws-ddb-sink", "kamelet:aws-ddb-streams-source",
"kamelet:aws-ec2-sink", "kamelet:aws-eventbridge-sink",
"kamelet:aws-eventbridge-source", "kamelet:aws-kinesis-fireh [...]
}, {
"ref" : "kamelet:ai-tool-source",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -3213,6 +3234,12 @@
}, {
"ref" : "kamelet:webhook-source",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ }, {
+ "ref" : "kamelet:websocket-sink",
+ "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ }, {
+ "ref" : "kamelet:websocket-source",
+ "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "kamelet:xj-identity-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -3573,6 +3600,9 @@
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
+ }, {
+ "ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "dependsOn" : [ ]
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index 3afd7f66d..339d553d4 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -231,6 +231,8 @@
* xref:value-to-key-action.adoc[]
* xref:velocity-template-action.adoc[]
* xref:webhook-source.adoc[]
+* xref:websocket-sink.adoc[]
+* xref:websocket-source.adoc[]
* xref:xj-identity-action.adoc[]
* xref:xj-template-action.adoc[]
* xref:xml-schema-validator-action.adoc[]
diff --git a/kamelets/websocket-sink.kamelet.yaml
b/kamelets/websocket-sink.kamelet.yaml
new file mode 100644
index 000000000..221ce139d
--- /dev/null
+++ b/kamelets/websocket-sink.kamelet.yaml
@@ -0,0 +1,85 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: websocket-sink
+ annotations:
+ camel.apache.org/kamelet.support.level: "Preview"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MjAiCmhlaWdodD0iNDIwIiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiPgo8cGF0aCBzdHJva2Utd2lkdGg9IjI2IgpkPSJNMjA5LDE1YTE5NSwxOTUgMCAxLDAgMiwweiIvPgo8cGF0aCBzdHJva2Utd2lkdGg9IjE4IgpkPSJtMjEwLDE1djM5MG0xOTUtMTk1SDE1TTU5LDkwYTI2MCwyNjAgMCAwLDAgMzAyLDAgbTAsMjQwIGEyNjAsMjYwIDAgMCwwLTMwMiwwTTE5NSwyMGEyNTAsMjUwIDAgMCwwIDAsMzgyIG0zMC
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "WebSocket"
+ camel.apache.org/kamelet.namespace: "HTTP"
+ labels:
+ camel.apache.org/kamelet.type: "sink"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "WebSocket Sink"
+ description: |-
+ Sends each message to a WebSocket server, as a text message or as a
binary message.
+
+ Use it to push events, commands or data to a service that takes them
over WebSocket, such as a chat, a dashboard or a data intake. To receive the
messages a WebSocket server pushes, use `websocket-source`.
+
+ Input: a text body is sent as a text message, and a bytes body as a
binary message. Turn structured data such as a Map into JSON text first, for
example with `json-serialize-action`. The headers of the message are not sent.
+
+ Output: when it is used inside a route, the body is unchanged, and the
headers that start with `CamelVertxWebsocket` are removed.
+
+ Good to know: it connects when the first message is sent, and keeps the
connection open for the next messages. After the connection is lost, for
example because the server restarts, the next message connects again. A message
fails when the server cannot be reached, or refuses the connection, for example
with a 401 response when the login is wrong. A message is done once it is
written to the connection: the server does not confirm it. The address comes
only from `url`: the headers t [...]
+ required:
+ - url
+ type: object
+ properties:
+ url:
+ title: URL
+ description: The address of the WebSocket server, with the path and
any query parameters. It starts with `ws://`, or with `wss://` for TLS. Without
a port, it is 80 for `ws://` and 443 for `wss://`.
+ type: string
+ example: "wss://events.example.com/ingest"
+ pattern: "^wss?://.+"
+ authorization:
+ title: Authorization
+ description: The value of the `Authorization` header to send when
connecting, for a server that asks for a login, such as `Bearer` followed by a
token. It is sent once, when the connection opens, not with each message.
+ type: string
+ example: "Bearer my-token"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ subProtocols:
+ title: Subprotocols
+ description: The subprotocols to ask the server for, separated by
commas, sent in the `Sec-WebSocket-Protocol` header when connecting. Set it
only for a server that needs one, such as a GraphQL server.
+ type: string
+ example: "graphql-transport-ws"
+ dataTypes:
+ # No 'default:' here on purpose: the type of the body decides between a
text and a binary
+ # message, and a default would turn every body into one of the two. See
#3117.
+ in:
+ headers: {}
+ dependencies:
+ - "camel:vertx-websocket"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - removeHeaders:
+ pattern: "CamelVertxWebsocket*"
+ - to:
+ uri: "vertx-websocket:{{url}}"
+ parameters:
+ clientSubProtocols: "{{?subProtocols}}"
+ "handshake.Authorization": "RAW({{?authorization}})"
diff --git a/kamelets/websocket-source.kamelet.yaml
b/kamelets/websocket-source.kamelet.yaml
new file mode 100644
index 000000000..f7257236f
--- /dev/null
+++ b/kamelets/websocket-source.kamelet.yaml
@@ -0,0 +1,94 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: websocket-source
+ annotations:
+ camel.apache.org/kamelet.support.level: "Preview"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MjAiCmhlaWdodD0iNDIwIiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiPgo8cGF0aCBzdHJva2Utd2lkdGg9IjI2IgpkPSJNMjA5LDE1YTE5NSwxOTUgMCAxLDAgMiwweiIvPgo8cGF0aCBzdHJva2Utd2lkdGg9IjE4IgpkPSJtMjEwLDE1djM5MG0xOTUtMTk1SDE1TTU5LDkwYTI2MCwyNjAgMCAwLDAgMzAyLDAgbTAsMjQwIGEyNjAsMjYwIDAgMCwwLTMwMiwwTTE5NSwyMGEyNTAsMjUwIDAgMCwwIDAsMzgyIG0zMC
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "WebSocket"
+ camel.apache.org/kamelet.namespace: "HTTP"
+ labels:
+ camel.apache.org/kamelet.type: "source"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "WebSocket Source"
+ description: |-
+ Connects to a WebSocket server, such as a feed of prices, notifications
or status updates, and sends on each message the server pushes.
+
+ Use it to receive live data that a partner or a public service pushes
over WebSocket. To send messages to a WebSocket server, use `websocket-sink`.
For a service that calls a URL of yours for each event (a webhook), use
`webhook-source`.
+
+ Output: the body is the message as the server sent it: text for a text
message, bytes for a binary message. No headers are set.
+
+ Good to know: it connects when the integration starts, and the
integration fails to start when the server cannot be reached, refuses the
connection or fails the TLS checks. When the connection is lost, for example
because the server restarts, it connects again every `reconnectInterval`
milliseconds, without end unless `maxReconnectAttempts` is set. Messages the
server sends while it is not connected are lost. The messages are passed on in
parallel, so they do not always go on in th [...]
+ required:
+ - url
+ type: object
+ properties:
+ url:
+ title: URL
+ description: The address of the WebSocket server, with the path and
any query parameters. It starts with `ws://`, or with `wss://` for TLS. Without
a port, it is 80 for `ws://` and 443 for `wss://`.
+ type: string
+ example: "wss://stream.example.com/prices?symbols=ACME"
+ pattern: "^wss?://.+"
+ authorization:
+ title: Authorization
+ description: The value of the `Authorization` header to send when
connecting, for a server that asks for a login, such as `Bearer` followed by a
token. It is sent once, when the connection opens, not with each message.
+ type: string
+ example: "Bearer my-token"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ subProtocols:
+ title: Subprotocols
+ description: The subprotocols to ask the server for, separated by
commas, sent in the `Sec-WebSocket-Protocol` header when connecting. Set it
only for a server that needs one, such as a GraphQL server.
+ type: string
+ example: "graphql-transport-ws"
+ reconnectInterval:
+ title: Reconnect Interval
+ description: How long to wait between two attempts to connect again
after the connection was lost, in milliseconds. The first attempt is made at
once.
+ type: integer
+ default: 1000
+ maxReconnectAttempts:
+ title: Max Reconnect Attempts
+ description: How many attempts to connect again it makes after the
connection was lost, before it gives up. After it gives up, it receives nothing
more until the integration is restarted. 0 means no limit.
+ type: integer
+ default: 0
+ dataTypes:
+ # No 'default:' here on purpose: the body is text or bytes, as the server
sent the message, and
+ # a default would turn every message into one of the two. See #3117.
+ out:
+ headers: {}
+ dependencies:
+ - "camel:vertx-websocket"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: "vertx-websocket:{{url}}"
+ parameters:
+ consumeAsClient: true
+ reconnectInterval: "{{reconnectInterval}}"
+ maxReconnectAttempts: "{{maxReconnectAttempts}}"
+ clientSubProtocols: "{{?subProtocols}}"
+ "handshake.Authorization": "RAW({{?authorization}})"
+ steps:
+ - to:
+ uri: kamelet:sink
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index d79a0bc9b..bb824ff6a 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -2319,6 +2319,26 @@
"group" : "Webhook",
"namespace" : "Cloud",
"provider" : "Apache Software Foundation"
+ }, {
+ "name" : "websocket-sink",
+ "type" : "sink",
+ "supportLevel" : "Preview",
+ "title" : "WebSocket Sink",
+ "summary" : "Sends each message to a WebSocket server, as a text message
or as a binary message.",
+ "description" : "Sends each message to a WebSocket server, as a text
message or as a binary message.\n\nUse it to push events, commands or data to a
service that takes them over WebSocket, such as a chat, a dashboard or a data
intake. To receive the messages a WebSocket server pushes, use
`websocket-source`.\n\nInput: a text body is sent as a text message, and a
bytes body as a binary message. Turn structured data such as a Map into JSON
text first, for example with `json-serialize-a [...]
+ "group" : "WebSocket",
+ "namespace" : "HTTP",
+ "provider" : "Apache Software Foundation"
+ }, {
+ "name" : "websocket-source",
+ "type" : "source",
+ "supportLevel" : "Preview",
+ "title" : "WebSocket Source",
+ "summary" : "Connects to a WebSocket server, such as a feed of prices,
notifications or status updates, and sends on each message the server pushes.",
+ "description" : "Connects to a WebSocket server, such as a feed of prices,
notifications or status updates, and sends on each message the server
pushes.\n\nUse it to receive live data that a partner or a public service
pushes over WebSocket. To send messages to a WebSocket server, use
`websocket-sink`. For a service that calls a URL of yours for each event (a
webhook), use `webhook-source`.\n\nOutput: the body is the message as the
server sent it: text for a text message, bytes for a [...]
+ "group" : "WebSocket",
+ "namespace" : "HTTP",
+ "provider" : "Apache Software Foundation"
}, {
"name" : "xj-identity-action",
"type" : "action",
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/websocket-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/websocket-sink.kamelet.yaml
new file mode 100644
index 000000000..221ce139d
--- /dev/null
+++
b/library/camel-kamelets/src/main/resources/kamelets/websocket-sink.kamelet.yaml
@@ -0,0 +1,85 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: websocket-sink
+ annotations:
+ camel.apache.org/kamelet.support.level: "Preview"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MjAiCmhlaWdodD0iNDIwIiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiPgo8cGF0aCBzdHJva2Utd2lkdGg9IjI2IgpkPSJNMjA5LDE1YTE5NSwxOTUgMCAxLDAgMiwweiIvPgo8cGF0aCBzdHJva2Utd2lkdGg9IjE4IgpkPSJtMjEwLDE1djM5MG0xOTUtMTk1SDE1TTU5LDkwYTI2MCwyNjAgMCAwLDAgMzAyLDAgbTAsMjQwIGEyNjAsMjYwIDAgMCwwLTMwMiwwTTE5NSwyMGEyNTAsMjUwIDAgMCwwIDAsMzgyIG0zMC
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "WebSocket"
+ camel.apache.org/kamelet.namespace: "HTTP"
+ labels:
+ camel.apache.org/kamelet.type: "sink"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "WebSocket Sink"
+ description: |-
+ Sends each message to a WebSocket server, as a text message or as a
binary message.
+
+ Use it to push events, commands or data to a service that takes them
over WebSocket, such as a chat, a dashboard or a data intake. To receive the
messages a WebSocket server pushes, use `websocket-source`.
+
+ Input: a text body is sent as a text message, and a bytes body as a
binary message. Turn structured data such as a Map into JSON text first, for
example with `json-serialize-action`. The headers of the message are not sent.
+
+ Output: when it is used inside a route, the body is unchanged, and the
headers that start with `CamelVertxWebsocket` are removed.
+
+ Good to know: it connects when the first message is sent, and keeps the
connection open for the next messages. After the connection is lost, for
example because the server restarts, the next message connects again. A message
fails when the server cannot be reached, or refuses the connection, for example
with a 401 response when the login is wrong. A message is done once it is
written to the connection: the server does not confirm it. The address comes
only from `url`: the headers t [...]
+ required:
+ - url
+ type: object
+ properties:
+ url:
+ title: URL
+ description: The address of the WebSocket server, with the path and
any query parameters. It starts with `ws://`, or with `wss://` for TLS. Without
a port, it is 80 for `ws://` and 443 for `wss://`.
+ type: string
+ example: "wss://events.example.com/ingest"
+ pattern: "^wss?://.+"
+ authorization:
+ title: Authorization
+ description: The value of the `Authorization` header to send when
connecting, for a server that asks for a login, such as `Bearer` followed by a
token. It is sent once, when the connection opens, not with each message.
+ type: string
+ example: "Bearer my-token"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ subProtocols:
+ title: Subprotocols
+ description: The subprotocols to ask the server for, separated by
commas, sent in the `Sec-WebSocket-Protocol` header when connecting. Set it
only for a server that needs one, such as a GraphQL server.
+ type: string
+ example: "graphql-transport-ws"
+ dataTypes:
+ # No 'default:' here on purpose: the type of the body decides between a
text and a binary
+ # message, and a default would turn every body into one of the two. See
#3117.
+ in:
+ headers: {}
+ dependencies:
+ - "camel:vertx-websocket"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - removeHeaders:
+ pattern: "CamelVertxWebsocket*"
+ - to:
+ uri: "vertx-websocket:{{url}}"
+ parameters:
+ clientSubProtocols: "{{?subProtocols}}"
+ "handshake.Authorization": "RAW({{?authorization}})"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/websocket-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/websocket-source.kamelet.yaml
new file mode 100644
index 000000000..f7257236f
--- /dev/null
+++
b/library/camel-kamelets/src/main/resources/kamelets/websocket-source.kamelet.yaml
@@ -0,0 +1,94 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: websocket-source
+ annotations:
+ camel.apache.org/kamelet.support.level: "Preview"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MjAiCmhlaWdodD0iNDIwIiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiPgo8cGF0aCBzdHJva2Utd2lkdGg9IjI2IgpkPSJNMjA5LDE1YTE5NSwxOTUgMCAxLDAgMiwweiIvPgo8cGF0aCBzdHJva2Utd2lkdGg9IjE4IgpkPSJtMjEwLDE1djM5MG0xOTUtMTk1SDE1TTU5LDkwYTI2MCwyNjAgMCAwLDAgMzAyLDAgbTAsMjQwIGEyNjAsMjYwIDAgMCwwLTMwMiwwTTE5NSwyMGEyNTAsMjUwIDAgMCwwIDAsMzgyIG0zMC
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "WebSocket"
+ camel.apache.org/kamelet.namespace: "HTTP"
+ labels:
+ camel.apache.org/kamelet.type: "source"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "WebSocket Source"
+ description: |-
+ Connects to a WebSocket server, such as a feed of prices, notifications
or status updates, and sends on each message the server pushes.
+
+ Use it to receive live data that a partner or a public service pushes
over WebSocket. To send messages to a WebSocket server, use `websocket-sink`.
For a service that calls a URL of yours for each event (a webhook), use
`webhook-source`.
+
+ Output: the body is the message as the server sent it: text for a text
message, bytes for a binary message. No headers are set.
+
+ Good to know: it connects when the integration starts, and the
integration fails to start when the server cannot be reached, refuses the
connection or fails the TLS checks. When the connection is lost, for example
because the server restarts, it connects again every `reconnectInterval`
milliseconds, without end unless `maxReconnectAttempts` is set. Messages the
server sends while it is not connected are lost. The messages are passed on in
parallel, so they do not always go on in th [...]
+ required:
+ - url
+ type: object
+ properties:
+ url:
+ title: URL
+ description: The address of the WebSocket server, with the path and
any query parameters. It starts with `ws://`, or with `wss://` for TLS. Without
a port, it is 80 for `ws://` and 443 for `wss://`.
+ type: string
+ example: "wss://stream.example.com/prices?symbols=ACME"
+ pattern: "^wss?://.+"
+ authorization:
+ title: Authorization
+ description: The value of the `Authorization` header to send when
connecting, for a server that asks for a login, such as `Bearer` followed by a
token. It is sent once, when the connection opens, not with each message.
+ type: string
+ example: "Bearer my-token"
+ format: password
+ x-descriptors:
+ - urn:camel:group:credentials
+ subProtocols:
+ title: Subprotocols
+ description: The subprotocols to ask the server for, separated by
commas, sent in the `Sec-WebSocket-Protocol` header when connecting. Set it
only for a server that needs one, such as a GraphQL server.
+ type: string
+ example: "graphql-transport-ws"
+ reconnectInterval:
+ title: Reconnect Interval
+ description: How long to wait between two attempts to connect again
after the connection was lost, in milliseconds. The first attempt is made at
once.
+ type: integer
+ default: 1000
+ maxReconnectAttempts:
+ title: Max Reconnect Attempts
+ description: How many attempts to connect again it makes after the
connection was lost, before it gives up. After it gives up, it receives nothing
more until the integration is restarted. 0 means no limit.
+ type: integer
+ default: 0
+ dataTypes:
+ # No 'default:' here on purpose: the body is text or bytes, as the server
sent the message, and
+ # a default would turn every message into one of the two. See #3117.
+ out:
+ headers: {}
+ dependencies:
+ - "camel:vertx-websocket"
+ - "camel:kamelet"
+ template:
+ from:
+ uri: "vertx-websocket:{{url}}"
+ parameters:
+ consumeAsClient: true
+ reconnectInterval: "{{reconnectInterval}}"
+ maxReconnectAttempts: "{{maxReconnectAttempts}}"
+ clientSubProtocols: "{{?subProtocols}}"
+ "handshake.Authorization": "RAW({{?authorization}})"
+ steps:
+ - to:
+ uri: kamelet:sink
diff --git a/tests/camel-kamelets-itest/src/test/java/WebSocketIT.java
b/tests/camel-kamelets-itest/src/test/java/WebSocketIT.java
new file mode 100644
index 000000000..392cde29b
--- /dev/null
+++ b/tests/camel-kamelets-itest/src/test/java/WebSocketIT.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.util.stream.Stream;
+
+import org.citrusframework.api.common.TestLoader;
+import org.citrusframework.container.SequenceAfterTest;
+import org.citrusframework.container.SequenceBeforeTest;
+import org.citrusframework.http.server.HttpServer;
+import org.citrusframework.junit.jupiter.CitrusSupport;
+import org.citrusframework.junit.jupiter.CitrusTestFactory;
+import org.citrusframework.junit.jupiter.CitrusTestFactorySupport;
+import org.citrusframework.spi.BindToRegistry;
+import org.junit.jupiter.api.DynamicTest;
+
+import static
org.citrusframework.actions.CreateVariablesAction.Builder.createVariables;
+import static
org.citrusframework.actions.PurgeEndpointAction.Builder.purgeEndpoints;
+import static org.citrusframework.http.endpoint.builder.HttpEndpoints.http;
+
+/**
+ * Tests the websocket-source and websocket-sink Kamelets against a WebSocket
server that is a Camel route in the
+ * integration of the test, and the opening handshake against a Citrus HTTP
server, which refuses it.
+ */
+@CitrusSupport
+public class WebSocketIT {
+
+ private static final String TESTS = "websocket-.*";
+
+ private final int resultServerPort = ServerPorts.next();
+ private final int controlServerPort = ServerPorts.next();
+ private final int sourceServerPort = ServerPorts.next();
+ private final int sinkServerPort = ServerPorts.next();
+
+ /** Receives what the routes of the test got, and the opening handshake of
the sink. */
+ @BindToRegistry
+ HttpServer websocketResultServer = http()
+ .server()
+ .port(resultServerPort)
+ .timeout(60000L)
+ .autoStart(true)
+ .build();
+
+ /** Tells the sink test when to send its next message, so that the
messages reach the result server in order. */
+ @BindToRegistry
+ HttpServer websocketControlServer = http()
+ .server()
+ .port(controlServerPort)
+ .timeout(60000L)
+ .autoStart(true)
+ .build();
+
+ @BindToRegistry
+ public SequenceBeforeTest beforeWebSocket() {
+ return new SequenceBeforeTest.Builder().onTests(TESTS).actions(
+ createVariables()
+ .variable("websocket.result.port",
String.valueOf(resultServerPort))
+ .variable("websocket.control.port",
String.valueOf(controlServerPort))
+ .variable("websocket.source.port",
String.valueOf(sourceServerPort))
+ .variable("websocket.sink.port",
String.valueOf(sinkServerPort))
+ ).build();
+ }
+
+ @BindToRegistry
+ public SequenceAfterTest afterWebSocket() {
+ return new SequenceAfterTest.Builder().onTests(TESTS).actions(
+
purgeEndpoints().endpoint(websocketResultServer).endpoint(websocketControlServer)
+ ).build();
+ }
+
+ @CitrusTestFactory
+ public Stream<DynamicTest> websocket() {
+ return
CitrusTestFactorySupport.factory(TestLoader.YAML).packageScan("websocket");
+ }
+}
diff --git
a/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-rejected-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-rejected-route.yaml
new file mode 100644
index 000000000..04d74e8c5
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-rejected-route.yaml
@@ -0,0 +1,47 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+- route:
+ from:
+ uri: "timer:send"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "Hello WebSocket"
+ - doTry:
+ steps:
+ # the Citrus HTTP server stands in for the WebSocket server, and
refuses the connection
+ - to:
+ uri: "kamelet:websocket-sink"
+ parameters:
+ url:
"ws://localhost:{{handshake.server.port}}/ws?room=blue"
+ # a token with & and %, as it is
+ authorization: "RAW({{ws.authorization}})"
+ subProtocols: "chat.v2,chat.v1"
+ - setBody:
+ constant: "sent"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - setBody:
+ simple: "${exception.message}"
+ - setHeader:
+ name: Content-Type
+ constant: "text/plain"
+ - to: "http://localhost:{{handshake.server.port}}/error"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-rejected.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-rejected.citrus.it.yaml
new file mode 100644
index 000000000..f4cfe159e
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-rejected.citrus.it.yaml
@@ -0,0 +1,75 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: websocket-sink-rejected-test
+variables:
+ - name: "ws.authorization"
+ value: "citrus:concat('Bearer ', citrus:randomString(16), '+/=&%')"
+actions:
+ - camel:
+ cli:
+ run:
+ waitForRunningState: false
+ integration:
+ file: "websocket/websocket-sink-rejected-route.yaml"
+ systemProperties:
+ properties:
+ - name: "handshake.server.port"
+ value: "${websocket.result.port}"
+ - name: "ws.authorization"
+ value: "${ws.authorization}"
+
+ # the opening handshake, with the login, the subprotocols and the query
parameter of the URL
+ - http:
+ server: "websocketResultServer"
+ receiveRequest:
+ GET:
+ path: "/ws"
+ parameters:
+ - name: "room"
+ value: "blue"
+ headers:
+ - name: "Upgrade"
+ value: "websocket"
+ - name: "Authorization"
+ value: "${ws.authorization}"
+ - name: "Sec-WebSocket-Protocol"
+ value: "chat.v2,chat.v1"
+ - http:
+ server: "websocketResultServer"
+ sendResponse:
+ response:
+ status: 401
+ reasonPhrase: "Unauthorized"
+ version: "HTTP/1.1"
+
+ # the message fails, with the status code of the answer
+ - http:
+ server: "websocketResultServer"
+ receiveRequest:
+ POST:
+ path: "/error"
+ type: "plaintext"
+ body:
+ data: "io.vertx.core.http.UpgradeRejectedException: WebSocket
upgrade failure: 401"
+ - http:
+ server: "websocketResultServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-route.yaml
new file mode 100644
index 000000000..de66ba022
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink-route.yaml
@@ -0,0 +1,67 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+# A WebSocket server that hands each message it receives to the test
+- route:
+ from:
+ uri: "vertx-websocket:localhost:{{ws.server.port}}/in"
+ steps:
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - removeHeaders:
+ pattern: "CamelVertxWebsocket*"
+ - convertBodyTo:
+ type: "String"
+ - setHeader:
+ name: Content-Type
+ constant: "text/plain"
+ - to: "{{result.server.url}}/received"
+
+- route:
+ from:
+ uri: "timer:send"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: "Hello WebSocket"
+ # headers that would send the message elsewhere: to the clients of the
server of this integration, of which
+ # there are none, so that the server would get nothing. The Kamelet
removes them.
+ - setHeader:
+ name: CamelVertxWebsocket.sendToAll
+ constant: "true"
+ - setHeader:
+ name: CamelVertxWebsocket.connectionKey
+ constant: "someone-else"
+ - to:
+ uri: "kamelet:websocket-sink"
+ parameters:
+ url: "ws://localhost:{{ws.server.port}}/in"
+ # the message after the Kamelet, and the go-ahead for the next one
once the server got this one
+ - setHeader:
+ name: X-After
+ simple:
"${body}|${header.CamelVertxWebsocket.sendToAll}|${header.CamelVertxWebsocket.connectionKey}"
+ - to: "{{control.server.url}}/next"
+ - setBody:
+ constant: "Hello bytes"
+ - convertBodyTo:
+ type: "byte[]"
+ - to:
+ uri: "kamelet:websocket-sink"
+ parameters:
+ url: "ws://localhost:{{ws.server.port}}/in"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink.citrus.it.yaml
new file mode 100644
index 000000000..722456894
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-sink.citrus.it.yaml
@@ -0,0 +1,91 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: websocket-sink-test
+actions:
+ - camel:
+ cli:
+ run:
+ waitForRunningState: false
+ integration:
+ file: "websocket/websocket-sink-route.yaml"
+ systemProperties:
+ properties:
+ - name: "ws.server.port"
+ value: "${websocket.sink.port}"
+ - name: "result.server.url"
+ value: "http://localhost:${websocket.result.port}"
+ - name: "control.server.url"
+ value: "http://localhost:${websocket.control.port}"
+
+ # a text body reaches the server as a text message, although its headers
asked to send it to all the clients
+ - http:
+ server: "websocketResultServer"
+ receiveRequest:
+ POST:
+ path: "/received"
+ type: "plaintext"
+ headers:
+ - name: "X-Body-Type"
+ value: "java.lang.String"
+ body:
+ data: "Hello WebSocket"
+ - http:
+ server: "websocketResultServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ # after the Kamelet, the body is the same, and the CamelVertxWebsocket
headers are gone
+ - http:
+ server: "websocketControlServer"
+ receiveRequest:
+ POST:
+ path: "/next"
+ type: "plaintext"
+ headers:
+ - name: "X-After"
+ value: "Hello WebSocket||"
+ - http:
+ server: "websocketControlServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ # a bytes body reaches the server as a binary message
+ - http:
+ server: "websocketResultServer"
+ receiveRequest:
+ POST:
+ path: "/received"
+ type: "plaintext"
+ headers:
+ - name: "X-Body-Type"
+ value: "[B"
+ body:
+ data: "Hello bytes"
+ - http:
+ server: "websocketResultServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-source-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-source-route.yaml
new file mode 100644
index 000000000..2dff614df
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-source-route.yaml
@@ -0,0 +1,70 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+# A WebSocket server that greets each client when it connects: with text the
first time, with bytes after that
+- route:
+ id: websocket-server
+ from:
+ uri: "vertx-websocket:localhost:{{ws.server.port}}/feed"
+ parameters:
+ fireWebSocketConnectionEvents: true
+ steps:
+ - filter:
+ simple: "${header.CamelVertxWebsocket.event} == 'OPEN'"
+ steps:
+ - choice:
+ when:
+ - simple: "${variable.global:connected} == null"
+ steps:
+ - setVariable:
+ name: "global:connected"
+ constant: "true"
+ - setBody:
+ simple: "Welcome ${header.user}"
+ otherwise:
+ steps:
+ - setBody:
+ simple: "Welcome back ${header.user}"
+ - convertBodyTo:
+ type: "byte[]"
+ # to the client that connected, by the connection key the server
set
+ - to: "vertx-websocket:localhost:{{ws.server.port}}/feed"
+
+- route:
+ from:
+ uri: "kamelet:websocket-source"
+ parameters:
+ url: "ws://localhost:{{ws.server.port}}/feed?user=Ann"
+ reconnectInterval: 200
+ steps:
+ - setHeader:
+ name: X-Header-Count
+ simple: "${headers.size()}"
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - convertBodyTo:
+ type: "String"
+ - setHeader:
+ name: Content-Type
+ constant: "text/plain"
+ - to: "{{result.server.url}}/result"
+ # the test answers the first message with X-Restart: the server stops,
which closes the connection, and starts again
+ - filter:
+ simple: "${header.X-Restart} == 'true'"
+ steps:
+ - to:
"controlbus:route?routeId=websocket-server&action=restart&async=true"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-source.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-source.citrus.it.yaml
new file mode 100644
index 000000000..c6d4ffaa3
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/websocket/websocket-source.citrus.it.yaml
@@ -0,0 +1,78 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ---------------------------------------------------------------------------
+
+name: websocket-source-test
+actions:
+ - camel:
+ cli:
+ run:
+ waitForRunningState: false
+ integration:
+ file: "websocket/websocket-source-route.yaml"
+ systemProperties:
+ properties:
+ - name: "ws.server.port"
+ value: "${websocket.source.port}"
+ - name: "result.server.url"
+ value: "http://localhost:${websocket.result.port}"
+
+ # the greeting of the server when the source connects, a text message, with
the query parameter of the URL
+ - http:
+ server: "websocketResultServer"
+ receiveRequest:
+ POST:
+ path: "/result"
+ type: "plaintext"
+ headers:
+ - name: "X-Body-Type"
+ value: "java.lang.String"
+ - name: "X-Header-Count"
+ value: "0"
+ body:
+ data: "Welcome Ann"
+ - http:
+ server: "websocketResultServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+ headers:
+ - name: "X-Restart"
+ value: "true"
+
+ # the server restarts and closes the connection: the source connects again,
and gets the next greeting, as bytes
+ - http:
+ server: "websocketResultServer"
+ receiveRequest:
+ POST:
+ path: "/result"
+ type: "plaintext"
+ headers:
+ - name: "X-Body-Type"
+ value: "[B"
+ - name: "X-Header-Count"
+ value: "0"
+ body:
+ data: "Welcome back Ann"
+ - http:
+ server: "websocketResultServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"