Service Virtualization

  • 1.  How to set HTTP Response Code from a rest step !(Quick help please)

    Posted Apr 23, 2018 09:55 AM

    Hi All,

     

    Need a quick help in setting the response code form rest step to VSI file.

     

    Scenario : I need to pass the HTTP response code from REST step in VSM to the VSI file so that the response code finally reaches the listener.

     

    I tried to parse the code from the header of the response and set it to a property, and then i passed the same property on to VSI File from where the response code is picked.But this method is not working for some reason.

     

    Am getting the below which i posted.



  • 2.  Re: How to set HTTP Response Code from a rest step !(Quick help please)

    Posted Apr 23, 2018 03:08 PM

    Hi Joel,

     

    I have added below code snippet in the java script step and filtered out the step response and added it in VSI.

     

    import com.itko.util.ParameterList;

    ParameterList pl = lisa_vse_response.get(0).getMetaData();
    pl.setDupes(false);
    pl.addParameters("HTTP-Response-Code=" + testExec.getStateString("lisa.POST_LIVE.http.responseCode", "200") );
    Code = lisa.vse.response.get(0).setMetaData( pl );
    Return Code;

     

    But am getting below error when i run the service.

    Please correct me if i made a mistake somewhere!!

     



  • 3.  Re: How to set HTTP Response Code from a rest step !(Quick help please)
    Best Answer

    Posted Apr 23, 2018 04:27 PM

    Here's a screenshot of a sample VSM followed by some screenshots of the code. 

    The VSI in the VSI Selection step is a standard VSI. This particular VSI has no operations inside it. It only returns a Service Image Not Found response that contains an XML payload with an HTTP 404 response code.

    Right after the VS Image Selection step, the VSM issues a REST call to www.google.com which returns an HTML page.

    The highlighted assertion in this step moves the HTTP response code from the REST call to the HTTP Response Code.  The assertion also overlays the VSI's response with the response from the call in the "http GET" REST step.

       

    When running in ITR Mode, the http GET step, displays a property containing the HTTP response code used during the overlay.

    The step was named "http GET"; therefore, the property name that is holding the response code would be lisa.http GET.http.responseCode. This step name must be accurate. You will change this to the name of your step. (e.g., lisa.POST_LIVE.http.responseCode)

    The VSI's Service Image Not Found response contains an XML; however, it is overlayed with an HTML response from the REST call. In Postman, this response looks as follows:

    I did not bother changing the Content-Type to html in this example, but the script could have done that as well.

     

    Please ensure that the Java Script Step in your VSM is not destroying the lisa_vse_response list or the TransientResponse object that is in this list. If your Java Script Step adds or removes entries from the response list, you might cause your service to have other issues as the Responder Step is expecting send its response based on the content of the TransientResponse object.