EGL and i

7 Posts tagged with the soa tag
8

Okay, I've written the first-generation RPG proxy program. Basically the proxy's job is to extract the request from the EGL Rich UI runtime and invoke the appropriate business logic.

It's a little more complex than that. If you're testing locally your request is automatically redirected to the local proxy that runs inside the workbench. The proxy calls your CGI service and your service extracts the data from the request. The request looks something like this:

{"bindingName":"PollService","method":"getPoll","params":[0]}

And you return data that looks something like this:

{"result" : { "name" : "Language Poll", "choices" : [{ "choice" : "RPG", "votes" : 87},{ "choice" : "EGL", "votes" : 33},{ "choice" : "PHP", "votes" : 2}]}}

Not too difficult. However, once you deploy to your host machine, things get a little more complex. The runtime no longer uses the proxy in the workbench, and instead it has to send to your proxy. Your proxy program then has to unbundle the request from the larger request, which now looks like this:

{"uri":"http:\/\/IRUIHOST\/cgi-bin\/POLLSVC2.PGM","queryParameters":{},"method":"POST","body":"{\"bindingName\":\"PollService\",\"method\":\"getPoll\",\"params\":[0]}","headers":{"EGLREST":"TRUE","egl_statefulsessionid":"JSESSIONID","Content-Type":"application\/json; charset=UTF-8"}}

A little more ugly, no? Not only that, you have to also buffer your reply into something just as complex. However, I managed to hide most of that complexity in a single program named EGLPRSCGI. I then have two programs, POLLCGI2 and CGIPROXY, each of which calls EGLCGIPRS to get the parameters from the client. Each then calls POLLSVC1, which is the actual business logic, and then formats the response as needed (CGIPROXY does a lot more formatting).

Eventually, CGIPROXY would have to recognize all the various requests and call the appropriate service program. But for now, you can get the project, and you can see the result on the SWICD website:

http://see-what-i-can-do.com/poll2.html

It's pretty slick, actually. :)

The project interchange file is on the project interchange discussion post.

8 Comments Permalink
2

Okay, with expert guidance from Chris, I managed to engineer a Java-free RUI application architecture. It's not exactly simple. In test mode, any REST request goes through an invisible proxy in the workbench. The request that your service sees is not what the proxy sees; the EGL JavaScript runtime actual wraps your request inside a larger request which is sent to the proxy. The proxy unbundles that and sends it to the target service. The proxy then takes the response, rebundles it and sends it back to the runtime.

So, if you're writing your own RPG version of the proxy, then you have to do all that bundling and unbundling. Then you have to invoke the target service. I, however, skipped that. Since I have control over all the pieces, I extracted the actual business logic and re-wrote the target service to call the business logic. Then I added code in the proxy to call the business logic directly.

It's not quite as complicated as it sounds and it works really well as a proof of concept. I can now say with certainty that it is entirely feasible to write a complete, Java-free EGL Rich UI application, using only RPG as the back end.

I'll clean up the code and export the project (including a savefile with the RPG code) in the next day or two.

2 Comments Permalink
8

It looks like I may have bitten off more than I can chew with this little project. I'm not completely certain, but it looks like the concept of an EGL Rich UI application using nothing but an HTTP server is not going to work. Unless I'm mistaken it looks like the Rich UI REST calls go through a proxy servlet. This is done for a practical reason; it allows the Rich UI to make calls to services other than the original host, a feat which is not allowed in normal AJAX calls. However, it does mean that even if the actual REST service is served by Apache (such as my RPG-CGI service), the proxy servlet still needs to be running in a web application server on the host.

Thus the vision of a Java-free Rich UI application has hit what may be a fatal roadblock. (Note: the reason it worked in debug is that evidently the workbench has that proxy server magically enabled. I still don't have all the details on that bit of sleight-of-hand, but I'll let you know if I get more specifics.)

It was still a useful learning experience, but all in all I'd have preferred a better outcome. In any case, I think it's time to put the Java-free RUI on the side and get back to traditional Rich UI development. And if nothing else, I've got a cool widget written.

Look for the "normal" version in the next day or two.

8 Comments Permalink
0

Well, this has been an interesting little excursion. I really wanted to make sure that I tried to test the boundaries of the "Java-free" EGL/RPG architecture and as soon as I did, I ran into a little bump.

The problem is that you can't use a variable as the URL of the REST request. I don't understand the limitation and I haven't really asked about it yet, but the limitation is real for now. And because of that, you can't just pass your parameters as variables in the URL and then retrieve them with simple calls to QzhbCgiParse in your RPG-CGI program.

All is not lost. As it turns out, when you call a function in a REST service the parameters for the function are passed to the REST service as a JSON string. The JSON string is somewhat buried in the POST data and to make it even more challenging the data is in ASCII, but the parameters are more or less accessible, depending on how hard you're willing to look.

