Download presentation
Presentation is loading. Please wait.
Published byGiuseppe Pasquale Tedesco Modified over 5 years ago
1
Consuming Web Services with 2E Generated Objects
2
Speakers Jonathan R Bolton C&D Technologies, Inc.
3
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.
4
System Prerequisites
5
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
6
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
7
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 2E-generated service program, the default 2E 7A return code parameter (P0Rtn) is included. It however does not need to be populated.
8
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.
9
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
10
RESTful Example The URL in this example is the following:
This is the response:
11
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.
12
Request and Response
13
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
14
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
15
Required Definition Specifications
16
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.
17
SOAP Request User Source
18
SOAP Array Data Structure
19
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
20
SOAP Response Data Update
21
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
22
The Execute External Function object
23
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
24
RESTful Web Service Response
25
RESTful Qualified Data Structure
26
RESTful Web Service Call and Parse
27
Demonstration
28
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
29
Useful links . . . HTTPAPI Library : YAJL JSON Parser:
30
Thank you for attending!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.