How to set custom response to lisa.vse.response
search cancel

How to set custom response to lisa.vse.response

book

Article ID: 136979

calendar_today

Updated On:

Products

CA Application Test Service Virtualization

Issue/Introduction

Sometime,  need to add Authorization header to the VSE request which goes to LIVE system using LIVE invocation Step in VSM but could not add header to LIVE invocation step directly. 

Environment

All supported DevTest releases.

 

Cause

Cannot modify the headers in VSE request when going to the LIVE system.

Resolution

Need to Use Web Service Execution XML step or REST step instead of the LIVE Invocation step in VSM and follow the below steps:

After adding the step, execute it and make sure getting the valid response and Store the step response into a property. For example, "Live-Response",  going to use this in the code.

Then add a "Scripted Assertion to the Web Service Execution XML step or REST step and set the logic "if False to Fail" as script going to return true in the code and assertion will never fail.

Note: Need to make the response as Transient object and then set to lisa.vse.response then only HTTP Responder can respond back.

Add the below code in Scripted Assertion:

----------------
import com.itko.lisa.vse.stateful.model.TransientResponse;
import com.itko.lisa.vse.stateful.model.Response;
import com.itko.util.ParameterList;

Response response1 = new Response();
response1.setBody(testExec.getStateObject("Live-Response").toString());
ParameterList metadata = response1.getMetaData();
metadata.setParameterValue("HTTP-Response-Code","200");
TransientResponse transRsp = response1.createTransientCopy();
testExec.setStateObject("lisa.vse.response", transRsp);
return true;

---------------

 

In the above code just added the response meta data with only the "HTTP-Response-Code". If needed more response headers can be added.

Additional Information

Add Authorization Header to Live Invocation