The Multiple Responses Generator is a powerful tool that allows you to easily handle hierarchical data scenarios, one-to-many asynchronous messaging, and more.
In this section:
Overview
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.
Requirements
- Parasoft Virtualize
Installation
- Extract the Multiple Responses Generator JAR file from the archive downloaded from the Parasoft marketplace.
- Open Virtualize and choose Parasoft> Preferences> System Properties from the main menu.
- Click Add JARs… and browse to the Multiple Responses Generator JAR file
- Click OK and restart Virtualize.
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.
Configuration
The Multiple Responses Generator is controlled using two main sets of options. The options in the Required section are required for the Multiple Responses Generator to function while the options in the Optional section grant more granular control for advanced scenarios.
Required Configuration
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 Path | Specify the HTTP path on which the backend virtual asset is listening. If the full URL is specified, only the path segment will be used. 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 setting. |
Optional Configuration
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 (i.e., 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. Default is responses . |
Output XML | The name of the child elements of Output XML Root Tag Name. 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. |
Performance Configuration
Use thread pool | Enable this option (set to true ) to send concurrent requests to the backend virtual asset. Default is false . |
---|---|
Thread pool type | Specify the type of pool to use for threads that make concurrent requests to the backend virtual asset. Options are If the If the Default is |
Number of threads | Specify the maximum number of concurrent requests to the backend asset that can be executed at a given time. This option is applicable then the Thread pool type option is set to FIXED . Default is 100 . |
Usage
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.
- Create a front end asset with one or more responders.
- For each responder that needs the asset, attach a Multiple Responses Generator to either the Incoming Request> Payload output of the message responder (if the responder will handle XML Input) or Incoming Request> Payload Converted to XML output of the message responder (if the responder will handle non-XML input).
- Configure the Multiple Responses Generator with at least the Name of element to send to backend asset and Backend Asset URL.
- 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.
- Attach an XML Data Bank or Text Data Bank to the Response XML output of the Multiple Responses Generator and configure it to pull out the aggregated responses.
- Use the aggregated responses in your response.
Example Scenarios
While there are many scenarios that the Multiple Responses Generator can handle, this section provides examples for those used most frequently.
Handling Lists with a Dynamic Number of Elements
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.
- Create a frontend asset with one or more responders:
- Right-click the VirtualAssets project and choose Add New> Virtual Asset (.pva) File.
- Enter
Example1-Frontend
in the File Name field when prompted and click Next. - Choose Empty from the list of options on the next screen and click Finish.
- Right-click Responder Suite in the newly created Example1-Frontend.pva and choose Add New > Responder.
- In the window that appears, choose Literal Message Responder and click Finish
- For each responder that needs it, attach a Multiple Responses Generator to either the Incoming Request > Payload output of the message responder (if the responder will handle XML Input) or Incoming Request > Payload Converted to XML output of the message responder (if the responder will handle non-XML input.
- Right-click the Literal Message Responder and choose Add Output…
- In the window that appears, choose Payload in the Incoming Request section and choose Multiple Responses Generator under Common Tools.
- Click Finish.
- Configure the Multiple Responses Generator with at least the Name of element to send to backend asset and Backend Asset URL.
- In the Name of element to send to backend asset field, enter
item
. - In the Backend Asset URL field, enter
http://localhost:9080/Example1-Backend
. - In the Optional section, enter
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.pva in the archive downloaded from the Marketplace uses a dynamic response.
- In the Name of element to send to backend asset field, enter
- Right-click on the VirtualAssets project and choose Add New> Virtual Asset (.pva) File.
- Enter
Example1-Backend
in the File Name field when prompted and click Next. - Choose Empty from the list of options on the next screen and click Finish.
- In the newly created Example1-Backend.pva, right-click the Responder Suite and choose Add New > Responder.
- Choose Literal Message Responder in the next screen and click Finish.
Enter the following XML:
<itemResponse> <balance>10</balance> </itemResponse>
- Attach an XML Data Bank or Text Data Bank to the Response XML output of the Multiple Responses Generator and configure it to pull out the aggregated responses.
- In the Example1-Frontend.pva, right-click MultipleResponsesGenerator and choose Add output…
- Choose Response XML on the left-hand side and choose XML Data Bank on the right-hand side.
- Click Add XPath
- Click the line that appears in the Selected XPaths column and click Modify.
- Change the XPath field to
/*
- Choose Entire Element from the Extract dropdown menu.
- Choose Data source column on the left-hand side of the editor and enter responses in the Custom column name field.
- Click OK.
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: