How to Handle Request and Response Messages in XML Format
How to Handle Request and Response Messages in XML Format
You have an XML file that contains an element hierarchy that you want to use to create the request message that the REST Web Service Consumer transformation sends to a web service. The XML file includes data that you can use to identify a person at your organization such as their ID, name, e-mail, and country. These elements might appear in the XML file in the following way:
You have another XML file that contains an element hierarchy that you want to use to create the response message. The XML file includes data on the type of greeting that you want to use to address each person. The greeting includes data on the individual's ID and the greeting content. These elements might appear in the XML file in the following way:
To use the element hierarchy in these XML files in a REST Web Service Consumer transformation, first import the XML files as schema objects in the Developer tool, then use the schema objects to define the method input and the method output when you create the REST Web Service Consumer transformation.
Complete the following steps to create a schema object for the method input. Repeat these steps to create a schema object for the method output.
In the Developer tool, click
File > New > Schema
to open the schema wizard.
Select
Create from sample file
.
Click
Browse
.
Navigate to the XML file and click
Open
.
Enter a name for the schema and verify the project location. If required, browse to a new location.
Click
Next
to view the schema elements.
Click Finish.
You can use the schema object that you created to define the method input in the transformation.
Repeat steps 1-7 to create a schema object for the method output.
Step 2. Create the REST Web Service Consumer Transformation.
Create the transformation. Use the schemas to define the method input and method output.
In the Developer tool mapping editor, scroll down in the mapping palette to locate the REST Web Service Consumer transformation and drag it into the mapping.
Enter a name for the transformation.
Select an HTTP method. For this example, select the HTTP method Post.
Click
Next
to define the method input.
Select
Create from an element in a Schema Object
.
Click
Browse
.
Select the parent element in the schema. In this example, the schema used for the method input contains the parent element
Person
.
Click
OK
.
Select
Input mapping
.
Map the elements under
RequestInput
in the Ports area to
Rest_Consumer_Input
in the Method input definition area. Remember to map the key from the Ports area to the Method input definition area.
To define the method output, click
Next
in the transformation wizard.
Select
Create from an element in a Schema Object
.
Select the parent element in the schema. In this example, the schema that we use for the method output contains the parent element
greeting
.
Map the elements under
Rest_Consumer_Output
in the Method output definition area to the Ports area. You are not required to map the key.
Click
Finish
.
The following image shows how the transformation might appear in the mapping workflow:
Select the REST Web Service Consumer transformation in the mapping editor.
Navigate to the
Properties
view and select the
Advanced
tab.
Configure the advanced properties. To enter a base URL, configure the property