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

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

book

Article ID: 97262

calendar_today

Updated On:

Products

CA Application Test CA Continuous Application Insight (PathFinder) Service Virtualization

Issue/Introduction

Is it possible to set HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property, in the VSI?.   

It only works if it is set to a hard-coded value like, 403, 200 etc. Trying to set HTTP response code to a variable extracted from HTTP Request header.

When using the property, getting 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
----------------------------------------------------------------------------

Setting HTTP-Response-Code in the Response to a value extracted from HTTP Request header like 403 or 502

Environment

All supported DevTest releases.

Cause

N/A

Resolution

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. 

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

HTTP-Response-Code to {{=request_string_local_name_returnCode_}} a property
 

Attachments

1558702570839000097262_sktwi1f5rjvs16kzc.png get_app
1558702569041000097262_sktwi1f5rjvs16kzb.png get_app
1558702567158000097262_sktwi1f5rjvs16kza.png get_app
1558702564992000097262_sktwi1f5rjvs16kz9.png get_app