Topic
7 replies Latest Post - ‏2012-09-12T06:18:17Z by devdp
devdp
devdp
37 Posts
ACCEPTED ANSWER

Pinned topic How to convert JSON to soap in XI52?

‏2012-09-11T08:41:20Z |
Hi,

Is there any action available in DP that is used to convert JSON message to soap message?

dev.
Updated on 2012-09-12T06:18:17Z at 2012-09-12T06:18:17Z by devdp
  • devdp
    devdp
    37 Posts
    ACCEPTED ANSWER

    Re: How to convert JSON to soap in XI52?

    ‏2012-09-11T09:58:24Z  in response to devdp
    I am trying to convert json message using "Convert Query Params to XMl" with default encoding as JSON.But I am getting error in the DP logs stating that "Invalid JSON format".
    I am using below JSON message to test "{"user":{"first_name":"firstname","email":"email@email.com"}}".
    Could anyone please help me why am I getting this error.

    dev
    • Liv2luv
      Liv2luv
      573 Posts
      ACCEPTED ANSWER

      Re: How to convert JSON to soap in XI52?

      ‏2012-09-11T13:10:16Z  in response to devdp
      This article explains JSON to SOAP conversion: http://www.ibm.com/developerworks/websphere/library/techarticles/0912_muschett/0912_muschett.html
      • devdp
        devdp
        37 Posts
        ACCEPTED ANSWER

        Re: How to convert JSON to soap in XI52?

        ‏2012-09-12T03:44:07Z  in response to Liv2luv
        Hi,

        I tried using the same steps as in the link but still getting error Invalid JSON format.

        dev.
    • HermannSW
      HermannSW
      4242 Posts
      ACCEPTED ANSWER

      Re: How to convert JSON to soap in XI52?

      ‏2012-09-11T13:20:37Z  in response to devdp
      Did you set request type to "JSON" as well?

      For me your request works and I did the steps you described:
      $ curl --data-binary @json.sample http://dp3-l3:2089 -s | tidy -q -xml
      <?xml version="1.0" encoding="utf-8"?>
      <json:object xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd">
       
        <json:object name="user">
          <json:string name="first_name">firstname</json:string>
          <json:string name="email">email@email.com</json:string>
        </json:object>
      </json:object>
       
      $ cat json.sample 
      {"user":{"first_name":"firstname","email":"email@email.com"}}
      $
      


       
      Hermann <myXsltBlog/> <myXsltTweets/>
      Updated on 2014-03-25T02:49:29Z at 2014-03-25T02:49:29Z by iron-man
      • devdp
        devdp
        37 Posts
        ACCEPTED ANSWER

        Re: How to convert JSON to soap in XI52?

        ‏2012-09-12T03:41:33Z  in response to HermannSW
        HiHerman,

        Thank you for the reply....

        I am using Request type as Non-XML(loopback XML Firewall).
        1) I tried to post the request using your curl command... "curl --data-binary @json.sample http://DPIP:port -s | tidy -q -xml"
        But I am getting error as below
        "'tidy' is not recognized as an internal or external command,
        operable program or batch file."

        2) I tried removing this | tidy -q -xml in the curl command "curl --data-binary @json.sample http://DPIP:port -s
        "Warning: Couldn't read data from file "json.sample", this makes an empty POST."

        3) I tried "curl --data-binary '{"user":{"first_name":"firstname","email":"email@email.com"}}' http://dpaau182dev01.dev.anz:2054 -s"
        In DP logs I am seeing "xmlfirewall (Test_XFW): request Test_XFW_request #1 convert-http: 'Converting INPUT with map Json2JsonX results stored in dpvar_1' failed: Invalid JSON format".

        dev
        • devdp
          devdp
          37 Posts
          ACCEPTED ANSWER

          Re: How to convert JSON to soap in XI52?

          ‏2012-09-12T04:08:12Z  in response to devdp
          Hi,

          It is working if I am using the curl command as below (escaped the double quotes)
          curl --data-binary {\"user\":{\"first_name\":\"firstname\",\"email\":\"email@email.com\"}} http://DPIP:port -S

          But if I use the below curl command I am getting the "Warning: Couldn't read data from file "json.sample", this makes an empty POST."
          "curl --data-binary @json.sample http://DPIP:port"

          dev.
          • devdp
            devdp
            37 Posts
            ACCEPTED ANSWER

            Re: How to convert JSON to soap in XI52?

            ‏2012-09-12T06:18:17Z  in response to devdp
            Hi,

            It is working now I forgot to give the file name with .txt
            curl --data-binary @json.sample.txt http://DPIP:port -S

            dev