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

   _Claude Code on behalf of davsclaus_
   
   ## Summary
   
   [CAMEL-27376](https://issues.apache.org/jira/browse/CAMEL-27376): the Camel 
CLI had `camel generate rest` (OpenAPI) and `camel generate schema`, but 
nothing for WSDL. To use camel-cxf in PAYLOAD mode (or the planned 
soap-source/soap-action Kamelets), a low-code user needs values that are buried 
in the WSDL: the service and port QNames, the address, the SOAP version, and 
for each operation its name, namespace, soapAction, request and response 
elements and faults. The kamelets prototype had to find them by hand.
   
   This adds `camel generate wsdl` to the generate plugin, next to `rest` and 
`schema` (phase 1 of the approved design):
   
   ```
   camel generate wsdl <wsdl>                      # table: one block per port, 
one row per operation
   camel generate wsdl <wsdl> --json               # the same as JSON, with the 
cxf endpoint options of each port
   camel generate wsdl <wsdl> --route=consumer|producer [--output=x.camel.yaml]
          [--service=<name>] [--port=<name>] [--operation=a,b] 
[--runtime=camel-main|spring-boot|quarkus]
   ```
   
   ```
   SERVICE    OrderService
   PORT       OrderPort
   BINDING    OrderSoapBinding
   SOAP       1.1
   STYLE      document/literal
   ADDRESS    http://localhost:18081/orders
   NAMESPACE  http://example.com/orders
   
    OPERATION   SOAP ACTION                           INPUT       OUTPUT        
      FAULTS
    getOrder    http://example.com/orders/getOrder    getOrder    
getOrderResponse    orderNotFound
    placeOrder  http://example.com/orders/placeOrder  placeOrder  
placeOrderResponse
   ```
   
   ## Design summary
   
   - **Where:** a third subcommand in `GeneratePlugin` (`CodeWsdlGenerator`, 
aesh `@CommandDefinition` on `CamelCommand`). There is no top-level `camel wsdl 
info`: `PluginType` maps one top-level command to a plugin, so listing is part 
of `camel generate wsdl`.
   - **Input:** WSDL 1.1 with SOAP 1.1/1.2 bindings, including `wsdl:import`, 
from a file or a http(s) URL. WSDL 2.0 is refused with a clear message. Ports 
with a binding that is not SOAP (such as HTTP GET) are left out with a warning. 
rpc/literal is listed but not scaffolded.
   - **Parser:** plain JDK DOM in a small `WsdlModel` class, with no CXF and no 
wsdl4j (its last release was in 2012), and no new dependency. The XSD types are 
not read in phase 1.
   - **Scaffold (YAML only, PAYLOAD mode, no generated classes):**
     - `consumer`: `from: cxf://<address>` with `wsdlURL`, `serviceName`, 
`portName`, `dataFormat: PAYLOAD` and `schemaValidationEnabled: true`. Then 
`convertBodyTo: String` and a `choice` on `${header.CamelCxfOperationName}` 
with one `when` per operation. Each `when` logs the request and returns a 
placeholder response element in the right namespace, with a `note: TODO`.
     - `producer`: one route `direct:<operation>` per operation: 
`removeHeaders`, then `to: cxf://<address>` with `wsdlURL`, `serviceName`, 
`portName`, `dataFormat: PAYLOAD`, `defaultOperationName` and 
`defaultOperationNamespace`, then `convertBodyTo: String` (left out for one-way 
operations).
     - `--runtime`: camel-main (the default, also for `camel run`) listens on 
`http://0.0.0.0:<port><path>` of the WSDL address. spring-boot and quarkus get 
the path, which the CXF servlet of the runtime serves. `wsdlURL` is the WSDL as 
given, with `file:` in front of a file name.
     - The YAML is written with snakeyaml (already a dependency of 
camel-jbang-core), not with string templates, in the canonical YAML DSL form.
   - **Security:**
     - The parser refuses a DOCTYPE and never loads an external entity, as 
`XmlChecks` does.
     - An import is followed only with the same scheme as the WSDL, so a remote 
WSDL cannot import a local file. There are at most 32 documents and 8 levels of 
imports, and each document is at most 16 MB.
     - Operation, service, port and element names must be NCNames, and 
namespaces and addresses plain URIs (no brace, quote, parenthesis or space), 
before they go into the YAML and the `simple` expressions. A hostile WSDL 
therefore cannot add YAML, `${...}` or `{{...}}`.
     - The user info of an address (`user:pw@`) is masked in the table and the 
JSON, and left out of the scaffold. The query of an address is left out too, 
because it would become endpoint parameters.
     - Control characters in WSDL values are replaced before they reach the 
terminal.
   
   Two choices that differ from the design text:
   - An unknown `--service`, `--port` or `--operation` exits with `NOT_FOUND` 
(3), not `USAGE` (2). The `CliExitCode` contract names "a service or other name 
given on the command line that does not exist" as 3. Invalid option 
combinations exit with 2, a WSDL that cannot be read or scaffolded with 1, and 
a missing file with 66.
   - The producer removes 
`Camel.*|operationName|operationNamespace|RequestContext|ResponseContext`, not 
only `Camel*`. `CxfProducer` still reads the former 
`operationName`/`operationNamespace` headers, and `RequestContext` can carry 
the endpoint address. This is the same set the soap-action Kamelet prototype 
removes.
   
   When the WSDL has more than one SOAP port (as many .NET services do, with a 
SOAP 1.1 and a SOAP 1.2 port), `--route` asks for `--service` and `--port` and 
lists the choices.
   
   ## Tests
   
   `CodeWsdlGeneratorTest` (23 tests) uses these WSDLs:
   - the kamelets prototype's `orders.wsdl` (document/literal wrapped, SOAP 
1.1; ASF header added);
   - SOAP 1.2 with a one-way operation and an address with user info and a 
