Blog Posts

Statistics: Blogs: 33 Blog Posts: 238   1 2 3 4 5 ... 16 Previous Next
Items per page
1

This blog post serves to keep an up-to-date list of known issues, observations, and feature requests reported by users of EGL CE.

Make sure you watched the introduction video at http://www-949.ibm.com/software/rational/cafe/community/egl/ce.

For troubleshooting, check Troubleshooting EGL Community Edition issues

CE Version Date Type Summary Details
1.0.0 09/14/09 Defect DojoDialog DojoDialog may be incorrectly sized
1.0.0 09/14/09 Defect Error Messages Dojo Google provider does not print error messages during startup
1.0.0 09/14/09 Enhancement Ajax Proxy Web Security and why EGL Rich UI needs an Ajax Proxy

1 Comments Permalink
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
0

I thought I'd take a moment and build upon Theresa's post Getting started with Rational EGL Community Edition and talk a little about the new Dojo Widgets in the EGL Community Edition (CE). For those that don't know, the Dojo Toolkit is an open source JavaScript library for developing web-based applications. It's available for free from the Dojo website and provides an array of widgets including menus, tabs, tables, dynamic charts and more. Takes this from me: Dojo is extreamlly powerful - but with power (in this case) comes a fair amount of complexity.

One of the best parts of EGL is that your not restricted to a single widget library. You can create your own custom widgets using any JavaScript your heart desires. With that in mind, back in April we launched an early version (0.6.0) of the EGL Dojo Widgets. Since then, the Dojo Widgets have come a long way and I'm very excited at what we've done for the 0.7.1 release. Unfortunatly the API has changed for certain widgets, but I assure you major changes like that won't happen again.

http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/38-1255-1726/projects.jpg

Of the 5 projects that are loaded by default when you start CE, 3 of them are related to Dojo. These are the Dojo Widgets, Samples and Runtime. You'll notice when using the Visual Editor the palette has the Dojo Widgets populated automatically. We encourage you to jump right into using Dojo in your EGL applications, go ahead and take a look at the Dojo Samples and see just what you can do. A great place to get started is the Gallery sample. This includes all the 0.7.1 Dojo widgets in a single sample.

Remoate vs Local Dojo

As I mentioned above, Dojo is extreamly powerful. What I didn't mention was that power brings not only complexity, but size. Luckily Dojo allows for their runtime to downloaded remotly through content providers like Google, Yahoo or AOL. This paradigm is widely on numerous sites including hpn.to & TechCrunch to name a few. This means you don't need to have the Dojo runtime in your local filesystem, instead Dojo will download the necessary files as your application is loading.

Sounds great, doesn't it? For the most part - but what if you don't have an internet connection or you want to deploy your application with Dojo available locally? Not to fear, we make it easy for you to switch between the remote version of Dojo to a compressed local version. Just follow these steps:

1) Click on the Help Menu -> Search
2) Search for 'Local Dojo'
3) Click on 'Loading the Dojo Toolkit into your local environment'
4) Click 'Get the Dojo Toolkit Project' under 'Import Projects'

At this point you'll see the new project in your worksapce holding the local Dojo Runtime (dojo.runtime.local). All you need to do now is update your EGL Build Path for the Projects you want to use the local Dojo. So in my case, I'll just update the Dojo Samples.

buildpath.jpg

I think that's enough for now, I hope everyone enjoys CE!

0 Comments Permalink
0

Why EGL in EGL Community Edition

Posted by will.smythe Sep 11, 2009

