What you'll learn
Using IBM's WebSphere Development Studio Client version 5 (WDSC) you will do the following:
- Take an RPG server program, create a Java Program Call bean, generate a Java Web application using the Web Interaction wizard.
- Test the generated Web application using the built-in WebSphere test environment.
This tip is derived from a QuickWebTip. You can download the entire tutorial at www.quickwebsupport.com.
Where you can use this
It makes a great deal of sense, and usually saves a ton of money in the short term and long term, to leverage your existing, proven business application logic by reusing those host applications (RPG, Cobol, etc.) in your e-business applications. IBM's WDSC tools offer the fastest, easiest way to Web-enable your existing applications for e-business.
The Web Interaction wizard in WDSC is a great tool that Web-enables any type of iSeries server application or Java bean easily. If you're building a Java Web application for users or a Web services application, this tool is key to creating those applications rapidly.
There are many alternatives to using the Web Interaction wizard for creating calls to RPG programs in Web applications. Many of the ones outside of WDSC require buying a special tool OR having a very high Java development skill level. Within WDSC, you could also use the Program Call bean wizard to create a program call bean and write your own JSP and Java code to invoke the Program Call bean and return the response, but that would also be more work.
Other options include using TCP sockets to call a host program or JDBC Stored Procedures. IF you need to return a result set to your Web page to navigate a set of rows, then Stored Procedures is definitely the right answer.
We use both Stored procedures and program call beans frequently in Web applications. The Web Interaction wizard can use both easily to build Web applications that call iSeries server programs.
What you'll do
In this simple example, we'll use an existing RPG and CL program we've created and Web-enable them with the Web Interaction wizard.
You'll do the following in this WDSC lab:
- Create a Web project
- Use the Web Interaction wizard to: * Create a program call bean * Generate a Web application using the program call bean * Test the application using the built-in WebSphere test environment
The sample RPG program used here simply does the following:
- Receives a library name, an employee number and an initial total pay value of 0
- Looks up the employee and calculates total pay from salary, commission and bonus
- Returns the updated total pay value and a status code
Skills you need
It is assumed you are an experienced iSeries developer in RPG or Cobol. You should be familiar with WDSC basics on using the workbench (take the tutorial in the online help first). And it helps to understand HTML, Java Web applications, Web application servers, HTTP servers, etc, but it's not necessary to build and test the sample WDSC applications.
What you'll use
To build the sample application, you'll need to do the following:
- Have an iSeries server at V4R5 or later with the proper group PTFs applied. (See http://www-3.ibm.com/software/awdtools/wds400/support/ for more information.)
- Install the WebSphere Development Studio Client on a Windows workstation (XP or 2000) with 512 MB (or more) of memory.
- Have a TCP connection to the iSeries server.
- If needed, in WDSC use the online help to access more detailed documentation on how to run a Web Interaction where needed.
You may use the sample database file definition and the CL and RPG program source definitions I used on the host end. Click here for Appendix A: EMPLOYEE table DDS source, and click here for Appendix B: Server source code.
The Web Interaction wizard actually does a number of tasks to generate Web applications and Web objects needed for different types of Web applications for many different development scenarios.
It can be used to create program Call beans that call existing iSeries server programs in RPG, Cobol, etc or to generate a Java Web application using a program call bean or a Java bean.
Also, the Web Interaction tool can be invoked from a Web diagram if you're building a Struts application. Then it can be used to generate the code.
Another way to use the Web Interaction tool is to create or import the Java Server Pages (JSPs) you want and then let the Web Interaction tool build the Java code to run the application.
The Web Interaction is a well-designed tool. It creates a .wit object that stores all the metadata for your Web Interaction. That's all of the input you gave the tool to define a Web application. What's the advantage? You can modify or enhance your application without re-entering any of the original data by opening up the Web Interaction using the existing definition. Many generators force you to recreate an application from scratch, but the Web Interaction saves all your work.
Build the example
To build our Web application that calls the employee pay inquiry RPG application we will do the following:
- Create a Web project
- Define the iSeries server for the Web project
- Create the Web Interaction definition using the Web Interaction wizard
- Run the generated Web application in the WebSphere test environment
1. Create a Web project
- Open the Web perspective
Click perspective icon on the Workbench and Web Java perspective to open
OR Workbench > Perspective > Open > Web
<< The Web perspective opens with a package view on the left.
- Create a new Web project named: ctw62
Click the new icon and select Web project as the type to create and click Next
OR Workbench > File > New > Project > Web > Web Project
<< The Project page opens
Enter the project name: ctw62, click create CSS file and click Next
<< The Project configuration workbook opens showing source, projects, libraries
Browse the information on each page and click Finished
<< The Web project is created and displayed in the packages view
2. Define the iSeries server for the Web project
Web projects that access iSeries servers can have a default iSeries server defined for Program Call beans and the related Web Interaction.
We'll select an available iSeries server to run our server program. If you're connected on your network to more than one iSeries server, select the one that has the right program and library you want to run.
Open the iSeries server connection property sheet:
>>Workbench > File > Specify iSeries Web Tools run-time configuration
<< The iSeries server configuration property sheet opens
>> Enter the specific information to connect to your iSeries server:
3. Create the Web Interaction definition
Create the Web Interaction header
We'll create a definition that defines the Web Interaction name, a package to store the generated Java classes and the options for this Interaction:
- Use a Program Call Bean or a Java Bean as input
- Import existing PCML (Program Call Markup Language) definition if it exists already
- Add existing JSP server pages or create new ones for input and output
On the next page, specify whether you are generating new JSPs for input and output or reusing existing ones.
Add the program definition to the Web Interaction
The program definition page prompts you for the name of the program object you want to run. (In this example I'm using a CL program that receives parm values, sets a library list and calls an RPG program. See the Appendices in the full tutorial for source code for both). If you want, click browse to search your iSeries by library to find the program object. You can also elect to see the source code to review the parameters by entering the source code name at the bottom of this page. This will open a separate viewer with your source member displayed for reference on the parameters.
Add the parameters for the Web Interaction
For each parameter in the program, we define its characteristics (e.g., packed decimal 9, 2, etc) and its usage (input, output or both) in the Web Interaction.
Define the input JSP page
Since we are generating new JSPs, a prompt opens to define our input page with a title and the input parameters we need. You can easily change the page attributes in the editor.
Define the output JSP page
The output page is defined like the input page.
Note the default title is Result Form, and we are changing the title in the properties box to: Employee Pay Query Results. All the default prompts in the wizard for your application are easily modified.
Completing this task, we click the Finish button and the application is generated. We produced JSPs for input and output results, Java beans for the Web action, the input form data, the output form and the program record format and, finally, a Web Interaction metadata object (here iwiGetPay31.wit). The wit object allows us to make modifications to a Web Interaction in the wizard without having to make low-level changes in code -- a very nice feature.
4. Run the generated Web application in the WebSphere test environment
Now that we've generated our application, we need to test it. This is even easier than building the application. It's a one-button exercise to run our application in a default WebSphere test environment.
We select the input page for our application (here iwiGetPay31.jsp ), RB menu and Run On Server.
From here, WDSC takes over and does the following:
- Creates a default WebSphere configuration
- Creates a WebSphere server instance
- Publishes our application to the server instance
- Starts the server instance running
- Loads our application and opens our JSP input page in a test Web browser
(Don't you wish you could add buttons in REAL life that did as much and worked as easily as 'Run On Server'?)
WDSC includes a number of runtime J2EE application server test environments, including WebSphere version 5, version 4 and WebSphere Express version 5. In addition, you access remote Web application servers for testing (WebSphere on your iSeries server, Tomcat locally or on the iSeries, etc). Testing is now a breeze.
Enter the employee input to get the total pay for:
The application connects to the iSeries server, calls your program, processes the request and returns the results to the output JSP page:
First, remember Web Interaction (built by the IBM iSeries development team in Toronto) is a little different than many other wizards in WDSC. Many of the others support one development scenario and only generate an application. Maintaining the application in many other wizards is not possible, so you're left to do Java coding. The Web Interaction wizard is different on both counts:
1. Multiple development scenarios supported: Creates a Web application for an iSeries program OR a Java bean, uses existing JSP pages or generates new ones.
2. Roundtrip engineering: Maintaining the application in the wizard is possible because the wizard generates a metadata object (a wit file -- here iwiGetPay31.wit) that stores all your custom information.
In the larger perspective this tool is valuable for two reasons:
- It reduces the skill levels needed to integrate existing iSeries server programs into Web applications
- It ramps up the productivity of a development project significantly.
The goal: Avoid coding more than necessary
A key goal for IT on any project should be to avoid coding more than necessary. In most iSeries companies the business runs on existing iSeries server programs in RPG and Cobol as package applications or custom software. Even if you like Java better than these languages for developing applications, it's smart to avoid building logic in Java that already exists and is reusable. The Web Interaction tool makes ANY server program reusable for e-business applications with the exception of the 5250 programs. (You have the WebFacing tool for that.)
If you compare the cost of using the Web Interaction tool to access existing business logic on the iSeries server vs. writing new application logic (even given the best tools and developers), it's a no-brainer that reuse is FAR less expensive.
Avoid the wrong WebSphere development solution
And what have we seen WAY too much of in the past? A number of iSeries IT managers assumed that e-business was NOT RPG or Cobol. As a result, they went out and hired excellent J2EE consultants to build Web applications. Were the J2EE consultants iSeries experts? No. Did they know about the iSeries version of the WebSphere Studio tools (WDSC)? No. So they use the more common tools: WebSphere Studio Application Developer. What's missing? All of the iSeries integration components you get in WDSC.
Did they know how to connect to an iSeries server from a J2EE application? No. So they assumed you needed MQ to connect to an iSeries server. Wrong one more time. MQ correctly DOES have a place in some iSeries e-business environments, but more often than not, it's incorrectly used. WDSC includes all the tools you need to take your iSeries server and Web-enable all the applications, data and many of the platform services productively.
What you learned
You learned that WDSC is the right choice for an iSeries customer to build e-business applications. You know easily how to create simple Web applications that call RPG or Cobol server programs easily. You know how to build Web projects with lower skills quicker now that reuse your existing applications well. A great accomplishment!
- For more on WDSC version 5, visit www.ibm.com/software/ad/wds400.
- Try the WDSC online documentation
- To get the full tutorial for this QuickWebTip and for more WebSphere Developer Studio for iSeries support, check out www.quickwebsupport.com.
---------------------------------------About the author: Jim Mason, president of ebt-now, is an iSeries WebSphere engineer. ebt-now provides iSeries WebSphere, WebFacing project management, engineering, development and training services. For more tutorials, visit www.quickwebsupport.com.
- Options for debugging Java applications
Debugging applications isn't usually an important consideration when you're deciding on application architectures or requirements. It's one of those items that becomes critical during development if you haven't planned ahead. With Java, iSeries developers usually have a good choice of debugging options. You can select the one that best fits your debug requirements. Web development expert Jim Mason points out your options and some considerations for getting started.
- Basic WebSphere troubleshooting concepts
If you're new to WebSphere, you're sure to come upon some problems that you need help figuring out. This tip introduces WebSphere basic concepts and a simple process to help identify some WebSphere configuration problems quickly.
- Seven steps to a Java Web database application
t would be great if iSeries programmers knew how to use Java to create e-business applications, but programmers can still forge ahead if they aren't trained in Java yet. WebSphere tools make it easy, and Jim Mason and Dave Slater show you just how easy it can be.
This was first published in April 2003