You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "Croway (via GitHub)" <gi...@apache.org> on 2026/10/01 14:11:26 UTC

[PR] CAMEL-25197: camel-cli-connector-starter - use the Spring WebSocket client for the websocket transport [camel-spring-boot]

Croway opened a new pull request, #2013:
URL: https://github.com/apache/camel-spring-boot/pull/2013

   _Claude Code on behalf of Croway_
   
   Spring Boot side of [CAMEL-25197](https://issues.apache.org/jira/browse/CAMEL-25197): the websocket transport of the Camel CLI connector uses Spring's WebSocket client when the application has it, and the JDK client otherwise, without adding any dependency to the application.
   
   **Depends on** apache/camel#27210 (the `CliWebSocketClient` SPI) and apache/camel#27214 (the application exits after the `stop` action). CI fails to compile until #27210 is merged and published as a snapshot.
   
   ## Changes
   
   - `SpringCliWebSocketClient`, a `CliWebSocketClient` on Spring's `StandardWebSocketClient` (Jakarta WebSocket, for example Tomcat's `tomcat-embed-websocket`):
     - sends through the asynchronous Jakarta remote endpoint, so the transport's send timeout can abort a hanging send;
     - reassembles partial messages itself, with the 16 MB cap of the SPI (the connection is aborted above it). Raising the Jakarta text buffer instead would allocate it for every connection: Tomcat allocates `maxTextMessageBufferSize` up front (`WsFrameBase`);
     - reports the HTTP status of a rejected handshake as a `CliWebSocketHandshakeException`: Jakarta WebSocket has no API for it, Tomcat puts it in the `DeploymentException` message (`[401]`);
     - Tomcat client options: 10 s connect timeout (as the JDK client), 10 s blocking send timeout (pings, close frames);
     - created lazily, so an application without a Jakarta WebSocket implementation still starts.
   - `CliConnectorAutoConfiguration`: registers it when `StandardWebSocketClient` and `jakarta.websocket.ContainerProvider` are on the classpath and there is no `CliWebSocketClient` bean. `spring-websocket` and `jakarta.websocket-client-api` are `<optional>`. A plain web application (`spring-boot-starter-web`) has Tomcat's Jakarta WebSocket but not `spring-websocket`, so it keeps the JDK client. `camel.cli.websocket.client=jdk` forces the JDK client (Camel option).
   - `camel.cli.websocket.ssl-bundle`: a Spring SSL bundle for `wss://` (`StandardWebSocketClient.setSslContext`, passed to `ClientEndpointConfig.getSSLContext()`, which Tomcat uses in `WsWebSocketContainer.createSSLEngine`).
   - `CliConnectorConfiguration`: `camel.cli.transport` and the `camel.cli.websocket.*` options, for configuration metadata (IDE completion). Camel reads them from the Spring environment. The starter now runs `spring-boot-configuration-processor` (it had no metadata).
   - `SpringLocalCliConnector`: the `stop` action (and `camel stop`) closes the application context instead of only stopping it, so the application exits (a stopped web application kept the JVM running). With apache/camel#27214, Spring Boot applications exit about 1 s after the `stop` action.
   - Docs: new starter page `starters/cli-connector.adoc` (generated from `src/main/doc`), and `cli-connector.json` regenerated.
   
   ## Tests
   
   - `CliConnectorAutoConfigurationTest` (`ApplicationContextRunner`): Spring client with `spring-websocket`; no bean without `StandardWebSocketClient` or without `jakarta.websocket` (`FilteredClassLoader`), so Camel uses the JDK client; an application bean wins; SSL bundle.
   - `SpringCliWebSocketClientTest`, against an embedded Tomcat WebSocket server: handshake headers, a 2 MB message (received in parts), ping/pong, close, abort, a message over 16 MB, a rejected handshake (HTTP 401).
   - `CliConnectorWebSocketSpringClientTest` / `CliConnectorWebSocketJdkClientTest`: a Spring Boot application with `camel.cli.transport=websocket` connects to the in-test tool, says `hello` with `transport` `spring` (or `jdk` with `camel.cli.websocket.client=jdk`), and executes an action.
   - `CliConnectorStopActionTest`: the `stop` action closes the application context.
   - `mvn install` in `dsl-starter/camel-cli-connector-starter`: 14 tests, 0 failures (against apache/camel#27210).
   - Soak (240 s, a tool server with a chaos proxy: the tool closes every connection, a network blackhole, the tool down, the token rejected), 6 applications: 2 Camel Main, 2 Spring Boot web applications (JDK client), 2 Spring Boot applications with `spring-boot-starter-websocket` (Spring client). Every application used the expected client, recovered from every disruption, reported the rejected token as HTTP 401, logged no unexpected error, and, with apache/camel#27214, exited about 1 s after the `stop` action.
   


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25197: camel-cli-connector-starter - use the Spring WebSocket client for the websocket transport [camel-spring-boot]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on code in PR #2013:
URL: https://github.com/apache/camel-spring-boot/pull/2013#discussion_r4157825440


##########
dsl-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/SpringLocalCliConnector.java:
##########
@@ -30,12 +32,27 @@ public SpringLocalCliConnector(CliConnectorFactory cliConnectorFactory,
         this.applicationContext = applicationContext;
     }
 
+    @Override
+    protected CliConnectorTransport createTransport(String name) {
+        // Camel refuses it with the Camel prod profile (camel.main.profile), which Spring profiles do not set
+        if ("websocket".equalsIgnoreCase(name)
+                && applicationContext.getEnvironment().acceptsProfiles(Profiles.of("prod"))) {
+            throw new IllegalStateException(
+                    "The Camel CLI connector websocket transport gives the connected tool full control of this"
+                                            + " application and cannot be used with the Spring prod profile."
+                                            + " Remove camel.cli.transport=websocket, or use another profile.");
+        }
+        return super.createTransport(name);
+    }
+
     @Override
     public void sigterm() {
         try {
             super.sigterm();
         } finally {
-            applicationContext.stop();
+            // close, not only stop: a stopped context keeps the JVM running (for example the embedded web server),
+            // while the Camel CLI (camel stop) and the websocket tools expect the application to exit
+            applicationContext.close();

Review Comment:
   _Claude Code on behalf of Croway_
   
   Done in 0a8cc3cefc3: a comment on the concurrent stop (Camel stops a context under a lock in `BaseService.stop()`, so whichever comes second waits for the first, then finds it stopped), and `CliConnectorSpringLifecycleTest.camelStopClosesTheApplicationContext` for the file transport (lock file deleted, context closed).



##########
dsl-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/CliConnectorAutoConfiguration.java:
##########
@@ -69,4 +73,30 @@ public CliConnectorFactory cliConnectorFactory(AbstractApplicationContext applic
         return answer;
     }
 
+    /**
+     * The Spring WebSocket client for the websocket transport, when the application has spring-websocket and a Jakarta
+     * WebSocket client (such as Tomcat with spring-boot-starter-websocket). Otherwise Camel uses the JDK client.
+     */
+    @Configuration(proxyBeanMethods = false)
+    @ConditionalOnClass(name = {
+            "org.springframework.web.socket.client.standard.StandardWebSocketClient",
+            "jakarta.websocket.ContainerProvider" })

Review Comment:
   _Claude Code on behalf of Croway_
   
   Done in 0a8cc3cefc3: `OnSpringWebSocketClientCondition` also requires a `ContainerProvider` service (looked up with `ServiceLoader` as `ContainerProvider.getWebSocketContainer()` does, without creating it), so the API alone no longer matches and Camel keeps the JDK client. Tested with a `FilteredClassLoader` hiding `META-INF/services/jakarta.websocket.ContainerProvider`.



##########
dsl-starter/camel-cli-connector-starter/src/test/java/org/apache/camel/springboot/cli/connector/CliConnectorWebSocketJdkClientTest.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.camel.springboot.cli.connector;
+
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.test.spring.junit6.CamelSpringBootTest;
+import org.apache.camel.test.spring.junit6.DisableJmx;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+
+/**
+ * The connector uses the JDK client when asked to, even with the Spring WebSocket client available.
+ */
+@DirtiesContext
+@CamelSpringBootTest
+// the status sent to the tool is built from the JMX management layer
+@DisableJmx(false)
+@SpringBootTest(classes = {
+        CamelAutoConfiguration.class, CliConnectorAutoConfiguration.class,
+        CliConnectorWebSocketTestSupport.Routes.class },
+                properties = {
+                        "camel.cli.transport=websocket",
+                        "camel.cli.websocket.snapshot-interval=200",
+                 "camel.cli.websocket.client=jdk" })

Review Comment:
   _Claude Code on behalf of Croway_
   
   Fixed in 0a8cc3cefc3.



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25197: camel-cli-connector-starter - use the Spring WebSocket client for the websocket transport [camel-spring-boot]

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #2013:
URL: https://github.com/apache/camel-spring-boot/pull/2013#discussion_r4157562225


##########
dsl-starter/camel-cli-connector-starter/src/test/java/org/apache/camel/springboot/cli/connector/CliConnectorWebSocketJdkClientTest.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.camel.springboot.cli.connector;
+
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.test.spring.junit6.CamelSpringBootTest;
+import org.apache.camel.test.spring.junit6.DisableJmx;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+
+/**
+ * The connector uses the JDK client when asked to, even with the Spring WebSocket client available.
+ */
+@DirtiesContext
+@CamelSpringBootTest
+// the status sent to the tool is built from the JMX management layer
+@DisableJmx(false)
+@SpringBootTest(classes = {
+        CamelAutoConfiguration.class, CliConnectorAutoConfiguration.class,
+        CliConnectorWebSocketTestSupport.Routes.class },
+                properties = {
+                        "camel.cli.transport=websocket",
+                        "camel.cli.websocket.snapshot-interval=200",
+                 "camel.cli.websocket.client=jdk" })

Review Comment:
   Nit: indentation is off compared to the two properties above (`mvn formatter:format` should fix it).
   
   ```suggestion
                           "camel.cli.websocket.client=jdk" })
   ```



##########
dsl-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/SpringLocalCliConnector.java:
##########
@@ -30,12 +32,27 @@ public SpringLocalCliConnector(CliConnectorFactory cliConnectorFactory,
         this.applicationContext = applicationContext;
     }
 
+    @Override
+    protected CliConnectorTransport createTransport(String name) {
+        // Camel refuses it with the Camel prod profile (camel.main.profile), which Spring profiles do not set
+        if ("websocket".equalsIgnoreCase(name)
+                && applicationContext.getEnvironment().acceptsProfiles(Profiles.of("prod"))) {
+            throw new IllegalStateException(
+                    "The Camel CLI connector websocket transport gives the connected tool full control of this"
+                                            + " application and cannot be used with the Spring prod profile."
+                                            + " Remove camel.cli.transport=websocket, or use another profile.");
+        }
+        return super.createTransport(name);
+    }
+
     @Override
     public void sigterm() {
         try {
             super.sigterm();
         } finally {
-            applicationContext.stop();
+            // close, not only stop: a stopped context keeps the JVM running (for example the embedded web server),
+            // while the Camel CLI (camel stop) and the websocket tools expect the application to exit
+            applicationContext.close();

Review Comment:
   Closing makes sense (the original `stop()` from CAMEL-18425 has no stated reason, and a stopped web app keeps the JVM alive). `super.sigterm()` has just started a "Terminate JVM task" that calls `camelContext.stop()`, so the two run at the same time. That's harmless as far as I can tell and was already the case with `stop()`, but a short comment would help the next reader. Could you also add a test for the file transport (lock file deleted → context closed)? Today only the websocket `stop` action is covered.



##########
dsl-starter/camel-cli-connector-starter/src/main/java/org/apache/camel/springboot/cli/connector/CliConnectorAutoConfiguration.java:
##########
@@ -69,4 +73,30 @@ public CliConnectorFactory cliConnectorFactory(AbstractApplicationContext applic
         return answer;
     }
 
+    /**
+     * The Spring WebSocket client for the websocket transport, when the application has spring-websocket and a Jakarta
+     * WebSocket client (such as Tomcat with spring-boot-starter-websocket). Otherwise Camel uses the JDK client.
+     */
+    @Configuration(proxyBeanMethods = false)
+    @ConditionalOnClass(name = {
+            "org.springframework.web.socket.client.standard.StandardWebSocketClient",
+            "jakarta.websocket.ContainerProvider" })

Review Comment:
   `ContainerProvider` is in the Jakarta WebSocket API, so this checks for the API rather than an implementation. An app with `spring-websocket` plus the API jar but no implementation (for example, WebFlux/Netty with the API pulled in transitively) gets this bean. Camel's `auto` mode then picks it from the registry, every connect fails ("no Jakarta WebSocket implementation"), and the transport keeps reconnecting instead of falling back to the JDK client. Would it be worth also checking that `ServiceLoader.load(ContainerProvider.class)` finds a provider (a custom `Condition`), or having the client fall back to the JDK client in that case?



-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25197: camel-cli-connector-starter - use the Spring WebSocket client for the websocket transport [camel-spring-boot]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on PR #2013:
URL: https://github.com/apache/camel-spring-boot/pull/2013#issuecomment-5935693991

   _Claude Code on behalf of Croway_
   
   Thanks for the review. Addressed in the third commit:
   
   1. **`stop()` → `close()`**: added a comment on the concurrent stop: Camel stops a context under a lock (`BaseService.stop()`), so whichever of the "Terminate JVM task" and `close()` comes second waits for the first one, then finds it stopped. Added `CliConnectorSpringLifecycleTest.camelStopClosesTheApplicationContext`: file transport, the lock file `~/.camel/{pid}` is deleted (what `camel stop` does), the context ends up closed.
   2. **Upgrade guide**: agreed, it is more of a fix. apache/camel#27210 and #27214 are merged, so it would be a small docs PR on Camel `main` (TBD).
   3. **Condition on an implementation**: right, the Jakarta API alone matched. Replaced the `@ConditionalOnClass` with `OnSpringWebSocketClientCondition`: spring-websocket, the Jakarta API, and a `ContainerProvider` service found with `ServiceLoader` (as `ContainerProvider.getWebSocketContainer()` looks it up, without creating it). It also does not match with `camel.cli.websocket.client=jdk`. Tested with a `FilteredClassLoader` hiding `META-INF/services/jakarta.websocket.ContainerProvider`.
   4. **`ssl-bundle` ignored**: a WARN at startup when `camel.cli.transport=websocket`, `camel.cli.websocket.ssl-bundle` is set and the JDK client is used (`client=jdk`, or no spring-websocket / Jakarta implementation). Tested for both cases.
   5. **Defaults drift**: added a comment on `CliConnectorConfiguration.Websocket` pointing at `WebSocketCliConnectorTransport`.
   6. **`Cli Connector` title**: the page is generated (`update-starter-doc-page`), which takes the title from the catalog for components, data formats and languages only, and capitalizes the starter name otherwise. Fixing it means teaching the generator about `other` catalog entries, which would change other generated pages too, so I left it out of this PR.
   
   Related to apache/camel#27220 (CAMEL-25230): the Spring client opened connections on a `SimpleAsyncTaskExecutor`, whose threads are not daemon threads by default. When the application fails to start, Camel never stops the connector, which keeps reconnecting, so a connect in progress could delay the exit. They are daemon threads now (tested), as the threads of the transport. The upgrade guide note of point 2 could also go next to the one #27220 adds in the `camel-cli-connector` section of the 4.23 guide.
   


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] CAMEL-25197: camel-cli-connector-starter - use the Spring WebSocket client for the websocket transport [camel-spring-boot]

Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway merged PR #2013:
URL: https://github.com/apache/camel-spring-boot/pull/2013


-- 
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: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org