informatica - 10.x - how to use a schema to create a rest ... library/1/1134... · files as schema...

13
How to Use a Schema to Create a REST Web Service Consumer Transformation © Copyright Informatica LLC 2017. Informatica and the Informatica logo are trademarks or registered trademarks of Informatica LLC in the United States and many jurisdictions throughout the world. A current list of Informatica trademarks is available on the web at https://www.informatica.com/trademarks.html. Other company and product names may be trade names or trademarks of their respective owners.

Upload: others

Post on 10-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

How to Use a Schema to Create a

REST Web Service Consumer

Transformation

© Copyright Informatica LLC 2017. Informatica and the Informatica logo are trademarks or registered trademarks of Informatica LLC in the United States and many jurisdictions throughout the world. A current list of Informatica trademarks is available on the web at https://www.informatica.com/trademarks.html. Other company and product names may be trade names or trademarks of their respective owners.

Page 2: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

AbstractA REST Web Service Consumer transformation might contain hundreds of elements. The process becomes time-consuming if you plan to configure all the elements manually. An alternative is to use a schema. A schema is a reusable object that pre-defines the elements and element hierarchy in a REST Web Service Consumer transformation. Use a schema to quickly add elements to the method input and method output in the transformation.

Supported Versions• Informatica 10.x

Table of ContentsOverview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Schema Elements in a REST Web Service Consumer Transformation. . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Schema Hierarchy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Method Input and Method Output. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Using a Schema to Design Request and Response Messages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Example - Handling Request and Response Messages in XML Format. . . . . . . . . . . . . . . . . . . . . . . . . 4

Example - Parsing Request and Response Messages in JSON Format. . . . . . . . . . . . . . . . . . . . . . . . 10

OverviewThe REST Web Service Consumer transformation is a transformation that sends a request for data to a web service. The web service receives the request and sends a response back to the transformation that contains the requested data. The request and response messages might have hundreds of elements that are that are difficult and time-consuming to define manually. In these cases, you might want to import a schema that contains all the elements that you want to include in the request message and the response message.

Schema Elements in a REST Web Service Consumer TransformationWhen you create a REST Web Service Consumer transformation, you can define the elements and XML hierarchy manually or you can import the elements and hierarchy from a schema object. A schema object is a hierarchical schema that you import to the Model repository. The transformation supports schema objects imported from an XML file or a JSON file.

Schema HierarchyThe request and response messages that you send and receive through a REST Web Service Consumer transformation contain elements that form an XML or JSON message hierarchy. When a request or a response message contains multiple-occurring elements, groups of elements form levels in the hierarchy. When one level is nested within another, the higher level is the parent element and the nested levels are the child elements.

2

Page 3: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

Method Input and Method OutputIn the REST Web Service Consumer transformation, the method input and method output are blueprints that define the structure of the request and response messages. These blueprints organize the message elements in an element hierarchy.

A schema object simplifies the process of defining elements in the method input and method output. If you use the schema object to create the method input, the schema object defines the method input elements and hierarchy. If you use the schema object to create the method output, the schema object defines the method output elements and hierarchy.

Using a Schema to Design Request and Response MessagesIf you have an XML or JSON file that contains an element hierarchy that you want to use in the REST Web Service Consumer transformation, import the XML or JSON file as a schema object and use the schema object to define the element hierarchy in the transformation method input or method output.

Designing a Request Message

You might have an XML file that contains the following data:

<location> <formatted_address>La Jota Hall, 2277 Napa Vallejo Hwy, Napa, CA 94558, USA</ formatted_address> <types>premise</types></location>

You can use this sample XML file to create a schema in the Developer tool and use the schema in the REST Web Service Consumer transformation to define the type of data that you want to request from a web service.

When you import the XML file as a schema object, you import the element hierarchy that includes the parent element location and the child elements formatted_address and types.

Use the schema object to create the method input in the transformation. When you create the method input, map the element hierarchy in the input mapping to design the request message. For this schema, the request message includes data on the parent element location that you identify through the child elements formatted_address and types.

Designing a Response Message

The web service identifies the location data that you send in the request message. It returns a response based on how you configure the response message.

In the response message, you might want to use an element hierarchy from another XML file. The XML file might contain the following data:

<address_components> <types>route</types> <short_name>Napa Vallejo Hwy</short_name> <long_name>Napa Vallejo Highway</long_name></address_components>

You can use this sample XML file to create a schema object in the Developer tool and use the schema in the REST Web Service Consumer transformation to define the type of data that you want to receive from a web service.

