Newsletters Subscriptions Media Kit About Us Contact Search Home

Stuff
OS/400 Edition
Volume 2, Number 8 -- April 10, 2003

Distributing iSeries Java Applications with Web Start


by Marc Logemann

[The code for this article is available for download.]

Many iSeries programmers are not used to worrying about the distribution of software, because native RPG software runs in a host mode. This means the software is on the server and all clients call the same software on the server again and again. The result is that only the screen output will be transferred to the client. The design is so good that companies like Citrix Systems make a good living by "recreating" this host feeling on windows when it comes to software.

These days, many companies running their business on iSeries machines are converting RPG or COBOL applications to more modern languages. The main porting target is, of course, Java. But with this transition, the issue of distribution comes up again, at least when they want to program GUI applications. Of course, there are Microsoft Windows-based software distribution systems available, like Microsoft Systems Management Server or LANDesk, where you can package your software and distribute it to clients, but this is not the preferred way when it comes to Java applications. Sun Microsystems has created a very sophisticated framework for doing things like distribution, and it has security features as well. And it comes with full Web compatibility. Sounds good? Then join me as I introduce you to Sun's Java Web Start.

What Is Java Web Start?

Java Web Start is a technology that simplifies the deployment of Java applications. You can start full-featured applications like CRM or calculation programs from your Web browser without going through complicated installation procedures. This means you can create a portal of applications, for instance, which the user should have access to, then the user just picks the application by clicking it, and if this is a first time triggering of the application, the software will be automatically downloaded and started on the desktop. The user can also choose to create a desktop icon, and the complete application will be put into a cache for faster startups in the future. If the same user clicks on the application link, or clicks the desktop icon some other day, the application checks its actuality with the server; if nothing has changed, it loads the application from the cache. If the programmers changed something in the software, the application will be updated and the user will see the most recent version of the software.

Set Up Your iSeries as a Distribution Server for Web Start

The iSeries is a perfect candidate to act as a distribution server for Java applications, but there are some things to set up before you can play the game. First you need a running Web server, because Web Start--more precisely, the underlying protocol, JNLP (Java Network Launch Protocol)--interacts with a Web server to initiate the download. The following description focuses on the Apache Web server that comes with the iSeries. If you are still using the original IBM Web server on the iSeries, you should consider changing to the Apache server. IBM recommends it, and in the long run I expect that the original Web server will be discarded. But if for some reason you want to stay with IBM's proprietary Web server, you should also be able to run Web Start.

First you start the administration instance of the Web server. This can be done with the following command:

STRTCPSVR SERVER(*HTTP) HTTPSVR(*ADMIN)

Then open your browser and point to your iSeries IP or DNS name on port 2001. Your browser URL bar might look like this: http://my.iseries.com:2001. After a browser login window, where you should enter a valid iSeries user with *IOSYSCONFIG rights, you should then see the iSeries Tasks screen (Figure 1).

Figure 1

Figure 1: Configure the iSeries Web server

In the HTTP Server configuration section, you will find a default instance of the Apache Web server with the name APACHEDFT. If this instance is not selected in the Server combo box, select it. Then click the item Add a directory to the Web, under the section Tasks and Wizards. For different release or PTF levels of the iSeries, the names of the menus can vary; if you cant find it, look for something like new directory wizard. The first screen asks you what type of information this directory should include. Use the first option: static web sites and files. Then you will be prompted for a directory location; enter /www/apachedft/htdocs/webstart and click Next. The directory will be created by the wizard. In the next screen you have to enter an alias for this directory; just use /webstart/. You have to confirm the entered data, and the rest is done by the administration interface. When you are finished, browse the iSeries IFS and look for the /www/apachedft/htdocs folder. Inside that folder you will see a newly created webstart folder, with a sample index.html file in it. If you are done, restart the server, so the changes will take effect. You should test your changes by pointing your browser to http://my.iseries.com/webstart/. Again, my.iseries.com should be a valid DNS name to your iSeries or the IP address itself. If everything went well, you should see an IBM sample Web page. Now you have to configure the MIME types for this special folder, which is where the Java applications and descriptors will reside. In your http configuration screen, choose folder /www/apachedft/htdocs/webstart, in the server area combo box at the top of the screen. In the left menu, select the content settings item in the Server Properties menu. You have to add the MIME types (Figure 2). (Again, the path to the correct screen can vary based on the installed operating system level on your iSeries. These examples are based on a V5R1 installation with the latest PTFs installed for the Web server parts, so the examples should look like a V5R2 environment. It seems that with an out-of-the-box V5R1 machine, you must look for Content Negotiations, under the Processing Requests headings.)

