Topic
  • 2 replies
  • Latest Post - ‏2013-05-22T11:33:33Z by HermannSW
Baruch
Baruch
1 Post

Pinned topic How to handle json response when using url-open

‏2013-05-21T09:46:26Z |

Hi,

I have a requirement where in I have a to send getUser request to backend with a token. The response from backend is json data. Once the response reaches, I need to read the json response to check if it is success or failure due to token expiry. In case of token exppiry, I need to make another call to backend to first get the new User token(again backend returns json response) and then make the getUser call with new token.

If I use, set routing-url, I could allow the response to hit my response rule and able to convert the json to xml. But is it good practise to check the response in the response rule and call get Token call and getUser call from response rule ? 

I think, I need to use url-open to make getUser call. I did that and decoded to get the json string. Noiw how do I convert the json string into jsonX and then XML ? How do I pass the value of this json string into another action, that could convert the json into jsonX ?

Can someone please help

 

 

  • Rohit-Goyal
    Rohit-Goyal
    137 Posts

    Re: How to handle json response when using url-open

    ‏2013-05-21T10:50:25Z  

    I don't think you can call a "Convert Query" from XSL.

    I suggest to make a new service (xml firewall or mpg) with "skip-backside" on. This new service will accept a JSON and will return JSONX. Wherever you need JSONX, use url-open to call that internal DP (http://127.0.0.1:<port>) service and get JSONX in XSL.

    Rohit

  • HermannSW
    HermannSW
    4736 Posts

    Re: How to handle json response when using url-open

    ‏2013-05-22T11:33:33Z  

    I don't think you can call a "Convert Query" from XSL.

    I suggest to make a new service (xml firewall or mpg) with "skip-backside" on. This new service will accept a JSON and will return JSONX. Wherever you need JSONX, use url-open to call that internal DP (http://127.0.0.1:<port>) service and get JSONX in XSL.

    Rohit

    Rohit is right.

    There are two mechanisms to "parse" JSON input in DataPower:

    1. convert-http action
    2. "JSON" request type of a service


    Both are not directly accessible from within a stylesheet.

    For getting the result of JSON parsing inside the XSLT you have to do what Rohit porposes,
    just "call" another loopback service just doing the JSON parsing by <dp:url-open>.


    Hermann<myXsltBlog/> <myXsltTweets/> <myCE/>
     

    Updated on 2013-05-22T11:34:29Z at 2013-05-22T11:34:29Z by HermannSW