Over the last few days, I have been asked several times - "Why EGL?". It's a good question. For those of us that have been around EGL, the answer is obvious: spend more time innovating and less time fighting with technology. For those of you that are not familiar with EGL and the new EGL Community Edition tool, here are some of the key benefits. These benefits should resonate if you've ever fought with JavaScript :)

  1. EGL does not replace HTML, JavaScript, or Java, but makes development of HTML, JavaScript, and Java easier. EGL code is compiled (on the fly) based on where it needs to run. EGL code that is expected to run in the browser is compiled into JavaScript and HTML. EGL code that is expected to run on an application server (like Apache Tomcat) is compiled into Java.
  2. Build a complete application in one language (EGL). So, instead of coding server-side logic in one language (like Java or PHP) and client-side logic in another (HTML and JavaScript), with EGL CE, you can code the entire application in EGL. This allows you to learn just one language and not several. Another major benefit of this approach is that data is represented the same way in both server-side and client-side EGL code. So, for example, you can define a Record (a record is an EGL concept similar to a Java bean for representing some data object) once and reference in both your server-side code and client-side code. The record is automatically compiled into Java and JavaScript as needed. EGL handles the serialization and parsing of the actual data being transported (between the server and browser) so you don't have to worry about it.
  3. Completely code, test, and debug without deploying anything to an application server. The Preview tab of the EGL editor provides a running version of your application. When you switch to this tab in the editor, your EGL code is compiled on-the-fly. You can also set breakpoints in your code for easier debugging (EGL CE uses the standard Eclipse Debug tools and perspective). Best of all, you don't have to deploy services to a server to debug them.
  4. Transparent client/server development. With EGL CE, all code - both code that will eventually run as JavaScript in a browser and Java on the server - is developed in the same Eclipse project (of course, you can always develop in separate projects if needed). From within your UI code, you can directly reference and call services. Under the covers, EGL will create a REST service for your services and take care of the bindings necessary at runtime.
  5. Integrating with existing services. EGL supports calling existing SOAP and REST (JSON or XML) services. So, if you already have Web services up and running, you can use EGL to build a new UI. Within your EGL code, input and output to the service is represented as EGL variables or records. In the case of SOAP services, EGL will automatically create the input and output records for you - all you need to do it import the WSDL file.
  6. Data access. EGL makes interacting with databases simple. EGL provides simple keywords (get, add, delete, etc) to easily work with a database.
  7. Easy deployment. With EGL, you can fully develop and test your application before ever deploying it to a server. Once you are ready to deploy, however, EGL CE deploys code into a standard Eclipse Dynamic Web project. This project can be run on Apache Tomcat or packaged as a .WAR file and deployed to an external application server.

0 Comments Permalink
0

In the following picture we show how easy it is in EGL CE to change visual attributes for any widget using the visual editor. In this case we show 4 buttons, each with different attributes defining distinguishing features.

styling.png

To add styling to your Rich UI applications, EGL CE offers the following three modes:

  1. Direct Attributes. Edit fields on a widget directly, using the visual editor or in the source editor. This allows you to set things like borderWidth, backgroundColor, font, etc. The source editor comes with content assist and the visual editor has a property editor to choose the attributes from. Advantage of this approach is that you do not need to learn CSS. Disadvantage is that the styling is hard-coded in the widget, which makes global changes more difficult to implement.
  2. Style Setting. Set the 'style' field on a widget (using the source editor) to assign multiple CSS styles directly on a widget. An example is widget.style = "border: 2px solid black; color: blue; overflow-x: hidden". Advantage of this approach is to allow you to quickly test out a given CSS fragment. Disadvantage is the same as with direct attributes, and that the styling is hard-coded in the widget.
  3. CSS Classes. Set the 'class' field on a widget to a given CSS class name. Add a 'cssFile' parameter to the main handler and refer to a CSS file. In the WebContent directory, create a CSS file and edit the class definitions you want to have applied. Advantage of this approach is that it uses widely accepted CSS styling. You can have a designer in your team who never gets involved in actual EGL development write a CSS style sheet and define a company branding that is inherited across all the applications you develop. A disadvantage is that UI definition and styling are detached now, and may be harder to debug and/or get right. See below for more on that topic.

In practice, we advise people that are just learning EGL to start with mode 1. and use direct attributes. This will give them an idea of the possible attributes and their effects most directly. Once a development process matures, we recommend stepping to mode 3, and use CSS classes.

Note that the EGL widgets and the Dojo widgets use various styles for each of their widgets (and the subcomponents inside those widgets). This means that without any EGL coding, you can make widgets look differently by simply adding a new stylesheet to your application. Use the xray tool described below to figure out what styles are used, or consult the source for each widget by selecting the typename and hitting F3.

In two blog postings that were published before we launched EGL CE, in the EGL Rich UI blog, I talked about two tools that can help develop and debug your CSS.

The first posting, Writing with Style, shows the xray tool, which allows you to inspect any given element in the browser's document, so you can find out what CSS class, padding, margin, and borders it has. This is useful for making sure you did not make any typos when referring to certain style classes, for instance.

The second posting, A CSS Validator written in EGL Rich UI, discusses a CSS Validator which can be used to verify the CSS you are entering in your CSS files is conforming to the W3 standards. For this purpose we wrote a widget in EGL Rich UI that calls services to the W3 Jigsaw validator.

Have fun with styling your EGL CE programs and share your tips and experiences in a comment below...

0 Comments Permalink
1

