Consuming Web Services with 2 E Generated Objects

Consuming Web Services with 2 E Generated Objects 1

Speakers Jonathan R Bolton C&D Technologies, Inc. 2

Presentation Objectives This presentation will demonstrate how a combination of user source objects in conjunction with standard CA 2 E action diagram processes can create a program to consume a web service. 3

System Prerequisites 4

System Prerequisites The following functions and freeware libraries are required to successfully created 2 E objects that will consume web services: – Generation mode must be ILE RPG (RP 4) – The 2 E compiler preprocessor must be present and active – The following freeware libraries must be installed on the System i: • HTTPAPI HTTP API library • YAJL JSON Parser library – The SOAPUI web service exerciser application 5

SOAP Web Services Web services using Simple Object Access Protocol (SOAP) were quite popular several years ago but have been displaced by RESTful web services SOAP services utilize an XML-based interface for both the request to the service and the response SOAPUi allows you to interrogate the service to determine the XML request format and verify the format of the response 6

SOAP Request • This example shows the request for a SOAP web service that accepts a manifest ID and a manifest line number as input data. Note that, as a web service powered by a 2 E-generated service program, the default 2 E 7 A return code parameter (P 0 Rtn) is included. It however does not need to be populated. 7

• SOAP Response This is the response from the web service request shown in the previous slide. The service returns the customer order number (WP 0003), the item number (WP 0004) and the item description (WP 0005). Note the 7 A return code is referenced but without a full tag pair. 8

RESTful Web Services The Representational State Transfer (REST) service is becoming the protocol of choice for web services Javascript Object Notation (JSON) is the preferred vehicle for the response and is a simplified name: value pair In its simplest form, the request is just a URL with parameters 9

RESTful Example • The URL in this example is the following: • This is the response: 10

A More Complex SOAP Service • This service returns multiple sets of data where there are 8 subfields in each data set. Since the service is powered by a 2 E generated program object, the response is populated by an *arrays object. Also note that the input parameter (WP 0001) comes after the definition of the return parameter. 11

Request and Response 12

Creating a consumption process in 2 E Both SOAP and RESTful web services can be consumed by a 2 E-generated program Execute User Source objects are needed for coding of these two functions: – The call to the web service via HTTP – The parsing of the response returned by the service 13

Execute User Source objects Execute User Source (EXCUSRSRC) objects are needed to manage these functions/activities: – Definition statements pertaining to variables needed in the object that are not part of the 2 E model database – Definition of the XML request packet – Coding of the HTTP call – Coding of the appropriate parser, based on the service type • XML-INTO for SOAP services • DATA-INTO (with YAJLINTO) for RESTful services 14

Required Definition Specifications 15

Required Definition Specifications Use the Y* compiler directive to dynamically additional libraries needed for compilation. If using SQL and not DDS, ensure that the compiler preprocessor option (RPGPPOPT) is set to *LVL 2 and not *NONE. If this is not done, the compiles will fail. Definition specifications allow the easy setup for the HTTP call using the HTTPAPI functions. Use the /include directive to add the required header files. Don’t use /copy directives. These are not correctly understood by the compile preprocessor. 16

SOAP Request User Source 17

SOAP Array Data Structure 18

SOAP Array Data Structure This user source defines a data structure that can be accessed by the XML-INTO process and 2 E generated source code The data structure array dimension value must match that of the 2 E array parameter you are using The key take away here is that the user source must define the data structure parameters using the names discovered by testing the web service with SOAPUi 19

SOAP Response Data Update 20

SOAP Response Data Update This user source is the connection point between the user source added to work with the data parsers and 2 E generated source code The input parameter defines the index value for the data set being processed The output parameters receive the parser results 21

The Execute External Function object 22

RESTful Web Service Differences The HTTP call does not require a formal request set in XML, just a URL with parameter(s) The response can be parsed into a qualified data structure 23

RESTful Web Service Response 24

RESTful Qualified Data Structure 25

RESTful Web Service Call and Parse 26

Demonstration 27

Conclusions. . . Web services are a powerful tool that extends the versatility of the IBM i platform, both as a provider of services or a consumer of services CA 2 E can easily be used to both create and consume web services Imaginative use of Execute User Source objects makes sophisticated programming techniques possible Web services help dispel the notion that the IBM i and CA 2 E are “legacy” systems ready for retirement 28

Useful links. . . HTTPAPI Library : http: //www. scottklement. com/httpapi/ YAJL JSON Parser: http: //www. scottklement. com/yajl/ 29

Thank you for attending! 30
- Slides: 30