search cancel

How to use Java custom step in a Virtual Service Model to return custom values in the response

book

Article ID: 134859

calendar_today

Updated On:

Products

Service Virtualization

Issue/Introduction

Need to customize the virtual service response. Have developed a small java function that would return some values which should be used in the response.

How to use java custom step in a Virtual Service Model to use custom values in the response?

Environment

All supported DevTest releases.

Cause

N/A

Resolution

A customization can be added in different ways to the VSI response or to the VSM. In this case we modified the VSM. 

A Scripted Assertion was added in the HTTP Listener step and the custom Java code was added to this assertion. 

 

We needed to add the following line to the code:

testExec.setStateValue("dynamicDates", temp); 

 

More information regarding the testExec Class, refer to section "The Test Exec Class" in the documentation of the DevTest release you are running.

 

With this line the values from temp, generate with the custom code, were saved to the dynamicDates.

In the VSI response, we replaced the list of dates with the property {{dynamicDates}}.

After saving the virtual service image, the service model was redeployed and a new request confirmed the response had the expected values.

Additional Information

For more information about Scripted Assertions, refer to section "Scripted Assertion" in the documentation of the DevTest release you are running.