Google's Latitude & Longitude for RPG

I was asked to add the Google geocoding functionality for longitude and latitude to a legacy green-screen (interactive) program.

Before this project, all of my Java code has run in a JEE container but, since my company's operations team wasn't very familiar with app servers, I designed my proof of concept to run as a simple Java program. The next choice was determining where the Java would run.

Having RPG make direct calls to Java seemed to be a poor choice as it would start a JVM for each user job that used the function. Another alternative, RPG's HTTP service, would require I write the RPG code needed to parse the JSON document Google returns and, in retrospect, I'm glad I avoided that option.

I developed a simple design in which one instance of the Java program can process all the requests made by users of the interactive IBM i program. The company's security plan requires the clients of external HTTP services run in a different tier from the production IBM i so the Java application runs on a Linux server in the web tier.

The design uses a single FIFO data queue to communicate requests from instances of the RPG program running in interactive jobs to a Java program and then to return the response via a single keyed data queue from the Java to the calling instance of the RPG program. The keyed data queue solves the problem of ensuring the response goes to the correct requesting job.

To make this work, each request sent from a RPG program will contain a unique key that the RPG program generates by using the IBM i UUID generator API. The RPG program sends the request by writing the key along with the address that was entered on the screen to the FIFO data queue. The Java program running on Unix reads the data queue and passes the address to the Google API. Google returns the lat/long (latitude and longitude) in the response which Java writes to the keyed data queue along with the key the RPG sent in the request. The RPG then performs a read on the keyed data queue to get the lat/long.

Screen Shot - Connecting With An Early Version of the Code

Sending the address to Google and getting the lat/long response the first time.



The Java writes the longitude and latitude extracted from Google's response to the keyed DTAQ along with the key the RPG program generated. And lastly, the RPG subprocedure reads the entry from the keyed DTAQ. The key ensures that only the original requestor will get the response for its request.

Blog Archive