Data Mapper mediator is a data mapping solution that can be integrated into a mediation sequence. It It converts and transforms one data format to another, or changes the structure of the data in a message. It provides a WSO2 Developer Studio-based tool to create a graphical mapping configuration and generates the files required to execute this graphical mapping configuration by the WSO2 Data Mapper engine.
...
Info |
---|
The Data Mapper mediator is a content-aware mediator. |
Table of Contents | ||
---|---|---|
|
Prerequisites
You need to install the WSO2 Developer Studio ESB Tool 45.10.0 to use the Data Mapper mediator. For instructions on installing this WSO2 ESB Tooling Plugin, see Installing WSO2 ESB Tooling.
...
Syntax
Code Block | ||
---|---|---|
| ||
<datamapper config="gov:datamapper/FoodMapping.dmc" inputSchema="gov:datamapper/FoodMapping_inputSchema.json" inputType="XML" outputSchema="gov:datamapper/FoodMapping_outputSchema.json" outputType="XML"/> |
...
...
UI configuration
The parameters available for configuring the Data Mapper mediator are as follows.
...
Parameter name | Description |
---|---|
Mapping Configuration | The file, which contains the script file that is used to execute the mapping. You need to create a mapping configuration file using the Dev Studio-based Tooling plugin, and store it either in the Configuration Registry or Governance Registry, to select and upload it from here. |
Input Schema | JSON schema, which represents the input message format. You need to create an input schema file using the Dev Studio-based Tooling plugin, and store it either in the Configuration Registry or Governance Registry to select and upload it from here. |
Output Schema | JSON schema, which represents the output message format. You need to create an output schema file using the Dev Studio-based Tooling plugin, and store it either in the Configuration Registry or Governance Registry to select and upload it from here. |
Input Type | Expected input message type (XML/JSON/CSV) |
Output Type | Target output message type (XML/JSON/CSV) |
...
Info | ||
---|---|---|
| ||
You can configure the mediator using XML. Click switch to source view in the Mediator window. |
...
Components of Data Mapper
WSO2 Data Mapper consists of two components. They are Data Mapper Tooling and Data Mapper Engine.
Data Mapper Tooling
Data Mapper Tooling component is the interface used to create configuration files that are required by the Data Mapper Engine to execute the mapping. Following three configuration files are needed by the Data Mapper engine.
- Input schema file
- Output schema file
- Mapping configuration file
These three files are generated by the Data Mapper Tool and saved in a Registry Resource project, which you deploy in a WSO2 server as shown in the example below.
Info |
---|
The |
Input and output schema files
Input and output schema files are custom-defined JSON schemas that define the input/output format of input/output messages. The Data Mapper tool generates them when loading the input and output files as shown below.
Info |
---|
You can also create the input and output JSON Schemas manually using the Data Mapper Diagram Editor. For instructions, see Creating a JSON Schema Manually. |
You can load the following input/output message formats:
...
Info |
---|
When loading a sample input XML file |
...
, you cannot have the default namespace (i.e. without a prefix in the namespace element). Also, you need to use the same prefix in all occurrences that refer to the same namespace within one XML file. For example, see the use of the prefix axis2ns11 in the example below.
|
- XML: to load a sample XML file
- JSON: to load a sample JSON file
- CSV: to load a sample CSV file with column names as the first record
- XSD: to load an XSD file, which is an actual schema for XML files
- JSONSCHEMA: to load a WSO2 Data Mapper JSON schema
- CONNECTOR: to use Data Mapper with WSO2 ESB Connectors. Connectors will contain JSON schemas for each operation that defines the message formats to which it will respond and expect. Therefore, when you integrate connectors in a project this Connector option searches through the workspace and find the available Connectors. Then, you can select the respective Connector in the operation, so that the related JSON schema will be loaded for the Data Mapper by the tool.
Mapping configuration file
This is a JavaScript file generated by looking at the diagram you draw in the Data Mapper Diagram Editor by connecting input elements to output elements. Every operation you define in the diagram gets converted to a JavaScript operation.
Data Mapper Engine
You need the following information to configure the Data Mapper Engine:
- Input message type
- Output message type
- Input schema Jjava Java Scripting API
- Output schema
- Mapping configuration
At the runtime, the Data Mapper Engine gets the input message and the runtime variable map object and outputs the transformed message. The Data Mapper Engine uses the Java Scripting API, t o execute the mapping configuration. Therefore, if your runtime is JAVA 7, it uses the Rhino JS Engine and if your runtime is JAVA 8, it uses the Nashorn JS engine.
When you use JAVA 7, there are several limitations in the Rhino engine that directly affects the Data mapper Engine. There are several functions that Rhino does not support. For example, String object functions like startsWith()
and endsWith()
. Therefore, the Rhino engine may have limitations in executing those when using custom functions and operators.
Using product-specific runtime variables
Also, the Data Mapper engine allows you to use runtime product-specific variables in the mapping. The intermediate component should construct a map object containing runtime product-specific variables and send it to the Data Mapper Engine, thereby, when the mapping happens in the Data Mapper Engine, these variables become available.
For example, the Data Mapper mediator provides ESB properties like axis2/transport/synapse/axis2client/operation/.
. In the Data Mapper diagram, you can use the Property operator and define the scope and the property name and use it in the mapping. Then, the Data Mapper mediator will identify the required properties to execute the mapping and populate a map with the required properties and will send it to the Data Mapper Engine.
...
Data Mapper element and attribute types
Following are the element and attribute types that are supported by the Data Mapper.
- {} - represents object elements
- [] - represents array elements
- <> - represents primitive field values
- A - represents XML attribute values
...
Data Mapper operations
The operations palette placed in the left-hand side of the WSO2 Data Mapping Diagram Editor displays the operations that the Data Mapper supports as shown below.
You can drag and drop these operations to the Editor area. There are six categories of operations as follows:
- Links
- Common
- Arithmetic
- Conditional
- Boolean
- Type Conversion
- String
Links
Data Mapping Link: maps elements with other operators and elements.
Common
Constant: defines String, number or boolean constant values.
...
Global Variable: instantiates global variables that you can access from anywhere.
Compare: compares two inputs in the mapping.
Arithmetic
Add: adds two numbers.
Subtract: subtracts two or more numbers.
...
Max: derives the maximum number from given inputs
Conditional
IfElse: uses a condition and selects one input from given two.
Boolean
AND: performs the boolean AND operation on inputs.
OR: performs the boolean OR operation on inputs.
...
Code Block | ||
---|---|---|
| ||
{ "books": { "book": { "id": "001", "author": "Writer", "title": "Great book on nature", "price": "44.95" } } } |
Samples
For a sample that demonstrates how to use the Data Mapper mediator, see: