i For Business Event Logo

Bookmark and Share
RSS

Recent Posts

IBM Cloud, Watson and Web Services Help Applications Fly

November 13, 2017

IBM i customers have substantial investment in Integrated Language Environment (ILE) applications, but how can these programs be integrated with outside applications or services? For instance, you may have heard discussions lately about IBM Watson and IBM Cloud (formerly known as IBM Bluemix), and the value they can bring to IBM i. What if you wanted to take advantage of these solutions? In today’s blog, guest blogger Bo Fan and I will show you a working example of how a green-screen ILE application can be given a new interface, a new home in the cloud and some new cognitive abilities.  

For this demonstration, I’d like to welcome guest writer (and developer extraordinaire) Bo Fan to demonstrate the ease and power of the Integrated Web Services (IWS) server, IBM Cloud and IBM Watson. In this article, I'll show you how simple it can be to create a Web service for an existing RPG application, and use it on IBM Cloud.

As a starting point, Bo used the “Flight400” application. This piece of software is a fictional airline ticketing system. It was developed as a sample application to show how to use RPG code to interact with the database and how to build 5250 screens to interact with the RPG.

figure-0.png

Without further ado, let’s explore how Bo gave this application new wings!

Plan
In the Flight400, there’s a procedure called findflight, which contains 5 parameters, FROMCITY, TOCITY, FLIGHTDATE, FLIGHTCOUNT, FLIGHTS. It searches for available fights between FROMCITY and TOCITY for the date specified by FIGHTDATE. I’d like to create a REST API for this procedure. Furthermore, I also try to provide a better searching experience by adding abilities to understand user input, provide other useful information related to the search, etc. Therefore, I decided to add the following three web services provided by IBM Cloud.
  1. Watson Natural Language Understanding service, which processes user input, extracts city names that will be used in searching flights
  2. WeatherCompany Data service, which looks up the destination city’s weather data for the next 3 days
  3. Watson Discovery service, which gets top five news articles for the destination city
Finally, on IBM Cloud, I’ll have a NodeJS app that manages interactions among above described RESTful web services, and presents results on a webpage.

The overall structure of the web application is shown in the diagram below.

figure-1.png

Creating Web Services on IBM i

Building web services on the IBM i platform is a straight-forward process. Integrated Web Services (IWS) for i enables ILE applications to play in the web services with very minimal efforts as it can help you to create the web service wrapper for an existing RPG program with just few steps.

The web service that wraps for our existing findflight procedure takes three input parameters: a flight departure city ({from}), a flight destination city ({to}) and a flight date ({date}). The response is a list of available flights in JSON format. The HTTP GET request looks like this:
GET http://common1.idevcloud.com:10076/web/services/findflight/{from}/{to}/{date}
 
Start by creating a new Web Services Server for this (or feel free to use an existing one if you wish). Then, Under the Web Services Wizards category, click Deploy New Service. The Deploy New Service wizard will guide you through the process.
  • Step 1: Select REST as web service type, and specify the library name and ILE Object name for the program object location.
  • Step 2: Specify the program object for the Web service.
  • Step 3: Specify Name for Service and define URI path template
  • Step 4: Select Export Procedures to Externalize as a Web Service. In my example, I export the FINDFLIGHTS procedure with 3 input parameters and 2 output parameters.
figure-2.jpg

  • Step 5: Specify Resource Method Information, mapping input parameters. I choose to use JSON as the Returned output media type.

 figure-3.jpg

  • Step 6: Specify User ID for this Service to run the program object that contains the Web service business logic
  • Step 7: Add required libraries to the library list
  • Step 8: Specify Transport Information to Be Passed to the web service implementation code.
  • Step 9: Confirm all setting are correct
  • Click Finish to deploy and host this new REST API on the IBM i.  

Configure Watson web services on IBM Cloud

Log in to your IBM Cloud account, go to the dashboard and click the Create button.
  • 1. To create the Watson Natural Language Understanding service, navigate to the Watson category and click on Watson Natural Language Understanding.

figure-4.jpg

  • 2. Navigate to the Watson category and click Discovery to create Watson Discovery Services

figure-5.jpg

  • 3. To create WeatherCompany Data Service, navigate to Data & Analytics category and click Weather Company Data

figure-6.jpg


The HTTP GET request for WeatherCompany Data service querying next 3 days weather is in the following format:

https://<username>:<password>@twcservice.mybluemix.net:443/api/weather/v1/geocode/<latitude>/<longitude>/forecast/daily/3day.json

It requires a geocode so I use Google Map API to translate addresses to geographic coordinates (e.g. latitude, longitude).

Finally, I created a Cloud Foundry NodeJS app on IBM Cloud. This app manages all interactions among the IWS REST API and IBM Watson web services and presents the results on a webpage. At this point, we have successfully created all necessary web services for our web application.

Deploy the App on IBM Cloud

Deploying a NodeJS app is easy on IBM Cloud, as there’s a Command Line Interface tool provided for that. All you need is to issue a couple of commands to connect your IBM Cloud account and push your app. In the IBM Cloud Dashboard, click the Cloud Foundry App that need to be deployed. Then click Getting started on the navigation pane, followed by Download Bluemix Command Line Interface. You can follow the instruction on this page to modify, test and redeploy your app. Once the app is deployed successfully, you can access it through the provided URL.

My demo site is available in here.

On the search flights page, enter a search string that contains departure and destination cities and a date of the flight.

figure-7.jpg


Once the Search button is clicked, the result page will be populated with fight information as shown below.


figure-8.png

Closing Thoughts (by Jesse)
Today, Bo relied on web services as the means to integrate with RPG applications from a remote system. As you know, deployed web services can extend an application to be accessed from the cloud, from a mobile device, or pretty much anywhere. The IWS server is a simple, user-friendly way to get web services deployed. Plus, it comes with the operating system with no additional costs.

Today we used IWS, but there are many ways to deploy web services. Stay tuned for my next article, which will explain how to implement web services using Node.js technology on IBM i. With all these options, your applications can fly, too!

Posted November 13, 2017 | Permalink

Post a Comment

Note: Comments are moderated and will not appear until approved

comments powered by Disqus