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-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new ff2c7794d chore: soap-source and soap-action bodyFormat json, with the
types of the XML schema of the WSDL (CAMEL-27375) (#3357)
ff2c7794d is described below
commit ff2c7794df6b831f42279c1c7fae4d93d85a4fb2
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 22 20:41:54 2026 +0100
chore: soap-source and soap-action bodyFormat json, with the types of the
XML schema of the WSDL (CAMEL-27375) (#3357)
* chore: soap-source answers a SOAP fault the route builds as text, and
soap-action address is optional with a WSDL that has one (CAMEL-27372,
CAMEL-27374)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: soap-action and soap-source WS-Security UsernameToken options
(CAMEL-27373)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: soap-action no longer needs --dep=camel:cxf-soap to catch a
SoapFault (CAMEL-27364), the password type must match, and the tests check the
no-address call by its order
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: the WS-Security test checks the reply by its order, as CXF adds
the soap namespace to the body
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: soap-action says that a refused UsernameToken gives a
SecurityError fault
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: soap-source and soap-action bodyFormat json, with the types of the
XML schema of the WSDL (CAMEL-27375)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: regenerate the catalog index and the SBOM
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: regenerate the catalog index
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: the JSON-mode test checks the whole SOAP response, with the
elements in the order and namespace of the schema
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel-kamelets-catalog-sbom.json | 18 +++-
kamelets/soap-action.kamelet.yaml | 61 ++++++++++-
kamelets/soap-source.kamelet.yaml | 55 +++++++++-
.../main/resources/META-INF/kamelets-index.json | 4 +-
.../resources/kamelets/soap-action.kamelet.yaml | 61 ++++++++++-
.../resources/kamelets/soap-source.kamelet.yaml | 55 +++++++++-
.../camel-kamelets-itest/src/test/java/SoapIT.java | 4 +
.../src/test/resources/soap/orders.wsdl | 1 +
.../resources/soap/soap-json-backend-route.yaml | 49 +++++++++
.../test/resources/soap/soap-json-front-route.yaml | 73 +++++++++++++
.../test/resources/soap/soap-json.citrus.it.yaml | 114 +++++++++++++++++++++
11 files changed, 481 insertions(+), 14 deletions(-)
diff --git a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
index 0dd3519b1..4940d33c2 100644
--- a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
+++ b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
@@ -2410,6 +2410,17 @@
"name" : "camel.apache.org/versioned-by",
"value" : "runtime"
} ]
+ }, {
+ "bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "type" : "library",
+ "group" : "org.apache.camel",
+ "name" : "camel-xsd-json",
+ "version" : "4.24.0-SNAPSHOT",
+ "purl" : "pkg:maven/org.apache.camel/[email protected]",
+ "properties" : [ {
+ "name" : "camel.apache.org/versioned-by",
+ "value" : "runtime"
+ } ]
}, {
"bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
"type" : "library",
@@ -3076,10 +3087,10 @@
"dependsOn" : [ "pkg:maven/net.snowflake/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.commons/[email protected]" ]
}, {
"ref" : "kamelet:soap-action",
- "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "kamelet:soap-source",
- "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "kamelet:solr-sink",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -3494,6 +3505,9 @@
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
+ }, {
+ "ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "dependsOn" : [ ]
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
diff --git a/kamelets/soap-action.kamelet.yaml
b/kamelets/soap-action.kamelet.yaml
index 1366a2009..2dcaafe2d 100644
--- a/kamelets/soap-action.kamelet.yaml
+++ b/kamelets/soap-action.kamelet.yaml
@@ -36,9 +36,9 @@ spec:
Use it to call an existing SOAP service from a route, such as an order
or customer service of an older system, with XML and without generating Java
code from the WSDL. To serve a SOAP service, use `soap-source`.
- Input: the body is the request element of the operation as XML text,
such as `<getOrder
xmlns="http://example.com/orders"><orderId>7</orderId></getOrder>`. It is put
in the SOAP Body as it is.
+ Input: the body is the request element of the operation as XML text,
such as `<getOrder
xmlns="http://example.com/orders"><orderId>7</orderId></getOrder>`. It is put
in the SOAP Body as it is. With `bodyFormat` `json`, the body is JSON text with
the fields of the request element, such as `{"orderId": "7"}`: it is written as
XML in the order and with the namespaces of the schema, and a field that the
schema does not have fails the message, unless `ignoreUnknownFields` is true.
- Output: the body is the content of the SOAP Body of the response as XML
text: the response element of the operation, such as `<getOrderResponse
xmlns="http://example.com/orders">...</getOrderResponse>`.
+ Output: the body is the content of the SOAP Body of the response as XML
text: the response element of the operation, such as `<getOrderResponse
xmlns="http://example.com/orders">...</getOrderResponse>`. With `bodyFormat`
`json`, the body is JSON text with the fields of the response element, such as
`{"order": {"orderId": "7", "item": [{"sku": "A-1", "quantity": 2}]}}`: each
value has the JSON type of its XML schema type, such as a number or `true`, and
an element that can repeat is [...]
Good to know: a SOAP fault from the service fails the message with an
`org.apache.cxf.binding.soap.SoapFault` error, whose message is the text of the
fault, so that a route can catch it by its class name. When `faultAsBody` is
true, the message goes on instead: the body is the content of the `detail`
element of the fault as XML text, such as the fault element the WSDL declares
(no body when the fault has no detail), the header `SoapFault` is the text of
the fault, and `SoapFaultCod [...]
required:
@@ -80,6 +80,22 @@ spec:
type: string
example: "{http://example.com/orders}OrderPort"
pattern: "^\\{[^}]*\\}[^{}]+$"
+ bodyFormat:
+ title: Body Format
+ description: The format of the request the Kamelet takes and of the
response it gives. `xml` is the XML of the SOAP Body as text. `json` is JSON
text that the XML schema of the WSDL types, see the description of the Kamelet.
The detail of a fault is XML text in both formats.
+ type: string
+ default: xml
+ enum: ["xml", "json"]
+ requestElement:
+ title: Request Element
+ description: Only used when `bodyFormat` is `json`. The element of the
XML schema that the JSON of a request is turned into, as `\{namespace}name` or
as a name that only one element of the schema has. When it is not set, the
element named as `operation`, which is the request element of a
document/literal wrapped service.
+ type: string
+ example: "{http://example.com/orders}getOrder"
+ ignoreUnknownFields:
+ title: Ignore Unknown Fields
+ description: Only used when `bodyFormat` is `json`. If true, a JSON
field of the request, or an XML element or attribute of the response, that the
XML schema of the WSDL does not have is left out. If false, it fails the
message.
+ type: boolean
+ default: false
faultAsBody:
title: Fault As Body
description: Whether a SOAP fault from the service gives a message
with the detail of the fault as body and the `SoapFault` and `SoapFaultCode`
headers, instead of failing the message.
@@ -135,6 +151,7 @@ spec:
- "camel:cxf-soap"
- "camel:xpath"
- "camel:kamelet"
+ - "camel:xsd-json"
template:
from:
uri: kamelet:source
@@ -144,12 +161,52 @@ spec:
# HTTP headers, and SOAP headers that came in through soap-source
would be relayed.
- removeHeaders:
pattern:
Camel.*|RequestContext|ResponseContext|operationName|operationNamespace|SoapFault.*|SOAPAction|Authorization|Proxy-Authorization|org\.apache\.cxf\..*
+ # In JSON mode, the JSON is turned into the request element:
requestElement, else the operation name
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{bodyFormat}}' == 'json'"
+ steps:
+ - setHeader:
+ name: CamelXsdJsonElement
+ expression:
+ constant:
+ expression: "{{?requestElement}}"
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "${header.CamelXsdJsonElement} ==
null || ${header.CamelXsdJsonElement} == ''"
+ steps:
+ - setHeader:
+ name: CamelXsdJsonElement
+ expression:
+ constant:
+ expression: "{{operation}}"
+ - marshal:
+ xsdJson:
+ schema: "{{wsdlURL}}"
+ ignoreUnknown: "{{ignoreUnknownFields}}"
+ - removeHeader:
+ name: CamelXsdJsonElement
- doTry:
steps:
- to:
uri:
"cxf://{{?address}}?wsdlURL=RAW({{wsdlURL}})&serviceName={{?serviceName}}&portName={{?portName}}&dataFormat=PAYLOAD&defaultOperationName={{operation}}&defaultOperationNamespace={{?operationNamespace}}&username=RAW({{?username}})&password=RAW({{?password}})&wsSecurityUsername=RAW({{?wsSecurityUsername}})&wsSecurityPassword=RAW({{?wsSecurityPassword}})&wsSecurityPasswordType={{?wsSecurityPasswordType}}"
- convertBodyTo:
type: java.lang.String
+ # the XML names its element, so no element is needed
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{bodyFormat}}' == 'json'"
+ steps:
+ - unmarshal:
+ xsdJson:
+ schema: "{{wsdlURL}}"
+ ignoreUnknown: "{{ignoreUnknownFields}}"
- doCatch:
exception:
- org.apache.cxf.binding.soap.SoapFault
diff --git a/kamelets/soap-source.kamelet.yaml
b/kamelets/soap-source.kamelet.yaml
index 2cfbebb66..fb09be56d 100644
--- a/kamelets/soap-source.kamelet.yaml
+++ b/kamelets/soap-source.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
Use it to keep existing SOAP clients working while the systems behind
the service are replaced: the route gets each call and can call REST services
or other systems to answer it. No Java code is generated from the WSDL. To call
a SOAP service, use `soap-action`.
- Output: the body is the content of the SOAP Body of the request as XML
text: the request element of the operation, such as `<getOrder
xmlns="http://example.com/orders"><orderId>7</orderId></getOrder>`. The header
`CamelCxfOperationName` is the name of the operation, such as `getOrder`, and
`CamelCxfOperationNamespace` its namespace. The HTTP headers of the request,
such as `User-Agent`, are headers too.
+ Output: the body is the content of the SOAP Body of the request as XML
text: the request element of the operation, such as `<getOrder
xmlns="http://example.com/orders"><orderId>7</orderId></getOrder>`. The header
`CamelCxfOperationName` is the name of the operation, such as `getOrder`, and
`CamelCxfOperationNamespace` its namespace. The HTTP headers of the request,
such as `User-Agent`, are headers too. With `bodyFormat` `json`, the body is
JSON text instead, with the fields of the [...]
- The reply of the route, as XML text, is the content of the SOAP Body of
the response: the response element of the operation, such as `<getOrderResponse
xmlns="http://example.com/orders">...</getOrderResponse>`. To answer with a
SOAP fault, the route sets the header `SoapFault` to the text of the fault, and
`SoapFaultCode` to `Client` when the request was wrong (`Sender` with SOAP 1.2;
otherwise the code is `Server`, or `Receiver`); the body, if any, is the
content of the detail of [...]
+ The reply of the route, as XML text, is the content of the SOAP Body of
the response: the response element of the operation, such as `<getOrderResponse
xmlns="http://example.com/orders">...</getOrderResponse>`. To answer with a
SOAP fault, the route sets the header `SoapFault` to the text of the fault, and
`SoapFaultCode` to `Client` when the request was wrong (`Sender` with SOAP 1.2;
otherwise the code is `Server`, or `Receiver`); the body, if any, is the
content of the detail of [...]
- Good to know: the service is served at `address`, its WSDL at `address`
followed by `?wsdl`, with SOAP 1.1 or 1.2 as the WSDL says. A request or a
reply that does not match the XML schema of the WSDL is refused with a SOAP
fault, unless `schemaValidation` is false, and so is a request for an operation
the WSDL does not have, and a request with a DOCTYPE. There is no login unless
`wsSecurityUsername` and `wsSecurityPassword` are set, which require a
WS-Security UsernameToken in each [...]
+ Good to know: the service is served at `address`, its WSDL at `address`
followed by `?wsdl`, with SOAP 1.1 or 1.2 as the WSDL says. A request or a
reply that does not match the XML schema of the WSDL is refused with a SOAP
fault, unless `schemaValidation` is false, and so is a request for an operation
the WSDL does not have, and a request with a DOCTYPE. There is no login unless
`wsSecurityUsername` and `wsSecurityPassword` are set, which require a
WS-Security UsernameToken in each [...]
required:
- address
- wsdlURL
@@ -100,6 +100,17 @@ spec:
type: string
enum: ["Text", "Digest"]
example: Digest
+ bodyFormat:
+ title: Body Format
+ description: The format of the request that the route gets and of the
reply it gives. `xml` is the XML of the SOAP Body as text. `json` is JSON text
that the XML schema of the WSDL types, see the description of the Kamelet. The
detail of a fault is XML text in both formats.
+ type: string
+ default: xml
+ enum: ["xml", "json"]
+ ignoreUnknownFields:
+ title: Ignore Unknown Fields
+ description: Only used when `bodyFormat` is `json`. If true, an XML
element or attribute of the request, or a JSON field of the reply, that the XML
schema of the WSDL does not have is left out. If false, it fails the call with
a SOAP fault.
+ type: boolean
+ default: false
loggingEnabled:
title: Log Messages
description: Whether to write each SOAP request and response to the
log. Do not turn it on when the messages hold personal data or secrets.
@@ -120,6 +131,7 @@ spec:
dependencies:
- "camel:cxf-soap"
- "camel:kamelet"
+ - "camel:xsd-json"
template:
from:
uri:
"cxf://{{address}}?wsdlURL=RAW({{wsdlURL}})&serviceName={{?serviceName}}&portName={{?portName}}&publishedEndpointUrl=RAW({{?publishedEndpointUrl}})&dataFormat=PAYLOAD&schemaValidationEnabled={{schemaValidation}}&loggingFeatureEnabled={{loggingEnabled}}&wsSecurityUsername=RAW({{?wsSecurityUsername}})&wsSecurityPassword=RAW({{?wsSecurityPassword}})&wsSecurityPasswordType={{?wsSecurityPasswordType}}"
@@ -136,6 +148,17 @@ spec:
expression: "${header.Content-Type}"
- convertBodyTo:
type: java.lang.String
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{bodyFormat}}' == 'json'"
+ steps:
+ # the XML names its element, so no element is needed
+ - unmarshal:
+ xsdJson:
+ schema: "{{wsdlURL}}"
+ ignoreUnknown: "{{ignoreUnknownFields}}"
- to:
uri: kamelet:sink
# The headers of the reply would be sent back as HTTP headers,
including the ones that came with the request
@@ -152,6 +175,32 @@ spec:
expression: "${header.SoapFaultCode}"
- removeHeaders:
pattern: "*"
+ # In JSON mode, a reply that is not a fault is turned into the
response element of the operation, as the
+ # WSDL message of its output names it. The detail of a fault stays XML
text.
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{bodyFormat}}' == 'json' &&
${variable.soapSourceFault} == null && ${body} != null"
+ steps:
+ - setVariable:
+ name: soapSourceOperation
+ expression:
+ simple:
+ expression:
"${exchangeProperty[org.apache.cxf.service.model.BindingOperationInfo]}"
+ - setHeader:
+ name: CamelXsdJsonElement
+ expression:
+ simple:
+ expression:
"${variable.soapSourceOperation.operationInfo.output.messageParts[0].elementQName}"
+ - marshal:
+ xsdJson:
+ schema: "{{wsdlURL}}"
+ ignoreUnknown: "{{ignoreUnknownFields}}"
+ - removeHeader:
+ name: CamelXsdJsonElement
+ - convertBodyTo:
+ type: java.lang.String
- choice:
when:
- expression:
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 8a886d6db..fc12a251f 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -2075,7 +2075,7 @@
"supportLevel" : "Preview",
"title" : "SOAP Action",
"summary" : "Calls an operation of a SOAP web service described by a WSDL
file for each message, and gives back the response.",
- "description" : "Calls an operation of a SOAP web service described by a
WSDL file for each message, and gives back the response.\n\nUse it to call an
existing SOAP service from a route, such as an order or customer service of an
older system, with XML and without generating Java code from the WSDL. To serve
a SOAP service, use `soap-source`.\n\nInput: the body is the request element of
the operation as XML text, such as `<getOrder
xmlns=\"http://example.com/orders\"><orderId>7</orde [...]
+ "description" : "Calls an operation of a SOAP web service described by a
WSDL file for each message, and gives back the response.\n\nUse it to call an
existing SOAP service from a route, such as an order or customer service of an
older system, with XML and without generating Java code from the WSDL. To serve
a SOAP service, use `soap-source`.\n\nInput: the body is the request element of
the operation as XML text, such as `<getOrder
xmlns=\"http://example.com/orders\"><orderId>7</orde [...]
"group" : "SOAP",
"namespace" : "HTTP",
"provider" : "Apache Software Foundation"
@@ -2085,7 +2085,7 @@
"supportLevel" : "Preview",
"title" : "SOAP Source",
"summary" : "Serves a SOAP web service described by a WSDL file, and
answers each call with the reply of the route.",
- "description" : "Serves a SOAP web service described by a WSDL file, and
answers each call with the reply of the route.\n\nUse it to keep existing SOAP
clients working while the systems behind the service are replaced: the route
gets each call and can call REST services or other systems to answer it. No
Java code is generated from the WSDL. To call a SOAP service, use
`soap-action`.\n\nOutput: the body is the content of the SOAP Body of the
request as XML text: the request element of [...]
+ "description" : "Serves a SOAP web service described by a WSDL file, and
answers each call with the reply of the route.\n\nUse it to keep existing SOAP
clients working while the systems behind the service are replaced: the route
gets each call and can call REST services or other systems to answer it. No
Java code is generated from the WSDL. To call a SOAP service, use
`soap-action`.\n\nOutput: the body is the content of the SOAP Body of the
request as XML text: the request element of [...]
"group" : "SOAP",
"namespace" : "HTTP",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/soap-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/soap-action.kamelet.yaml
index 1366a2009..2dcaafe2d 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/soap-action.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/soap-action.kamelet.yaml
@@ -36,9 +36,9 @@ spec:
Use it to call an existing SOAP service from a route, such as an order
or customer service of an older system, with XML and without generating Java
code from the WSDL. To serve a SOAP service, use `soap-source`.
- Input: the body is the request element of the operation as XML text,
such as `<getOrder
xmlns="http://example.com/orders"><orderId>7</orderId></getOrder>`. It is put
in the SOAP Body as it is.
+ Input: the body is the request element of the operation as XML text,
such as `<getOrder
xmlns="http://example.com/orders"><orderId>7</orderId></getOrder>`. It is put
in the SOAP Body as it is. With `bodyFormat` `json`, the body is JSON text with
the fields of the request element, such as `{"orderId": "7"}`: it is written as
XML in the order and with the namespaces of the schema, and a field that the
schema does not have fails the message, unless `ignoreUnknownFields` is true.
- Output: the body is the content of the SOAP Body of the response as XML
text: the response element of the operation, such as `<getOrderResponse
xmlns="http://example.com/orders">...</getOrderResponse>`.
+ Output: the body is the content of the SOAP Body of the response as XML
text: the response element of the operation, such as `<getOrderResponse
xmlns="http://example.com/orders">...</getOrderResponse>`. With `bodyFormat`
`json`, the body is JSON text with the fields of the response element, such as
`{"order": {"orderId": "7", "item": [{"sku": "A-1", "quantity": 2}]}}`: each
value has the JSON type of its XML schema type, such as a number or `true`, and
an element that can repeat is [...]
Good to know: a SOAP fault from the service fails the message with an
`org.apache.cxf.binding.soap.SoapFault` error, whose message is the text of the
fault, so that a route can catch it by its class name. When `faultAsBody` is
true, the message goes on instead: the body is the content of the `detail`
element of the fault as XML text, such as the fault element the WSDL declares
(no body when the fault has no detail), the header `SoapFault` is the text of
the fault, and `SoapFaultCod [...]
required:
@@ -80,6 +80,22 @@ spec:
type: string
example: "{http://example.com/orders}OrderPort"
pattern: "^\\{[^}]*\\}[^{}]+$"
+ bodyFormat:
+ title: Body Format
+ description: The format of the request the Kamelet takes and of the
response it gives. `xml` is the XML of the SOAP Body as text. `json` is JSON
text that the XML schema of the WSDL types, see the description of the Kamelet.
The detail of a fault is XML text in both formats.
+ type: string
+ default: xml
+ enum: ["xml", "json"]
+ requestElement:
+ title: Request Element
+ description: Only used when `bodyFormat` is `json`. The element of the
XML schema that the JSON of a request is turned into, as `\{namespace}name` or
as a name that only one element of the schema has. When it is not set, the
element named as `operation`, which is the request element of a
document/literal wrapped service.
+ type: string
+ example: "{http://example.com/orders}getOrder"
+ ignoreUnknownFields:
+ title: Ignore Unknown Fields
+ description: Only used when `bodyFormat` is `json`. If true, a JSON
field of the request, or an XML element or attribute of the response, that the
XML schema of the WSDL does not have is left out. If false, it fails the
message.
+ type: boolean
+ default: false
faultAsBody:
title: Fault As Body
description: Whether a SOAP fault from the service gives a message
with the detail of the fault as body and the `SoapFault` and `SoapFaultCode`
headers, instead of failing the message.
@@ -135,6 +151,7 @@ spec:
- "camel:cxf-soap"
- "camel:xpath"
- "camel:kamelet"
+ - "camel:xsd-json"
template:
from:
uri: kamelet:source
@@ -144,12 +161,52 @@ spec:
# HTTP headers, and SOAP headers that came in through soap-source
would be relayed.
- removeHeaders:
pattern:
Camel.*|RequestContext|ResponseContext|operationName|operationNamespace|SoapFault.*|SOAPAction|Authorization|Proxy-Authorization|org\.apache\.cxf\..*
+ # In JSON mode, the JSON is turned into the request element:
requestElement, else the operation name
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{bodyFormat}}' == 'json'"
+ steps:
+ - setHeader:
+ name: CamelXsdJsonElement
+ expression:
+ constant:
+ expression: "{{?requestElement}}"
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "${header.CamelXsdJsonElement} ==
null || ${header.CamelXsdJsonElement} == ''"
+ steps:
+ - setHeader:
+ name: CamelXsdJsonElement
+ expression:
+ constant:
+ expression: "{{operation}}"
+ - marshal:
+ xsdJson:
+ schema: "{{wsdlURL}}"
+ ignoreUnknown: "{{ignoreUnknownFields}}"
+ - removeHeader:
+ name: CamelXsdJsonElement
- doTry:
steps:
- to:
uri:
"cxf://{{?address}}?wsdlURL=RAW({{wsdlURL}})&serviceName={{?serviceName}}&portName={{?portName}}&dataFormat=PAYLOAD&defaultOperationName={{operation}}&defaultOperationNamespace={{?operationNamespace}}&username=RAW({{?username}})&password=RAW({{?password}})&wsSecurityUsername=RAW({{?wsSecurityUsername}})&wsSecurityPassword=RAW({{?wsSecurityPassword}})&wsSecurityPasswordType={{?wsSecurityPasswordType}}"
- convertBodyTo:
type: java.lang.String
+ # the XML names its element, so no element is needed
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{bodyFormat}}' == 'json'"
+ steps:
+ - unmarshal:
+ xsdJson:
+ schema: "{{wsdlURL}}"
+ ignoreUnknown: "{{ignoreUnknownFields}}"
- doCatch:
exception:
- org.apache.cxf.binding.soap.SoapFault
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/soap-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/soap-source.kamelet.yaml
index 2cfbebb66..fb09be56d 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/soap-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/soap-source.kamelet.yaml
@@ -36,11 +36,11 @@ spec:
Use it to keep existing SOAP clients working while the systems behind
the service are replaced: the route gets each call and can call REST services
or other systems to answer it. No Java code is generated from the WSDL. To call
a SOAP service, use `soap-action`.
- Output: the body is the content of the SOAP Body of the request as XML
text: the request element of the operation, such as `<getOrder
xmlns="http://example.com/orders"><orderId>7</orderId></getOrder>`. The header
`CamelCxfOperationName` is the name of the operation, such as `getOrder`, and
`CamelCxfOperationNamespace` its namespace. The HTTP headers of the request,
such as `User-Agent`, are headers too.
+ Output: the body is the content of the SOAP Body of the request as XML
text: the request element of the operation, such as `<getOrder
xmlns="http://example.com/orders"><orderId>7</orderId></getOrder>`. The header
`CamelCxfOperationName` is the name of the operation, such as `getOrder`, and
`CamelCxfOperationNamespace` its namespace. The HTTP headers of the request,
such as `User-Agent`, are headers too. With `bodyFormat` `json`, the body is
JSON text instead, with the fields of the [...]
- The reply of the route, as XML text, is the content of the SOAP Body of
the response: the response element of the operation, such as `<getOrderResponse
xmlns="http://example.com/orders">...</getOrderResponse>`. To answer with a
SOAP fault, the route sets the header `SoapFault` to the text of the fault, and
`SoapFaultCode` to `Client` when the request was wrong (`Sender` with SOAP 1.2;
otherwise the code is `Server`, or `Receiver`); the body, if any, is the
content of the detail of [...]
+ The reply of the route, as XML text, is the content of the SOAP Body of
the response: the response element of the operation, such as `<getOrderResponse
xmlns="http://example.com/orders">...</getOrderResponse>`. To answer with a
SOAP fault, the route sets the header `SoapFault` to the text of the fault, and
`SoapFaultCode` to `Client` when the request was wrong (`Sender` with SOAP 1.2;
otherwise the code is `Server`, or `Receiver`); the body, if any, is the
content of the detail of [...]
- Good to know: the service is served at `address`, its WSDL at `address`
followed by `?wsdl`, with SOAP 1.1 or 1.2 as the WSDL says. A request or a
reply that does not match the XML schema of the WSDL is refused with a SOAP
fault, unless `schemaValidation` is false, and so is a request for an operation
the WSDL does not have, and a request with a DOCTYPE. There is no login unless
`wsSecurityUsername` and `wsSecurityPassword` are set, which require a
WS-Security UsernameToken in each [...]
+ Good to know: the service is served at `address`, its WSDL at `address`
followed by `?wsdl`, with SOAP 1.1 or 1.2 as the WSDL says. A request or a
reply that does not match the XML schema of the WSDL is refused with a SOAP
fault, unless `schemaValidation` is false, and so is a request for an operation
the WSDL does not have, and a request with a DOCTYPE. There is no login unless
`wsSecurityUsername` and `wsSecurityPassword` are set, which require a
WS-Security UsernameToken in each [...]
required:
- address
- wsdlURL
@@ -100,6 +100,17 @@ spec:
type: string
enum: ["Text", "Digest"]
example: Digest
+ bodyFormat:
+ title: Body Format
+ description: The format of the request that the route gets and of the
reply it gives. `xml` is the XML of the SOAP Body as text. `json` is JSON text
that the XML schema of the WSDL types, see the description of the Kamelet. The
detail of a fault is XML text in both formats.
+ type: string
+ default: xml
+ enum: ["xml", "json"]
+ ignoreUnknownFields:
+ title: Ignore Unknown Fields
+ description: Only used when `bodyFormat` is `json`. If true, an XML
element or attribute of the request, or a JSON field of the reply, that the XML
schema of the WSDL does not have is left out. If false, it fails the call with
a SOAP fault.
+ type: boolean
+ default: false
loggingEnabled:
title: Log Messages
description: Whether to write each SOAP request and response to the
log. Do not turn it on when the messages hold personal data or secrets.
@@ -120,6 +131,7 @@ spec:
dependencies:
- "camel:cxf-soap"
- "camel:kamelet"
+ - "camel:xsd-json"
template:
from:
uri:
"cxf://{{address}}?wsdlURL=RAW({{wsdlURL}})&serviceName={{?serviceName}}&portName={{?portName}}&publishedEndpointUrl=RAW({{?publishedEndpointUrl}})&dataFormat=PAYLOAD&schemaValidationEnabled={{schemaValidation}}&loggingFeatureEnabled={{loggingEnabled}}&wsSecurityUsername=RAW({{?wsSecurityUsername}})&wsSecurityPassword=RAW({{?wsSecurityPassword}})&wsSecurityPasswordType={{?wsSecurityPasswordType}}"
@@ -136,6 +148,17 @@ spec:
expression: "${header.Content-Type}"
- convertBodyTo:
type: java.lang.String
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{bodyFormat}}' == 'json'"
+ steps:
+ # the XML names its element, so no element is needed
+ - unmarshal:
+ xsdJson:
+ schema: "{{wsdlURL}}"
+ ignoreUnknown: "{{ignoreUnknownFields}}"
- to:
uri: kamelet:sink
# The headers of the reply would be sent back as HTTP headers,
including the ones that came with the request
@@ -152,6 +175,32 @@ spec:
expression: "${header.SoapFaultCode}"
- removeHeaders:
pattern: "*"
+ # In JSON mode, a reply that is not a fault is turned into the
response element of the operation, as the
+ # WSDL message of its output names it. The detail of a fault stays XML
text.
+ - choice:
+ when:
+ - expression:
+ simple:
+ expression: "'{{bodyFormat}}' == 'json' &&
${variable.soapSourceFault} == null && ${body} != null"
+ steps:
+ - setVariable:
+ name: soapSourceOperation
+ expression:
+ simple:
+ expression:
"${exchangeProperty[org.apache.cxf.service.model.BindingOperationInfo]}"
+ - setHeader:
+ name: CamelXsdJsonElement
+ expression:
+ simple:
+ expression:
"${variable.soapSourceOperation.operationInfo.output.messageParts[0].elementQName}"
+ - marshal:
+ xsdJson:
+ schema: "{{wsdlURL}}"
+ ignoreUnknown: "{{ignoreUnknownFields}}"
+ - removeHeader:
+ name: CamelXsdJsonElement
+ - convertBodyTo:
+ type: java.lang.String
- choice:
when:
- expression:
diff --git a/tests/camel-kamelets-itest/src/test/java/SoapIT.java
b/tests/camel-kamelets-itest/src/test/java/SoapIT.java
index b3b621d00..a1c87fd20 100644
--- a/tests/camel-kamelets-itest/src/test/java/SoapIT.java
+++ b/tests/camel-kamelets-itest/src/test/java/SoapIT.java
@@ -38,6 +38,8 @@ public class SoapIT {
private final int frontPort = ServerPorts.next();
private final int soap12Port = ServerPorts.next();
private final int wssecPort = ServerPorts.next();
+ private final int jsonBackendPort = ServerPorts.next();
+ private final int jsonFrontPort = ServerPorts.next();
@BindToRegistry
public SequenceBeforeTest beforeSoap() {
@@ -47,6 +49,8 @@ public class SoapIT {
.variable("soap.front.port", String.valueOf(frontPort))
.variable("soap.soap12.port",
String.valueOf(soap12Port))
.variable("soap.wssec.port", String.valueOf(wssecPort))
+ .variable("soap.json.backend.port",
String.valueOf(jsonBackendPort))
+ .variable("soap.json.front.port",
String.valueOf(jsonFrontPort))
).build();
}
diff --git a/tests/camel-kamelets-itest/src/test/resources/soap/orders.wsdl
b/tests/camel-kamelets-itest/src/test/resources/soap/orders.wsdl
index 5826635ea..3ebe6fc86 100644
--- a/tests/camel-kamelets-itest/src/test/resources/soap/orders.wsdl
+++ b/tests/camel-kamelets-itest/src/test/resources/soap/orders.wsdl
@@ -30,6 +30,7 @@
<xs:element name="sku" type="xs:string"/>
<xs:element name="quantity" type="xs:int"/>
<xs:element name="price" type="xs:decimal"/>
+ <xs:element name="gift" type="xs:boolean" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Order">
diff --git
a/tests/camel-kamelets-itest/src/test/resources/soap/soap-json-backend-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/soap/soap-json-backend-route.yaml
new file mode 100644
index 000000000..ca6ae0f16
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/soap/soap-json-backend-route.yaml
@@ -0,0 +1,49 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+# The service of orders.wsdl, served by soap-source with JSON for the route
+- route:
+ id: "json-backend"
+ from:
+ uri: "kamelet:soap-source"
+ parameters:
+ address: "http://0.0.0.0:{{soap.json.backend.port}}/orders"
+ wsdlURL: "classpath:orders.wsdl"
+ bodyFormat: "json"
+ steps:
+ - log: "JSON backend ${header.CamelCxfOperationName}: ${body}"
+ - setVariable:
+ name: "orderId"
+ jq: ".orderId"
+ - choice:
+ when:
+ # the declared fault of getOrder: its detail is XML text also in
JSON mode
+ - simple: "${variable.orderId} == '404'"
+ steps:
+ - setHeader:
+ name: "SoapFault"
+ constant: "Order 404 not found"
+ - setHeader:
+ name: "SoapFaultCode"
+ constant: "Client"
+ - setBody:
+ constant: '<orderNotFound
xmlns="http://example.com/orders"><orderId>404</orderId></orderNotFound>'
+ otherwise:
+ steps:
+ # the fields in another order than the schema, which the XML
gets; one item, typed values
+ - setBody:
+ simple: '{"order": {"status": "SHIPPED", "item": [{"gift":
true, "price": 9.95, "quantity": 2, "sku": "A-1"}], "customer": "ACME",
"orderId": "${variable.orderId}"}}'
diff --git
a/tests/camel-kamelets-itest/src/test/resources/soap/soap-json-front-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/soap/soap-json-front-route.yaml
new file mode 100644
index 000000000..3c1f525ec
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/soap/soap-json-front-route.yaml
@@ -0,0 +1,73 @@
+# ---------------------------------------------------------------------------
+# 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 SOAP front with JSON in the middle: soap-source and soap-action with
bodyFormat json
+- route:
+ id: "json-front"
+ from:
+ uri: "kamelet:soap-source"
+ parameters:
+ address: "http://0.0.0.0:{{soap.json.front.port}}/orders"
+ wsdlURL: "classpath:orders.wsdl"
+ bodyFormat: "json"
+ steps:
+ - log: "JSON front request: ${body}"
+ - to:
+ uri: "kamelet:soap-action"
+ parameters:
+ address: "http://localhost:{{soap.json.backend.port}}/orders"
+ wsdlURL: "classpath:orders.wsdl"
+ operation: "getOrder"
+ bodyFormat: "json"
+ faultAsBody: true
+ - log: "JSON front got SoapFault=${header.SoapFault}: ${body}"
+# A request with a field that the schema does not have: refused, or left out
with ignoreUnknownFields
+- route:
+ from:
+ uri: "timer:unknown"
+ parameters:
+ repeatCount: 1
+ delay: 3000
+ steps:
+ - setBody:
+ constant: '{"orderId": "9", "color": "red"}'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:soap-action"
+ parameters:
+ address:
"http://localhost:{{soap.json.backend.port}}/orders"
+ wsdlURL: "classpath:orders.wsdl"
+ operation: "getOrder"
+ bodyFormat: "json"
+ - log: "Unknown field accepted: ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Unknown field refused: ${exception.class.name}:
${exception.message}"
+ - setBody:
+ constant: '{"orderId": "10", "color": "red"}'
+ - to:
+ uri: "kamelet:soap-action"
+ parameters:
+ address: "http://localhost:{{soap.json.backend.port}}/orders"
+ wsdlURL: "classpath:orders.wsdl"
+ operation: "getOrder"
+ bodyFormat: "json"
+ ignoreUnknownFields: true
+ - log: "Unknown field ignored: ${body}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/soap/soap-json.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/soap/soap-json.citrus.it.yaml
new file mode 100644
index 000000000..a082b09cc
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/soap/soap-json.citrus.it.yaml
@@ -0,0 +1,114 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+
+name: soap-json-test
+description: 'soap-source and soap-action with bodyFormat json: a SOAP front
that works with typed JSON and calls a SOAP service whose route works with JSON
too; an element that repeats is an array with one item; a field the schema does
not have is refused or left out; a fault keeps its XML detail'
+actions:
+ - camel:
+ cli:
+ run:
+ resources:
+ - "orders.wsdl"
+ integration:
+ file: "soap/soap-json-backend-route.yaml"
+ systemProperties:
+ properties:
+ - name: "soap.json.backend.port"
+ value: "${soap.json.backend.port}"
+ - camel:
+ cli:
+ run:
+ resources:
+ - "orders.wsdl"
+ integration:
+ file: "soap/soap-json-front-route.yaml"
+ systemProperties:
+ properties:
+ - name: "soap.json.backend.port"
+ value: "${soap.json.backend.port}"
+ - name: "soap.json.front.port"
+ value: "${soap.json.front.port}"
+
+ # getOrder through the front: the client sends and gets SOAP XML, with the
elements in the order and the
+ # namespace of the schema, whatever the order of the JSON fields of the
backend
+ - http:
+ client: "http://localhost:${soap.json.front.port}"
+ sendRequest:
+ POST:
+ path: "/orders"
+ contentType: "text/xml"
+ body:
+ data: '<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><o:getOrder
xmlns:o="http://example.com/orders"><o:orderId>7</o:orderId></o:getOrder></soap:Body></soap:Envelope>'
+ - http:
+ client: "http://localhost:${soap.json.front.port}"
+ receiveResponse:
+ response:
+ status: 200
+ type: "plaintext"
+ body:
+ data: '<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><tns:getOrderResponse
xmlns:tns="http://example.com/orders"><tns:order><tns:orderId>7</tns:orderId><tns:customer>ACME</tns:customer><tns:status>SHIPPED</tns:status><tns:item><tns:sku>A-1</tns:sku><tns:quantity>2</tns:quantity><tns:price>9.95</tns:price><tns:gift>true</tns:gift></tns:item></tns:order></tns:getOrderResponse></soap:Body></soap:Envelope>'
+ # The routes in the middle had JSON: the request, and the response with
typed values and an array of one item
+ - camel:
+ cli:
+ verify:
+ integration: "soap-json-front-route"
+ logMessage: 'JSON front request: {"orderId":"7"}'
+ - camel:
+ cli:
+ verify:
+ integration: "soap-json-backend-route"
+ logMessage: 'JSON backend getOrder: {"orderId":"7"}'
+ - camel:
+ cli:
+ verify:
+ integration: "soap-json-front-route"
+ logMessage: 'JSON front got SoapFault=:
{"order":{"orderId":"7","customer":"ACME","status":"SHIPPED","item":[{"sku":"A-1","quantity":2,"price":9.95,"gift":true}]}}'
+
+ # A field that the schema does not have
+ - camel:
+ cli:
+ verify:
+ integration: "soap-json-front-route"
+ logMessage: "Unknown field refused: "
+ - camel:
+ cli:
+ verify:
+ integration: "soap-json-front-route"
+ logMessage: 'Unknown field ignored: {"order":{"orderId":"10",'
+
+ # The declared fault, passed on by the front with its XML detail
+ - http:
+ client: "http://localhost:${soap.json.front.port}"
+ sendRequest:
+ POST:
+ path: "/orders"
+ contentType: "text/xml"
+ body:
+ data: '<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><o:getOrder
xmlns:o="http://example.com/orders"><o:orderId>404</o:orderId></o:getOrder></soap:Body></soap:Envelope>'
+ - http:
+ client: "http://localhost:${soap.json.front.port}"
+ receiveResponse:
+ response:
+ status: 500
+ type: "plaintext"
+ body:
+ data:
'@contains(''<faultcode>soap:Client</faultcode><faultstring>Order 404 not
found</faultstring><detail><orderNotFound
xmlns="http://example.com/orders"><orderId>404</orderId></orderNotFound></detail>'')@'
+ - camel:
+ cli:
+ verify:
+ integration: "soap-json-front-route"
+ logMessage: 'JSON front got SoapFault=Order 404 not found:
<orderNotFound
xmlns="http://example.com/orders"><orderId>404</orderId></orderNotFound>'