Service Virtualization

 View Only
  • 1.  HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property

    Posted Mar 30, 2018 10:31 AM

    Is it possible to  set HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property, in the VSI?.  When I try I get the following error.  I updated the local.properties file to accept nonstandard http return codes but it is still not working.  It only works if I set to a hardcoded value like, 403, 200 etc.  Is it reading this value as a string instead of a number?

     

    java.lang.RuntimeException: The response object is not formed properly.  It is missing the response code meta data entry or it is invalid: code=403
    ============================================================================
    | Step:        Virtual HTTPS Responder
    ----------------------------------------------------------------------------
    | Message:     The response object is not formed properly.  It is missing the response code meta data entry or it is invalid: code=403
    ----------------------------------------------------------------------------
    | Trapped Exception: The response object is not formed properly.  It is missing the response code meta data entry or it is invalid: code=403
    | Trapped Message:   java.lang.RuntimeException: The response object is not formed properly.  It is missing the response code meta data entry or it is invalid: code=403
    ----------------------------------------------------------------------------
    STACK TRACE
    java.lang.RuntimeException: The response object is not formed properly.  It is missing the response code meta data entry or it is invalid: code=403
     at com.itko.lisa.vse.stateful.protocol.http.HttpRespondStep.setResponseInfo(HttpRespondStep.java:314)
     at com.itko.lisa.vse.stateful.protocol.http.HttpRespondStep.setupResponseInfoHeaderAndContent(HttpRespondStep.java:174)
     at com.itko.lisa.vse.stateful.protocol.http.HttpRespondStep.respond(HttpRespondStep.java:125)
     at com.itko.lisa.vse.stateful.BaseRespondStep.execute(BaseRespondStep.java:231)
     at com.itko.lisa.test.TestNode.executeNode(TestNode.java:981)
     at com.itko.lisa.test.TestCase.execute(TestCase.java:1294)
     at com.itko.lisa.test.TestCase.execute(TestCase.java:1198)
     at com.itko.lisa.test.TestCase.executeNextNode(TestCase.java:1183)
     at com.itko.lisa.test.TestCase.executeTest(TestCase.java:1124)
     at com.itko.lisa.coordinator.Instance.run(Instance.java:204)
    ============================================================================



  • 2.  Re: HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property

    Posted Mar 30, 2018 02:03 PM

    Hi Tamika, can you attach a sample picture of the VSI's Response Meta Data?

     

    Response Meta Data is stored internally as a ParameterList object, and this object expects key/value pairs.

    In an HTTP service, the key side of the Meta Data must contain a key for "HTTP-Response-Code". I believe the Responder Step has code that specifically checks the ParameterList to ensure it contains this key. The Value side of the pair could be a magic string value such as {{specialResponseCd}}. If the property is not on the incoming request, '=request_' would be omitted unless you had this prefix in the property name. And, best practice would be to ensure that this property is set somewhere in the service before the Responder Step.

    You can also set the value specifically in certain responses and leave others as a 200, OK.

     

    Why did you feel it necessary to update the local.properties file? So, long as you are referring to lisa.vse.http.response.allowNonStandardResponseCode=true, that is fine. If you are adding service-specific values, use the project.config instead.



  • 3.  Re: HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property

    Posted Mar 30, 2018 02:31 PM

    I set the property in the data filter on the incoming http request step.  It extracts the value properly it just doesn't seem to be able to use as a string.  Not sure.

     

    VSI metadata

     



  • 4.  Re: HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property
    Best Answer

    Posted Apr 02, 2018 09:41 AM

    Hum, I wonder if the parseInState that replaces the HTTP Return Code happens after the check of the HTTP-Response-Code for a valid value in the processing logic.  Just a hunch....

     

    As a simple test, try adding a Scriptable Assertion in the VS Image Selection step.

    Run the VSM in ITR mode and send a request.

    When the SI Selection step executes, CLICK on the Events tab and look for a log display produced by the Scriptable.

    - Set your Scriptable Assertion to Fail the Test if the Return is False - a typo below will cause a failure.

    import com.itko.util.ParameterList;

    // get response meta data

    ParameterList pl = lisa_vse_response.get(0).getMetaData();

    // see if response code is found and print out some values

    if ( pl.containsKey("HTTP-Response-Code") ) {

        _logger.info("Response Meta contains an HTTP response code");

        _logger.info("Response Code Value before parseInState is: {}", pl.get("HTTP-Response-Code") );

        _logger.info("Response after parse in state is is: {}",

                      testExec.parseInState( pl.get("HTTP-Response-Code") );

    } else {

        _logger.info("HTTP-Response-Code was NOT FOUND in the VSI response Meta Data");

    }

    return true; // prevent failure if possible

    The assertion only validates that the key is found and that data is in the field. We are simply trying to peek into what might be sent. The assertion does not set any values into the Response Code field.

    It may be that you have to fire parseInState and manually set the actual parsed value into HTTP-Response-Code prior to the Responder step to return the desired response code. 



  • 5.  Re: HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property

    Broadcom Employee
    Posted May 18, 2018 05:26 PM

    As mentioned , In the VSI  , the  Meta Data must contain a key for "HTTP-Response-Code".. The Value side of the pair would be a magic string value  {{=request_string_local_name_returnCode_}},  Also 

     

    Add a Scriptable Assertion in the VS Image Selection step.

     

    We have validated this code and it worked

     

    import com.itko.util.ParameterList;

    ParameterList pl = lisa_vse_response.get(0).getMetaData();
    pl.setAllowDupes( false );
    //HTTP-Response-Code={{=request_string.....}}&key2=value2&
    pl.addParameters( testExec.parseInState( pl.toString() ) );
    lisa_vse_response.get(0).setMetaData( pl );


    return true;

     

    The assertion only validates that the key is found and that data is in the field.   This worked.