Service Virtualization

  • 1.  Can we send response based on previous request call

    Posted Nov 15, 2018 05:50 PM

    Hi Team,

     

    Below is my requirement,can some one help with solution to handle virtual service

     

    1)  I will call 'A' API and send X response

    2)  Then I will call 'B' API or 'C' API

    3) Again I will call 'A' API but I need to send response X or Y based on my earlier call B or C.If my earlier call is 'B' i need to send X response if it is C i need to send Y response

     

    Is their any script or filter I need to use to complete this scenario?



  • 2.  Re: Can we send response based on previous request call
    Best Answer

    Posted Nov 15, 2018 10:59 PM

    You have a couple of options. One is to simply record your transactions as stateful conversation. However, I personally prefer to write some code to handle it. I typically put my code in the match script in the VSI. 

     

    You can can use the com.itko.lisa.vse.SharedModelMap which is a “global” hashmap where you can put and get values.

     

    You can use it in the following way:

     

    Add a match script to API B and C where they save a value to the hashmap to indicate that it was called.

    Also add a match script in API A to check the hashmap which API was previously called and return the desired response based on that condition. You may also need to clear the previous entry for API B or C. 



  • 3.  Re: Can we send response based on previous request call

    Posted Nov 20, 2018 02:32 PM

    Can you please tell me the steps to use hashmap,i am new to this concept



  • 4.  Re: Can we send response based on previous request call

    Posted Nov 20, 2018 04:41 PM
      |   view attached

    I'm attaching a sample project implementation on the requirement you posted. You can customize this baseline implementation to meet additional requirements if needed.

     

    The scripts using SharedModelMap is in the VSI match script. I have created three transactions in the VSI:

     

    API_A - Response X or Response Y

    API_B - Response X

    API_C - Response Y

     

    Each of them have a match script where we are caching the sessions so that we can look it up to see which response to return in a subsequent API call. API_A match script has the core of the script and reads in the response dynamically from a file. The file selection is based on the condition that API_B or C was called.

     

    Since I am dynamically reading in the contents of the response payload for API_A, I had to create a MAR Info file so that I can include these external response files when I deploy the virtual service.

     

    So when you test this sample project, be sure to deploy the virtual service by right clicking on the MAR Info file (.mari) and deploy the virtual service using this file

    Attachment(s)

    zip
    RespBasedOnPrevReq.zip   27 KB 1 version


  • 5.  Re: Can we send response based on previous request call

    Posted Dec 18, 2018 11:58 AM

    Hi,

     

    Can we have webex to validate my scenarios?Please let me know your free time 

     

    Thanks in Advance,

     

    Regards,

    Bala Subrahmanyam.T