Reputation: 1
I am consuming a SOAP service on Mule 3.8.3 and have run into a scenario that I can't figure the solution out on my own. I have the following flow that looks straight forward.
SOAP request looks like :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:jcm="http://www.oracle.com/JCM">
<soapenv:Header/>
<soapenv:Body>
<jcm:GenericRequest webKey="cs">
<jcm:Service ServiceId="GET_FILE">
<jcm:Document>
<!--Zero or more repetitions:-->
<jcm:Field name="documentName">abcd.pdf</jcm:Field>
<jcm:Field name="documentID">156</jcm:Field>
</jcm:Document>
</jcm:Service>
</jcm:GenericRequest>
</soapenv:Body>
</soapenv:Envelope>
How do I correctly map input parameters (webKey,ServiceId, documentName & documentID ) from the payload in the Mule transform? Obviously the below attempt is incorrect so any help is appreciated.
%dw 1.0
%output application/xml
%namespace ns0 http://www.oracle.com/JCM
---
{
ns0#GenericRequest @(webKey: payload.WebKey): {
ns0#Service @(ServiceId: payload.IdcService): {
ns0#Document: {
ns0#Field @(name: payload.DocIDName): null
++ payload.DocID
ns0#Field @(name: payload.DocumentName): null
++ payload.DocName
}
}
}
}
Upvotes: 0
Views: 3557
Reputation: 1023
%dw 1.0
%output application/json
---
{
webKey: payload.Envelope.Body.GenericRequest.@webKey,
serviceId: payload.Envelope.Body.GenericRequest.Service.@ServiceId,
documents: payload.Envelope.Body.GenericRequest.Service.*Document map {
documentName: $[?($.@name == 'documentName')][0],
documentID: $[?($.@name == 'documentID')][0]
}
}
produces:
{
"webKey": "cs",
"serviceId": "GET_FILE",
"documents": [
{
"documentName": "abcd.pdf",
"documentID": "156"
},
{
"documentName": "efgh.pdf",
"documentID": "850"
}
]
}
%dw 1.0
%output application/xml
%namespace soapenv http://schemas.xmlsoap.org/soap/envelope/
%namespace jcm http://www.oracle.com/JCM
---
{
soapenv#Envelope: {
soapenv#Header: '',
soapenv#Body:
jcm#GenericRequest @(webkey: payload.webKey):
jcm#Service @(ServiceId: payload.serviceId):
{(payload.documents map (
jcm#Document: $ mapObject {
jcm#Field @(name: $$): $
}
))}
}
}
produces:
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<jcm:GenericRequest xmlns:jcm="http://www.oracle.com/JCM" webkey="cs">
<jcm:Service ServiceId="GET_FILE">
<jcm:Document>
<jcm:Field name="documentName">abcd.pdf</jcm:Field>
<jcm:Field name="documentID">156</jcm:Field>
</jcm:Document>
<jcm:Document>
<jcm:Field name="documentName">efgh.pdf</jcm:Field>
<jcm:Field name="documentID">850</jcm:Field>
</jcm:Document>
</jcm:Service>
</jcm:GenericRequest>
</soapenv:Body>
</soapenv:Envelope>
Upvotes: 2