VSI HTTP-Response-Code as property {{=request_string_local_name_returnCode_}}

Document ID : KB000097262
Last Modified Date : 21/05/2018
Show Technical Document Details
Introduction:
Is it possible to  set HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property, in the VSI?.   It only works if I set to a hard-coded value like, 403, 200 etc.  I am trying to set HTTP response code to a variable extracted from HTTP Request header.

When  using the property I get the following error. 

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=404
============================================================================
| 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=404
----------------------------------------------------------------------------
| Trapped Exception: The response object is not formed properly. It is missing the response code meta data entry or it is invalid: code=404
| 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=404
----------------------------------------------------------------------------
Background:
Setting HTTP-Response-Code in the Response to a value extracted from HTTP Request header like 403 or 502
Environment:
All supported DevTest Environments
Instructions:

Step to follow:
****************
1. Using the Request Data Manager DPH, extract the header value from the MetaData. 



2. In the VSI, Set this property value as the HTTP-Response Code  in the Response META Data. 

VSI metadata

HTTP-Response-Code  has a value  {{=request_string_local_name_returnCode_}}. 

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 {{=request_string_local_name_returnCode_}}. 

3. Add a Scriptable Assertion in the VS Image Selection step to parse this return code. 

The code sets the actual parsed value into HTTP-Response-Code prior to the Responder step to return the desired response code. 

    ------------------------------------------------------------
    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 validates that the key is found and that data is in the field. 

    This should return the desired code  as  HTTP Response code.  

     

    Additional Information:
    https://communities.ca.com/thread/241794956-http-response-code-to-requeststringlocalnamereturncode-a-property