How to extract request and response from a created VSI

Document ID : KB000072945
Last Modified Date : 29/03/2018
Show Technical Document Details
Introduction:
Have a need to extract req/response information that was acquired from recording/learning web service traffic from a transaction during playback.
Question:
How to capture Virtual Service Request and Response?
Environment:
DevTest supported versions.
Answer:
The raw traffic file should contain the raw requests and responses from the time virtual service was created. 

When you record a VS using DevTest Portal, the raw traffic is created under the $LISA_HOME/vseRecording/VSE_2013/<randomName>/Project/Data/ folder.  
using
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, you have to 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. You can open the VSI with a text editor and you will be able to see all the requests and responses or you 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 you the recoded request. Response can be captured from Transaction-->Response-->Body. 

If you would like to save the requests and responses during playback, then you can 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 you can 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, you need to convert that using some code. Support recommended 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. You can use the same file which you used to capture Request and select "Append" option.
Additional Information:
Documentation on this is available at https://docops.ca.com/devtest-solutions/9-5/en/reference/filter-descriptions/utility-filters/save-property-value-to-file.