Extracting the request and response from a created VSI
search cancel

Extracting the request and response from a created VSI

book

Article ID: 72945

calendar_today

Updated On:

Products

CA Application Test CA Continuous Application Insight (PathFinder) Service Virtualization

Issue/Introduction

Have a need to extract req/response information that was acquired from recording/learning web service traffic from a transaction during playback.

How to capture Virtual Service Request and Response?

Environment

All supported DevTest releases.

Cause

N/A

Resolution

The raw traffic file should contain the raw requests and responses from the time virtual service was created. 

When recording a VS using DevTest Portal, the raw traffic is created under the $LISA_HOME/vseRecording/VSE_2013/<randomName>/Project/Data/ folder.  

When creating a VS from request and response pairs using Portal, the raw traffic file is created under $LISA_HOME/<ProjectName>/Data/ folder. 

In the Workstation, select the option to export the raw traffic file when creating the VS. 

After the VS is created there is no out of the box feature that "exports" the request and response used to create that virtual service.

Open the VSI with a text editor and then able to see all the requests and responses or can also capture them after the VS is created by download the MAR file from VSE and open the VSI.

Then capture the Request from the Transaction-->Request Data-->Attributes tab-->recorded_raw_request. This one will give the recoded request. Response can be captured from Transaction-->Response-->Body. 

If wanting to save the requests and responses during playback, then customize the VSM to capture Request and Response into properties and then store both into a file using "Save Property Value to a File" filter.

Here is how to do this. 
- Request: HTTP Requests hitting VSE is available in a property lisa.vse.http.current.transaction.body and this can be stored in a file using "Save Property Value to a File" filter. 
- Response: VSE response is available in lisa.vse.response (if it is from VSI) or lisa.vse.live.response (if it is from LIVE) and it is in Transient form. To see the response body, convert that using some code.

Support recommends to add "Scripted Assertions" in VS Image Response Selection step and VS LIVE Invocation step and shared the below code snippets to capture the response to a property. 

VS Image Response Selection step: 
--------------------------------------------------------------- 
import com.itko.lisa.vse.stateful.model.TransientResponse; 
import com.itko.lisa.vse.stateful.model.Response; 
import java.util.List; 

List responseList = testExec.getStateObject("lisa.vse.response"); 
TransientResponse response = responseList.get(0); 
String respText = testExec.parseInState(response.getBodyText()); 
testExec.setStateValue("responseBodyText", respText);  
return true; 

VS LIVE Invocation step: 
--------------------------------------- 
import com.itko.lisa.vse.stateful.model.TransientResponse; 
import com.itko.lisa.vse.stateful.model.Response; 
import java.util.List; 

List responseList = testExec.getStateObject("lisa.vse.live.response"); 
TransientResponse response = responseList.get(0); 
String respText = testExec.parseInState(response.getBodyText()); 
testExec.setStateValue("responseBodyText", respText);  
return true; 

With the above code, the response is captured in the "responseBodyText" property and this can be stored in the file using "Save Property Value to a File" filter.  Use the same file which you used to capture Request and select "Append" option.

Additional Information

Refer to section "Save Property Value to File" in the documentation of the DevTest release you are running.