davsclaus opened a new pull request, #3379:
URL: https://github.com/apache/camel-kamelets/pull/3379

   Two new Kamelets on `camel-vertx-websocket`, used as a client. Both are 
**Preview**.
   
   ### `websocket-source`
   Connects to a `ws://` or `wss://` URL and sends on each message the server 
pushes: a text message as text, a binary message as bytes. No headers are set.
   - Options: `url` (required, pattern `^wss?://.+`), `authorization` 
(credential, sent as the `Authorization` header of the handshake), 
`subProtocols`, `reconnectInterval` (ms, default 1000), `maxReconnectAttempts` 
(default 0 = no limit).
   - When the connection is lost, it connects again every `reconnectInterval`. 
The integration fails to start when the server cannot be reached at start.
   - **Dropped: a first message after connecting (e.g. a subscribe request).** 
`vertx-websocket` gives a client consumer no way to send on connect (connection 
events exist only for its server side), so the Kamelet does not offer it and 
the description says so.
   
   ### `websocket-sink`
   Sends each message to the URL: a text body as a text message, a bytes body 
as a binary message. It connects on the first message and again on the next 
message after the connection is lost. A refused handshake or an unreachable 
server fails the message.
   - Options: `url` (required, pattern), `authorization` (credential), 
`subProtocols`.
   - **Security:** `removeHeaders: CamelVertxWebsocket*` runs before the 
producer. Without it, `CamelVertxWebsocket.sendToAll=true` on a message sends 
it to the clients of a `vertx-websocket` server in the same application instead 
of to the URL, and the message is lost when there are none (checked: the sink 
test times out with the removal taken out).
   
   TLS for both: Java's trusted CAs with host name verification, or a private 
CA with `camel.ssl.enabled/trustStore/trustStorePassword` plus 
`camel.component.vertx-websocket.useGlobalSslContextParameters=true`.
   
   ### Tests (`WebSocketIT`, 3 tests, about 20 s, no containers)
   The WebSocket server is a `vertx-websocket` route inside the test 
integration, on a `ServerPorts.next()` port.
   - `websocket-source`: the server greets each new connection. The source gets 
`Welcome Ann` as a `String`, with the `user` query parameter of the URL and no 
headers. Citrus then makes the test route restart the server route 
(controlbus), which closes the connection. The source connects again and gets 
the next greeting as `byte[]`. No sleeps.
   - `websocket-sink`: a text body with `CamelVertxWebsocket.sendToAll` and 
`connectionKey` headers reaches the server as a text message. Afterwards the 
body is the same and those headers are gone. A bytes body then reaches the 
server as a binary message. A second Citrus server orders the two messages.
   - `websocket-sink-rejected`: a Citrus HTTP server takes the handshake. It 
checks `Upgrade: websocket`, the `Authorization` value (with `+/=&%`), 
`Sec-WebSocket-Protocol: chat.v2,chat.v1` and the `room=blue` query parameter, 
then answers 401. The message fails with `UpgradeRejectedException: WebSocket 
upgrade failure: 401`.
   
   Local results: `./mvnw -o clean install -DskipITs` passes, and 
`-Dit.test=WebSocketIT` gives 3/3 passing.
   
   Checked by hand with `camel run`, not in the ITs:
   - TLS with a self-signed `localhost` certificate: without the trust store 
the connection fails PKIX. With `camel.ssl.*` alone it still fails. With 
`useGlobalSslContextParameters=true` it connects. With `wss://127.0.0.1` it 
fails the host name check.
   - `maxReconnectAttempts=3` gives up after 3 attempts.
   - Default ports are 80 and 443.
   - An unreachable server fails the start of the source.
   - The sink reconnects on its next message after a server restart.
   - Source messages are passed on out of order: 20 messages pushed in a row 
arrived shuffled. The description says so.
   - `%26` and `%2B` in a query value of `url` arrive changed. The description 
says so.
   
   ### Upgrade note
   - New Kamelets `websocket-source` and `websocket-sink` (Preview): receive 
the messages a WebSocket server pushes, and send messages to a WebSocket 
server, over `ws://` or `wss://`, with an optional `Authorization` header and 
reconnects.
   
   Fixes #3377.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to