Load CSV data file

Look up by row and column

To load the data in the response use {{csvDataFile 'row,col'}} in the response definition.

For example,
{{csvDataFile '2,4'}} will read file trafficparrot-release-x.y.z/data/data.csv
then load the 2nd row in the file and then lookup the 4th column value.

Select data using condition

For more advanced CSV data loading, you can put your CSV file with any name in the trafficparrot-release-x.y.z/data directory.

To select data from a CSV use {{select 'a from x.csv where b equals' value}} in the response definition.

For example,
{{select 'title from jobs.csv where name equals' 'example' }}
will read the file trafficparrot-release-x.y.z/data/titles.csv
then load the value of the column title where the value of the column name
is equal to the value example.

The value parameter passed to the {{select}} can be a dynamic value that
is taken from the request e.g. xPath or jsonPath.

Generate random values

To generate a random value in the response use one of the following:

{{randomInteger}} - A random integer, e.g. 1543243211

{{randomInteger min max}} - A random integer between the given min and max, e.g. 10

Handlebars helpers

Transform strings

{{defaultIfEmpty value ["default value"]}}} - Render a default value if the specified value is not available, for example {{defaultIfEmpty request.query.username "Username parameter was not present in the request"}}

Variables

The standard {{#with}}defined in the handlebars specification is available.
As an example the following use of {{#with}} in a response body allows reuse of the same variable multiple times in the block:

Conditionals (if, else)

Standard Handlebars block helpers

All block helpers defined in handlebars specification are available.
As an example the following use of {{#if}} in a response body will render a different response based on availability of a request paramater:

Copy
target/trafficparrot-sdk-workspace-x.y.z.jarto directory trafficparrot-enterprise-release-x.y.z/lib/virtualservice-x.y.z to use with HTTP
or to directory trafficparrot-enterprise-release-x.y.z/lib/external to use with JMS

If the name of the class you have created is RandomInteger
the extension you will use in response templates
will be called {{randomInteger}} by default.
The name can be changed by implementing the TrafficParrotHelper.getName method.

Edit an existing mapping and put {{randomInteger}} anywhere in the response body.

Make a request to the virtual service

The response you receive should contain the randomly generated integer.

Custom HTTP response transformers

Traffic Parrot allows for creating custom HTTP response transformers.
They allow for altering any part of the HTTP response in any way you like,
and have access to the request data.

If you would like to add a new HTTP response transformer, have a look at the following example:

Explore the project and the Java classes available in the SDK.
They provide example usages of HTTP response transformers.
Look for usages of HttpResponseTransformer and
HttpResponseDefinitionTransformer.
Have a look at both main and test classes.

Create a new extension class based on the examples provided in the
SDK (by extending HttpResponseTransformer class). For example:

Explore the project and the Java classes available in the SDK.
They provide example usages of JMS response transformers.
Look for usages of JmsResponseTransformer and
TextJmsResponseTransformer.
Have a look at both main and test classes.

Create a new extension class based on the examples provided in the
SDK (by extending TextJmsResponseTransformer class). For example: