The Multiple Responses Generator is a powerful tool that allows you to easily handle hierarchical data scenarios, one-to-many asynchronous messaging, and more.
For a piece of XML (input
), the name of an XML element (elementName
), and the URL of a backend asset (backendURL
), the Multiple Responses Generator finds each occurrence of elementName
in input
and sends the occurrences separately to backendURL
. The backend asset is a virtual asset configured to respond to messages with elementName
as their root element and sends back responses to the Multiple Responses Generator. Once it has these responses, the Multiple Responses Generator aggregates them together into a single XML document for use in responses.
After performing this setup, you will be able to see the Multiple Responses Generator tool in the list of tools available to attach to a message responder.
The Multiple Responses Generator is controlled using two main sets of options. The options in the Required Configuration section are required for the Multiple Responses Generator to function while the options in the Optional Configuration section grant more granular control for advanced scenarios.
The following options must be configured in order for the Multiple Responses Generator to function.
Name of element to send to backend asset | The name of an XML element, including the namespace prefix, if applicable. Each occurrence of an element in the incoming XML that matches this name will be split and sent to the virtual asset specified in Backend Asset URL. In addition, the tool will create combinations of all list elements if there are multiple lists in the request. Exclude any other lists if you want to use a single list. |
---|---|
Backend Asset URL | The URL of a virtual asset. The virtual asset should have a responder that handles XML messages whose root element is the element defined in Name of element to send to backend asset. |
Elements excluded from splitting process | A comma-separated list of element names, including the namespace prefix, if applicable. By default, if the XML specified in the Name of element to send to backend asset option contains any sibling elements that share the same name (that is, a list), then the Multiple Responses Generator will create a separate request for each repetition of the sibling elements. |
---|---|
Response Type | If the virtual asset specified in Backend Asset URL returns XML, leave this field blank. If the virtual asset specified in Backend Asset URL returns a non-XML payload, enter Other . |
Output XML Root Tag Name | The name of the root tag for the Response XML output. The default is responses . |
Output XML | The name of the child elements of Output XML Root Tag Name. The default is response . |
SOAPAction List | For each SOAPAction specified in this comma-separated list, every occurrence of the element specified in Name of element to send to backend asset will be sent to Backend Asset URL with that SOAPAction. This is useful if each occurrence of the element requires multiple responses. |
The Multiple Responses Generator can be attached to any XML output of a Parasoft Virtualize message responder. This encompasses the Incoming Request > Payload for any XML-based responders or the Incoming Request > Payload Converted to XML for any non-XML based responders. The basic procedure for using the Multiple Responses Generator is described below. A more detailed description is provided in Example Scenarios.
While there are many scenarios that the Multiple Responses Generator can handle, this section provides examples for those used most frequently.
The most common scenario handled by the Multiple Responses Generator is messages that contain lists with a dynamic number of elements. For example:
<root> <items> <item> <name>Name1</name> <id>1</id> </item> <item> <name>Name2</name> <id>2</id> </item> |
This request can contain N sub-requests, where N >= 1. The response we will expect looks like this:
<root> <itemResponses> <itemResponse> <balance>10</balance> </itemResponse> <itemResponse> <balance>20</balance> </itemResponse> |
Using the process described in Usage, the following instructions will help you set up an asset with the above requests and responses.
Example1-Frontend
in the File Name field when prompted and click Next. Example1-Frontend.pva
and choose Add New > Responder. item
.http://localhost:9080/Example1-Backend
.itemResponses.
Create a backend asset to handle the messages that the Multiple Responses Generator will send. Be sure the backend asset is deployed at the URL specified in Backend Asset URL in the Multiple Responses Generator.
For simplicity, we will use a fixed response on the backend. However, the |
Example1-Backend
in the File Name field when prompted and click Next. Example1-Backend.pva
, right-click the Responder Suite and choose Add New > Responder. Enter the following XML:
<itemResponse> <balance>10</balance> </itemResponse> |
Example1-Frontend.pva
, right-click MultipleResponsesGenerator and choose Add output…/*
To use the aggregated responses in your response, double-click Literal Message Responder and enter the following into the text field:
<root> ${responses} </root> |
The following diagram describes the complete scenario: