Service Virtualization

Expand all | Collapse all

Need suggestion to handle different response body and metadata in one transaction itself.

  • 1.  Need suggestion to handle different response body and metadata in one transaction itself.

    Posted Nov 19, 2015 02:24 PM

    Hi ,

     

    I Need a suggest to handle this scenario..

     

    I have developed rest based virtual services(not completely all API calls) which are integrated into front end mobile app..

     

    The scenario here is I have a transaction(signature in LISA) which calls two times in the whole mobile app journey (example : -- login - do some checks - logout)

     

    So this transaction has only one request element but it expects different response header value and response body each time..

     

    first time when it calls it needs some response and http code as 200 .

     

    When it calls second time it needs some other response and http code as 201.

     

    I can't have these two in two separate scenario because app sends same input value both the time.

     

    any suggest will be helpful.



  • 2.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Posted Nov 19, 2015 07:17 PM

    Hi ,

     

    You can select the check box in VSI below operation name : Allow duplicate specific transactions

    Specifies whether to allow DevTest to respond more than once to the same call, choosing a different response.

     

    Transactions Tab for Stateless Transactions - DevTest Solutions - 8.5 - CA Technologies Documentation

     



  • 3.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Posted Nov 20, 2015 06:55 AM

    Thanks Tausif..

     

    But this is not the exact way I am looking for .. because this will dispatch different responses one after the other for the same call at the same time.

     

    What I am looking is when first time request matches it has to respond only first message in that, when second time same request matches it has to respond the second message from the response..



  • 4.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Broadcom Employee
    Posted Nov 20, 2015 07:22 AM

    I believe the behaviour you want is specifically what the "Allow Duplicate Specific Transactions" checkbox is for. It round-robins through each response, sending only one response per request, i.e.: "when first time request matches it has to respond only first message in that, when second time same request matches it has to respond the second message from the response..".

     

    If you use the checkbox during your recording process, you will even see each of the response messages, along with their 200 & 201 response codes (in metadata), and response-1 will be returned the first time a request is made to the virtual service, and response-2 will be returned the second time.

     

    I haven't used it recently, but this is how it was developed for me. It came from instances I had where NTLM negotiation & authentication is a multi-step process, where the client makes a request and the server has to respond with a 401.2 code. The client has to resend the message with authentication details in the header and the server has to respond with a different 401.2 code. the client has to resend the message with negotiation details in the header and the server has to (finally) respond with the business response. Only one response is sent for each time the same request is received, cycling through each of the possible responses in the specific order in which those responses are stored.

     

    Rick



  • 5.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Posted Nov 23, 2015 02:54 PM

    Thanks Rick..

     

    I did this approach and tested from lisa test which directly hits the url which I deployed and worked fine..

     

    every alternative call it respond first response, and second time second response..

     

    whereas when I integrated this virtual service with my client application (in my case it is mobile app) this logic is not working.. it is always getting the first response..

     

    please suggest what might be the wrong here



  • 6.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Broadcom Employee
    Posted Nov 23, 2015 04:41 PM

    Are you sure you're hitting the same response when using your app as you are when using your test? Check whether EXACT or SIGNATURE matches are being made (you can check this in the DevTest Console, selecting your virtual service and looking at the responses).



  • 7.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Posted Nov 23, 2015 06:59 PM

    yes, matches to transaction is happening properly.. I am using Exact match here as I use argument in this operation which has value as well..

     

    I can see devtest console all the time it is matching the operation and proper transaction but response is only whatever stored in first response section.. second response is never returned back to client.



  • 8.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Broadcom Employee
    Posted Nov 23, 2015 08:48 PM

    hmm ... as an excessively techie response, I suppose you could create a script between the Response Selection step and the Respond step, which would get / set a sharedModelMap value (toggle responseNo between 0 and 1), and then get the specific response you want from the responseList. Something like (not syntax checked):

    -----

    import com.itko.lisa.vse.stateful.model.TransientResponse;

    String responseNo = com.itko.lisa.vse.SharedModelMap.get("responseNo", "responseNo");

    if(responseNo == null) responseNo = "0";

    responseList = testExec.getStateObject("lisa.vse.response");

    TransientResponse response = responseList.get(Integer.parseInt(responseNo));

    responseList.get(0).setBody(response.getBodyText());

    if(responseNo.equals("0")) com.itko.lisa.vse.SharedModelMap.put("responseNo", "responseNo", "1");

    else com.itko.lisa.vse.SharedModelMap.put("responseNo", "responseNo", "0");

    -----

    However, more interesting to me is what difference there must be between the request coming from your test and the request coming from your app. I think debug logs or even wireshark on your VSE server might give hints as to what's causing a reset of the response number.



  • 9.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Broadcom Employee
    Posted Nov 23, 2015 09:00 PM

    gah! I forgot to set lisa.vse.response property to the new responseList, which is done like this:

    testExec.setStateValue("lisa.vse.response", responseList);



  • 10.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Posted Nov 27, 2015 02:44 AM

    Another solution may be to use a stateful conversation, just for the login operation, but it would required to identify one argument in order to set the session, you can use the user login itself in order to have separate session for each login.

    The benefit of the conversation will be that you can see both login operation one after another in different blocks, showing exactly the workflow you described earlier.



  • 11.  Re: Need suggestion to handle different response body and metadata in one transaction itself.

    Broadcom Employee
    Posted Nov 27, 2015 03:43 AM

    DevTestUser,

     

    What about embedding a magic string in the meta response updating a property that automatically increments the counter?  I am thinking along the lines of the following:

     

         {{logonRespCount=logonRespCount+1}}

     

    You establish logonRespCount in the project file with an initial value of whatever you want and every time access the login function the value of logonRespCount goes up one.

     

    Ralph Godwin