I'm going to take the time to write a simple procedure to extract the parameter string from the POST data. Then in order to make things simple I'll write a second procedure to treat the parameter string as a single string parameter (if that's not too confusing). It will assume that any REST function has only a single parameter of type string.

With that, I can then build comma delimited data in the Rich UI client and parse it in the RPG program using %scan. It's not quite as seamless or flexible as the magic Record-to-Data Structure conversion of EGL, but it will prove the point. Once that's done, though, I think it will be time for me to move to a true EGL Service implementation.

Anyway, that's what I'm working on. Hopefully I'll have it done in the next day or so. It's just a little bit of a speed bump.

Comments would be great. And if an IBMer happens along this and thinks I'm doing something completely bizarre, feel free to let me know... :)

0 Comments Permalink
0

Given how easy it was to create an RPG-only service, I've decided to kill two birds with one stone with V2R1. I'm going to create my first persistent widget, and I'm going to do it without any Java code (and thus, without the requirement for a web application server). I'll eventually return to this code and rewrite it using traditional host-side EGL for the service, but this first non-Java version will be an interesting exercise.

The concept of a "persistent widget" is going to be crucial to this project. The term means a widget that persists between accesses and can be accessed by multiple sessions. In its simplest form, a persistent widget is simply a widget backed by a database. In my first go-round I think I'll create a "Poll" widget. A poll will have a unique name, and for children it will have choices, each of which has an attribute of choice text and number of votes.

The EGL record for this will be wonderfully simple, and unless I'm mistaken the RPG program will be very simple as well. I think that by my next blog entry I ought to be able to create an RPG program that not only returns a Poll object, but also allows update. That should then make it almost trivial to create a user interface that allows anyone to vote in the poll.

What do you think? My idea is that we ought to be able to create a whole library of self-contained persistent widgets which can then be used to build applications. What other widgets do you think might make sense?

0 Comments Permalink
0

See What i Can Do - V2R0

Posted by JoePluta Aug 30, 2009

Okay, I'm now in the pre-flight phase of version two. I'll leave V1 alone for the time being, although I may circle back to it later in order to investigate other pure client-side issues. But I want to get right to the core of what's important to EGl and i, calling business logic on the i. The purpose of V2 is to address the issue that EGL Rich UI requires WebSphere (or some other web application server) to run.

That's simply not the case. Rich UI handles both SOAP and REST service calls, which means that it talks to anything that does either of those. Most platforms can create SOAP services. The problem is that SOAP is over-engineered bloatware; the correct answer is to use REST.

Unfortunately, I don't have any examples of using pure RPG-CGI as either a SOAP service provider or a REST service provider. I could use the wizard provided with the standard i5/OS web administration tool to create a "Web Service Server" but that's still a SOAP service. I'm going to try a sidetrack to write my own code that will provide a simple REST response.

As always I'll be relying on groundwork done by others, in this case I'll probably be reviewing and probably liberally re-engineering code from Craig Pelkie and Scott Klement, as well as making use of Chris Laffra's service monitor. I'll need all the help I can get, because this is completely untraveled territory.

Wish me luck - I'll get back to you in a day or two.

0 Comments Permalink
6

Notes from iSeries DevCon

Posted by JoePluta Oct 30, 2008

I haven't been posting this month because I've been really busy getting ready for iSeries DevCon. This is one of the best technical conferences, although you might consider me a little biased; in four days, I give one all-day jumpstart (this year on migrating from PDM and SEU to RDi) and then 10 sessions and hands-on labs. It's always been a forward-thinking conference; I did sessions there on Eclipse and Visual Age for Java (Eclipse's predecessor) as far back as 2001, along with some of my first web-enabling sessions.

Since then, they've always been ready to present the latest technologies and so this year I gave what I'm pretty sure was the first hands-on EGL lab at an i technical conference, along with a number of other sessions and labs ranging from multi-tier architecture development to extending Rational tools with Eclipse plugins. My session on Eclipse, WebSphere and Rational was repeated, and even though the second one was in the last slot on the last day, we still had good turnout.

In the i space, EGL has to deal with all the buzz surrounding PHP and MySQL. To me, that buzz is nothing more than white noise because PHP just doesn't stand up to EGL when it comes to ease of use, adoption of advanced technology and integration - especially with the i. As a simple example, PHP's connection to the i involves using a PHP knockoff of IBM's Java toolbox, and while the toolbox is phenomenal technology, using it directly requires a lot of code; a simple program call might require dozens of lines of code. With EGL, it's a simple CALL statement. And when I demonstrated how easy it was to build entire applications using RDi-SOA to write EGL front ends and RPG back ends, people started getting excited. In a simple 90-minutes lab attendees with no prior Java experience were able to create an EGL record, build a JSF page, then flip over to the RSE perspective to compile the RPG business logic, and then back to the EGL to add a few lines of code to attach the two.

I also did a lab on multi-tiered architecture without EGL (using plain old JSP and Java) and the people who attended both really got an understanding of what EGL was all about: simplifying the plumbing. Even the simplest web application requires a significant amount of plumbing code in any 3GL, whether it's Java or PHP or RPG-CGI. EGL removes all of that for you. Not only that, but the very nature of the language makes it easy to reuse code, so that once you've created a JSF client, it's simple to turn around and create a rich client or a web service. I think that really hit home with a lot of the attendees.

Anyway, I'm back now and I'm focused on the Rich UI book. You'll see a lot more about that in the coming weeks. It's good to be back, and thanks for reading!

6 Comments Permalink
Bottom Banner