When you import the XML file as a schema object, you import the element hierarchy that includes the parent element address_components and the child elements types, short_name, and long_name.

Use the schema object to create the method output in the transformation. When you create the method output, map the element hierarchy in the output mapping to design the response message. For this schema, the response message includes data on the parent element address_components and the child elements types, short_name, and long_name.

3

Page 4: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

Example - Handling Request and Response Messages in XML FormatYou 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:

<Person><ID>sample</ID><Name>sample</Name><Email>sample</Email><Country>sample</Country></Person>

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:

<Greeting><ID>sample</ID><Content>sample</Content></Person>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.

Step 1. Create schemas from the XML files.

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.

1. In the Developer tool, click File > New > Schema to open the schema wizard.

2. Select Create from sample file.

3. Click Browse.

4. Navigate to the XML file and click Open.

5. Enter a name for the schema and verify the project location. If required, browse to a new location.

4

Page 5: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

6. Click Next to view the schema elements.

7. Click Finish.

You can use the schema object that you created to define the method input in the transformation.

8. 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.

1. In the Developer tool mappings editor, scroll down in the mapping palette to locate the REST Web Service Consumer transformation and drag it to the mapping.

2. Enter a name for the transformation.

5

Page 6: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

3. Select an HTTP method. For this example, select the HTTP method Post.

4. Click Next to define the method input.

5. Select Create from an element in a Schema Object.

6. Click Browse.

6

Page 7: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

7. Select the parent element in the schema. In this example, the schema used for the method input contains the parent element Person.

8. Click OK.

9. Select Input mapping.

10. 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.

11. To define the method output, click Next in the transformation wizard.

12. Select Create from an element in a Schema Object.

7

Page 8: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

13. Select the parent element in the schema. In this example, the schema that we use for the method output contains the parent element greeting.

8

Page 9: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

14. 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.

15. Click Finish.

The following image shows how the transformation might appear in the mapping workflow:

16. Select the REST Web Service Consumer transformation in the mapping editor.

17. Navigate to the Properties view and select the Advanced tab.

9

Page 10: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

18. Configure the advanced properties. To enter a base URL, configure the property URL or enter an HTTP connection in the property Connection.

Example - Parsing Request and Response Messages in JSON FormatFollow the steps in the previous example to create a REST Web Service Consumer transformation using schemas in JSON format.

If you configure the transformation method output based on a JSON schema and you want to parse the JSON response that the transformation receives, there are additional tasks that you must complete. To set up the REST Web Service Consumer transformation to parse the JSON response, set the log level to Verbose Data in the Developer tool preferences. Open the verbose data log and copy the response to an XML file. Import the XML file as a schema object and use the schema to create the transformation. After you create the transformation, configure the transformation to receive a JSON response.

Step 1. Set the log level to Verbose Data.

To set the log level to Verbose Data, complete the following steps:

1. In the Developer tool, click Window > Preferences.

2. On the left-hand side of the Preferences window, click Run Configurations > Mapping.

3. On the right-hand side, select the Advanced tab.

4. For the property Override tracing level, select Verbose Data.

10

Page 11: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

5. Open the verbose data log.

6. Search for HTTP Response BODY: <?xml

7. Copy the data between <xmlRoot> and </xmlRoot> and save the data as an XML file.

8. Import the XML file as a schema object in the Developer tool.

Step 2. Use the schema to create a REST Web Service Consumer transformation.

To use the schema to parse the data that the REST Web Service Consumer transformation receives, complete the following steps:

1. Create the transformation. Configure the HTTP method and the method input.

2. When you configure the method output, select Create from an element in a Schema object.

3. Click Browse.

4. Select the element xmlRoot.

The following image shows how the element xmlRoot might appear:

5. Configure the output mapping. If a parent element contains child elements, you must map the child elements manually. Drag the parent and child element groups from the Method output definition area to the Ports area.

11

Page 12: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

You might have a mapping that looks like the following image:

6. Configure the REST Web Service Consumer transformation properties. For the property Output Format, specify JSON.

12

Page 13: Informatica - 10.x - How to Use a Schema to Create a REST ... Library/1/1134... · files as schema objects in the Developer tool, then use the schema objects to define the method

7. Run the transformation.

The following image shows an example of a response you might receive:

Note that the data in the response is parsed to form groups that consist of a parent element and nested child elements.

AuthorsMargarita PelyushenkoTechnical Writer

Pranav AchantaAssociate Product Specialist

13