Figure 2

Figure 2: Add the MIME types

Look at the last three MIME types; these must be present. Because my iSeries is configured for the German language, Figure 2 has German titles, but you should get it by comparing the columns with your version. It's important to know that the word inhaltstyp must be contenttype in English, and that hinzufugen is add in English.

Now the Web server is configured for Java Web Start. To be sure everything is in place, you can view the Apache configuration file at the bottom of the left menu, at the view configuration file item in the Tools menu. Within the configuration file, there must be a section like this:

   <Directory /www/apachedft/htdocs/webstart>
        Order Allow,Deny
        Allow From all
        DirectoryIndex index.html
        AddType application/x-java-jnlp-file .jnlp
        AddType application/java-archive .jar
        AddType text/vnd.sun.j2me.app-descriptor .jad
   </Directory>

Just focus on the AddType attributes. If these are the same on your output, everything should be in place and we've finished configuration of the Web server.

(For all those not using the Apache Web server on the iSeries: You can administer the original IBM Web server with the very same Administration instance. You have to choose the DEFAULT – Original item in the Server combo box and search for an item called folder symbols in the menu folders and welcome site. Keep in mind that, regardless of which Web server you use or how you configure it, you have to define the three mentioned MIME types.)

A Simple Web-Start-Ready Java Application

Because this article doesn't focus on the application development itself, I will use a very simple application, showing a Swing-based GUI with some iSeries data, like "Version, Release, Modification Status" or "last signon date." The data will be gathered from the iSeries with the JTOpen library from IBM.

As you can see in the attached source code, programming a Java application that should be deployed by Web Start is not much different from programming a stand-alone Java application. You just have to be aware that you need to sign the resulting JAR file, because the security has a strong focus on Web Start. This, as you can imagine, is necessary in order to avoid the deployment and execution of malicious software on your computer. Remember that with Web Start the installation and execution of a program is just one browser click away. With the signing and security processes embedded in Web Start, the program asks for specific permissions before first startup of the application, so that you can be sure what the program is permitted to do later on. The reason why you have to sign your application is that you must establish a Sockets connection to your iSeries in order to retrieve system status. The process for loading resources, such as images, is different.

In this simple application, which consists of only one class, you will only create an AS/400 object with given authentication data, like user name and password, and receive some data that you will display on a Swing GUI. One thing you should know is that loading images is done through a classloader and the images themselves must be in the resulting JAR file of your application; see the following line:

ImageIcon weheader = new ImageIcon(getClass().
   getResource("/images/weheader.gif"));

With the getResource() method of our current class, you activate the classloader to load the GIF file from the JAR file. In this case, there must be an image folder in the JAR file with the specified GIF image file in it.

The do400Call() method just connects to the iSeries with the AS/400 object and presents the received data on a JPanel. But when you look very closely at the constructor of the AS/400 object, you will notice that I use command line parameters to connect to the machine. This is for two reasons:

  1. I am not weird, and code my authentication details from my machine into this code.
  2. You can change the authentication data to connect to your machine without recompiling the code.

But where do you define the command line parameters? That's easy. The major descriptor file, when it comes to Web Start, is the JNLP file. We'll go through it in the next section.

The JNLP File for Your Web Start Java Application

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://my.iseries.com/webstart/" 
 href="mpowebstart.jnlp">
  <information>
    <title>MPOWebstartExample</title>
    <vendor>Marc Logemann</vendor>
    <description>Webstart Example for 
   itjungle.com</description>
    <offline-allowed/>
  </information>
  <security>
   <all-permissions/> 
  </security>
  <resources>
    <j2se version="1.4"/>
    <jar href="mpowebstart.jar"/>
    <jar href="TableLayout.jar" download="eager"/>
    <jar href="jt400.jar" download="eager"/>
  </resources>
  <application-desc main-class="MPOWebstart">
    <argument>100.100.100.100</argument>
    <argument>myusername</argument>
    <argument>mypassword</argument>
  </application>
</jnlp>

I will discuss the contents of the JNLP very briefly; for a full description of what is possible, check Sun's Web Start/JNLP specification.