In an earlier posting I mentioned the importance of using external style sheets to separate look and feel from behavior in EGL Rich UI applications. In practice, some EGL Rich UI users have experienced challenges in keeping the CSS syntactically valid. The CSS editors that come with Eclipse/WTP, and which we use without change in RBD, do not validate the CSS that is being edited inside them. And RBD does not add any extra help either.

Not having CSS validation in our tooling makes CSS error detection and debugging more difficult. The best technique we can come up with is to use Firebug in Firefox, but that requires quite some extra setup and work by the developer. A very useful online service called Jigsaw is also available at w3.org. You simply enter your CSS into a form, and the service will tell if it is valid CSS or not. Here is the service with an intentionally invalid sample:

css-validator.png

After pressing the "Check" button, you will see a result looking like this:

css-validator-result.png

While using the Jigsaw service, I was thinking that the Rich UI application that I was developing could easily validate itself by making a REST service call to the same Jigsaw service, passing its own CSS files as an argument. So, I wrote an EGL Rich UI widget (without needing any JavaScript, of course). It basically does the following:

  1. Inspect the document body, and find all elements with tag name equal to "LINK".
  2. Download each CSS file and send it to the CSS to the Jigsaw service.
  3. Parse the result by finding all the "td" elements with class equal to "parse-error" (which is how Jigsaw reports its errors).
  4. If we find any error, report them. Otherwise, be silent.

After including the widget into our EGL Rich UI application that uses the bad CSS, we now see an error message appear automatically when we run the application:

http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/downloadImage/38-1112-1190/css-error.png

The widget itself defines a VEWidget annotation, so you can easily drag and drop it from the palette in the visual editor (make sure to hit the "refresh palette" button on the design toolbar). Here is how the widget can be used:

handler CSSErrorsDemo type RUIhandler { 
		initialUI = [ validator ], 
		includeFile="css/bad.css" // located in WebContent directory!
	}
	validator css.CSSValidator{};
end

The actual widget is shown below. Copy it to your workspace, feel free to rename the package name. Let me know when you find any problems with it.

1 Comments Permalink
0

For those of you who are learning about EGL, here is an overview of EGL projects to help you get started...

A project is a container for a group of related files. An EGL project is an enhanced project that you will be using to hold EGL source files in your application.

The structure of an EGL project is simple. By default, it contains two top-level folders, EGLSource and WebContent. You should create all EGL source files under the EGLSource folder. EGL will generate these source files into JavaScript or Java, depending upon whether the code will run in a browser or on an application server. You should create all Web resources such as cascading style sheets, images, and icons under the WebContent folder. EGL will deploy these Web resources with your HTML file.

You can use EGL to develop both client-side and server-side code by doing the following:

  • Define a Web page that runs in a browser by creating an EGL Rich UI handler part
  • Define business logic that runs on an application server such as Apache Tomcat by creating an EGL service part
  • Define data and logic in EGL records and libraries that can be used by both Rich UI handlers as well as by services.
Within an EGL project, we recommend that you use packages to separate your client from your server code. At deployment time, you can use EGL deployment descriptors to control which parts to deploy and which Web projects to deploy to.

You can define your Web application code in either a single EGL project or in multiple ones. If your application is small and will probably not contain code that will be shared by other applications, putting your code in a single project provides simplicity and ease of use. On the other hand, if your application is complex, you can use multiple projects to help organize your code and allow parts such as libraries, records, and services to be easily shared across projects.

When programming in EGL, you only need to be concerned about EGL code, not about generated Java, JavaScript, or HTML. Therefore, resources containing generated code do not show up in your project when using the Project Explorer. If you want to see these resources for some reason, you can do so by using the Navigator view.

Creating an EGL project

When you are ready to develop some code, begin by creating an EGL project to hold your files. There are several ways to invoke the New EGL Project wizard:

  • Click on the New EGL Project icon newegl_wiz.gif, fourth in the toolbar
  • Click on File > New > EGL Project
  • Right click in the Project Explorer. Then click New > EGL Project.
NewProjectDialogL.JPG

In most cases, you can specify a project name in the New EGL Project dialog, and click Finish.

Setting project dependencies

When you create a new project, the New EGL Project wizard adds two project dependencies - com.ibm.egl.rui_1.0.2 and com.ibm.egl.rui.dojo.runtime.google_1.3.2 - by default. These projects are already loaded into your workspace; you can see them in the Project Explorer. These dependencies allow the EGL Rich UI and Dojo widgets to be accessible from your project when you develop a Web page using an EGL Rich UI handler.

