1

Scenario : My service calls another rest service multiple times based on a count. I am using event sink action in datapower.

I am able to trigger the other service multiple times, and it responded back. But I'm not able to capture the response (JSON) in the following XSL Multiple context variables have been created:

var://context/URLOUTPUT_1,  var://context/URLOUTPUT_2/ 

How do I extract the JSON response from context variable. The service I am calling is a rest service with JSON request and response

How can I extract JSON response for each call after event-sink? Where does the response JSON body get stored?

devlin carnate
  • 8,309
  • 7
  • 48
  • 82

3 Answers3

0

I am not sure I follow to 100% but how are you doing the triggering to the other service?

First of all if you are on FW 7+ then consider using GatewayScript (GWS ~Node.js)!

If you are using the Result action you should get the Response (Server to client) rule executed for each request.

Else you'd need to set it into a "loop" by calling a template for each request (trigger) and then in the url-open() you'd get the response for each request.

If you'd be using GWS it would be the same but in JavaScript instead, create a loop, call url-open for each event and grab the response for each call.

Anders
  • 3,198
  • 1
  • 20
  • 43
  • I am calling using result action, call is asynchronous. So when i keep multiple output as NO. i am able to see the content in context inside probe(last triggered response) . But when i keep multiple output as YES. I cant seen the content in probe, But two(based on of request) context variables are defined. Basically I am looking for any xsl which can extract the response(JSON) from these created context variable. – faris backer Apr 28 '16 at 05:09
  • OK, so since this is asynchronous it will actually become separate transactions and thus not fetched in the probe. Do you have to use the Result action or can you run all requests from a XSLT Transform Action instead? – Anders Apr 28 '16 at 12:55
  • I will try the other two ways. I have another kind of same issue while trying to extract output after DPA(XML to cpy) action.Output is in binary format. How can we extract the binary content and use in following xsl. Normally we decode binary using below code . But it thrown error stating binary encode not possible. – faris backer Apr 28 '16 at 15:07
  • If you use the url-open() the response will be in: $binaryResponse//result/binary/node() – Anders Apr 28 '16 at 15:44
0

Try this in response before Template match.

_ var://context/

Now do for each for the service variable which you created .

do response transformation in for each , how you like.

0

You can access the context contents as if it were a context variable.

Try something like this:

<xsl:variable name="json-result">
    <xsl:copy-of select="dp:decode(
        dp:binary-encode(
        dp:variable('var://context/URLOUTPUT_1')/node()), 'base-64')"/>
</xsl:variable>
bjimba
  • 928
  • 8
  • 13