It's important to define the code base of the JNLP file. The URL should be the same as the one we used to check if the Web Start folder was successfully created in the Web server. The href attribute should be the name of the JNLP file itself. The security tag indicates that we want to have all-permissions. You can fine grain the levels of security needed by the application, of course. The resources tag is very important and defines all the necessary Java archives to run this application. In our case, the application itself, with all of its resources, is archived in mpowebstart.jar. Because we also need two third party libraries, we have to add the other two JAR files as well. With download=eager, we define that the classes should be loaded on startup. At the end, we define the main class of our application and the command line parameters, as discussed before. You should provide a valid IP address to your iSeries and a correct user name and password combination for the system.

You have to place the following files into the webstart folder of your Web server:

  • the mpowebstart.jnlp file
  • the three Java archives defined in the JNLP file
  • an index.html with the following content:
<html><body><h1>Download Page</h1>
<a href="mpowebstart.jnlp">Start MPOWebstart 
   Application</a>
</body></html>

Ready to Go

Now you can point your browser to the created index.html file, with a URL like this: http://my.iseries.com/webstart/index.html. Then click the link on the page. Web Start should then be triggered on your client, and the application will be downloaded and started. Figure 3 shows what you can expect to see.

Figure 3

Figure 3: Web Start launches an application

Be sure that you have a recent Java Runtime Environment on your client computer; you can download the Java Plug-in from Sun's Web site without a hassle. This is just a very basic demonstration of what Web Start can do for you.


Marc Logemann is a senior e-business consultant at Spirit/21 AG, a German consulting company that focuses on iSeries services and development. Marc is involved in Java- and PHP-based open-source projects and likes reading books about new technologies. E-mail: ms@logemann.info


Sponsored By
DRV TECHNOLOGIES

DRV Technologies announces a new tool -- Add PCL

now available in SpoolFlex v1.6

The SpoolFlex suite of spool management tools just got better! Now with the addition of the Add PCL tool, you can control many printer output functions at the spool page level. With the ability to add PCL commands to a spooled file page based on user-defined conditions, you can now perform tasks such as calling electronic form overlays, selecting source drawer and output bins, and even specifying the number of copies, page by page -- all without custom programming.

COPY ♦ MOVE ♦ DELETE ♦ SORT ♦ SPLIT ♦ EMAIL
♦ CONVERT ♦ MONITOR ♦ INTEGRATE

and now. . .Add PCL commands

Suppose you print checks and need one copy on laser check stock, but the other copy on less expensive paper. Now with the Add PCL tool, you can control which spool pages are printed from which source drawer - copy one can print on laser check stock from drawer one, the accounting copy can print on yellow stock from drawer two.

Suppose you have an electronic forms package that requires you to alter your spooled file by adding PCL commands to call and merge the overlay with the spooled file. Now, without custom programming you can add those commands and control which macro is called on a page by page basis. Based on user-defined data, you can control which overlay is merged with each page.

Suppose you have a spooled file that contains General Ledger detail and summary information. You need 3 copies of the summary pages, but only one copy of the detail pages but because they are all in the same spooled file you have to print pages you don't want. Now with the Add PCL tool, you can control how many copies to print on a page by page basis.

Add PCL is only one tool, but as you can see has many applications. But, combine the Add PCL tool with any of the other SpoolFlex tools and you can perform almost any spool-related task you can think of.

If however, you need a feature or function that is not included in the existing tools, send us your request and our staff will promptly review it for future versions. The Add PCL tool is a direct result of customer requests.
We welcome your input!

April Special

Now you can get the complete SpoolFlex Suite of tools including Add PCL
for only $2,995

(a savings of over $5,000)

Visit www.drvtech.com/addpcl.htm for a FREE 30-day trial


THIS ISSUE
SPONSORED BY:

Profound Logic Software
ASNA
DRV Technologies
WorksRight Software


BACK ISSUES

TABLE OF
CONTENTS
Calling Java from RPG: Beyond the Basics

Just Push a Button to Get AS/400 Query Results in Excel

Distributing iSeries Java Applications with Web Start

An Alternative Method of Serving Web Pages from AS/400


Editors
Shannon O'Donnell
Kevin Vandever

Managing Editor
Shannon Pastore

Contributing Editors:
Howard Arner
Raymond Everhart
Joe Hertvik
Ted Holt
David Morris

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com


Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.