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

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

    Re: How to convert JSON to soap in XI52?

    ‏2012-09-11T09:58:24Z  
    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

    Re: How to convert JSON to soap in XI52?

    ‏2012-09-11T13:10:16Z  
    • devdp
    • ‏2012-09-11T09:58:24Z
    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
    This article explains JSON to SOAP conversion: http://www.ibm.com/developerworks/websphere/library/techarticles/0912_muschett/0912_muschett.html
  • HermannSW
    HermannSW
    4657 Posts

    Re: How to convert JSON to soap in XI52?

    ‏2012-09-11T13:20:37Z  
    • devdp
    • ‏2012-09-11T09:58:24Z
    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
    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

    Re: How to convert JSON to soap in XI52?

    ‏2012-09-12T03:41:33Z  
    • HermannSW
    • ‏2012-09-11T13:20:37Z
    Did you set request type to "JSON" as well?

    For me your request works and I did the steps you described:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">$ 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"}} $ </pre>

     
    Hermann <myXsltBlog/> <myXsltTweets/>
    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

    Re: How to convert JSON to soap in XI52?

    ‏2012-09-12T03:44:07Z  
    • Liv2luv
    • ‏2012-09-11T13:10:16Z
    Hi,

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

    dev.
  • devdp
    devdp
    37 Posts

    Re: How to convert JSON to soap in XI52?

    ‏2012-09-12T04:08:12Z  
    • devdp
    • ‏2012-09-12T03:41:33Z
    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
    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

    Re: How to convert JSON to soap in XI52?

    ‏2012-09-12T06:18:17Z  
    • devdp
    • ‏2012-09-12T04:08:12Z
    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.
    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