Service Virtualization

Expand all | Collapse all

Sending multiple responses to single request

Jump to Best Answer

Girija Kotturu02-07-2018 07:16 AM

  • 1.  Sending multiple responses to single request

    Posted 02-07-2018 07:09 AM

    Hi All,

     

    I have a requirement where i wanted to send multiple responses to a single request.

    For example I have request holdings_request1 and responses holdings_response1, transactions_response1. When i send holdings_request ill have to get holdings_response1 and immediately transactions_response1.

     

    I added the transactions_response in VSI using add a new response to the transactions option available in VSI response tab.

    But still when i hit request am getting only top response. i.e response 1 of 2.

     

    Could you please help me what needs to be fixed.

     

    Thanks in advance!

     

    Regards,

    Girija K



  • 2.  Re: Sending multiple responses to single request

    Posted 02-07-2018 07:16 AM

    VSI that i have created



  • 3.  Re: Sending multiple responses to single request

    Posted 02-07-2018 10:58 AM

    Hello Girija,

     

    What is the transport protocol? With HTTP/S you cannot have one request two responses. The client system sends the request, receives the response and does not expect a second response.

    Is this second response a request that needs to be sent to a different endpoint?

     

    Take a look at this thread as well: https://communities.ca.com/thread/241731433#241804623 

     

    Hope it helps,

    Heloisa



  • 4.  Re: Sending multiple responses to single request

    Posted 02-07-2018 11:17 AM

    Hi Maria,

     

    Yeah its a Http protocol and need to send to same port.

    I have gone through the thread that you provided and followed the same, but i got only top response.

     

    Regards,

    Girija K.



  • 5.  Re: Sending multiple responses to single request

    Posted 02-07-2018 11:14 AM

    Hi,

         As @Maria Heloisa Flores said With HTTP/S you cannot have one request two responses.But if some time delay is acceptable to them it can be done.

                                                                 Thanks,

    Vish



  • 6.  Re: Sending multiple responses to single request

    Posted 02-07-2018 11:16 AM

    Hi LearnNow,

     

    Thats fine if its some time delay.

    Could you please help me in this case.

    Yes its Http transport protocol.

     

    Regards,

    Girija K.



  • 7.  Re: Sending multiple responses to single request

    Posted 02-07-2018 11:50 AM

    Hi,

         Assuming that you have response endpoint.The first response message will be in the image and the second response message can be dropped to the response endpoint via SOAP web service step.

                                                    Thanks,

    Vish



  • 8.  Re: Sending multiple responses to single request

    Posted 02-07-2018 12:12 PM

    Hi,

     

    I dont have response endpoint.

    I have only response XMLs. How can we send via SOAP step without endpoint, as i dont have seperate endpoint from where second response comes.

    I tried to create VIrtual service using RR pair recording.

     

    Could you please elaborate. 

     

    Thanks 

    Girija K.



  • 9.  Re: Sending multiple responses to single request

    Posted 02-08-2018 07:10 PM

    Is the consumer app using HTTP 2.0 or web sockets. 

    DevTest supports HTTP 1.1 which uses a specification of 1 request and 1 response. As Maria said there is no workaround unless the second response can be sent as an HTTP request to an endpoint -- which you don't have in this app.



  • 10.  Re: Sending multiple responses to single request

    Posted 02-12-2018 08:12 AM



  • 11.  Re: Sending multiple responses to single request

    Posted 02-12-2018 08:24 AM

    Thank you for the screen shots.

    In your model, we can see multiple VSI selection steps (Summary & Holdings), REST calls, database table look-ups and Responder step.  We even see the VSM branching to End the Test after one of the steps. I would suggest that tracking and learning modes can be completely removed from this model as they are probably useless.

     

    Given the complexity of this model, it is doubtful that we can help without investing additional time to understand all of the requirements. The VSM can make REST calls to a callback endpoint, it can access databases, and it can have multiple VSI selection steps so long as the model can keep this straight; however, there is no technique for sending multiple responses, via the OOTB HTTP Responder Step, to the consumer thread that sent the request. To do this, you will need a transport TPH that can hold the HTTP socket open long enough to send multiple responses.



  • 12.  Re: Sending multiple responses to single request

    Posted 02-13-2018 03:05 AM

    Hi Joel,

     

    Yes as u said I have number of steps in the VSM.

    1.  Actually in my below snippet1 Am verifying the request is summary or holding. If its summary it will  check the db and update db and goes to Summary VSI, and responds back. If its holding request, then it will fetch the db and goes to holding VSI.

     

    2. The requirement is after sending the Holdings response I have to send ongoing_transactions response as well. In ongoing_transactions again I have four response XMLs , but no request. So what I did is I created a Virtual service with holdings request and those ongoing transactions response XMLs.

    3. Going back to point No.1 , after Holdings VSI selection I placed a rest step and sent lisa.vse.request as request parameter.(bcoz the incoming request is the request for ongoing_transactions VSM). and gave the Ongoing_transactions VSM endpoint.(Snippet2)

    4. But finally there also I have to send the ongoing transactions response as request to one REST URL. So I added REST Step in ongoing_transactions VSM.

    But still am not able to post the response to the REST URL.(snippet3)

     

    I hope my explanation gives an idea about my VS.

     

    Could you please suggest me how to send the response as request to REST service and is it right approach that I followed.?Required Any changes in the VSM flow.?

     

     

    Thank you

     

    Regards,

    Girija K.



  • 13.  Re: Sending multiple responses to single request

    Posted 02-13-2018 02:08 PM

    Are the additional responses sent immediately or is there usually a delay between them?



  • 14.  Re: Sending multiple responses to single request
    Best Answer

    Posted 02-13-2018 11:24 PM

    Using this requirement:

    2. The requirement is after sending the Holdings response I have to send ongoing_transactions response as well. In ongoing_transactions again I have four response XMLs , but no request. So what I did is I created a Virtual service with holdings request and those ongoing transactions response XMLs.

     

    I believe the above means that a consumer application sends a Holdings Request. When this happens, you need to:

    • Send a holdings response first then
    • Send 4 Ongoing Transaction Responses
    • The Holdings VSI has 5 responses (Rsp 1 = holdings, Rsp 2 - 5 = the 4 Ongoing Txn Responses)

     

    If the above is true, what we are trying to communicate is: 

    - The VSM Listen Step receives a holdings request, 

    - At a minimum, the VSI Selection Step selects a holdings response but could select up to 5.

    - The VSM Responder Step sends holdings response only

    Under HTTP 1.1, the sending of the holdings response closes the socket between the consumer and virtual service. This is standard HTTP 1.0 & 1.1 behavior.

     

    So the issue is, the 4 Ongoing Transactions need to be sent after the Holdings transaction has been sent.

     

    The caveat is that the Ongoing transactions must be sent back to the consumer application using a REST or Webservice step (assuming everything is HTTP) where the endpoint of the REST or WS step is some endpoint on the Consumer application.  The point is that the Ongoing Transactions will not be sent on the HTTP connection (i.e., socket) that was used to send the Holdings request - because this socket is closed when the Respond Step for Holdings executes. This is OOTB behavior.

     

    After the Holdings VSI Selection step executes, the lisa_vse_response (object of type List), contains all 5 responses.  By design an HTTP Responder Step only sends the first occurrence from this list (e.g., lisa_vse_response.get(0) ).

     

    Your decision will be how to deal with response 2, 3, 4, & 5.  But, you cannot deal with these responses until you have dealt with the Holdings response.

     

    1) You might add an assertion in the Responder step that checks the size of the lisa_vse_response list.  If the List has a size greater than 1, then VSM branches to a series of steps that iterate over the List and send REST calls for each of the Ongoing Transaction request XMLs.  Perhaps a Sleep step is added to this loop to slow down the responses.  NOTE: Due to the complexity of the VSM model (it handles Summary, Holdings, Database I/O, etc.), it would be best to iterate over the list returned by the Holdings VSI Selection Step (e.g., lisa_vse_response.get( i ).setBody(testExec.parseInState( lisa_vse_response.get( i ).getBodyAsString() where "i" is an index in a for loop). This logic sets the body on each occurrence and should be performed before the Holdings Responder Step executes so you don't lose references to magic string data. 

     

     

    2) Given your example and the complexity of this VSM, I would consider delegating the job of sending the Ongoing Transactions to a second VSM. The Holdings VSM would place each of the Ongoing Transactions on the Shared Model Map or Persistent Model Map and the second VSM would contain the logic to send REST or WS Ongoing Transactions calls back to the consumer application. The issue is that each response placed on the Model Map a) needs to call testExec's parseInState() method before the transaction is placed on the map and b) the key to each Ongoing Transaction request needs to be unique so entries on the Model Map are not overlayed.  I would consider using a key of date/time/millis.  The key represents the "time" you want the second VSM to send the transaction. Perhaps, the Holdings VSM calculates this as current time plus "n" number of seconds.  The second VSM has no Listen Step, rather it just has a Marker Step. A loop step iterates the Model map and based on a comparison of current date/time/millis in the second VSM to the date/time key from the Map's keyset, the VSM sends the transaction to the consumer if the date/time/millis on the Map is less than the current date/time/millis. The second VSM removes the "sent" transaction from the map, makes the REST or WS call, looks to see if any more transactions need to be sent. If no transactions to send, the VSM sleeps for 10 seconds, wakes up and iterates the map again. The VSM does this every 10 seconds, 24 hours / day, 365 days / year. The majority of this option requires JSR script logic and Model Map processing. 



  • 15.  Re: Sending multiple responses to single request

    Posted 08-13-2018 09:55 AM

    Hi Joel,

     

    i am trying to implement similar solution.

    I have three responses in my specific transaction. First response (1 of 3) will be respond through Virtual HTTPS Responder, responses (2 of 3) and (3 of 3) will sent to application endpoint. 

    I am able to get the first response from the lisa.vse.response property. But 2 and 3 responses i am not ablet to get.

     

    Does lisa.vse.response hold all the three responses as objects ?

     

    Best Regards,

    Venkata Yedida 



  • 16.  Re: Sending multiple responses to single request

    Posted 08-13-2018 10:56 AM

    lisa_vse_response [or testExec.getStateObject("lisa.vse.response"); ] is an object of type List where each item in the List is of type TransientResponse.

    When multiple responses exist in the VSI, each of the transient responses is returned in the lisa_vse_response List. 

    The HTTP Responder step is designed to only send the first item [e.g., lisa_vse_response.get(0) ] whereas, the OOTB MOM-based steps have automatic behavior to deal with multiple responses -- a much more common practice in MOM-based architectures. 

    Before the HTTP Responder Step executes, the VSM should store off the other List items (i.e., items 2 thru 'n') into a different property. After the Responder step, the VSM needs to loop over the remaining items and send each remaining 'response' as a callback.

    Note: The reason for saving these items off into a separate property is that the HTTP Responder step destroys the lisa_vse_request and lisa_vse_response objects; therefore, a different property of type List needs to hold responses 2 thru 'n'. 

    Note: Since the request and response objects are destroyed, best practice would be to call testExec.parseInState( <response's body as string> ) in the logic that stores responses 2 thru 'n' in the new List object if the service has magic strings that need to be processed.