• No results found

HTML to Host sample program

Chapter 3. XML Legacy Gateway

3.3 HTML to Host sample program

Host Publisher 2.2 provides a sample program that shows you how to use the XML interface to write servlets that can interact with host applications. You

The XML Gateway feature is a runtime function only and it does not require you to use the Host Publisher Studio.

can modify this sample to create a servlet that manipulates host application XML data-handling techniques. To do this, the sample code uses two Host Publisher-supplied JavaBeans.

• The first bean is called HostConnection bean, and it allows a program to acquire and release session beans using the Host Publisher Server runtime environment.

• The second bean is called the xmlAppData Bean, and it provides the XML interface to the host application windows.

The sample code uses these two beans and the XSL processor that comes with IBM WebSphere to translate the XML data into HTML format. This transformation can give you insight into how you can use XSL processing to render XML data on devices that have different display criteria.

The sample code implements a subset of the functionality that comes with the Host Publisher XML Legacy Gateway feature. This feature allows users to view and interact with host application windows in a Web browser.

3.3.0.1 Sample servlet

The sample servlet renders host data windows in an HTML format and posts these windows to a Web browser. This sample is a subset of the servlet which Host Publisher uses to perform that same function as part of the Host Publisher XML Legacy Gateway feature. As such, the sample has been simplified to provide the Java programmer with the essentials for creating an application that can interface to host application windows using an XML interface. The source code is provided in the SDK and is documented throughout with comments so the programmer can understand the necessary steps involved in writing similar servlets. This sample displays every host application windows to the user.

A more typical application may want to drive several application windows automatically, and only display to the user a few pieces of data from the host application windows. The user may then input data into the HTML form and then the application can drive more host windows with this input, and so on. The general flow of the servlet processing is as follows:

1. The user first accesses the servlet, causing the xmlLegacyGWSample servlet to be instantiated and the doGet method to be invoked.

2. The servlet receives the host connection parameters via the parameters passed with the URL.

3. The servlet sets up a hashtable to store these values, along with other initial values. This hashtable is stored in a vector, which is then stored in a

static hashtable. The key value for the vector in the static hashtable is the Web session ID. This allows for multiple instances of the servlet, for the same Web session ID, to be easily manipulated.

4. The doGet method will also initialize an IBM Host On-Demand (HOD) properties object, to be used for establishing a connection to the host. 5. An xmlLegacyProcessSample object is then instantiated and the first

access method of this object is called.

6. The xmlLegacyProcessSample object will then use the stored parameters to establish a connection with the host. This is done by instantiating a Host Publisher HostConnection JavaBean, and calling the

acquireHostConnection method. This function will return an HOD Session JavaBean.

7. The xmlLegacyProcessSample object will then instantiate a Host

Publisher xmlAppData JavaBean, and wire this bean to events generated by the HOD Session bean.

8. Then the xmlLegacyProcessSample will wire itself to events generated by the xmlAppData bean. In this way the xmlLegacyProcessSample bean can communicate with the xmlAppData bean using XML data formats, and the xmlAppData bean communicates with the host using the HOD Session bean. This path yields the desired XML data interface to a host

application.

A block diagram of the relationship of these components is illustrated in Figure 26 on page 32.

Figure 26. XML Legacy Gateway architecture

When the xmlAppData bean signals that it has received data from the host, the xmlLegacyProcessSample object retrieves this data in XML format. It then combines this data with a stylesheet (an XSL file) using a stylesheet

processor that is included in IBM's WebSphere product. This process produces HTML output. The HTML output contains JavaScript calls. The JavaScript file is called lxgwfunctions.js, and is included in this sample. The user then is presented with the host window, and is able to fill in the input data fields and select an action to take on the windows (for example, Enter, PF1 function key, PF3, and so on) by clicking one of the buttons presented on the HTML page.

When a button is clicked, this causes a doPost command to be sent to the servlet, and the xmlLegacyGWSample servlet receives this doPost. The doPost does some status and error checking and then instantiates an xmlLegacyProcessSample object, and calls the "execute" method of this object. The execute method will then read in the HTML data that represents the host window with the user's input, into an XML data structure. Next the xmlLegacyProcessSample will invoke a method of the xmlAppData bean to

send this new data to the host. The xmlLegacyProcessSample will then wait for the xmlAppData bean to send back the new host window in XML format. Then, as stated before, this data is combined with a stylesheet to produce an HTML page at the browser. This process continues until the user disconnects.

Related documents