Service Virtualization

 View Only
  • 1.  Dynamic HTTP-Response-Code & HTTP-Response-Code-Text to update

    Posted Jul 10, 2018 05:46 PM
      |   view attached

    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.

     

    Request:

    {"Id":"XXXX","morlevel":"abc","vid":"0.3"}

     

    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

    Response.Status.BAD_REQUEST. 

    Please find screenshot for the same. Really appreciate your help!!



  • 2.  Re: Dynamic HTTP-Response-Code & HTTP-Response-Code-Text to update

    Broadcom Employee
    Posted Jul 11, 2018 12:32 AM

    Hi,

     

    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?

     

    Thank you,



  • 3.  Re: Dynamic HTTP-Response-Code & HTTP-Response-Code-Text to update

    Posted Jul 11, 2018 02:35 PM

    I'm using DevTest 10.1 version. I tried to create new virtual service



  • 4.  Re: Dynamic HTTP-Response-Code & HTTP-Response-Code-Text to update
    Best Answer

    Posted Jul 11, 2018 09:47 AM

    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.



  • 5.  Re: Dynamic HTTP-Response-Code & HTTP-Response-Code-Text to update

    Broadcom Employee
    Posted Jul 11, 2018 09:47 AM

    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.



  • 6.  Re: Dynamic HTTP-Response-Code & HTTP-Response-Code-Text to update

    Posted Jul 11, 2018 02:33 PM

    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.

     

    Thanks again!!