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.git
The following commit(s) were added to refs/heads/main by this push:
new 15ef3bdf3d8a CAMEL-27511: camel-jbang-mcp - the context of
camel_wsdl_inspect samples starts without the CLI connector (#30772)
15ef3bdf3d8a is described below
commit 15ef3bdf3d8afcecc7dff895f469e7fe731c0cd4
Author: Aurélien Pupier <[email protected]>
AuthorDate: Wed Nov 25 10:13:42 2026 +0100
CAMEL-27511: camel-jbang-mcp - the context of camel_wsdl_inspect samples
starts without the CLI connector (#30772)
The CamelContext that camel_wsdl_inspect starts to make the samples of a
WSDL was a bare DefaultCamelContext, so it started the Camel CLI
connector. The connector names its lock file after the pid of the JVM,
~/.camel/<pid>, which every context of the JVM shares, and deletes it
when the context closes. The poll of the other contexts of the JVM shuts
them down when the lock file is gone, as camel stop does. In the
camel-jbang-mcp tests this made OpenApiScaffoldRestOpenApiTest fail with
a null body or a DirectConsumerNotAvailableException when WsdlToolsTest
ran at the same time: the route was stopped while the request was in
flight.
The context now goes through ScratchContextHelper.withoutCliConnector,
as the scratch context of ExpressionEvaluator does since CAMEL-26396.
First attempt of OpenApiScaffoldRestOpenApiTest and WsdlToolsTest,
without reruns: 5 failures in 30 runs before, 0 in 30 after.
Co-authored-by: IBM Bob 2.2.1
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../dsl/jbang/core/commands/mcp/WsdlTools.java | 3 +-
.../commands/mcp/WsdlToolsCliConnectorTest.java | 70 ++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlTools.java
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlTools.java
index 0a162aaf025f..b64e9dc7fe3b 100644
---
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlTools.java
+++
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlTools.java
@@ -32,6 +32,7 @@ import io.quarkiverse.mcp.server.ToolArg;
import io.quarkiverse.mcp.server.ToolCallException;
import io.quarkiverse.mcp.server.ToolGuardrails;
import org.apache.camel.dataformat.xsdjson.XsdJsonSamples;
+import org.apache.camel.dsl.jbang.core.common.ScratchContextHelper;
import org.apache.camel.dsl.jbang.wsdl.WsdlModel;
import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Fault;
import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Operation;
@@ -225,7 +226,7 @@ public class WsdlTools {
+ " is not read, as the WSDL is given as
content");
};
Map<Port, List<Sample>> answer = new LinkedHashMap<>();
- try (DefaultCamelContext context = new DefaultCamelContext()) {
+ try (DefaultCamelContext context =
ScratchContextHelper.withoutCliConnector(new DefaultCamelContext())) {
context.start();
XsdJsonSamples xsd;
try {
diff --git
a/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlToolsCliConnectorTest.java
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlToolsCliConnectorTest.java
new file mode 100644
index 000000000000..b5153fbc97db
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlToolsCliConnectorTest.java
@@ -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.
+ */
+package org.apache.camel.dsl.jbang.core.commands.mcp;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.camel.dsl.jbang.core.commands.mcp.WsdlTools.InspectResult;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.api.parallel.Isolated;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * CAMEL-27511: the CamelContext that camel_wsdl_inspect starts for the
samples must not start the CLI connector. The
+ * connector names its lock file after the pid of the JVM, {@code
~/.camel/<pid>}, which every context of the JVM
+ * shares. When the context of the tool closed, it deleted that lock, and the
other contexts of the MCP server (or of
+ * the tests) shut themselves down as if the Camel CLI had stopped them.
+ * <p>
+ * Isolated because it changes {@code user.home}, where the connector writes
its files.
+ */
+@Isolated
+class WsdlToolsCliConnectorTest {
+
+ @TempDir
+ Path userHome;
+
+ private String previousUserHome;
+
+ @BeforeEach
+ void useHome() {
+ previousUserHome = System.getProperty("user.home");
+ System.setProperty("user.home", userHome.toString());
+ }
+
+ @AfterEach
+ void restoreHome() {
+ System.setProperty("user.home", previousUserHome);
+ }
+
+ @Test
+ void theSamplesAreMadeWithoutTheCliConnector() throws Exception {
+ String wsdl =
Files.readString(Paths.get("src/test/resources/wsdl/orders.wsdl"));
+
+ InspectResult result = new WsdlTools().camel_wsdl_inspect(wsdl,
"getOrder", true);
+
+ // the context did start: the samples are there
+
assertThat(result.ports().get(0).operations().get(0).samples()).isNotEmpty();
+ // and it neither wrote nor deleted the lock file of the JVM
+ assertThat(userHome.resolve(".camel")).doesNotExist();
+ }
+}