Original Message:
Sent: Thu May 11, 2023 01:00 AM
From: Vyasavardhan Ramagiri
Subject: Handling JSON/XML Body inside SOAP Payload.
Hi @Steve Linn ,
Good Morning,
My question is like from the input soap field "DomainName" is not a static one. It will be changed for another requests and in the response based on this field we should generate the original response.
Now i need a change like code should be generic for all the requests.
If in input a field like "CCCCC" is came then in my output is should be like CCCCCResponse and in this element CCCCCResult should be generated through that code.
And if Input has "DDDDDD" then in my output is should be like DDDDDResponse and in this element DDDDDResult should be generated through that code.
what is the possible way to achieve this?
Hope you understood now.
Thanks and regards,
------------------------------
Vyasavardhan Ramagiri
Original Message:
Sent: Wed May 10, 2023 04:59 PM
From: Steve Linn
Subject: Handling JSON/XML Body inside SOAP Payload.
Hi Vyasavardhan,
I'm not exactly sure what you're asking. Are you saying that you need to post the JSON from the following XML that has an additional element between the SOAP root body element and the input element? So for
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soapenv:Header/> <soapenv:Body> <tem:DomainName> <tem:inputDetails> { "CustomerName":"", "Gender":"", "DateOfBirth":"", "Address":"", "PanNo":"", "AadhaarNo":"01ad09eb-5dee-425c-9207-1a0013a21bbb", "VoterID":"", "DrivingLicense":"", "MegaCard":"", "Passport":"", "MobileNumber":"" } </tem:inputDetails> </tem:DomainName></soapenv:Body></soapenv:Envelope>
Your XPath to get the JSON payload would be <xsl:variable name="inputDetails" select="/soapenv:Envelope/soapenv:Body/tem:DomainName/tem:inputDetails" />
and if your SOAP response is different from above, you would simply use the urlopen results as before to get the JSON response and and output the SOAP response from your stylesheet as your requirements dictate. Perhaps I'm not understanding the question?
Best Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Wed May 10, 2023 10:15 AM
From: Vyasavardhan Ramagiri
Subject: Handling JSON/XML Body inside SOAP Payload.
Hi @Steve Linn ,
came with another issue.
Please go with the attachment attached below.
Thanks in Advance!!
------------------------------
Vyasavardhan Ramagiri
Original Message:
Sent: Wed May 03, 2023 09:12 AM
From: Steve Linn
Subject: Handling JSON/XML Body inside SOAP Payload.
Hi Vyasavardhan,
1. Access to the soap root body element: Within the xslt, you would simply Xpath into the SOAP document, ie,
<xsl:variable name="inputDetails" select="/soapenv:Envelope/soapenv:Body/inputDetails" />
ensure that you have property specified on your xsl:stylesheet the soapenv namespace, ie
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
This also assumes that your soap root body element is inputDetails. Since you're asking for a generic stylesheet, you could specify a * to get any child element of soapenv:Body
and unless your stylesheet is outputting a soap document, you should also include soapenv in your exclude-result-prefixes attribute.
2. Pass that value to a backend: In xslt that would be using the dp:url-open extension function. See https://www.ibm.com/docs/en/datapower-gateway/10.0.1?topic=elements-dpurl-open. One thing of note is that if your data that you'd be posting is JSON, then you'll be getting a non XML (ie, JSON) response, so you should specify for the response attribute a value of responsecode-binary. Note the documentation will show you that the response will looking like the following:
<result> <binary>***BINARY NODE***</binary> <responsecode>200</responsecode> <reasonphrase>OK</reasonphrase> <httpversion>...</httpversion> <headers> ... </headers></result>
so you should wrap the dp:url-open with a xsl:variable, then you can xpath into that variable with $varName/result/binaryNode to get the value. So what to do with a binaryNode? See https://www.ibm.com/docs/en/datapower-gateway/10.0.1?topic=functions-dpbinarynodetostring for the dp:binaryNodeToString extension function to convert this binary node to a string. If you need to do anything to look within the JSON, you could also use the dp:binaryNodeToJSONx extension function to created an XML equivalent of the JSON that you can use xpath to extract specific values if that is desired.
3. how to pass the json response again in a soap message. You can easily output from your xsl a soap document where you would simply output the value of your JSON string, ie
<xsl:variable name="jsonString" select="dp:binaryNodeToString($urlopen-result/result/binary)" /><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/> <soapenv:Body> <responseDetails> <xsl:value-of select="$jsonString"/> </responseDetails> </soapenv:Body></soapenv:Envelope>
Regards,
Steve Linn
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Tue May 02, 2023 01:30 AM
From: Vyasavardhan Ramagiri
Subject: Handling JSON/XML Body inside SOAP Payload.
Hi @Steve Linn and All,
Iam trying to access the data inside soap:Body in Soap Payload, it may have XML or JSON inside the soap:Body. how to make a generic xslt for handling both xml and json inside the soap:Body and i want to pass the json inside soap:body to backend and i will get a json response,how to pass the json response again in the soap:body.Sample SOAP:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<inputDetails>
{
"CustomerName":"",
"Gender":"",
"DateOfBirth":"",
"Address":"",
"MobileNumber":"1234567678990"
}
</inputDetails>
</soapenv:Body>
</soapenv:Envelope>
Help me in achieving this.
Thanks in Advance!!!
------------------------------
Vyasavardhan Ramagiri
------------------------------