300 likes | 312 Views
Learn how to create a program using user source objects and CA 2E action diagram processes to consume web services.
E N D
Speakers Jonathan R Bolton C&D Technologies, Inc.
Presentation Objectives This presentation will demonstrate how a combination of user source objects in conjunction with standard CA 2E action diagram processes can create a program to consume a web service.
System Prerequisites The following functions and freeware libraries are required to successfully created 2E objects that will consume web services: • Generation mode must be ILE RPG (RP4) • The 2E 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
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
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 2E-generated service program, the default 2E 7A return code parameter (P0Rtn) is included. It however does not need to be populated. SOAP Request
SOAP Response This is the response from the web service request shown in the previous slide. The service returns the customer order number (WP0003), the item number (WP0004) and the item description (WP0005). Note the 7A return code is referenced but without a full tag pair.
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
The URL in this example is the following: This is the response: RESTful Example
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 2E generated program object, the response is populated by an *arrays object . Also note that the input parameter (WP0001) comes after the definition of the return parameter.
Creating a consumption process in 2E Both SOAP and RESTful web services can be consumed by a 2E-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
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 2E 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
Required Definition Specifications Use the Y* compiler directive to dynamically add additional libraries needed for compilation. If using SQL and not DDS, ensure that the compiler preprocessor option (RPGPPOPT) is set to *LVL2 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.
SOAP Array Data Structure This user source defines a data structure that can be accessed by the XML-INTO process and 2E generated source code The data structure array dimension value must match that of the 2E 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
SOAP Response Data Update This user source is the connection point between the user source added to work with the data parsers and 2E generated source code The input parameter defines the index value for the data set being processed The output parameters receive the parser results
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
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 2E 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 2E are “legacy” systems ready for retirement
Useful links . . . HTTPAPI Library : http://www.scottklement.com/httpapi/ YAJL JSON Parser: http://www.scottklement.com/yajl/