DataPower

 View Only
Expand all | Collapse all

How to do service orchestration/request chaining

  • 1.  How to do service orchestration/request chaining

    Posted Thu November 16, 2023 04:00 PM

    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
    ------------------------------


  • 2.  RE: How to do service orchestration/request chaining

    IBM Champion
    Posted Thu November 16, 2023 04:43 PM

    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 errors
    
    function 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
    ------------------------------



  • 3.  RE: How to do service orchestration/request chaining

    Posted Fri November 17, 2023 04:18 AM

    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
    ------------------------------