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 43668a16775d CAMEL-27396: camel-jbang - MCP tools and a TUI view for a
WSDL (camel-jbang-wsdl) (#30616)
43668a16775d is described below
commit 43668a16775dac4e462a4da69f5b4dfa4aa01cfb
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 21:57:37 2026 +0100
CAMEL-27396: camel-jbang - MCP tools and a TUI view for a WSDL
(camel-jbang-wsdl) (#30616)
CAMEL-27397: camel-xsd-json - XsdJsonSamples: a sample of a global element
as JSON and XML
A new public class XsdJsonSamples gives a sample of a global element of a
schema, as JSON in the form of the xsdJson data format and as the XML that
the data format writes from it. Every element and attribute has a value of
its type: the first value of an enumeration, a date for xs:date, a number
for xs:int, and so on; a repeating element has one item, of an xs:choice
only the first member is filled in, and a type that contains itself is
filled in once.
The simple types of the model keep the built-in type they derive from and
their first enumeration value for that. An optional DocumentReader reads
the schema and its imports instead of the CamelContext, so a caller can
restrict where they are read from.
CAMEL-27397: camel-jbang - camel generate wsdl --samples: a sample request
and response per operation
With --samples, camel generate wsdl writes for each operation (or those of
--operation) a sample request, response and faults, as XML and as JSON in
the xsdJson form (XsdJsonSamples of camel-xsd-json), and the request in a
SOAP envelope of the SOAP version of the port with a curl command that
posts it to the address of the WSDL. They are printed, written as files
with --output=<dir>, or put into the listing with --json.
The XML schema of a remote WSDL is read with the rules of a wsdl:import:
the host of the WSDL only, and a redirect only to the same scheme, host and
port. A SOAP action or address that is not a plain URI is not put into the
curl command, and only NCNames go into file names.
CAMEL-27397: XsdJsonSamples is AutoCloseable, and documents that a schema
that cannot be loaded fails
Addresses the review: close() stops the data format the samples are
written with, camel generate wsdl closes it, and the constructors document
the RuntimeCamelException of a schema that cannot be loaded.
CAMEL-27396: camel-jbang-wsdl - the WSDL code of camel generate wsdl in a
module of its own
WsdlModel, WsdlRouteScaffold and WsdlSamples move from
camel-jbang-plugin-generate into the new module camel-jbang-wsdl (public, in
org.apache.camel.dsl.jbang.wsdl), so the MCP server and the TUI can use them
without the generate plugin and its openapi-generator. WsdlModel.parse reads
a WSDL given as content and follows no import.
CAMEL-27396: camel-jbang-mcp - camel_wsdl_inspect and camel_wsdl_scaffold
Two MCP tools do what camel generate wsdl does, from the content of a WSDL:
camel_wsdl_inspect lists the services, ports and operations with the cxf
endpoint options, and with samples=true the sample messages of each
operation; camel_wsdl_scaffold writes a consumer or producer route. They
read no file and call no host: the imports of the WSDL are not followed.
CAMEL-27396: camel-jbang - the Endpoints tab shows the WSDL of a cxf
endpoint
For a cxf endpoint with a wsdlURL, w shows its WSDL in the bottom panel of
the Endpoints tab, in place of the documentation: the services and ports
with the SOAP version and address, and a table of the operations with their
request, response and fault elements. A file: or classpath: WSDL is looked
up in the folder of the integration (and src/main/resources), an http(s)
one is read with the rules of camel generate wsdl; it is read once, on a
thread of its own.
CAMEL-27396: camel-jbang - review nits: the rest-openapi comment above its
dependency, the selectedEndpoint javadoc on its method
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Claus Ibsen <[email protected]>
---
bom/camel-bom/pom.xml | 5 +
.../modules/ROOT/pages/camel-jbang-mcp.adoc | 32 +++
dsl/camel-jbang/camel-jbang-mcp/pom.xml | 5 +
.../dsl/jbang/core/commands/mcp/WsdlTools.java | 309 +++++++++++++++++++++
.../dsl/jbang/core/commands/mcp/WsdlToolsTest.java | 122 ++++++++
.../src/test/resources/wsdl/orders.wsdl | 116 ++++++++
.../camel-jbang-plugin-generate/pom.xml | 4 +-
.../core/commands/generate/CodeWsdlGenerator.java | 15 +-
.../commands/generate/CodeWsdlGeneratorTest.java | 31 +--
dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml | 4 +
.../dsl/jbang/core/commands/tui/EndpointsTab.java | 88 +++++-
.../dsl/jbang/core/commands/tui/WsdlView.java | 189 +++++++++++++
.../src/main/resources/tui/help/endpoints.md | 15 +
.../core/commands/tui/EndpointsTabRenderTest.java | 30 ++
.../dsl/jbang/core/commands/tui/WsdlViewTest.java | 91 ++++++
.../src/test/resources/wsdl/orders.wsdl | 116 ++++++++
dsl/camel-jbang/camel-jbang-wsdl/pom.xml | 62 +++++
.../apache/camel/dsl/jbang/wsdl}/WsdlModel.java | 84 ++++--
.../camel/dsl/jbang/wsdl}/WsdlRouteScaffold.java | 21 +-
.../apache/camel/dsl/jbang/wsdl}/WsdlSamples.java | 28 +-
.../apache/camel/dsl/jbang/wsdl/WsdlModelTest.java | 101 +++++++
.../src/test/resources/wsdl/orders.wsdl | 116 ++++++++
dsl/camel-jbang/pom.xml | 1 +
parent/pom.xml | 5 +
24 files changed, 1499 insertions(+), 91 deletions(-)
diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index 393e8296265b..51b48eec5057 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -1412,6 +1412,11 @@
<artifactId>camel-jbang-run</artifactId>
<version>4.24.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jbang-wsdl</artifactId>
+ <version>4.24.0-SNAPSHOT</version>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jcache</artifactId>
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
index 3694d8559c1c..d6bf1db96be3 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-mcp.adoc
@@ -258,6 +258,12 @@ The assistant discovers components, looks up
documentation, builds a YAML route,
Combine both for a complete prototyping workflow: validate, scaffold, then
implement routes one at a time while Camel mocks the rest.
+=== SOAP services from a WSDL
+
+* _"What operations does this WSDL have, and what does a getOrder request look
like?"_ — uses `camel_wsdl_inspect`
+ with `samples=true`
+* _"Write a Camel route that serves this WSDL"_ — uses `camel_wsdl_scaffold`
with `route=consumer`
+
=== Runtime introspection
Start a route with `camel run my-route.yaml`, then ask:
@@ -789,6 +795,32 @@ help validate and scaffold that workflow, following the
rules of the `rest-opena
otherwise HTTP 204 with an empty body.
|===
+=== SOAP (WSDL)
+
+These tools do what `camel generate wsdl` does, from the content of a WSDL 1.1
document with SOAP 1.1 or 1.2
+bindings. As the WSDL is given as content, they read no file and call no host:
a `wsdl:import` of the WSDL is not
+followed but listed as a warning, and the samples of the elements in a schema
that it imports are left out.
+
+[cols="1,3",options="header"]
+|===
+| Tool | Description
+
+| `camel_wsdl_inspect`
+| Lists the services, ports and operations of the WSDL: the SOAP version and
address of each port, with the
+ xref:components::cxf-component.adoc[CXF] endpoint options (`serviceName`,
`portName`, `address`,
+ `defaultOperationNamespace`), and the SOAP action, request, response and
fault elements of each operation. With
+ `samples=true`, each operation also has a sample request, response and
faults, as XML and as JSON in the form of
+ the xref:next@components:dataformats:xsdJson-dataformat.adoc[XSD JSON] data
format, and the request in a SOAP
+ envelope with a `curl` command that posts it.
+
+| `camel_wsdl_scaffold`
+| Scaffolds a YAML route for a port in `PAYLOAD` mode, with no generated
classes. `route=consumer` is a SOAP service:
+ a `cxf:` consumer with schema validation, whose address is the path of the
WSDL address (such as `cxf:/orders`,
+ served under `/services` by Camel Main, Spring Boot and Quarkus), and a
`when` per operation that returns a
+ placeholder response. `route=producer` is a SOAP client: a
`direct:<operation>` route per operation. `wsdlUrl` is
+ where the route finds the WSDL at runtime (default `classpath:service.wsdl`).
+|===
+
=== Migration
[cols="1,3",options="header"]
diff --git a/dsl/camel-jbang/camel-jbang-mcp/pom.xml
b/dsl/camel-jbang/camel-jbang-mcp/pom.xml
index 648fcfef5f78..4e32e112b9fb 100644
--- a/dsl/camel-jbang/camel-jbang-mcp/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-mcp/pom.xml
@@ -127,6 +127,11 @@
<artifactId>camel-yaml-dsl</artifactId>
</dependency>
+ <!-- the wsdl tools -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jbang-wsdl</artifactId>
+ </dependency>
<!-- rest-openapi component: the OpenAPI tools follow its rules
(generated operation ids) -->
<dependency>
<groupId>org.apache.camel</groupId>
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
new file mode 100644
index 000000000000..0a162aaf025f
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlTools.java
@@ -0,0 +1,309 @@
+/*
+ * 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.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import jakarta.enterprise.context.ApplicationScoped;
+
+import io.quarkiverse.mcp.server.Tool;
+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.wsdl.WsdlModel;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Fault;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Operation;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Port;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Service;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.WsdlException;
+import org.apache.camel.dsl.jbang.wsdl.WsdlRouteScaffold;
+import org.apache.camel.dsl.jbang.wsdl.WsdlSamples;
+import org.apache.camel.dsl.jbang.wsdl.WsdlSamples.Sample;
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * MCP Tools for SOAP services: what camel generate wsdl does, from the
content of a WSDL. The WSDL is given as content,
+ * so the tools read no file and call no host: a wsdl:import or an xs:import
of the WSDL is not followed (it is listed
+ * as a warning, or the samples of its elements are left out).
+ */
+@McpSecured
+@ApplicationScoped
+public class WsdlTools {
+
+ /**
+ * The location of the WSDL content for the XML schema loader; only this
document is read.
+ */
+ private static final String CONTENT = "content:service.wsdl";
+
+ @ToolGuardrails(input = McpArgumentGuardrail.class, output =
McpArgumentGuardrail.class)
+ @Tool(annotations = @Tool.Annotations(readOnlyHint = true, destructiveHint
= false, openWorldHint = false),
+ description = "List the services, ports and operations of a WSDL 1.1
(SOAP 1.1 or 1.2), with the cxf endpoint"
+ + " options of each port (serviceName, portName,
address, defaultOperationNamespace) and the"
+ + " request, response and fault elements of each
operation. With samples=true, each operation"
+ + " also has a sample request, response and faults, as
XML and as JSON in the form of the"
+ + " xsdJson data format, and the request in a SOAP
envelope with a curl command."
+ + " Imports of the WSDL are not followed.")
+ public InspectResult camel_wsdl_inspect(
+ @ToolArg(description = "The WSDL document (XML content)") String
wsdl,
+ @ToolArg(description = "The operations to list (comma separated;
default: all)",
+ required = false) String operations,
+ @ToolArg(description = "Whether to add sample messages to each
operation (default: false)",
+ required = false) Boolean samples) {
+
+ WsdlModel model = parse(wsdl);
+ List<String> ops = names(operations);
+ List<String> warnings = new ArrayList<>(model.warnings());
+ Map<Port, List<Sample>> all = new LinkedHashMap<>();
+ if (Boolean.TRUE.equals(samples)) {
+ all = samples(wsdl, model.services(), ops, warnings);
+ }
+
+ List<PortInfo> ports = new ArrayList<>();
+ for (Service s : model.services()) {
+ for (Port p : s.ports()) {
+ List<OperationInfo> list = new ArrayList<>();
+ for (Operation o : selected(p, ops)) {
+ List<FaultInfo> faults = new ArrayList<>();
+ for (Fault f : o.faults()) {
+ faults.add(new FaultInfo(f.name(), f.element() != null
? f.element().toString() : null));
+ }
+ List<SampleInfo> sampleInfos = null;
+ if (all.containsKey(p)) {
+ sampleInfos = new ArrayList<>();
+ for (Sample sample : all.get(p)) {
+ if (sample.operation().equals(o.name())) {
+ sampleInfos.add(new SampleInfo(
+ sample.kind(),
"fault".equals(sample.kind()) ? sample.name() : null,
+ sample.element().toString(),
sample.xml(), sample.json(), sample.soap(),
+ sample.curl()));
+ }
+ }
+ }
+ list.add(new OperationInfo(
+ o.name(), o.soapAction(), o.style(), o.oneWay(),
+ o.input() != null ? o.input().toString() : null,
+ o.output() != null ? o.output().toString() : null,
faults, sampleInfos));
+ }
+ String address = WsdlModel.maskedAddress(p.address());
+ Map<String, String> cxf = new LinkedHashMap<>();
+ cxf.put("serviceName", p.service().toString());
+ cxf.put("portName", p.qname().toString());
+ if (address != null) {
+ cxf.put("address", address);
+ }
+ cxf.put("defaultOperationNamespace", p.namespace());
+ ports.add(new PortInfo(
+ s.name().getLocalPart(), p.name(),
p.binding().toString(), p.soapVersion(), p.style(), address,
+ p.namespace(), cxf, list));
+ }
+ }
+ return new InspectResult(model.targetNamespace(), ports, warnings);
+ }
+
+ @ToolGuardrails(input = McpArgumentGuardrail.class, output =
McpArgumentGuardrail.class)
+ @Tool(annotations = @Tool.Annotations(readOnlyHint = true, destructiveHint
= false, openWorldHint = false),
+ description = "Scaffold a Camel YAML route for a port of a WSDL, in
PAYLOAD mode with no generated classes."
+ + " route=consumer is a SOAP service: a cxf consumer
(with schema validation) whose address is"
+ + " the path of the WSDL address, such as cxf:/orders,
served under /services by Camel Main,"
+ + " Spring Boot and Quarkus, with a choice of one when
per operation that returns a placeholder"
+ + " response. route=producer is a SOAP client: a
direct:<operation> route per operation that"
+ + " calls the service with the request element as the
body.")
+ public ScaffoldResult camel_wsdl_scaffold(
+ @ToolArg(description = "The WSDL document (XML content)") String
wsdl,
+ @ToolArg(description = "consumer (a SOAP service) or producer (a
SOAP client)") String route,
+ @ToolArg(description = "The wsdlURL of the endpoints, where the
route finds the WSDL at runtime"
+ + " (default: classpath:service.wsdl)",
+ required = false) String wsdlUrl,
+ @ToolArg(description = "The service (its name), when the WSDL has
more than one", required = false) String service,
+ @ToolArg(description = "The port (its name), when the service has
more than one", required = false) String port,
+ @ToolArg(description = "The operations to scaffold (comma
separated; default: all)",
+ required = false) String operations) {
+
+ String kind = route == null ? "" :
route.strip().toLowerCase(Locale.ROOT);
+ if (!"consumer".equals(kind) && !"producer".equals(kind)) {
+ throw new ToolCallException("'route' must be 'consumer' or
'producer', got: " + route, null);
+ }
+ String url = wsdlUrl == null || wsdlUrl.isBlank() ?
"classpath:service.wsdl" : wsdlUrl.strip();
+ WsdlModel model = parse(wsdl);
+
+ List<Port> ports = new ArrayList<>();
+ for (Service s : model.services()) {
+ if (service != null && !service.isBlank() &&
!matches(s.name().getLocalPart(), s.name().toString(), service)) {
+ continue;
+ }
+ for (Port p : s.ports()) {
+ if (port == null || port.isBlank() || matches(p.name(),
p.qname().toString(), port)) {
+ ports.add(p);
+ }
+ }
+ }
+ if (ports.isEmpty()) {
+ throw new ToolCallException("No port matches the service and port
given", null);
+ }
+ if (ports.size() > 1) {
+ StringBuilder sb = new StringBuilder("The WSDL has more than one
port; choose one with service and port:");
+ for (Port p : ports) {
+ sb.append("
service=").append(p.service().getLocalPart()).append(" port=").append(p.name())
+ .append(" (SOAP ").append(p.soapVersion()).append(')');
+ }
+ throw new ToolCallException(sb.toString(), null);
+ }
+ Port p = ports.get(0);
+ List<String> ops = names(operations);
+ List<Operation> selected = selected(p, ops);
+ for (String op : ops) {
+ if (selected.stream().noneMatch(o -> o.name().equals(op))) {
+ throw new ToolCallException(
+ "Unknown operation: " + op + " (the operations: "
+ + String.join(", ",
p.operations().stream().map(Operation::name).toList())
+ + ")",
+ null);
+ }
+ }
+ WsdlRouteScaffold scaffold = new WsdlRouteScaffold(p, selected, url);
+ String yaml;
+ try {
+ yaml = "consumer".equals(kind) ? scaffold.consumer() :
scaffold.producer();
+ } catch (WsdlException e) {
+ throw new ToolCallException(e.getMessage(), null);
+ }
+ List<String> warnings = new ArrayList<>(model.warnings());
+ warnings.addAll(scaffold.warnings());
+ String explanation = "consumer".equals(kind)
+ ? "The consumer is served on the HTTP server of the runtime
under /services (Camel Main needs"
+ + " camel-cxf-platform-http, which camel run adds). Replace
the placeholder response of each operation:"
+ + " until then the schema validation answers with a SOAP
fault that names the first missing element."
+ : "Send the request element (XML) to direct:<operation>. The
route removes the Camel and CXF operation"
+ + " headers first, so a caller cannot choose another
operation or address.";
+ return new ScaffoldResult(
+ yaml, kind, p.service().getLocalPart(), p.name(),
p.soapVersion(), url, explanation,
+ warnings);
+ }
+
+ private static WsdlModel parse(String wsdl) {
+ if (wsdl == null || wsdl.isBlank()) {
+ throw new ToolCallException("'wsdl' parameter is required and must
not be blank", null);
+ }
+ try {
+ return WsdlModel.parse(wsdl.getBytes(StandardCharsets.UTF_8));
+ } catch (WsdlException e) {
+ throw new ToolCallException("Cannot read the WSDL: " +
e.getMessage(), null);
+ }
+ }
+
+ private static Map<Port, List<Sample>> samples(
+ String wsdl, List<Service> services, List<String> operations,
List<String> warnings) {
+ byte[] content = wsdl.getBytes(StandardCharsets.UTF_8);
+ XsdJsonSamples.DocumentReader reader = uri -> {
+ if (CONTENT.equals(uri)) {
+ return content;
+ }
+ throw new IOException(
+ "The document " + WsdlModel.printable(uri)
+ + " is not read, as the WSDL is given as
content");
+ };
+ Map<Port, List<Sample>> answer = new LinkedHashMap<>();
+ try (DefaultCamelContext context = new DefaultCamelContext()) {
+ context.start();
+ XsdJsonSamples xsd;
+ try {
+ xsd = new XsdJsonSamples(context, CONTENT, reader);
+ } catch (RuntimeException e) {
+ warnings.add("No samples: the XML schema of the WSDL cannot be
read: " + WsdlModel.printable(e.getMessage()));
+ return answer;
+ }
+ try (xsd) {
+ for (Service s : services) {
+ for (Port p : s.ports()) {
+ WsdlSamples ws = new WsdlSamples(p, selected(p,
operations), xsd);
+ answer.put(p, ws.samples(""));
+ warnings.addAll(ws.warnings());
+ }
+ }
+ }
+ } catch (IOException e) {
+ // closing the CamelContext of the samples
+ warnings.add("Cannot stop the CamelContext of the samples: " +
e.getMessage());
+ }
+ return answer;
+ }
+
+ private static List<String> names(String operations) {
+ if (operations == null || operations.isBlank()) {
+ return List.of();
+ }
+ return
Arrays.stream(operations.split(",")).map(String::strip).filter(o ->
!o.isEmpty()).toList();
+ }
+
+ private static List<Operation> selected(Port p, List<String> operations) {
+ if (operations.isEmpty()) {
+ return p.operations();
+ }
+ return p.operations().stream().filter(o ->
operations.contains(o.name())).toList();
+ }
+
+ private static boolean matches(String localName, String qname, String
option) {
+ String o = option.strip();
+ return o.equals(localName) || o.equals(qname);
+ }
+
+ // -- Result records --
+
+ public record InspectResult(String targetNamespace, List<PortInfo> ports,
List<String> warnings) {
+ }
+
+ public record PortInfo(
+ String service, String port, String binding, String soapVersion,
String style, String address,
+ String namespace, Map<String, String> cxf, List<OperationInfo>
operations) {
+ }
+
+ public record OperationInfo(
+ String name, String soapAction, String style, boolean oneWay,
String input, String output,
+ List<FaultInfo> faults, List<SampleInfo> samples) {
+ }
+
+ public record FaultInfo(String name, String element) {
+ }
+
+ /**
+ * A sample message of an operation.
+ *
+ * @param kind request, response or fault
+ * @param fault the name of the fault, for a fault
+ * @param element the element of the message
+ * @param xml the XML document
+ * @param json the JSON in the form of the xsdJson data format
+ * @param soap the request in a SOAP envelope (request only)
+ * @param curl a curl command that posts the envelope, saved as a file,
to the address of the port (request only)
+ */
+ public record SampleInfo(
+ String kind, String fault, String element, String xml, String
json, String soap, String curl) {
+ }
+
+ public record ScaffoldResult(
+ String yaml, String route, String service, String port, String
soapVersion, String wsdlUrl,
+ String explanation, List<String> warnings) {
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlToolsTest.java
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlToolsTest.java
new file mode 100644
index 000000000000..0a396854733d
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/WsdlToolsTest.java
@@ -0,0 +1,122 @@
+/*
+ * 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.Paths;
+
+import io.quarkiverse.mcp.server.ToolCallException;
+import org.apache.camel.dsl.jbang.core.commands.mcp.WsdlTools.InspectResult;
+import org.apache.camel.dsl.jbang.core.commands.mcp.WsdlTools.OperationInfo;
+import org.apache.camel.dsl.jbang.core.commands.mcp.WsdlTools.PortInfo;
+import org.apache.camel.dsl.jbang.core.commands.mcp.WsdlTools.SampleInfo;
+import org.apache.camel.dsl.jbang.core.commands.mcp.WsdlTools.ScaffoldResult;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class WsdlToolsTest {
+
+ private final WsdlTools tools = new WsdlTools();
+
+ private static String orders() throws Exception {
+ return
Files.readString(Paths.get("src/test/resources/wsdl/orders.wsdl"));
+ }
+
+ @Test
+ void inspectListsThePortsAndOperations() throws Exception {
+ InspectResult result = tools.camel_wsdl_inspect(orders(), null, null);
+
+
assertThat(result.targetNamespace()).isEqualTo("http://example.com/orders");
+ PortInfo port = result.ports().get(0);
+ assertThat(port.service()).isEqualTo("OrderService");
+ assertThat(port.soapVersion()).isEqualTo("1.1");
+ assertThat(port.cxf()).containsEntry("serviceName",
"{http://example.com/orders}OrderService")
+ .containsEntry("address", "http://localhost:18081/orders");
+
assertThat(port.operations()).extracting(OperationInfo::name).containsExactly("getOrder",
"placeOrder");
+ OperationInfo getOrder = port.operations().get(0);
+
assertThat(getOrder.input()).isEqualTo("{http://example.com/orders}getOrder");
+
assertThat(getOrder.faults()).extracting(WsdlTools.FaultInfo::name).containsExactly("orderNotFound");
+ // no samples unless asked for
+ assertThat(getOrder.samples()).isNull();
+ }
+
+ @Test
+ void inspectWithSamples() throws Exception {
+ InspectResult result = tools.camel_wsdl_inspect(orders(), "getOrder",
true);
+
+ OperationInfo getOrder = result.ports().get(0).operations().get(0);
+ assertThat(result.ports().get(0).operations()).hasSize(1);
+
assertThat(getOrder.samples()).extracting(SampleInfo::kind).containsExactly("request",
"response", "fault");
+ SampleInfo request = getOrder.samples().get(0);
+ assertThat(request.xml()).contains("<tns:getOrder
xmlns:tns=\"http://example.com/orders\">");
+ assertThat(request.json()).contains("\"orderId\"");
+ assertThat(request.soap()).contains("<soapenv:Body>");
+ assertThat(request.curl()).contains("SOAPAction:
\"http://example.com/orders/getOrder\"");
+ assertThat(result.warnings()).isEmpty();
+ }
+
+ @Test
+ void theImportsOfTheWsdlAreNotFollowed() throws Exception {
+ String wsdl = orders().replace("<wsdl:types>", """
+ <wsdl:import namespace="urn:y" location="file:///etc/hosts"/>
+ <wsdl:types>
+ <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:t">
+ <xs:import namespace="urn:t2" schemaLocation="types.xsd"/>
+ </xs:schema>""");
+
+ InspectResult result = tools.camel_wsdl_inspect(wsdl, null, true);
+
+ assertThat(result.ports()).hasSize(1);
+ assertThat(String.join("\n", result.warnings())).contains("is not
followed, as the WSDL is given as content")
+ .contains("Cannot load content:types.xsd");
+ }
+
+ @Test
+ void scaffoldAConsumer() throws Exception {
+ ScaffoldResult result = tools.camel_wsdl_scaffold(orders(),
"consumer", "classpath:orders.wsdl", null, null, null);
+
+ assertThat(result.yaml()).contains("uri: cxf:/orders", "wsdlURL:
classpath:orders.wsdl",
+ "${header.CamelCxfOperationName} == 'getOrder'");
+ assertThat(result.port()).isEqualTo("OrderPort");
+ assertThat(result.explanation()).contains("/services");
+ }
+
+ @Test
+ void scaffoldAProducerOfOneOperation() throws Exception {
+ ScaffoldResult result = tools.camel_wsdl_scaffold(orders(),
"producer", null, null, null, "placeOrder");
+
+ assertThat(result.yaml()).contains("uri: direct:placeOrder", "uri:
cxf://http://localhost:18081/orders",
+ "wsdlURL:
classpath:service.wsdl").doesNotContain("direct:getOrder");
+ }
+
+ @Test
+ void invalidArguments() throws Exception {
+ String wsdl = orders();
+ assertThatThrownBy(() -> tools.camel_wsdl_scaffold(wsdl, "both", null,
null, null, null))
+
.isInstanceOf(ToolCallException.class).hasMessageContaining("'route' must be");
+ assertThatThrownBy(() -> tools.camel_wsdl_scaffold(wsdl, "consumer",
null, null, null, "nope"))
+
.isInstanceOf(ToolCallException.class).hasMessageContaining("Unknown operation:
nope");
+ assertThatThrownBy(() -> tools.camel_wsdl_scaffold(wsdl, "consumer",
null, "Nope", null, null))
+
.isInstanceOf(ToolCallException.class).hasMessageContaining("No port matches");
+ assertThatThrownBy(() -> tools.camel_wsdl_inspect(" ", null, null))
+
.isInstanceOf(ToolCallException.class).hasMessageContaining("required");
+ assertThatThrownBy(() -> tools.camel_wsdl_inspect("<foo/>", null,
null))
+
.isInstanceOf(ToolCallException.class).hasMessageContaining("Not a WSDL 1.1
document");
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-mcp/src/test/resources/wsdl/orders.wsdl
b/dsl/camel-jbang/camel-jbang-mcp/src/test/resources/wsdl/orders.wsdl
new file mode 100644
index 000000000000..5f6361ba4a92
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-mcp/src/test/resources/wsdl/orders.wsdl
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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 small document/literal wrapped SOAP 1.1 service, written for the
soap-source / soap-action prototype. -->
+<wsdl:definitions name="OrderService"
+ targetNamespace="http://example.com/orders"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com/orders">
+
+ <wsdl:types>
+ <xs:schema targetNamespace="http://example.com/orders"
elementFormDefault="qualified">
+ <xs:complexType name="Item">
+ <xs:sequence>
+ <xs:element name="sku" type="xs:string"/>
+ <xs:element name="quantity" type="xs:int"/>
+ <xs:element name="price" type="xs:decimal"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="Order">
+ <xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ <xs:element name="customer" type="xs:string"/>
+ <xs:element name="status" type="xs:string"/>
+ <xs:element name="item" type="tns:Item" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="getOrder">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ <xs:element name="getOrderResponse">
+ <xs:complexType><xs:sequence>
+ <xs:element name="order" type="tns:Order"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+
+ <xs:element name="placeOrder">
+ <xs:complexType><xs:sequence>
+ <xs:element name="customer" type="xs:string"/>
+ <xs:element name="item" type="tns:Item" maxOccurs="unbounded"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ <xs:element name="placeOrderResponse">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ <xs:element name="status" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+
+ <xs:element name="orderNotFound">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ </xs:schema>
+ </wsdl:types>
+
+ <wsdl:message name="getOrderRequest"><wsdl:part name="parameters"
element="tns:getOrder"/></wsdl:message>
+ <wsdl:message name="getOrderResponse"><wsdl:part name="parameters"
element="tns:getOrderResponse"/></wsdl:message>
+ <wsdl:message name="placeOrderRequest"><wsdl:part name="parameters"
element="tns:placeOrder"/></wsdl:message>
+ <wsdl:message name="placeOrderResponse"><wsdl:part name="parameters"
element="tns:placeOrderResponse"/></wsdl:message>
+ <wsdl:message name="orderNotFoundFault"><wsdl:part name="fault"
element="tns:orderNotFound"/></wsdl:message>
+
+ <wsdl:portType name="OrderPortType">
+ <wsdl:operation name="getOrder">
+ <wsdl:input message="tns:getOrderRequest"/>
+ <wsdl:output message="tns:getOrderResponse"/>
+ <wsdl:fault name="orderNotFound" message="tns:orderNotFoundFault"/>
+ </wsdl:operation>
+ <wsdl:operation name="placeOrder">
+ <wsdl:input message="tns:placeOrderRequest"/>
+ <wsdl:output message="tns:placeOrderResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="OrderSoapBinding" type="tns:OrderPortType">
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getOrder">
+ <soap:operation soapAction="http://example.com/orders/getOrder"/>
+ <wsdl:input><soap:body use="literal"/></wsdl:input>
+ <wsdl:output><soap:body use="literal"/></wsdl:output>
+ <wsdl:fault name="orderNotFound"><soap:fault name="orderNotFound"
use="literal"/></wsdl:fault>
+ </wsdl:operation>
+ <wsdl:operation name="placeOrder">
+ <soap:operation soapAction="http://example.com/orders/placeOrder"/>
+ <wsdl:input><soap:body use="literal"/></wsdl:input>
+ <wsdl:output><soap:body use="literal"/></wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:service name="OrderService">
+ <wsdl:port name="OrderPort" binding="tns:OrderSoapBinding">
+ <soap:address location="http://localhost:18081/orders"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
diff --git a/dsl/camel-jbang/camel-jbang-plugin-generate/pom.xml
b/dsl/camel-jbang/camel-jbang-plugin-generate/pom.xml
index 902c243a9c49..acc442e6f12e 100644
--- a/dsl/camel-jbang/camel-jbang-plugin-generate/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-plugin-generate/pom.xml
@@ -94,10 +94,10 @@
</exclusion>
</exclusions>
</dependency>
- <!-- the sample messages of the samples option of camel generate wsdl
-->
+ <!-- camel generate wsdl -->
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-xsd-json</artifactId>
+ <artifactId>camel-jbang-wsdl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeWsdlGenerator.java
b/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeWsdlGenerator.java
index 1f6d881a4ac7..07941479292b 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeWsdlGenerator.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeWsdlGenerator.java
@@ -41,15 +41,18 @@ import org.aesh.command.option.Option;
import org.apache.camel.CamelContext;
import org.apache.camel.dataformat.xsdjson.XsdJsonSamples;
import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Fault;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Operation;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Port;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Service;
-import
org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.WsdlException;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlSamples.Sample;
import org.apache.camel.dsl.jbang.core.common.CliExitCode;
import org.apache.camel.dsl.jbang.core.common.CompletionCandidates;
import org.apache.camel.dsl.jbang.core.common.JsonOutput;
+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;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Port;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Service;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.WsdlException;
+import org.apache.camel.dsl.jbang.wsdl.WsdlRouteScaffold;
+import org.apache.camel.dsl.jbang.wsdl.WsdlSamples;
+import org.apache.camel.dsl.jbang.wsdl.WsdlSamples.Sample;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/test/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeWsdlGeneratorTest.java
b/dsl/camel-jbang/camel-jbang-plugin-generate/src/test/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeWsdlGeneratorTest.java
index 604ae7edfd6d..7125ee822a39 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/test/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeWsdlGeneratorTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-generate/src/test/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeWsdlGeneratorTest.java
@@ -21,7 +21,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -37,6 +36,8 @@ import com.sun.net.httpserver.HttpServer;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.common.CommandLineTestHelper;
import org.apache.camel.dsl.jbang.run.common.StringPrinter;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel;
+import org.apache.camel.dsl.jbang.wsdl.WsdlRouteScaffold;
import org.apache.camel.dsl.yaml.validator.YamlValidator;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.ChoiceDefinition;
@@ -430,34 +431,6 @@ class CodeWsdlGeneratorTest {
}
}
- @Test
- void aRemoteWsdlImportsFromItsHostOverHttpOrHttps() throws Exception {
- URI http = URI.create("http://example.com/svc?wsdl");
- URI https = URI.create("https://example.com/svc?wsdl");
- URI file = URI.create("file:///tmp/svc.wsdl");
-
- // the same host, also on another port, and from http up to https
- assertThat(WsdlModel.refusedImport(http, http,
URI.create("http://example.com/types.wsdl"))).isNull();
- assertThat(WsdlModel.refusedImport(http, http,
URI.create("http://EXAMPLE.com:8080/types.wsdl"))).isNull();
- assertThat(WsdlModel.refusedImport(http, http,
URI.create("https://example.com/types.wsdl"))).isNull();
- assertThat(WsdlModel.refusedImport(https, https,
URI.create("https://example.com/types.wsdl"))).isNull();
- assertThat(WsdlModel.refusedImport(file, file,
URI.create("file:///tmp/types.wsdl"))).isNull();
-
- // not from https down to http, not to another host, and not across
files and http(s)
- assertThat(WsdlModel.refusedImport(https, https,
URI.create("http://example.com/types.wsdl")))
- .isEqualTo("a WSDL read over https does not import over http");
- assertThat(WsdlModel.refusedImport(http,
URI.create("https://example.com/types.wsdl"),
- URI.create("http://example.com/more.wsdl")))
- .isEqualTo("a WSDL read over https does not import over http");
- assertThat(WsdlModel.refusedImport(http, http,
URI.create("http://169.254.169.254/latest/meta-data")))
- .startsWith("it is on the host 169.254.169.254, not on the
host of the WSDL (example.com)");
- assertThat(WsdlModel.refusedImport(http, http, file)).isEqualTo("a
remote WSDL only imports over http(s), not file");
- assertThat(WsdlModel.refusedImport(https, https, file))
- .isEqualTo("a remote WSDL only imports over http(s), not
file");
- assertThat(WsdlModel.refusedImport(file, file, http)).isEqualTo("a
WSDL file only imports files, not http");
- assertThat(WsdlModel.refusedImport(file, file, https)).isEqualTo("a
WSDL file only imports files, not https");
- }
-
@Test
void anHttpWsdlFollowsAnHttpsImport() throws Exception {
// nothing listens on the https port: the import is followed (and
fails to connect) rather than refused
diff --git a/dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml
b/dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml
index 8c4f091c1bc9..ba58e132f406 100644
--- a/dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml
@@ -45,6 +45,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-ai-observability-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jbang-wsdl</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jbang-core</artifactId>
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/EndpointsTab.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/EndpointsTab.java
index 05dc7467a3cd..90d92c70f075 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/EndpointsTab.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/EndpointsTab.java
@@ -47,6 +47,7 @@ import org.apache.camel.catalog.CamelCatalog;
import org.apache.camel.dsl.jbang.core.common.EndpointScope;
import org.apache.camel.tooling.model.BaseOptionModel;
import org.apache.camel.tooling.model.ComponentModel;
+import org.apache.camel.util.URISupport;
import org.apache.camel.util.json.JsonArray;
import org.apache.camel.util.json.JsonObject;
@@ -61,6 +62,8 @@ class EndpointsTab extends AbstractTableTab {
private static final int PANEL_CHART = 0;
private static final int PANEL_DETAIL = 1;
+ // the WSDL of a cxf endpoint, in the place of the detail panel
+ private static final int PANEL_WSDL = 2;
private final Map<String, LinkedList<Long>> endpointInHistory;
private final Map<String, LinkedList<Long>> endpointOutHistory;
@@ -78,6 +81,7 @@ class EndpointsTab extends AbstractTableTab {
private int filter;
private int chartMode = CHART_ALL;
private int panelMode = PANEL_CHART;
+ private final WsdlView wsdlView = new WsdlView();
private int detailScroll;
private boolean detailFocused;
private int chartPanelHeight = 16;
@@ -122,7 +126,12 @@ class EndpointsTab extends AbstractTableTab {
if (ke.isChar('!') && ChaosHere.handleKey(ke, ctx, info,
ChaosHere.forEndpoint(selectedEndpoint(info), info))) {
return true;
}
- if (ke.isKey(KeyCode.TAB) && panelMode == PANEL_DETAIL) {
+ if (ke.isCharIgnoreCase('w') && wsdlUrl(info) != null) {
+ panelMode = panelMode == PANEL_WSDL ? PANEL_DETAIL : PANEL_WSDL;
+ detailScroll = 0;
+ return true;
+ }
+ if (ke.isKey(KeyCode.TAB) && isTextPanel()) {
detailFocused = !detailFocused;
return true;
}
@@ -140,7 +149,7 @@ class EndpointsTab extends AbstractTableTab {
detailFocused = false;
return true;
}
- if (panelMode == PANEL_DETAIL && detailFocused) {
+ if (isTextPanel() && detailFocused) {
if (ke.isPageUp() || ke.isKey(KeyCode.PAGE_UP)) {
detailScroll = Math.max(0, detailScroll - 10);
return true;
@@ -155,7 +164,7 @@ class EndpointsTab extends AbstractTableTab {
@Override
public boolean handleMouseEvent(MouseEvent me, Rect area) {
- if (panelMode == PANEL_DETAIL && lastDetailArea != null &&
lastDetailArea.contains(me.x(), me.y())) {
+ if (isTextPanel() && lastDetailArea != null &&
lastDetailArea.contains(me.x(), me.y())) {
if (me.kind() == MouseEventKind.SCROLL_UP) {
detailScroll = Math.max(0, detailScroll - 3);
return true;
@@ -295,7 +304,7 @@ class EndpointsTab extends AbstractTableTab {
widths.add(Constraint.length(8));
widths.add(Constraint.fill());
- boolean showDetailFocus = panelMode == PANEL_DETAIL;
+ boolean showDetailFocus = isTextPanel();
Style tableBorderStyle = ctx.paneBorder(!(showDetailFocus &&
detailFocused));
Style tableTitleStyle = showDetailFocus && detailFocused ?
Style.EMPTY.fg(Theme.accent()) : Theme.title();
String tableTitle = " Endpoints"
@@ -324,11 +333,11 @@ class EndpointsTab extends AbstractTableTab {
hasSizeHistory = false;
}
- boolean showPanel = panelMode == PANEL_DETAIL
+ boolean showPanel = isTextPanel()
|| (chartMode != CHART_OFF && ctx.shellPercent < 50);
List<Rect> chunks;
if (showPanel) {
- if (panelMode == PANEL_DETAIL) {
+ if (isTextPanel()) {
// doc panel gets 60% of area
int detailH = Math.max(5, area.height() * 60 / 100);
chunks = Layout.vertical().constraints(Constraint.fill(),
Constraint.length(detailH)).split(area);
@@ -347,10 +356,14 @@ class EndpointsTab extends AbstractTableTab {
frame.renderStatefulWidget(table, chunks.get(0), tableState);
renderScrollbar(frame, table, sortedEndpoints.size());
- if (showPanel && panelMode == PANEL_DETAIL) {
+ if (showPanel && isTextPanel()) {
hSplit.clearBorderPos();
lastDetailArea = chunks.get(1);
- renderDetail(frame, chunks.get(1), sortedEndpoints, info);
+ if (panelMode == PANEL_WSDL) {
+ renderWsdl(frame, chunks.get(1), info);
+ } else {
+ renderDetail(frame, chunks.get(1), sortedEndpoints, info);
+ }
} else if (showPanel) {
lastDetailArea = null;
// Determine selected endpoint URI for single-endpoint chart
@@ -396,7 +409,10 @@ class EndpointsTab extends AbstractTableTab {
String[] filterLabels = { "all", "remote", "remote+stub" };
List<SubViewBar.View> views = List.of(
new SubViewBar.View("Chart", panelMode == PANEL_CHART, true,
() -> pressKey('d')),
- new SubViewBar.View("Detail", panelMode == PANEL_DETAIL, true,
() -> pressKey('d')));
+ new SubViewBar.View("Detail", panelMode == PANEL_DETAIL, true,
() -> pressKey('d')),
+ new SubViewBar.View(
+ "WSDL", panelMode == PANEL_WSDL,
wsdlUrl(ctx.findSelectedIntegration()) != null,
+ () -> pressKey('w')));
List<SubViewBar.Toggle> toggles = new ArrayList<>();
toggles.add(new SubViewBar.Toggle("f", "filter",
filterLabels[filter]));
if (panelMode == PANEL_CHART) {
@@ -413,9 +429,12 @@ class EndpointsTab extends AbstractTableTab {
public void renderFooter(List<Span> spans) {
hint(spans, "Esc", "back");
hint(spans, "s", "sort");
- if (panelMode == PANEL_DETAIL) {
+ if (isTextPanel()) {
hint(spans, "Tab", detailFocused ? "table" : "detail");
}
+ if (wsdlUrl(ctx.findSelectedIntegration()) != null) {
+ hint(spans, "w", panelMode == PANEL_WSDL ? "detail" : "wsdl");
+ }
ChaosHere.hint(spans, ctx.findSelectedIntegration());
}
@@ -447,6 +466,53 @@ class EndpointsTab extends AbstractTableTab {
}
}
+ /** Whether the bottom panel is the detail or the WSDL of the endpoint
(text with focus and scroll). */
+ private boolean isTextPanel() {
+ return panelMode == PANEL_DETAIL || panelMode == PANEL_WSDL;
+ }
+
+ /**
+ * The wsdlURL of the selected endpoint when it is a cxf endpoint (a SOAP
service or client), else null.
+ */
+ private String wsdlUrl(IntegrationInfo info) {
+ EndpointInfo ep = selectedEndpoint(info);
+ if (ep == null || ep.uri == null || !"cxf".equals(ep.component)) {
+ return null;
+ }
+ try {
+ Object url =
URISupport.parseQuery(URISupport.extractQuery(ep.uri), false,
true).get("wsdlURL");
+ return url != null && !url.toString().isBlank() ? url.toString() :
null;
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+
+ private void renderWsdl(Frame frame, Rect area, IntegrationInfo info) {
+ String url = wsdlUrl(info);
+ String md;
+ if (url == null) {
+ md = "*The selected endpoint is not a cxf endpoint with a
wsdlURL*";
+ } else {
+ String location = WsdlView.location(url, info.directory);
+ md = location != null
+ ? wsdlView.markdown(url, location)
+ : "*The WSDL " + WsdlView.escape(url) + " is not found in
the folder of the integration*";
+ }
+ Style borderStyle = ctx.paneBorder(detailFocused);
+ Style titleStyle = detailFocused ? Theme.title() :
Style.EMPTY.fg(Theme.accent());
+ frame.renderWidget(
+ MarkdownView.builder()
+ .source(md)
+ .scroll(detailScroll)
+
.block(Block.builder().borderType(BorderType.ROUNDED).borders(Borders.ALL)
+ .borderStyle(borderStyle)
+ .title(Title.from(Line.from(Span.styled(" WSDL
", titleStyle)))).build())
+ .styles(Theme.markdownStyles())
+ .syntaxTheme(Theme.syntaxTheme())
+ .build(),
+ area);
+ }
+
/** The endpoint selected in the table, as filtered and sorted. */
private EndpointInfo selectedEndpoint(IntegrationInfo info) {
Integer sel = tableState.selected();
@@ -771,7 +837,7 @@ class EndpointsTab extends AbstractTableTab {
@Override
public Boolean isDetailFocused() {
- if (panelMode != PANEL_DETAIL) {
+ if (!isTextPanel()) {
return null;
}
return detailFocused;
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/WsdlView.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/WsdlView.java
new file mode 100644
index 000000000000..d892336e6177
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/java/org/apache/camel/dsl/jbang/core/commands/tui/WsdlView.java
@@ -0,0 +1,189 @@
+/*
+ * 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.tui;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.xml.namespace.QName;
+
+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;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Port;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Service;
+
+/**
+ * The WSDL of a cxf endpoint, as markdown for the Endpoints tab: the ports of
its services and the request, response
+ * and fault elements of each operation.
+ * <p>
+ * The WSDL is the wsdlURL of the endpoint: a file: or classpath: resource is
looked up in the folder of the integration
+ * (and its src/main/resources), and an http(s) URL is read with the rules of
camel generate wsdl (imports only from its
+ * host, a redirect only to the same scheme, host and port). It is read once,
on a thread of its own, so a slow server
+ * does not block the screen.
+ */
+final class WsdlView {
+
+ static final String LOADING = "*Reading the WSDL...*";
+
+ private final Map<String, String> markdown = new ConcurrentHashMap<>();
+ private final Map<String, Boolean> loading = new ConcurrentHashMap<>();
+
+ /**
+ * The markdown of the WSDL at the location, or {@link #LOADING} while it
is read.
+ */
+ String markdown(String wsdlUrl, String location) {
+ String md = markdown.get(location);
+ if (md != null) {
+ return md;
+ }
+ if (loading.putIfAbsent(location, Boolean.TRUE) == null) {
+ Thread.ofVirtual().name("CamelTuiWsdl").start(() -> {
+ try {
+ markdown.put(location, toMarkdown(wsdlUrl, location,
WsdlModel.load(location)));
+ } catch (Exception e) {
+ markdown.put(location, "*Cannot read the WSDL " +
escape(wsdlUrl) + ":* "
+ + escape(e.getMessage() != null ?
e.getMessage() : e.toString()));
+ } finally {
+ loading.remove(location);
+ }
+ });
+ }
+ return LOADING;
+ }
+
+ /**
+ * Where to read the WSDL of a wsdlURL from: an http(s) URL as it is, a
file: or classpath: resource (or a plain
+ * name) as a file in the folder of the integration, or its
src/main/resources; null when it is not found.
+ */
+ static String location(String wsdlUrl, String directory) {
+ if (wsdlUrl == null || wsdlUrl.isBlank()) {
+ return null;
+ }
+ String url = wsdlUrl.strip();
+ String lower = url.toLowerCase(Locale.ROOT);
+ if (lower.startsWith("http://") || lower.startsWith("https://")) {
+ return url;
+ }
+ String name;
+ if (lower.startsWith("classpath:")) {
+ name = url.substring("classpath:".length());
+ } else if (lower.startsWith("file:")) {
+ name = url.substring("file:".length());
+ } else if (url.contains(":") && !url.startsWith("/")) {
+ // another scheme, such as a bean reference or a property
placeholder that is not resolved
+ return null;
+ } else {
+ name = url;
+ }
+ while (name.startsWith("//")) {
+ name = name.substring(1);
+ }
+ Path path = Path.of(name);
+ if (path.isAbsolute()) {
+ return Files.isRegularFile(path) ? path.toString() : null;
+ }
+ Path base = directory != null ? Path.of(directory) : Path.of("");
+ for (Path candidate : new Path[] { base.resolve(name),
base.resolve("src/main/resources").resolve(name) }) {
+ if (Files.isRegularFile(candidate)) {
+ return candidate.toAbsolutePath().normalize().toString();
+ }
+ }
+ return null;
+ }
+
+ static String toMarkdown(String wsdlUrl, String location, WsdlModel model)
{
+ StringBuilder md = new StringBuilder();
+ md.append("## WSDL ").append(escape(wsdlUrl)).append("\n\n");
+ for (Service service : model.services()) {
+ for (Port port : service.ports()) {
+ String ns = port.namespace();
+ md.append("###
").append(escape(service.name().getLocalPart())).append(" · port ")
+ .append(escape(port.name())).append("\n\n");
+ md.append("SOAP
").append(escape(port.soapVersion())).append(", ").append(escape(port.style()))
+ .append(" style");
+ String address = WsdlModel.maskedAddress(port.address());
+ if (address != null) {
+ md.append(", at `").append(code(address)).append('`');
+ }
+ md.append("\n\n");
+ if (port.operations().isEmpty()) {
+ md.append("*No operations*\n\n");
+ continue;
+ }
+ md.append("| Operation | Request | Response | Faults
|\n|---|---|---|---|\n");
+ for (Operation op : port.operations()) {
+ StringBuilder faults = new StringBuilder();
+ for (Fault f : op.faults()) {
+ if (!faults.isEmpty()) {
+ faults.append(", ");
+ }
+ faults.append(escape(f.name()));
+ if (f.element() != null &&
!f.element().getLocalPart().equals(f.name())) {
+ faults.append("
(").append(escape(name(f.element(), ns))).append(')');
+ }
+ }
+ md.append("| **").append(escape(op.name())).append("** | ")
+ .append(escape(name(op.input(), ns))).append(" | ")
+ .append(op.oneWay() ? "*one-way*" :
escape(name(op.output(), ns))).append(" | ")
+ .append(faults).append(" |\n");
+ }
+ md.append('\n');
+ }
+ }
+ for (String warning : model.warnings()) {
+ md.append("- ").append(escape(warning)).append('\n');
+ }
+ if (!model.warnings().isEmpty()) {
+ md.append('\n');
+ }
+ md.append("Sample messages: `camel generate wsdl
").append(code(location)).append(" --samples`\n");
+ return md.toString();
+ }
+
+ /**
+ * The local name of an element in the namespace of the port, else
{namespace}name.
+ */
+ private static String name(QName name, String namespace) {
+ if (name == null) {
+ return "";
+ }
+ return name.getNamespaceURI().equals(namespace) ? name.getLocalPart()
: name.toString();
+ }
+
+ /**
+ * A value of the WSDL as markdown text: printable, on one line, and
without a character that would end a table cell
+ * or start a code span.
+ */
+ static String escape(String text) {
+ if (text == null) {
+ return "";
+ }
+ // printable turns a line break or other control character into ?
+ return WsdlModel.printable(text).replace("\\", "\\\\").replace("|",
"\\|").replace('`', '\'');
+ }
+
+ /**
+ * A value of the WSDL in an inline code span: printable, without
backticks.
+ */
+ private static String code(String text) {
+ return WsdlModel.printable(text).replace('`', '\'').replace('|', '/');
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/endpoints.md
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/endpoints.md
index 79d8b59d4b95..4c1c42962bb3 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/endpoints.md
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/main/resources/tui/help/endpoints.md
@@ -96,6 +96,20 @@ For each configured option you'll see:
Use `PgUp/PgDn` to scroll the documentation panel.
+## WSDL
+
+For a `cxf` endpoint (a SOAP service or client) with a `wsdlURL`, press
+`w` to show its WSDL in the bottom panel instead of the documentation:
+the services and ports, with the SOAP version and address of each port,
+and a table of the operations with their request, response and fault
+elements. Press `w` again to go back to the documentation.
+
+A `file:` or `classpath:` WSDL is looked up in the folder of the
+integration, and in its `src/main/resources`; an `http(s)` URL is read
+from its server, with the rules of `camel generate wsdl` (imports only
+from its host). The panel ends with the `camel generate wsdl ... --samples`
+command that writes sample messages for the operations.
+
## Keys
- `Up/Down` — select endpoint
@@ -103,4 +117,5 @@ Use `PgUp/PgDn` to scroll the documentation panel.
- `S` — reverse sort order
- `f` — cycle filter mode
- `d` — toggle endpoint documentation panel
+- `w` — show the WSDL of a cxf endpoint (and back)
- `PgUp/PgDn` — scroll documentation (when doc panel is open)
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/EndpointsTabRenderTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/EndpointsTabRenderTest.java
index 04e8a93be721..068a5132236f 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/EndpointsTabRenderTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/EndpointsTabRenderTest.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.dsl.jbang.core.commands.tui;
+import java.nio.file.Paths;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@@ -33,6 +35,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -246,6 +249,33 @@ class EndpointsTabRenderTest {
assertThat(TuiTestHelper.renderToString(tab, 140,
30)).contains("http://example.com/api");
}
+ @Test
+ void theWsdlOfACxfEndpoint() {
+ // the WSDL is in the folder of the integration
+ info.directory =
Paths.get("src/test/resources/wsdl").toAbsolutePath().toString();
+ addEndpoint("cxf",
"cxf:///orders?dataFormat=PAYLOAD&wsdlURL=classpath:orders.wsdl", "in",
"OrderService", 3);
+ addEndpoint("timer", "timer://tick", "in", "route1", 10);
+
+ EndpointsTab tab = new EndpointsTab(ctx, new MetricsCollector());
+ assertThat(TuiTestHelper.renderToString(tab, 160,
50)).doesNotContain("getOrderResponse");
+
+ tab.handleKeyEvent(KeyEvent.ofChar('w', KeyModifiers.NONE));
+ await().atMost(Duration.ofSeconds(10))
+ .until(() -> TuiTestHelper.renderToString(tab, 160,
50).contains("getOrderResponse"));
+ String rendered = TuiTestHelper.renderToString(tab, 160, 50);
+ assertThat(rendered).contains(" WSDL ", "OrderService · port
OrderPort", "getOrder", "orderNotFound");
+ }
+
+ @Test
+ void noWsdlForAnEndpointThatIsNotCxf() {
+ addEndpoint("timer", "timer://tick?wsdlURL=classpath:orders.wsdl",
"in", "route1", 10);
+
+ EndpointsTab tab = new EndpointsTab(ctx, new MetricsCollector());
+ tab.handleKeyEvent(KeyEvent.ofChar('w', KeyModifiers.NONE));
+
+ assertThat(TuiTestHelper.renderToString(tab, 160,
50)).doesNotContain(" WSDL ");
+ }
+
private EndpointInfo addEndpoint(String component, String uri, String
direction, String routeId, long hits) {
EndpointInfo ep = new EndpointInfo();
ep.component = component;
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/WsdlViewTest.java
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/WsdlViewTest.java
new file mode 100644
index 000000000000..caeec4f0d7c1
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/java/org/apache/camel/dsl/jbang/core/commands/tui/WsdlViewTest.java
@@ -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.
+ */
+package org.apache.camel.dsl.jbang.core.commands.tui;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.Duration;
+
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+class WsdlViewTest {
+
+ @TempDir
+ Path dir;
+
+ @Test
+ void theLocationOfTheWsdlUrlInTheFolderOfTheIntegration() throws Exception
{
+ Files.copy(Paths.get("src/test/resources/wsdl/orders.wsdl"),
dir.resolve("orders.wsdl"));
+ Files.createDirectories(dir.resolve("src/main/resources"));
+ Files.copy(Paths.get("src/test/resources/wsdl/orders.wsdl"),
dir.resolve("src/main/resources/stock.wsdl"));
+ String d = dir.toString();
+
+ assertThat(WsdlView.location("file:orders.wsdl",
d)).isEqualTo(dir.resolve("orders.wsdl").toString());
+ assertThat(WsdlView.location("classpath:orders.wsdl",
d)).isEqualTo(dir.resolve("orders.wsdl").toString());
+ assertThat(WsdlView.location("orders.wsdl",
d)).isEqualTo(dir.resolve("orders.wsdl").toString());
+ // a Maven project
+ assertThat(WsdlView.location("classpath:stock.wsdl", d))
+
.isEqualTo(dir.resolve("src/main/resources/stock.wsdl").toString());
+ assertThat(WsdlView.location("file:" + dir.resolve("orders.wsdl"),
"/elsewhere"))
+ .isEqualTo(dir.resolve("orders.wsdl").toString());
+ assertThat(WsdlView.location("https://example.com/orders?wsdl",
d)).isEqualTo("https://example.com/orders?wsdl");
+
+ assertThat(WsdlView.location("classpath:nope.wsdl", d)).isNull();
+ assertThat(WsdlView.location("{{wsdl.url}}", d)).isNull();
+ assertThat(WsdlView.location("bean:wsdl", d)).isNull();
+ assertThat(WsdlView.location(null, d)).isNull();
+ }
+
+ @Test
+ void theOperationsOfTheWsdlAsMarkdown() throws Exception {
+ String location = "src/test/resources/wsdl/orders.wsdl";
+ String md = WsdlView.toMarkdown("classpath:orders.wsdl", location,
WsdlModel.load(location));
+
+ assertThat(md).contains("## WSDL classpath:orders.wsdl",
+ "### OrderService · port OrderPort",
+ "SOAP 1.1, document style, at `http://localhost:18081/orders`",
+ "| Operation | Request | Response | Faults |",
+ "| **getOrder** | getOrder | getOrderResponse | orderNotFound
|",
+ "| **placeOrder** | placeOrder | placeOrderResponse | |",
+ "camel generate wsdl " + location + " --samples");
+ }
+
+ @Test
+ void theValuesOfTheWsdlCannotBreakTheTable() {
+ assertThat(WsdlView.escape("a|b`c\nd")).isEqualTo("a\\|b'c?d");
+ assertThat(WsdlView.escape(null)).isEmpty();
+ }
+
+ @Test
+ void theWsdlIsReadOnAThreadOfItsOwn() throws Exception {
+ WsdlView view = new WsdlView();
+ String location =
Paths.get("src/test/resources/wsdl/orders.wsdl").toAbsolutePath().toString();
+
+ String first = view.markdown("classpath:orders.wsdl", location);
+ assertThat(first).isIn(WsdlView.LOADING,
WsdlView.toMarkdown("classpath:orders.wsdl", location,
+ WsdlModel.load(location)));
+ await().atMost(Duration.ofSeconds(10))
+ .until(() ->
!WsdlView.LOADING.equals(view.markdown("classpath:orders.wsdl", location)));
+ assertThat(view.markdown("classpath:orders.wsdl",
location)).contains("getOrderResponse");
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/resources/wsdl/orders.wsdl
b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/resources/wsdl/orders.wsdl
new file mode 100644
index 000000000000..5f6361ba4a92
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-plugin-tui/src/test/resources/wsdl/orders.wsdl
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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 small document/literal wrapped SOAP 1.1 service, written for the
soap-source / soap-action prototype. -->
+<wsdl:definitions name="OrderService"
+ targetNamespace="http://example.com/orders"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com/orders">
+
+ <wsdl:types>
+ <xs:schema targetNamespace="http://example.com/orders"
elementFormDefault="qualified">
+ <xs:complexType name="Item">
+ <xs:sequence>
+ <xs:element name="sku" type="xs:string"/>
+ <xs:element name="quantity" type="xs:int"/>
+ <xs:element name="price" type="xs:decimal"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="Order">
+ <xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ <xs:element name="customer" type="xs:string"/>
+ <xs:element name="status" type="xs:string"/>
+ <xs:element name="item" type="tns:Item" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="getOrder">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ <xs:element name="getOrderResponse">
+ <xs:complexType><xs:sequence>
+ <xs:element name="order" type="tns:Order"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+
+ <xs:element name="placeOrder">
+ <xs:complexType><xs:sequence>
+ <xs:element name="customer" type="xs:string"/>
+ <xs:element name="item" type="tns:Item" maxOccurs="unbounded"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ <xs:element name="placeOrderResponse">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ <xs:element name="status" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+
+ <xs:element name="orderNotFound">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ </xs:schema>
+ </wsdl:types>
+
+ <wsdl:message name="getOrderRequest"><wsdl:part name="parameters"
element="tns:getOrder"/></wsdl:message>
+ <wsdl:message name="getOrderResponse"><wsdl:part name="parameters"
element="tns:getOrderResponse"/></wsdl:message>
+ <wsdl:message name="placeOrderRequest"><wsdl:part name="parameters"
element="tns:placeOrder"/></wsdl:message>
+ <wsdl:message name="placeOrderResponse"><wsdl:part name="parameters"
element="tns:placeOrderResponse"/></wsdl:message>
+ <wsdl:message name="orderNotFoundFault"><wsdl:part name="fault"
element="tns:orderNotFound"/></wsdl:message>
+
+ <wsdl:portType name="OrderPortType">
+ <wsdl:operation name="getOrder">
+ <wsdl:input message="tns:getOrderRequest"/>
+ <wsdl:output message="tns:getOrderResponse"/>
+ <wsdl:fault name="orderNotFound" message="tns:orderNotFoundFault"/>
+ </wsdl:operation>
+ <wsdl:operation name="placeOrder">
+ <wsdl:input message="tns:placeOrderRequest"/>
+ <wsdl:output message="tns:placeOrderResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="OrderSoapBinding" type="tns:OrderPortType">
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getOrder">
+ <soap:operation soapAction="http://example.com/orders/getOrder"/>
+ <wsdl:input><soap:body use="literal"/></wsdl:input>
+ <wsdl:output><soap:body use="literal"/></wsdl:output>
+ <wsdl:fault name="orderNotFound"><soap:fault name="orderNotFound"
use="literal"/></wsdl:fault>
+ </wsdl:operation>
+ <wsdl:operation name="placeOrder">
+ <soap:operation soapAction="http://example.com/orders/placeOrder"/>
+ <wsdl:input><soap:body use="literal"/></wsdl:input>
+ <wsdl:output><soap:body use="literal"/></wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:service name="OrderService">
+ <wsdl:port name="OrderPort" binding="tns:OrderSoapBinding">
+ <soap:address location="http://localhost:18081/orders"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
diff --git a/dsl/camel-jbang/camel-jbang-wsdl/pom.xml
b/dsl/camel-jbang/camel-jbang-wsdl/pom.xml
new file mode 100644
index 000000000000..2208452346f4
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-wsdl/pom.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jbang-parent</artifactId>
+ <version>4.24.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>camel-jbang-wsdl</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: JBang :: WSDL</name>
+ <description>Camel CLI WSDL: read a WSDL, scaffold a cxf route and sample
messages, for the Camel CLI, its MCP server and TUI</description>
+ <properties>
+ <firstVersion>4.24.0</firstVersion>
+ <label>jbang</label>
+ <supportLevel>Preview</supportLevel>
+ <camel-prepare-component>false</camel-prepare-component>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-xsd-json</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>${snakeyaml-version}</version>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlModel.java
b/dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlModel.java
similarity index 93%
rename from
dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlModel.java
rename to
dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlModel.java
index 7e57262697c4..cf915f467b25 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlModel.java
+++
b/dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlModel.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.dsl.jbang.core.commands.generate;
+package org.apache.camel.dsl.jbang.wsdl;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -65,7 +65,7 @@ import org.xml.sax.SAXParseException;
* scheme, host and port, for the same reason. At most {@link #MAX_DOCUMENTS}
documents and {@link #MAX_DEPTH} levels
* are read.
*/
-final class WsdlModel {
+public final class WsdlModel {
static final String WSDL_NS = "http://schemas.xmlsoap.org/wsdl/";
static final String WSDL2_NS = "http://www.w3.org/ns/wsdl";
@@ -75,7 +75,12 @@ final class WsdlModel {
static final int MAX_DOCUMENTS = 32;
static final int MAX_DEPTH = 8;
static final int MAX_BYTES = 16 * 1024 * 1024;
- static final int MAX_REDIRECTS = 5;
+ public static final int MAX_REDIRECTS = 5;
+
+ /**
+ * The location of a WSDL given as content (see {@link #parse(byte[])}).
+ */
+ private static final URI CONTENT = URI.create("content:wsdl");
/**
* An NCName (the type of the name attributes of WSDL 1.1): no colon, no
space, no quote, no $ or brace, so it can
@@ -94,7 +99,7 @@ final class WsdlModel {
* @param name the name of the fault
* @param element the element of the fault detail, or <tt>null</tt>
*/
- record Fault(String name, QName element) {
+ public record Fault(String name, QName element) {
}
/**
@@ -110,7 +115,7 @@ final class WsdlModel {
* @param oneWay whether the operation has no response
* @param faults the faults
*/
- record Operation(
+ public record Operation(
String name, String namespace, String soapAction, String style,
String use, QName input, QName output,
boolean oneWay, List<Fault> faults) {
}
@@ -128,18 +133,18 @@ final class WsdlModel {
* @param namespace the namespace of the port type, which is the
namespace of the operations
* @param operations the operations
*/
- record Port(
+ public record Port(
QName service, String name, QName binding, String soapVersion,
String style, String transport, String address,
String namespace, List<Operation> operations) {
- QName qname() {
+ public QName qname() {
return new QName(service.getNamespaceURI(), name);
}
/**
* Whether the operations are all document style (rpc is listed, but
not scaffolded).
*/
- boolean isDocument() {
+ public boolean isDocument() {
return operations.stream().allMatch(o ->
"document".equals(o.style()));
}
}
@@ -150,14 +155,14 @@ final class WsdlModel {
* @param name the name
* @param ports the SOAP ports
*/
- record Service(QName name, List<Port> ports) {
+ public record Service(QName name, List<Port> ports) {
}
/**
* The WSDL cannot be read: it is not well formed, not WSDL 1.1, has a
DOCTYPE, refers to something it does not
* define, or imports a document that cannot be read.
*/
- static final class WsdlException extends Exception {
+ public static final class WsdlException extends Exception {
WsdlException(String message) {
super(message);
}
@@ -204,28 +209,28 @@ final class WsdlModel {
/**
* The target namespace of the WSDL (of the first document).
*/
- String targetNamespace() {
+ public String targetNamespace() {
return targetNamespace;
}
/**
* The services with at least one SOAP port, in the order of the WSDL.
*/
- List<Service> services() {
+ public List<Service> services() {
return services;
}
/**
* What was left out, such as a port with a binding that is not SOAP.
*/
- List<String> warnings() {
+ public List<String> warnings() {
return warnings;
}
/**
* The location of a WSDL as a URI: a http or https URL, a file: URL, or a
file name.
*/
- static URI toUri(String location) {
+ public static URI toUri(String location) {
String lower = location.toLowerCase(Locale.ROOT);
if (lower.startsWith("http://") || lower.startsWith("https://") ||
lower.startsWith("file:")) {
return URI.create(location);
@@ -241,7 +246,7 @@ final class WsdlModel {
* @throws IOException when the WSDL cannot be read
* @throws WsdlException when the WSDL, or a document it imports, is
not a WSDL 1.1 document this can read
*/
- static WsdlModel load(String location) throws IOException, WsdlException {
+ public static WsdlModel load(String location) throws IOException,
WsdlException {
URI base;
try {
base = toUri(location);
@@ -262,6 +267,30 @@ final class WsdlModel {
}
}
+ /**
+ * Reads a WSDL given as its content, such as by an AI assistant through
the MCP server. Nothing else is read: a
+ * {@code wsdl:import} is not followed but listed as a warning, so the
services, ports and operations are those of
+ * this document.
+ *
+ * @param content the WSDL document
+ * @throws WsdlException when the content is not a WSDL 1.1 document this
can read
+ */
+ public static WsdlModel parse(byte[] content) throws WsdlException {
+ if (content == null || content.length == 0) {
+ throw new WsdlException("The WSDL content is empty");
+ }
+ if (content.length > MAX_BYTES) {
+ throw new WsdlException("The WSDL is larger than " + MAX_BYTES + "
bytes");
+ }
+ try (Reader reader = new Reader(CONTENT, content)) {
+ reader.read(CONTENT, 0);
+ return reader.build();
+ } catch (IOException e) {
+ // nothing is read but the content
+ throw new WsdlException(e.getMessage(), e);
+ }
+ }
+
/**
* Reads a document of a remote WSDL that is not a WSDL document, such as
a schema that its types import, with the
* rules of a {@code wsdl:import}: only from the host of the WSDL, not
from https down to http, and a redirect only
@@ -271,7 +300,7 @@ final class WsdlModel {
* @param uri the document
* @throws IOException when the document cannot be read, or is refused
*/
- static byte[] readDocument(URI root, String uri) throws IOException {
+ public static byte[] readDocument(URI root, String uri) throws IOException
{
URI target;
try {
target = new URI(uri);
@@ -350,7 +379,7 @@ final class WsdlModel {
/**
* Whether the name is an NCName, which can go into YAML and into a simple
expression as it is.
*/
- static boolean isNcName(String name) {
+ public static boolean isNcName(String name) {
return name != null && NCNAME.matcher(name).matches();
}
@@ -362,6 +391,7 @@ final class WsdlModel {
private static final class Reader implements AutoCloseable {
private final URI root;
+ private final byte[] content;
private HttpClient client;
private final Set<URI> visited = new HashSet<>();
private String targetNamespace;
@@ -372,7 +402,15 @@ final class WsdlModel {
private final List<String> warnings = new ArrayList<>();
Reader(URI root) {
+ this(root, null);
+ }
+
+ /**
+ * @param content the content of the root, which is then the only
document read (or null)
+ */
+ Reader(URI root, byte[] content) {
this.root = root;
+ this.content = content;
}
@Override
@@ -427,6 +465,11 @@ final class WsdlModel {
if (location.isBlank()) {
return;
}
+ if (content != null) {
+ warnings.add("The import " + printable(location) + " is not
followed, as the WSDL is given as content:"
+ + " its services, ports and operations are left
out");
+ return;
+ }
if (depth + 1 > MAX_DEPTH) {
throw new WsdlException("The imports of the WSDL are nested
deeper than " + MAX_DEPTH + " levels");
}
@@ -660,6 +703,9 @@ final class WsdlModel {
}
private Fetched readBytes(URI uri) throws IOException, WsdlException {
+ if (content != null) {
+ return new Fetched(uri, content);
+ }
if ("file".equalsIgnoreCase(uri.getScheme())) {
Path path = Path.of(uri);
if (!Files.isRegularFile(path)) {
@@ -868,7 +914,7 @@ final class WsdlModel {
* The text with the control characters (such as the escape of a terminal
color code) replaced by a question mark,
* so a value from a remote WSDL cannot change the terminal.
*/
- static String printable(String text) {
+ public static String printable(String text) {
if (text == null) {
return null;
}
@@ -886,7 +932,7 @@ final class WsdlModel {
/**
* The address with the user info (user:password@) masked, for the listing.
*/
- static String maskedAddress(String address) {
+ public static String maskedAddress(String address) {
if (address == null) {
return null;
}
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlRouteScaffold.java
b/dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlRouteScaffold.java
similarity index 95%
rename from
dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlRouteScaffold.java
rename to
dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlRouteScaffold.java
index 72a7e5666862..16ce0def392f 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlRouteScaffold.java
+++
b/dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlRouteScaffold.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.dsl.jbang.core.commands.generate;
+package org.apache.camel.dsl.jbang.wsdl;
import java.net.URI;
import java.net.URISyntaxException;
@@ -29,9 +29,9 @@ import java.util.stream.Collectors;
import javax.xml.namespace.QName;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Operation;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Port;
-import
org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.WsdlException;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Operation;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Port;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.WsdlException;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
@@ -40,7 +40,7 @@ import org.yaml.snakeyaml.Yaml;
* classes. The YAML is written with a YAML writer, and every name from the
WSDL that goes into it is an NCName, and
* every namespace a plain URI, so a hostile WSDL cannot add YAML, a simple
expression or a property placeholder.
*/
-final class WsdlRouteScaffold {
+public final class WsdlRouteScaffold {
/**
* The characters of a namespace or an address that can go into an
endpoint parameter, a constant and an XML
@@ -52,7 +52,8 @@ final class WsdlRouteScaffold {
* The headers that decide which operation and which address the cxf
producer calls: they are removed before the
* call, so a caller of the route (or a consumer that copied them from a
request) cannot steer it.
*/
- static final String PRODUCER_REMOVE_HEADERS =
"Camel.*|operationName|operationNamespace|RequestContext|ResponseContext";
+ public static final String PRODUCER_REMOVE_HEADERS
+ =
"Camel.*|operationName|operationNamespace|RequestContext|ResponseContext";
private static final int DEFAULT_PORT = 8080;
@@ -66,7 +67,7 @@ final class WsdlRouteScaffold {
* @param operations the operations of the port to scaffold
* @param wsdlUrl the wsdlURL of the endpoints
*/
- WsdlRouteScaffold(Port port, List<Operation> operations, String wsdlUrl) {
+ public WsdlRouteScaffold(Port port, List<Operation> operations, String
wsdlUrl) {
this.port = port;
this.operations = operations;
this.wsdlUrl = wsdlUrl;
@@ -75,7 +76,7 @@ final class WsdlRouteScaffold {
/**
* What the scaffold changed from the WSDL, such as the query of an
address that it left out.
*/
- List<String> warnings() {
+ public List<String> warnings() {
return warnings;
}
@@ -84,7 +85,7 @@ final class WsdlRouteScaffold {
* is the path of the address of the port: Camel Main
(camel-cxf-platform-http), Spring Boot and Quarkus all serve
* it on their HTTP server, under the path of their CXF services (default
/services).
*/
- String consumer() throws WsdlException {
+ public String consumer() throws WsdlException {
check();
String path = address().getRawPath();
String uri = "cxf:" + path;
@@ -140,7 +141,7 @@ final class WsdlRouteScaffold {
/**
* A route with a cxf: producer per operation, called with
direct:operation and the request element as the body.
*/
- String producer() throws WsdlException {
+ public String producer() throws WsdlException {
check();
URI address = address();
String uri = "cxf://" + address;
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlSamples.java
b/dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlSamples.java
similarity index 92%
rename from
dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlSamples.java
rename to
dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlSamples.java
index 53da47b229a0..317fe92d8cad 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/WsdlSamples.java
+++
b/dsl/camel-jbang/camel-jbang-wsdl/src/main/java/org/apache/camel/dsl/jbang/wsdl/WsdlSamples.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.dsl.jbang.core.commands.generate;
+package org.apache.camel.dsl.jbang.wsdl;
import java.net.URI;
import java.net.URISyntaxException;
@@ -26,9 +26,9 @@ import java.util.regex.Pattern;
import javax.xml.namespace.QName;
import org.apache.camel.dataformat.xsdjson.XsdJsonSamples;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Fault;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Operation;
-import org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Port;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Fault;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Operation;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Port;
/**
* The sample messages of the operations of a port: the request, the response
and the faults as XML and as JSON in the
@@ -38,10 +38,10 @@ import
org.apache.camel.dsl.jbang.core.commands.generate.WsdlModel.Port;
* they must be NCNames and plain URIs (no quote, space or brace); a message
whose values are not is left out with a
* warning, as a hostile WSDL could otherwise put a command into the curl line.
*/
-final class WsdlSamples {
+public final class WsdlSamples {
- static final String SOAP11_ENV =
"http://schemas.xmlsoap.org/soap/envelope/";
- static final String SOAP12_ENV = "http://www.w3.org/2003/05/soap-envelope";
+ public static final String SOAP11_ENV =
"http://schemas.xmlsoap.org/soap/envelope/";
+ public static final String SOAP12_ENV =
"http://www.w3.org/2003/05/soap-envelope";
/**
* The characters of an address or a SOAP action that can go into a
single-quoted shell argument as they are.
@@ -61,18 +61,18 @@ final class WsdlSamples {
* @param soap the request in a SOAP envelope, else null
* @param curl the curl command that sends the SOAP envelope (from
the file {@link #soapFile()}), else null
*/
- record Sample(
+ public record Sample(
String prefix, String operation, String kind, String name, QName
element, String xml, String json, String soap,
String curl) {
/**
* The base name of the files of this sample, such as getOrder-request
or getOrder-fault-orderNotFound.
*/
- String baseName() {
+ public String baseName() {
return prefix + ("fault".equals(kind) ? operation + "-fault-" +
name : operation + "-" + kind);
}
- String soapFile() {
+ public String soapFile() {
return baseName() + ".soap.xml";
}
}
@@ -82,13 +82,13 @@ final class WsdlSamples {
private final XsdJsonSamples samples;
private final List<String> warnings = new ArrayList<>();
- WsdlSamples(Port port, List<Operation> operations, XsdJsonSamples samples)
{
+ public WsdlSamples(Port port, List<Operation> operations, XsdJsonSamples
samples) {
this.port = port;
this.operations = operations;
this.samples = samples;
}
- List<String> warnings() {
+ public List<String> warnings() {
return warnings;
}
@@ -97,7 +97,7 @@ final class WsdlSamples {
*
* @param prefix the prefix of the file names, such as the port name when
there is more than one port (or empty)
*/
- List<Sample> samples(String prefix) {
+ public List<Sample> samples(String prefix) {
List<Sample> answer = new ArrayList<>();
if (!port.isDocument()) {
warnings.add("The port " + port.name() + " uses the rpc style,
which has no samples (only document style)");
@@ -159,7 +159,7 @@ final class WsdlSamples {
/**
* The request in a SOAP envelope of the SOAP version of the port.
*/
- String envelope(String xml) {
+ public String envelope(String xml) {
String body = xml;
if (body.startsWith("<?xml")) {
int end = body.indexOf("?>");
diff --git
a/dsl/camel-jbang/camel-jbang-wsdl/src/test/java/org/apache/camel/dsl/jbang/wsdl/WsdlModelTest.java
b/dsl/camel-jbang/camel-jbang-wsdl/src/test/java/org/apache/camel/dsl/jbang/wsdl/WsdlModelTest.java
new file mode 100644
index 000000000000..1f3afa386746
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-wsdl/src/test/java/org/apache/camel/dsl/jbang/wsdl/WsdlModelTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.wsdl;
+
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Operation;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.Port;
+import org.apache.camel.dsl.jbang.wsdl.WsdlModel.WsdlException;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class WsdlModelTest {
+
+ private static final String ORDERS = "src/test/resources/wsdl/orders.wsdl";
+
+ @Test
+ void parsesTheContentOfAWsdl() throws Exception {
+ WsdlModel model =
WsdlModel.parse(Files.readAllBytes(Paths.get(ORDERS)));
+
+
assertThat(model.targetNamespace()).isEqualTo("http://example.com/orders");
+ Port port = model.services().get(0).ports().get(0);
+ assertThat(port.name()).isEqualTo("OrderPort");
+
assertThat(port.operations()).extracting(Operation::name).containsExactly("getOrder",
"placeOrder");
+ assertThat(model.warnings()).isEmpty();
+ }
+
+ @Test
+ void theContentOfAWsdlFollowsNoImport() throws Exception {
+ // the services of the WSDL itself, and two imports that would read a
file and call another host
+ byte[] wsdl =
Files.readString(Paths.get(ORDERS)).replace("<wsdl:types>", """
+ <wsdl:import namespace="urn:y" location="file:///etc/hosts"/>
+ <wsdl:import namespace="urn:z"
location="http://169.254.169.254/latest/meta-data"/>
+ <wsdl:types>""").getBytes(StandardCharsets.UTF_8);
+
+ WsdlModel model = WsdlModel.parse(wsdl);
+
+ assertThat(model.services()).hasSize(1);
+ assertThat(model.warnings()).hasSize(2)
+ .allSatisfy(w -> assertThat(w).contains("is not followed, as
the WSDL is given as content"));
+ }
+
+ @Test
+ void theContentMustBeAWsdl() {
+ assertThatThrownBy(() -> WsdlModel.parse(new
byte[0])).isInstanceOf(WsdlException.class)
+ .hasMessageContaining("empty");
+ assertThatThrownBy(() ->
WsdlModel.parse("<foo/>".getBytes(StandardCharsets.UTF_8)))
+ .isInstanceOf(WsdlException.class).hasMessageContaining("Not a
WSDL 1.1 document");
+ assertThatThrownBy(() -> WsdlModel.parse(
+ "<!DOCTYPE x [<!ENTITY e SYSTEM
\"file:///etc/hosts\">]><x>&e;</x>".getBytes(StandardCharsets.UTF_8)))
+ .isInstanceOf(WsdlException.class);
+ }
+
+ @Test
+ void aRemoteWsdlImportsFromItsHostOverHttpOrHttps() throws Exception {
+ URI http = URI.create("http://example.com/svc?wsdl");
+ URI https = URI.create("https://example.com/svc?wsdl");
+ URI file = URI.create("file:///tmp/svc.wsdl");
+
+ // the same host, also on another port, and from http up to https
+ assertThat(WsdlModel.refusedImport(http, http,
URI.create("http://example.com/types.wsdl"))).isNull();
+ assertThat(WsdlModel.refusedImport(http, http,
URI.create("http://EXAMPLE.com:8080/types.wsdl"))).isNull();
+ assertThat(WsdlModel.refusedImport(http, http,
URI.create("https://example.com/types.wsdl"))).isNull();
+ assertThat(WsdlModel.refusedImport(https, https,
URI.create("https://example.com/types.wsdl"))).isNull();
+ assertThat(WsdlModel.refusedImport(file, file,
URI.create("file:///tmp/types.wsdl"))).isNull();
+
+ // not from https down to http, not to another host, and not across
files and http(s)
+ assertThat(WsdlModel.refusedImport(https, https,
URI.create("http://example.com/types.wsdl")))
+ .isEqualTo("a WSDL read over https does not import over http");
+ assertThat(WsdlModel.refusedImport(http,
URI.create("https://example.com/types.wsdl"),
+ URI.create("http://example.com/more.wsdl")))
+ .isEqualTo("a WSDL read over https does not import over http");
+ assertThat(WsdlModel.refusedImport(http, http,
URI.create("http://169.254.169.254/latest/meta-data")))
+ .startsWith("it is on the host 169.254.169.254, not on the
host of the WSDL (example.com)");
+ assertThat(WsdlModel.refusedImport(http, http, file)).isEqualTo("a
remote WSDL only imports over http(s), not file");
+ assertThat(WsdlModel.refusedImport(https, https, file))
+ .isEqualTo("a remote WSDL only imports over http(s), not
file");
+ assertThat(WsdlModel.refusedImport(file, file, http)).isEqualTo("a
WSDL file only imports files, not http");
+ assertThat(WsdlModel.refusedImport(file, file, https)).isEqualTo("a
WSDL file only imports files, not https");
+ }
+
+}
diff --git
a/dsl/camel-jbang/camel-jbang-wsdl/src/test/resources/wsdl/orders.wsdl
b/dsl/camel-jbang/camel-jbang-wsdl/src/test/resources/wsdl/orders.wsdl
new file mode 100644
index 000000000000..5f6361ba4a92
--- /dev/null
+++ b/dsl/camel-jbang/camel-jbang-wsdl/src/test/resources/wsdl/orders.wsdl
@@ -0,0 +1,116 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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 small document/literal wrapped SOAP 1.1 service, written for the
soap-source / soap-action prototype. -->
+<wsdl:definitions name="OrderService"
+ targetNamespace="http://example.com/orders"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://example.com/orders">
+
+ <wsdl:types>
+ <xs:schema targetNamespace="http://example.com/orders"
elementFormDefault="qualified">
+ <xs:complexType name="Item">
+ <xs:sequence>
+ <xs:element name="sku" type="xs:string"/>
+ <xs:element name="quantity" type="xs:int"/>
+ <xs:element name="price" type="xs:decimal"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="Order">
+ <xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ <xs:element name="customer" type="xs:string"/>
+ <xs:element name="status" type="xs:string"/>
+ <xs:element name="item" type="tns:Item" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+
+ <xs:element name="getOrder">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ <xs:element name="getOrderResponse">
+ <xs:complexType><xs:sequence>
+ <xs:element name="order" type="tns:Order"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+
+ <xs:element name="placeOrder">
+ <xs:complexType><xs:sequence>
+ <xs:element name="customer" type="xs:string"/>
+ <xs:element name="item" type="tns:Item" maxOccurs="unbounded"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ <xs:element name="placeOrderResponse">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ <xs:element name="status" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+
+ <xs:element name="orderNotFound">
+ <xs:complexType><xs:sequence>
+ <xs:element name="orderId" type="xs:string"/>
+ </xs:sequence></xs:complexType>
+ </xs:element>
+ </xs:schema>
+ </wsdl:types>
+
+ <wsdl:message name="getOrderRequest"><wsdl:part name="parameters"
element="tns:getOrder"/></wsdl:message>
+ <wsdl:message name="getOrderResponse"><wsdl:part name="parameters"
element="tns:getOrderResponse"/></wsdl:message>
+ <wsdl:message name="placeOrderRequest"><wsdl:part name="parameters"
element="tns:placeOrder"/></wsdl:message>
+ <wsdl:message name="placeOrderResponse"><wsdl:part name="parameters"
element="tns:placeOrderResponse"/></wsdl:message>
+ <wsdl:message name="orderNotFoundFault"><wsdl:part name="fault"
element="tns:orderNotFound"/></wsdl:message>
+
+ <wsdl:portType name="OrderPortType">
+ <wsdl:operation name="getOrder">
+ <wsdl:input message="tns:getOrderRequest"/>
+ <wsdl:output message="tns:getOrderResponse"/>
+ <wsdl:fault name="orderNotFound" message="tns:orderNotFoundFault"/>
+ </wsdl:operation>
+ <wsdl:operation name="placeOrder">
+ <wsdl:input message="tns:placeOrderRequest"/>
+ <wsdl:output message="tns:placeOrderResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="OrderSoapBinding" type="tns:OrderPortType">
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getOrder">
+ <soap:operation soapAction="http://example.com/orders/getOrder"/>
+ <wsdl:input><soap:body use="literal"/></wsdl:input>
+ <wsdl:output><soap:body use="literal"/></wsdl:output>
+ <wsdl:fault name="orderNotFound"><soap:fault name="orderNotFound"
use="literal"/></wsdl:fault>
+ </wsdl:operation>
+ <wsdl:operation name="placeOrder">
+ <soap:operation soapAction="http://example.com/orders/placeOrder"/>
+ <wsdl:input><soap:body use="literal"/></wsdl:input>
+ <wsdl:output><soap:body use="literal"/></wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <wsdl:service name="OrderService">
+ <wsdl:port name="OrderPort" binding="tns:OrderSoapBinding">
+ <soap:address location="http://localhost:18081/orders"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
diff --git a/dsl/camel-jbang/pom.xml b/dsl/camel-jbang/pom.xml
index 7816ed290cf1..253b383a1665 100644
--- a/dsl/camel-jbang/pom.xml
+++ b/dsl/camel-jbang/pom.xml
@@ -46,6 +46,7 @@
<module>camel-jbang-plugin-test</module>
<module>camel-jbang-plugin-tui</module>
<module>camel-jbang-plugin-validate</module>
+ <module>camel-jbang-wsdl</module>
<module>camel-jbang-it</module>
<module>camel-launcher</module>
<module>camel-launcher-container</module>
diff --git a/parent/pom.xml b/parent/pom.xml
index 96fa6f572e7b..6ee35f5d0e04 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -3422,6 +3422,11 @@
<artifactId>camel-jbang-run</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jbang-wsdl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<!-- camel catalog -->
<dependency>