Layer 7 API Management

Expand all | Collapse all

Convertion from JSON to SOAP XML

Jump to Best Answer
  • 1.  Convertion from JSON to SOAP XML

    Posted 6 days ago
    Hi all,

    we have a requirement that client will sent the below JSON Payload that we need to convert as a soap XML(as shown below) and sent it to the back-end can you please help me how to achieve this.

    Json payload:
     {
          "contactInquiryRequest":
          {
             "majorVersion": "3",
             "minorVersion": "3",
             "contactId": "ABC123ABC",
             "recordType": "ORG",
             "resultOptions":
             {
                "contactProfile":
                {
                   "name": null,
                   "address": null,
                   "telecommunication": null,
                   "email": null,
                   "socialMedia": null,
                   "alternativeIdentifiers": null,
                   "additionalInfo": null
                },
                "relationshipProfile": null
             }
          }
       }

    Sample Soap XML:
    <soapenv:Envelope xmlns:Soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://xmlns.xxxxs.com/customerContact">
       <soapenv:Header/>
       <soapenv:Body>
          <cus:contactInquiryRequest majorVersion="3" minorVersion="3">
             <!--You have a CHOICE of the next 2 items at this level-->
             <!--1 to 100 repetitions:-->
             <cus:contactId>ABC123ABC</cus:contactId>
             <cus:recordType>ORG</cus:recordType>
             <cus:resultOptions>
                <!--Optional:-->
                <cus:contactProfile>
                   <!--Optional:-->
                   <cus:name/>
                   <!--Optional:-->
                   <cus:address/>
                   <!--Optional:-->
                   <cus:telecommunication/>
                   <!--Optional:-->
                   <cus:email/>
                   <!--Optional:-->
                   <cus:SocialMedia/>
                   <!--Optional:-->
                   <cus:alternativeIdentifiers/>
                   <!--Optional:-->
                   <cus:additionalInfo/>
                </cus:contactProfile>
                <!--Optional:-->
                <cus:relationshipProfile/>
             </cus:resultOptions>
          </cus:contactInquiryRequest>
       </soapenv:Body>
    </soapenv:Envelope>

    ------------------------------
    Thanks,
    Jagan.
    ------------------------------


  • 2.  RE: Convertion from JSON to SOAP XML

    Posted 6 days ago
    Hi,

    The gateway has a Javascrip assertion with is pretty handy to handle JSON objects. I would try using guidance provided in the doc: https://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/layer7-api-management/api-gateway/9-4/policy-assertions/assertion-palette/service-availability-assertions/execute-javascript-assertion.html#concept.dita_cf8aa0494b68faea95e0835e981e96aaa1f35529_XMLSupport

    Best regards,
    Christian


  • 3.  RE: Convertion from JSON to SOAP XML

    Posted 4 days ago
    Hi Christian thanks for the reply,

    The above mentioned javascript assertion is available from 9.4 policy manager,
    but our client is using 9.2 
    can you please help me on this.



  • 4.  RE: Convertion from JSON to SOAP XML

    Posted 5 days ago
    Hi.

    Another option is to transform json to XML and use XLST to perform xml transformation as needed.

    ------------------------------
    Sr. Consultant Services
    HCL Enterprise Studio
    ------------------------------



  • 5.  RE: Convertion from JSON to SOAP XML

    Posted 4 days ago
    Hi Leandro,

    I'm new to APIM and not having a good knowledge on xslt files,
    can you please help me on this.

    thanks in advance


  • 6.  RE: Convertion from JSON to SOAP XML
    Best Answer

    Posted 4 days ago
    Edited by Christian Oberle yesterday
      |   view attached
    Hi Jagan,
    Here is a sample policy that should get you a good start. Create a policy (call it JsonToSoap and use jsontosoap as the resolution path) into the gateway and import this policy.
    You can call it (from postman) with one of the following: http://<gateway>:8080/jsontosoap?type=soap (or http://<gateway>:8080/jsontosoap?type=html).
    Line 3 of the policy is the JSON to XML transformation, line 9 the XSLT to obtain HTML and line 10 the XSLT to obtain SOAP. 

    As you are new to both the gateway and XSLT, I would suggest you get some training on the gateway and also use on-line XSLT transformation to get the XSLT file rignt before cutting/pasting into the policy (it is quicker). There is a good tool here: https://xslttest.appspot.com/

    There are also some good XSLT docs on-line (https://www.w3schools.com/xml/xsl_intro.asp, https://www.ics.uci.edu/~alspaugh/cls/shr/xslt.html, https://www.tutorialspoint.com/xslt/index.htm).

    Note that XSLT is a lot about "trial and error" so you can easily consume a lot of time getting it right ...

    Best regards,
    Christian

    Attachment(s)

    xml
    jsontosoap.xml   6K 1 version