If you need to reference additional EGL code in another project, you need to add a dependency on that project. To do so from the New EGL Project wizard,

  • Click the Next button after specifying a project name.
  • On the EGL Settings page, select the additional project that this project will reference. In this example, it is reallyUsefulProject.
  • Click Finish.
EGLSettingsL.JPG

Your new project can now access code in reallyUsefulProject.

You can add a new project dependency in an existing project as well. To do so,

  • In the Project Explorer, right click on your project name, like myProject, then click Properties.
  • Click EGL Build Path.
  • Select the project that myProject will reference, like reallyUsefulProject.
  • Click OK.
EGLBuildPathL.JPG

In myProject, you can now use code from reallyUsefulProject.

I hope that you have found this introduction to EGL projects helpful in getting started. Stay tuned to this blog for upcoming posts on useful topics such as developing with Dojo widgets, defining and calling services, and deploying EGL projects. Have fun trying out EGL CE!

0 Comments Permalink
2

When developing browser applications, you will sooner or later want to call a service to download some data. That service itself is encoded in either SOAP or REST, and can reside at either the same server where the UI came from, or be at a completely different server. EGL hides all this complexity and generalizes the access and encoding of services into a clean and easy to use abstraction.

What is an Ajax Proxy?

The following picture would be a practical situation:

proxy.png

In the above sample we show a EGL Rich UI application that is served up from a given web server. While executing, it makes service requests to 3 services, one of which is located on the same server it was hosted on, and two services from other servers.

To understand what a proxy is, let’s look at this online definition at dictionary.reference.com:

1. the agency, function, or power of a person authorized to act as the deputy or substitute for another.
2. the person so authorized; substitute; agent.
3. a written authorization empowering another person to vote or act for the signer, as at a meeting of stockholders.
4. an ally or confederate who can be relied upon to speak or act in one's behalf.

In our case, the Ajax proxy takes care of routing the service requests to local or remote services. It can handle SOAP and REST. It is also able to deal with HTTPS tunneling to authenticate to remote services, for instance. It acts on behalf of the program running in the browser to call services on its behalf.

Why an Ajax Proxy?

But, why do we actually need a proxy at all? The reason is the so-called same origin policy, implemented by all web browsers, and that aims to avoid cross-site scripting attacks. It basically ensures that JavaScript hosted on server A can only make Ajax calls to services directly defined on server A, and not on server B or C. A spoofing hacker would love to be able to load his or her JavaScript in your web page, and later make service calls to completely unrelated servers to send them all your cookies and passwords, for instance. To overcome this policy, so that we can actually make a mashup, an Ajax proxy is needed.

It is not just EGL that needs an Ajax proxy. This is a common requirement for Web 2.0 frameworks. A Google search on Ajax Proxy yields over 2 million hits, for instance.

During development, both RBD and EGL CE have an Ajax proxy running right in the IDE. This allows you to call third party services while previewing an EGL Rich UI application in the IDE.

When you deploy an EGL Rich UI application to WAS or Tomcat, which are the supported modes, the EGL tooling will automatically generate an Ajax Proxy servlet and transparently publish it for you, right next to the deployed application. The servlet is implemented in Java (actually it’s really small).

If you want to deploy your EGL Rich UI application yourself to a server without using Tomcat or WAS, an alternative proxy is needed. Alternative are to use a proxy written in PHP (for a LAMP stack) or RPG (for IBM i).

How about Security?

Finally, a few more words on security…. As the EGL tooling puts the Ajax proxy in place to allow browsers to make cross-site calls, it is potentially opening you up for a security attack. For critical applications, the proxy should be secured using JEE security. Furthermore, the proxy should filter the set of third party services it supports, to avoid injected code calling third party rogue services.

Currently, the Ajax proxy used by RBD and EGL CE is not published API, but here is something that may work for you. Once you created a web project to deploy your Rich UI application to, locate its (Java) src folder. In that create a new package called com.ibm.javart.services. In that package, create a new Java class called FilteringAjaxProxy and insert the following code:

package com.ibm.javart.services;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for filtering Ajax proxy
 *
 */
 public class FilteringAjaxProxy extends RestServiceServlet {
	 
	//
	// The function that allows filtering of the URL
	// 	 
	private void applyFilter(HttpServletRequest httpServletReq) {
		if (!httpServletReq.getServerName().equals("localhost")) {
			throw new IllegalArgumentException("Filtered URL: "+httpServletReq.getServerName());
		}
	}
	
	//
	// Overloaded methods from RestServiceServlet
	//
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		applyFilter(req);
		super.doPost(req, resp);
	}
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		applyFilter(req);
		super.doGet(req, resp);
	}
	protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		applyFilter(req);
		super.doDelete(req, resp);
	}
	protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException	{
		applyFilter(req);
		super.doPut(req, resp);
	}
}