query;
   - two services with SOAP 1.1, SOAP 1.2 and HTTP ports, over two levels of 
`wsdl:import`, with a fault element in another namespace;
   - rpc/literal, WSDL 2.0, and a DOCTYPE with an external entity;
   - WSDLs written by the test: an import with another scheme, an import cycle, 
a name that is not an NCName, a namespace with `{{env:HOME}}`, and a remote 
WSDL served over HTTP by a JDK `HttpServer` that imports `file:///etc/hosts`.
   
   The table, the JSON and both scaffolds are compared against golden files 
(`-Dcamel.wsdl.updateGolden=true` rewrites them). Every scaffold is checked 
with `YamlValidator` (classic and canonical schema) and loaded with the YAML 
DSL into route definitions, and the test checks the endpoint URIs, the `when` 
expressions and the placeholders.
   
   ```
   mvn -o test 
-Dtest='CodeWsdlGeneratorTest,CodeRestGeneratorTest,CodeSchemaGeneratorTest'   
(camel-jbang-plugin-generate)
   Tests run: 35, Failures: 0, Errors: 0, Skipped: 0
   mvn -o verify -Psourcecheck -DskipTests   BUILD SUCCESS
   ```
   
   Runtime check (a throwaway test in camel-cxf-soap, not committed): the 
scaffolded consumer and producer, as the same endpoint URIs, ran against each 
other over Undertow. `placeOrder` got its response through the producer, and a 
`CamelDestinationOverrideUrl` header set by the caller was removed and did not 
redirect the call. The empty placeholder of `getOrder` fails the response 
schema validation, and the caller gets a SOAP fault that names the missing 
element (`One of '{"http://example.com/orders":order}' is expected`). The 
scaffold comment and the docs say this.
   
   ## Docs
   
   - `camel-jbang-projects.adoc`: a new section "SOAP routes from a WSDL" under 
the Generate plugin, next to `generate rest`.
   - `jbang-commands/camel-jbang-generate-wsdl.adoc`, 
`camel-jbang-generate.adoc` and the plugin's 
`camel-jbang-plugin-commands-metadata.json` are regenerated by the build.
   
   ## Follow-ups (not in this PR)
   
   - An MCP tool `camel_wsdl_scaffold` (like `camel_openapi_scaffold`) and a 
TUI view.
   - `--samples`: a sample request and response per operation from the XSD, 
once the schema model of CAMEL-27375 exists.
   - `--kamelet`: scaffold the soap-source/soap-action Kamelets instead of raw 
`cxf:`, once they are released.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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

To unsubscribe, e-mail: [email protected]

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

Reply via email to