Service Virtualization

Expand all | Collapse all

Based on argument value select response from different-different transactions having same operation

Jump to Best Answer
  • 1.  Based on argument value select response from different-different transactions having same operation

    Posted 10-01-2018 05:42 AM

    Hi All,

     

    I am working on requirement where the three stateless transactions having same operation name and based on one arguments key (like ID ) value match in every request response should be selected from VSI.

     

    For example.

     

    If ID = 3,  select transaction first (Transaction  id : 20) response .

    If ID = 4,  select transaction (Transaction  id : 30)  second response.

    If ID = 5,  select transaction (Transaction  id : 40)  third response.

     

     

    Note: Signature of the request hitting to VSI will be different once ID value matched corresponding response should be send. Data protocol is XML.

     

    Your inputs would be very much appreciated.

     

    Thanks in advance.



  • 2.  Re: Based on argument value select response from different-different transactions having same operation

    Posted 10-01-2018 05:54 AM

    Hi,

     

    During creation of virtual services:

     

       

    •   add a Request Data Manager DPH (data protocol handler), position it after the XML DPH

       

    •   Add the rule “ ’Keep’ + ‘Argument’ + ‘ID’ “

     

    Now for each incoming transaction, whatever the real runtime signature is, the signature used for matching will be:

     

       

    •   Operation name

       

    •   + 1 argument: ID

     

    You can now add exact matches:

     

       

    •   If ID = 3,  first response (Transaction  id : 20).

       

    •   If ID = 4,  second response (Transaction  id : 30)  .

       

    •   If ID = 5,  third response (Transaction  id : 40)  .

    Cheers,

    Danny



  • 3.  Re: Based on argument value select response from different-different transactions having same operation

    Posted 10-01-2018 10:05 AM

    Hi Danny,

     

    Thanks for the response.

    I tried with the same approach and getting specific response for exact match configured for ID = 3 but if request contains the ID = 4 its executing the meta response configured for ID=3.

    Added match script in every transaction to discard the particular transaction if "ID" didn't match, move the request to the new transaction but I am getting the same meta response. 

     

    Thanks in advance.



  • 4.  Re: Based on argument value select response from different-different transactions having same operation

    Posted 10-01-2018 10:36 AM

    We are not talking about exactly the same approach, I can see this from your response: “… its executing the meta response configured for ID=3 …”

    So it seems that you have different transactions for different ID values, I believe you have something like this:

     

    Can you confirm?

     

    I was talking about this:

     

     

    Is there a reason why my suggestion cannot be used?

     

    Due to the matching algorithm, in your VSI the second transaction “MyOperation”+”ID=4” will never be reached, because the first transaction has exactly the same signature, as soon as the matchine algorithm encounters a matching signature then it decides I will provide an response from this transaction, if there is no exact match within this transaction, then I will respond with the META from this transaction. As far as I understand exactly what you are experiencing.

     

    Cheers,

    Danny



  • 5.  Re: Based on argument value select response from different-different transactions having same operation
    Best Answer

    Posted 10-01-2018 10:51 AM

    By the way, if it is absolutely needed to have multiple transactions then you can make the signatures unique by changing the request operation name and including the ID value in there:

     

       

    •   Add a Request Data Copier to the listen step (after the Request Data Manager with the Keep-action)

       

    •   Copy the arguments to request_<arg_name>

     

     

     

       

    •   Add a Scriptable DPH to the listen step (as the last filter)

       

    •   Put in something like this (top of my head, not verified if it actually works)

     

    %beanshell%

    // Assumption: the operation with the special requirment is called "MyOperation"

    // Assumption: the argument that makes the signature unique is called "ID"

     

    import com.itko.util.ParameterList;

     

    String operation = lisa_vse_request.getOperation();

    if (operation.equals("MyOperation"))

    {

        String valueID = testExec.getStateValue("request_ID");

        lisa_vse_request.setOperation(operation + "_ID_" + valueID);

    }

     

     

       

    •   In your VSI change the operation names to “MyOperation_ID_3” and MyOperation_ID_4”

     

     

     

     

     

    Cheers,

    Danny