Sorry, I was typing of the top of my head in the xslt example. The example should read:
Original Message:
Sent: Mon January 15, 2024 09:32 AM
From: Akani Chabalala
Subject: How to do service orchestration/request chaining
Hi Joseph
I managed to complete the task using the result action method, it's super cool.
however I have a context variable called fname (it contains the name of the data being stored to the sftp, and this changes all the time hence i have it as a context variable), I was wondering if i can save the content with this context variable. e.g
destination: IP:port/A/B/C/fname.anthing . is it possible to access that context variable and use it on the result action, if not possible any suggestions will make a positive impact.
thank you
------------------------------
Akani Chabalala
Original Message:
Sent: Thu November 30, 2023 09:54 AM
From: Joseph Morgan
Subject: How to do service orchestration/request chaining
According to the documentation, GWS urlOpen only supports HTTP, HTTPS and MQ. There might be a 3rd party JS that can do it, but I don't have a suggestion.
In the Results action, yes, you just put the SFTP server and path as you've indicated.
In the User Agent SFTP policy setting, you simply type a URL pattern. If you only have one endpoint SFTP server, you can do something as simple as "sftp*", but if you have multiple, then a more fully qualified URL pattern may be required.
------------------------------
Joseph Morgan
Original Message:
Sent: Thu November 30, 2023 09:13 AM
From: Akani Chabalala
Subject: How to do service orchestration/request chaining
To answer your question: yes
noted, I just want to confirm something here.
Lets say I use results action, this means that i will be targeting the server lile:
sftp://(which is already choosen), e.g
destination: IP:port/A/B/C/mydata.anthing. is that right
THEN: same story to the ssh: sftp://ip:port/*
option 2 for a stylsheet, I get it but the idea here was to stick to js only, so cant i do it using a gatewayscript?
well for this options I will use one as testing, and the other as a solution.
Thank you.
------------------------------
Akani Chabalala
Original Message:
Sent: Wed November 29, 2023 01:14 PM
From: Joseph Morgan
Subject: How to do service orchestration/request chaining
OK. Help me get some clarity on where you are. The context variable storing the response from MPG2, this is a context following what I imagine to be a GatewayScript action contained within a processing policy?
If I'm correct, the you can use a "Results" action without having to write any code. That is, let's say your context variable (the one coming out of the GWS Action) is named "mpg2_response". Add a "Results" action. The input to that action should be "mpg2_response". Drop down the first selection box beside "Destination", and select "sftp://". Fill out the destination to the SFTP server.
At this point, you will need to save the action, and then the policy and close that window.
Then follow the link to the XML manager associated with the service.
From there, follow the link to the User Agent associated with the XML Manager.
Within the User Agent, locate the "SFTP Client Policies" tab (Old UI) or the "SFTP client policy" tab (New UI).
Add a new SFTP client policy ensuring the URL matching expression matches that of the URL configured within the results action. You will also need, if you haven't already, to configure an SSH Client Profile to manage the security of the connection.
Save the User Agent and then you can test.
If, however, you'd rather write code, you'll have to create a transform action using the "mpg2_response" as your input. The transform will then require you to develop XSLT to use the url-open extension function to write to the SFTP server. You can see an example here. However, with this approach, you will still need to configure an SSH Client and configure the SFTP Client Policy within the correct user agent.
------------------------------
Joseph Morgan
Original Message:
Sent: Wed November 29, 2023 02:56 AM
From: Akani Chabalala
Subject: How to do service orchestration/request chaining
Hi Joseph,
this info was useful.
It gave me a good starting point, i managed to do this, however I am struggling to save the response (from mpg2) to sftp server, I also want to do it inside the datapower, not with postman and I want to use the gatewayscript.
NB. I already have a context variable that store this response (from mpg2)
------------------------------
Akani Chabalala
Original Message:
Sent: Fri November 17, 2023 09:21 AM
From: Joseph Morgan
Subject: How to do service orchestration/request chaining
Yes, you can do it that way. However, to get the "response" from the gateway script to show up in the context, you need to get rid of the "callMPG2" function and do something like this:
function processMPG1Response(error, responseJSON) { if (error) { // In this example, the response wasn't JSON } else { // Instead of calling MPG2 from here, just write to the output context. session.output.write(JSON.stringify(responseJSON)); // Again, writing off the top of my head. I'm not 100% the stringify is required }}
At this point, your gatewayscript action output context should go to MPG1's back end (which I suspect is MPG2???).
In MPG2, you'll do it all over again...with the output context of the gatewayscript action being sent to the back end, which is MPG3???
Just as a note: Why don't you just do three gateway scripts in a row on the processing policy of MPG1? Or, consider three rules in MPG1. It seems "messy" to me to have MPGs being used basically as functions here.
------------------------------
Joseph Morgan
Original Message:
Sent: Fri November 17, 2023 04:17 AM
From: Akani Chabalala
Subject: How to do service orchestration/request chaining
Thank you Joseph.
And yes the content-type is Json
one more thing:
for this to work as expected I should add a (gateway Action) gatewayscript on my server to client rule for mpg1 to foward the response to mpg2, (gateway Action) gatewayscript on my server to client rule for mpg2 to foward the response to mpg3 and (gateway Action) gatewayscript on my server to client rule for mpg3 to save the response to sftp?
------------------------------
Akani Chabalala
Original Message:
Sent: Thu November 16, 2023 04:43 PM
From: Joseph Morgan
Subject: How to do service orchestration/request chaining
Gatewaysript has an object to call a back end. You need to start with:
var urlOpen = require('urlopen');
Then, you'll have a number of places where you're calling the various endpoints, something like:
// Disclaimer: Typed this right off the top of my head. Please forgive errorsfunction callMPG1() { var options = { target: mpg1URL, // the URL to the MPG method: 'post', // or 'get' timeout: 20, // whatever sslClientProfile: 'TheNameOfAnSSLClientProfileObject', headers: 'whatever headers you need', data: 'any POST data if that is the method of the request' }; urlOpen.open(options, handleMPG1Response);}function handleMPG1Response(error, response) { if (error) { // do whatever you need to do for the error to MPG1 } else { var statusCode = response.statusCode; // if you need it, because a 401 or 403 isn't likely an error if (statusCode == 200) { // Just an example now, because your data may not be JSON response.readAsJSON(processMPG2Response); } }}function processMPG1Response(error, responseJSON) { if (error) { // In this example, the response wasn't JSON } else { callMPG2(responseJSON); }}function callMPG2(dataForMPG2) { var options = { target: mpg2URL, // the URL to the MPG method: 'post', // or 'get' timeout: 20, // whatever sslClientProfile: 'TheNameOfAnSSLClientProfileObject', headers: 'whatever headers you need', data: dataForMPG2 }; // This data may have to be converted to something else in your case urlOpen.open(options, handleMPG2Response);}// ... and so on. Note, this is verbose and removes a complication of many, many closures, but// should give you a general idea.
------------------------------
Joseph Morgan
Original Message:
Sent: Thu November 16, 2023 02:48 AM
From: Akani Chabalala
Subject: How to do service orchestration/request chaining
Hi all
I have 3 Multiprotocol gateways in the DataPower.
mpg1, I send a request username@password, then I receive a response "encrypted username@password"
mpg2, I send "encrypted username@password" from mpg1 and receive a token as a response.
mpg3, I send a token from mpg2 then i receive a certificate.
All these works, how ever I want to automate this whole process I want to forward the response of mpg1 to mpg2 then the response of mpg2 to mpg3. I want to send one request to mpg1 then receive a certificate and that certificate must be stored in sftp server.I tried to do request chaining in postman (outside of the Datapower), I managed to send one request to mpg1 then receive a certificate (response) and I managed to save it to the sftp server.
now I want to do this inside the Datapower using a gatewayscript if possible:
I tried using a gatewayscript to store the message body in context variable as a start I couldn't get it right.
Please share any links, to help me resolve this.
thank you.
------------------------------
Akani Chabalala
------------------------------