Download Using PowerCenter as a RESTful Web Service Client

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Cross-site scripting wikipedia , lookup

Semantic Web wikipedia , lookup

Hypertext Transfer Protocol wikipedia , lookup

Transcript
Using PowerCenter as a RESTful
Web Service Client
© 2012 Informatica Corporation. No part of this document may be reproduced or transmitted in any form, by any means
(electronic, photocopying, recording or otherwise) without prior consent of Informatica Corporation.
Abstract
This article shows an example of how you can create a PowerCenter workflow and use RESTbased methods to access a web service. The example uses an HTTP Transformation to invoke
HTTP commands to get data from the web service resource. It uses the HTTP GET method to
access the web service.
Supported Versions

PowerCenter 8.5.x – 9.5.x
Overview
REST (REpresentational State Transfer) is a style of architecture for distributed systems. It is the
design principle in stateless client-server systems such as web services. REST treats web
services as resources identified by their URLs. REST principles determine how clients access
web services using standard web service protocols such as HTTP and URI, and XML.
A web service built using REST principles is called a RESTful web service and conforms to the
constraints of the REST architecture. A typical method of accessing web resources in a RESTful
system is through HTTP methods such as POST, GET, PUT, and DELETE.
You can find more information about REST and RESTful design in the following web sites:
http://www.oracle.com/technetwork/articles/javase/index-137171.html
http://en.wikipedia.org/wiki/Representational_State_Transfer
SOAP or REST
Unlike SOAP, REST is not a protocol but a style of architecture. A RESTful design can use
different protocols to send and receive messages. A SOAP-based design must use the SOAP
protocol to send and receive messages. Developers need to determine whether a REST- or
SOAP-based design is appropriate for their systems.
You can use a RESTful design in the following situations:
 Web services are entirely stateless.
 Web services use a caching infrastructure.
 Web services require peer to peer interaction and the content must be known to the web
service and client.
 Limited bandwidth.
 Web sites use front-end technologies such as AJAX and DWR.
Use a SOAP-based design in the following situations:
 Interface for the web service must be established and defined in a WSDL.
 Complex non-functional requirements must be handled in a standardized way.
 Asynchronous processing and invocation must be supported.
The following table shows the difference in the way a web service client makes calls using SOAP
or REST:
SOAP Web Service Client (pseudo code)
RESTful Web Service Client (pseudo code)
Login to ServerObject.
Authentication is usually part of the request.
ServerObject.getCustomerList()
http GET “http://informatica.com/customers/”
ServerObject.getCustomer(1234)
http GET “http://informatica.com/customers/1234”
ServerObject.deleteCustomer(1234)
http DELETE “http://informatica.com/customers/1234”
2
SOAP Web Service Client (pseudo code)
RESTful Web Service Client (pseudo code)
ServerObject.findCustomersByNameFirstLast("John",
"Doe")
http GET
“http://informatica.com/customers?first=John&last=Doe”
PowerCenter as a RESTful Web Service Client
You can create only SOAP-based web services in PowerCenter. The Web Service Hub does not
support REST-based calls. However, you can use PowerCenter as a web service client to a
RESTful web service outside of PowerCenter.
In this example, you create a PowerCenter mapping and use an HTTP Transformation to invoke
HTTP commands to access the web service resources. The workflow searches a web site for a
zip code you specify and returns the results of the search.
To create the workflow example, complete the following tasks:
1. Create a text file that specifies the search parameters. The mapping uses this text file as a
source and performs the search according to the search string defined in the file. The text file
allows you to easily make changes to the search parameters or specify multiple searches.
2. Create a mapping with an HTTP Transformation. You can invoke the GET method of the
HTTP Transformation to perform the search.
3. Create a workflow and run the mapping.
Source File
Create a text file for this example with the following entries:
"postalcode","maxRows","username"
"94055","10","demo"
Create a mapping and add a flat file source definition with the following columns:
 PostalCode. Zip code to search.
 MaxRows. Maximum number of rows to return.
 UserName. User account required by the web service.
HTTP Transformation
Add an HTTP Transformation to the mapping with the following input ports:
 PostalCode
 MaxRows
 UserName
Set the Base URL to the following URL:
http://api.geonames.org/postalCodeSearch
The base URL generates the following final URL:
http://api.geonames.org/postalCodeSearch?postalcode=$postalcode&maxrows=$maxrows&user
name=$username
Add a flat file target to the mapping and connect the HTTP Transformation ports to the target.
Workflow and Output
Create a workflow for the mapping and run the workflow.
3
The HTTP Transformation uses the GET method to connect to final HTTP URL:
http://api.geonames.org/postalCodeSearch?postalcode=94055&maxrows=10&username=demo
The result of the GET call is in XML format similar to the following text:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
<totalResultsCount>2</totalResultsCount>
<code>
<postalcode>94055 CEDEX</postalcode>
<name>Creteil</name>
<countryCode>FR</countryCode>
<lat>48.78333</lat>
<lng>2.46667</lng>
<adminCode1 ISO3166-2="J">A8</adminCode1>
<adminName1>Ale-de-France</adminName1>
<adminCode2>94</adminCode2>
<adminName2>Val-de-Marne</adminName2>
<adminCode3>941</adminCode3>
<adminName3>Arrondissement de Creteil</adminName3>
</code>
<code>
<postalcode>94-055</postalcode>
<name>Lodz</name>
<countryCode>PL</countryCode>
<lat>51.75</lat>
<lng>19.46667</lng>
<adminCode1/>
<adminName1>Lodzkie</adminName1>
<adminCode2/>
<adminName2>Lodz</adminName2>
<adminCode3/>
<adminName3/>
</code>
</geonames>
Authors
Sumeet K. Agrawal
Product Manager
Malleswari Naga
Principal Software Engineer - QA
4