Inside the applyFilter method you can do whatever filtering you want. In this sample, I simply limit all Ajax calls to target only localhost. Use content assist on request to see what other things you can filter on, such as port number.

Then edit the web.xml for this project (under WebContent/WEB-INF). Make sure the ajax proxy is configured as follows:

<servlet>
	<display-name>EGLRichUIProxy</display-name>
	<servlet-name>EGLRichUIProxy</servlet-name>
	<servlet-class>com.ibm.javart.services.FilteringAjaxProxy</servlet-class>
	<load-on-startup>-1</load-on-startup>
</servlet>

Just be aware that RestServiceServlet is internal API and is subject to change.

2 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
1

Once you download and run Rational EGL Community Edition, you'll notice the Welcome page which provides useful information about the product and links to tutorials, samples, and Web resources.

You'll also notice some projects are loaded into your workspace. These projects contain the widgets for EGL Rich UI and Dojo, as well as samples of how to use the widgets. Explore the com.ibm.egl.rui.samples.ce project, by opening the contents.egl file under EGLSource>gallery and clicking on the Preview tab. Similarly, you can start exploring the com.ibm.egl.rui.dojo.samples project by opening Gallery.egl under EGLSource>dojo.sample. The Preview tab allows you to interact with the running application. You can make changes and see them in action, without having to deploy to a Web application server. Using the Preview can really help speed up your development.

Once you've had a chance to explore the samples, create your own EGL project. More on EGL projects in a later post...

We hope you'll find EGL easy to learn and use!

1 Comments Permalink
0

Welcome to the official developer community site for EGL Community Edition! The goal of this site is to provide you with the information you need to download and successfully use EGL Community Edition.

If you run into a problem, visit the Support and Help page to find out where to get help.

Thanks for visiting! And happy programming ...

Will Smythe

0 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

Okay, this was a lot easier than I expected. I'm not saying it didn't requier a little research; the QzhbCgiParse API is not for the faint of heart. But a little research, a little careful reverse engineering, and I was able to create a program that responds to a Rich UI REST request. And it takes nine lines:

QzhbCgiParse( '-v Cust': 'CGII0100': cust: %size(cust):
              bytesRead : dsError);
if (bytesRead > 1);
  cust = %subst( cust: 1: bytesRead-1);
endif;

data = 'Content-Type: text/html' + CRLF + CRLF;
QtmhWrStout(data: %len(data): dsError);

data = '{"result" : "' + 'Name-' +
       %trim(cust) + '"}' + CRLF;
QtmhWrStout(data: %len(data): dsError);

return;


The simplicity of the code is rather impressive. The first line gets the data from the URL, the next three strip off the trailing LF that QzhbCgiParse insists on giving you. The next two lines send the header, the last two send the response formatted as a JSON string. That's all there is to it. There are obviously a couple of prototypes, and the ubiquitous error data structure that is familiar to anybody who codes API calls in RPG, but those can be /COPY'd in. The meat of the code is the eight lines above (nine counting the return).

The code in the test program is even simpler:

testService testService { @RESTBinding
  {baseURI = 
    "http://IRUIHOST/cgi-bin/RUIT1.PGM?Cust=77654"}};
call testService.getName() 
  returning to ts1listen
  onException ServiceLib.serviceExceptionHandler;


It's a standard REST call, except I change the baseRUI to pass the parameters. Now, I haven't gotten around to figuring out how to pass the parameter via the actual method call, but for this particular proof of concept I don't care about that. The point of this exercise is to prove that anything you can do with "traditional" EGL - that is, a web service written in EGL and deployed in an application server that calls an RPG program - can be done using nothing but the Powered by Apache server and standard RPG-CGI - that is, no Java, no WebSphere, nothing you wouldn't have to know for any other approach. You just have to learn the EGL Rich UI syntax.

Now, I wouldn't recommend this approach since if you can write EGL Rich UI you can write host-based EGL just as easily, but if you absolutely cannot run WebSphere or Tomcat, then this will allow you to still use EGL Rich UI.

Nifty, huh?

Let me clean up the example to something a little less trivial and I'll post this project, probably tomorrow sometime. As I noted at the beginning, I'm doing this solely in my free time and I used up most of that time tonight writing this blog post :).

0 Comments Permalink
1 2 3 4 5 ... 16 Previous Next
Bottom Banner