I'm trying to implement a virtual service. Taking consideration of one field from request, Response Status has to be updated as Response.Status.BAD_REQUEST, Response.Status.FORBIDDEN, Response.Status.UNAUTHORIZED etc.
Here depends on vid value, Response status has to be updated.
If vid > 1 & vid <1.5, No response from service but Response status has to be updated as
Please find screenshot for the same. Really appreciate your help!!
What version of DevTest are you using? Do you try to modify the existing virtual services(vsm/vsi files) or try to create by a different way?
I'm using DevTest 10.1 version. I tried to create new virtual service
The following might be oversimplified. One approach is to use the VSI's Comparison Operator to send a response.
1) In the VSI, assign the 'vid' as a numeric
2) Allow META to respond with the HTTP 400 Bad Response
Body is empty
Meta Data has HTTP 400 Bad Response
3) Create two specific transactions.
In the first specific txn, the comparison is vid <1 (response for all VID values less than 1)
In the second specific txn, the comparison is vid >= 1.5 (response for VIDs greater than 1.5)
Running the test from Postman:
Your requirements are likely more complex than the scenario above demonstrates.
Other techniques range from examining the 'vid' attribute via a Scriptable Data Protocol filter and setting the response meta data values accordingly to using response-side DPHs to set the HTTP Response Code and HTTP Response Code text. These techniques are a bit difficult to describe in a thread such as this, but Prema's approach above is the most likely way forward.
You can write code in a Scripted assertion or in Scriptable DPH in VSM-->HTTP Listen step and set the response text to a property and use that property in the VSI Response-->Meta Data-->HTTP-Response-Code & HTTP-Response-Code-Text.
Appreciate your responses
I followed same as Joel's approach. Because of specific transactions i.e., vid value range. So I chosen regular expression as comparison operator for vid and provided value ranges [1-1]+\.[1-5]. Accordingly set HTTP Response Code and HTTP Response Code text. Now it is working as expected.