HTTP-Response-Code to a property
search cancel

HTTP-Response-Code to a property

book

Article ID: 191717

calendar_today

Updated On:

Products

CA Cloud Test Mobile CA Application Test Service Virtualization

Issue/Introduction

We are trying to change the HTTP response code to a parameterized value, but it is getting error ed out in respond step.

Any other approach we have to consider here, Kindly advise.

Environment

Release : 10.6 and above

Component : CA Service Virtualization

Resolution

Please add below logic in javascript step and place this step before HTTP Responder step to update the response details:

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

List responseList = testExec.getStateObject("lisa.vse.response");
TransientResponse response = responseList.get(0);
ParameterList metaData = new ParameterList();
metaData.addParameter(new Parameter("HTTP-Response-Code","200"));
metaData.addParameter(new Parameter("HTTP-Response-Code-Text", "OK"));
metaData.addParameter(new Parameter("Content-Type", "application/json"));
response.setMetaData(metaData);
TransientResponse transientResponse = new TransientResponse(response);
testExec.setStateObject("lisa.vse.response", transientResponse);