e-docs > Tuxedo > Using JOLT > Using Jolt ASP Connectivity for BEA Tuxedo |
Using JOLT |
Using Jolt ASP Connectivity for BEA Tuxedo
Jolt Active Server Pages (ASP) connectivity for BEA Tuxedo provides an easy-to-use interface for processing and generating dynamic HTML pages. You do not need to learn how to write Common Gateway Interface (CGI) transactional programs to access BEA Tuxedo services.
This topic includes the following sections:
Key Features
Jolt ASP Connectivity for BEA Tuxedo, an extension to the Jolt class library, enables BEA Tuxedo services and transactions to be invoked from a Web server using a scripting language.
This architecture has several benefits:
Note: Asynchronous notification is not available in the ASP Connectivity for BEA Tuxedo. It is recommended that Jolt-enabled Java clients (applets) be written using a retained connection to support asynchronous notification.
How Jolt ASP Connectivity for BEA Tuxedo Works
The Jolt ASP Connectivity for BEA Tuxedo architecture includes three main components: a session, a session pool, and a session pool manager. A session object represents a connection with the BEA Tuxedo system. A session pool represents many physical connections between the Web server and the BEA Tuxedo system. It also associates a session with an HTTP request.
The session pool manager is responsible for maintaining a set of session objects, each having a unique session identifier.
Jolt ASP Connectivity for BEA Tuxedo works as follows:
A graphical representation of the ASP Connectivity for BEA Tuxedo architecture is shown in the following figure.
Figure 8-1 Jolt ASP Connectivity for BEA Tuxedo Architecture
For additional information about the SessionPool and SessionPoolManager classes, see the online BEA Jolt API Reference.
ASP Connectivity for BEA Tuxedo Toolkit
The ASP Connectivity for BEA Tuxedo Toolkit is an extension of the Jolt Class Library. The Toolkit allows the Jolt Client Class Library to be used in a Web server (such as Microsoft Active Server) to provide an interface between HTML clients or browsers, and a BEA Tuxedo application.
Samples delivered with the software support four services: INQUIRY, WITHDRAWAL, DEPOSIT, and TRANSFER. This section explains the steps you follow to use an HTML client interface with the TRANSFER service of the BEA Tuxedo BankApp application. The TRANSFER service illustrates the use of parameters with multiple occurrences. This walkthrough explains the use of the TRANSFER service only.
Jolt ASP Connectivity for BEA Tuxedo Walkthrough
A complete listing of all examples used in this chapter are distributed with the Jolt software. In this section, segments of code from these samples are used to illustrate the use of the Toolkit.
The samples delivered with the software support four services: INQUIRY, WITHDRAWAL, DEPOSIT, and TRANSFER. This chapter explains the steps you can follow to use an HTML client interface to the TRANSFER service of the BEA Tuxedo Bankapp application. The TRANSFER service illustrates the use of parameters with multiple occurrences. This walkthrough explains the use of the TRANSFER service only.
Note: The walkthrough illustrates the use of the ASP Connectivity for BEA Tuxedo with Microsoft IIS and VBScript.
To use the information in the following sections, you should be familiar with:
Overview of the ASP for BEA Tuxedo Walkthrough
Follow the steps below to complete the ASP Connectivity for BEA Tuxedo walkthrough.
Getting Started Checklist
Review this checklist before starting the TRANSFER Request Walkthrough.
Note: This checklist applies to Microsoft Active Server Pages only. It also assumes that you have already installed BEA Tuxedo and the Jolt Server on a host machine, as well as the BEA Jolt client on a machine where Microsoft IIS is installed.
Tuxedo Host Running Jolt Server
Machine Running Jolt Client and Microsoft IIS
On a Windows NT 4.0 platform, this SDK is not installed if you chose the Typical form of installation for the Microsoft NT Option Pack 4.0. Select the SHOW SUBCOMPONENTS option on the installer to display additional options under IIS. Look for the SDK and install it.
On Windows NT or 2000, you can also obtain the Microsoft Java Component Framework classes from the Microsoft SDK for Java. To download Microsoft Java Component Framework files, complete the following procedure:
http://www.microsoft.com
Search for the following string: Microsoft SDK for Java.
Alternatively, go directly to the download page:
http://www.microsoft.com/java/download/dl_sdk40.htm
...\Program Files\Microsoft SDK for Java 4.0\Samples\ASP\aspcomp> copy *.class C:\WINNT\java\TrustLib\aspcomp
Overview of the TRANSFER Service
The TRANSFER service in BankApp moves funds between two accounts. The service takes two account numbers, an input amount, and returns two balances—one for each account. In addition, the service returns an error message if there is an application or system error.
A TRANSFER is a WITHDRAWAL and a DEPOSIT executed as a single transaction. The transaction is created on the server, so the client does not need to create a transaction.
The client interface consists of an HTML page with a form used to enter the required data—account numbers and a dollar amount. This data is sent to the Web server as a "POST" request.
In the Web server, this request is processed using a VBScript Active Server Page. This program extracts the input data fields from the request, formats them for use with the Jolt ASP Connectivity for BEA Tuxedo class library, and dispatches the request to the TRANSFER service in the BankApp application. The TRANSFER service returns the results of the transaction. These results are returned to the VBScript program that merges them into a dynamically created HTML page. This page is returned to the client by way of the Web server infrastructure.
In the final part of this walkthrough, run the necessary HTML pages and server-side VBScript logic to execute a TRANSFER.
TRANSFER Request Walkthrough
This section explains what happens when you execute a TRANSFER request. Each step is not include here; only those steps that are necessary, as follows:
Initializing the Jolt Session Pool Manager
To start the walkthrough, use the browser on your client to connect to the Web server where the Jolt Asp Connectivity for BEA Tuxedo classes are installed. The first page to download is tellerForm.asp (see the following figure for an example of a tellerForm.asp page). If the teller sample has been installed as described in the Getting Started Checklist, the URL for this page will be:
http://<web-server:port>/teller/tellerForm.asp
Note: The use of the port number is optional, depending on how your Web server is configured. In most cases, you are not required to add the ":port" in the URL.
Figure 8-2 tellerForm.asp Example
The page, tellerForm.asp, contains VBScript procedures required to initialize the Jolt Session Pool Manager. The initialization code is contained in an ASP Script block. This code tells the Web server to execute this block of code on the server, instead of sending it to the client. Listing 8-1 tellerForm.asp: Initialize the Jolt Session Pool Manager The VBScript procedure web_initSessionMgr() calls other VBScript procedures to establish a pool of Jolt sessions. A Jolt session is established between the Jolt ASP Connectivity for BEA Tuxedo in the Web server and the Jolt Servers that reside in your BEA Tuxedo application. One of the procedures called is web_start(). This procedure (in the file web_start.inc) should have been edited as part of the teller application installation process in the Getting Started Checklist. The procedure web_cacheTemplates() reads various HTML template files into a memory cache. This step is not required, but it improves performance. Listing 8-2 tellerForm.asp: Allow the User to Choose TRANSFER Service The HTML segment shown in the previous listing displays a button labeled "Transfer." When this button is selected, the browser loads the page transferForm.htm. This page presents a form used to enter the data required by the TRANSFER service. Submitting a TRANSFER Request from the Client The form in the following figure is generated by the page transferForm.htm. This page presents you with a form for input. The page consists of three text fields (two account numbers and a dollar amount), and a button that, when pressed, causes the TRANSFER service to be invoked. Figure 8-3 transferForm.htm Example
<%
'// Initialize the session manager and cache templates
Call web_initSessionMgr(Null)
Call web_cacheTemplates()
%><INPUT TYPE="button" VALUE="Transfer"
onClick="window.location='transferForm.htm'">
The code segment in the following listing shows the key HTML elements for this page. The bolded text in the following listing correspond to the elements in the table Key HTML Elements and Descriptions. Listing 8-3 transferForm.htm: TRANSFER Form
<FORM NAME="teller" ACTION="tlr.asp" METHOD="POST">
<TABLE>
<TR><TD ALIGN=RIGHT>From Account Number: </TD>
<TD><INPUT TYPE="text" NAME="ACCOUNT_ID_0"></TD></TR>
<TR><TD ALIGN=RIGHT>To Account Number: </TD>
<TD><INPUT TYPE="text" NAME="ACCOUNT_ID_1"></TD></TR>
<TR><TD ALIGN=RIGHT>Amount: $</TD>
<TD><INPUT TYPE="text" NAME="SAMOUNT"></TD></TR>
</TABLE>
<CENTER>
<INPUT TYPE="hidden" NAME="SVCNAME" VALUE="TRANSFER">
<INPUT TYPE="submit" VALUE="Transfer">
<INPUT TYPE="reset" VALUE="Clear">
</CENTER>
</FORM>
The HTML form field names used in this example exactly match the BEA Tuxedo field names expected by the TRANSFER service. This is not required, but doing so facilitates processing on the server because you do not have to map these inputs to BEA Tuxedo field names. This is done by the Jolt ASP Connectivity for BEA Tuxedo classes. The hidden field SVCNAME is assigned a value of TRANSFER. This field does not appear on the client form, but it is sent to the Web server as part of the request. The VBScript program retrieves the value of this field in order to determine which BEA Tuxedo service is to be called (in this example, the service is TRANSFER). Complete the fields From Account Number, To Account Number, and Amount. (10000 and 10001 are valid BankApp account numbers). Click the Transfer button. The data entered on the form is sent to the Web server for processing by the program tlr.asp as specified in the ACTION field of the form. Processing the Request When the Web server receives the TRANSFER request, it runs the program tlr.asp. Client requests are turned into a Request object in the Web server. This Request object has members containing all the data that was input to the form along with other form data, such as hidden fields. The Web server makes the Request object available to the program being invoked. The program tlr.asp contains only VBScript. The first action performed by this program verifies that the Jolt Session Pool Manager is initialized. The code example shown in the following listing performs the initialization check and returns an HTML error page if the pool is not initialized. Listing 8-4 tlr.asp: Verify the Jolt Session Pool Manager Is Initialized If the session pool is initialized, the program continues to process the request. The program locates a Session from the Session Pool Manager as shown in the following listing. Listing 8-5 tlr.asp: Locate a Session Once a valid session is located, the program retrieves an HTML template that is used to return the results to the client. In this example, these templates were cached in the initialization section. The template retrieved is identified by the name of the service being invoked, Request("SVCNAME") as shown in the following listing. Listing 8-6 tlr.asp: Retrieve a Cached HTML Template Next, call the BEA Tuxedo service as shown in the following listing. In the following listing, the input data from the Request object is passed to the call() method of the session. The call() method uses the built-in ASP Request object as input. The results of the call() are stored in the output object and an array, iodata. Listing 8-7 tlr.asp: Invoke the BEA Tuxedo Service After you invoke the BEA Tuxedo service, the output object and the second element of the array iodata contain the results of the service call. Note: Because the initial form specified field names match the BEA Tuxedo service parameter names, the Request object can be used in the call() method. If these names do not match, create an input array with "name=value" elements for each service parameter before invoking the call() method. Returning the Results to the Client At this stage, no results have been returned to the client. The final step sends an HTML page containing the results of the service call back to the client. The HTML page consists of the template merged with the data returned by the service call shown in Listing 8-7. The template file contains placeholders for variable (call-specific) data. These placeholders are identified by the special tag <%=NAME%>. In the code example shown in the following listing, an index is used to indicate which occurrence of a parameter name is used. For example, ACCOUNT_ID[0] specifies the first occurrence of the field ACCOUNT_ID. Listing 8-8 transfer.temp: Placeholders for TRANSFER Results To substitute the placeholders in the template with the actual values of the data returned from the service call, use the eval() method of the Template object shown in the following listing. This method matches placeholders in the template file with fields of the same name in the results data and replaces them accordingly. A check for valid results (output object) is done as shown in the following listing. If there is no output object, an error template page is returned. Listing 8-9 tlr.asp: Template Processing Note: The array iodata contains both the input request and the results from the service call. This is useful if you want the results page to contain data that is part of the input. When the template is processed, the resulting HTML is returned to the client as shown in the following figure. Figure 8-4 tlr.asp Results Page
<%
If Not IsObject(Application("mgr")) Then
%>
<HTML>
<HEAD><TITLE>Error</TITLE></HEAD>
<BODY><CENTER>
<H2>Session Manager is not initialized</H2>
<P>Make sure that you access the correct HTML
</CENTER></BODY>
</HTML>
<%
End If
%>Set pool = Application("mgr").getSessionPool(Null)
'// Choose the response template
If IsEmpty(Application("templates")) Then
Set template = Server.CreateObject("BEAWEB.Template")
Else
Select Case Request("SVCNAME")
Case "INQUIRY"
Set template = Application("templates")(INQUIRY)
Case "DEPOSIT"
Set template = Application("templates")(DEPOSIT)
Case "WITHDRAWAL"
Set template = Application("templates")(WITHDRAWAL)
Case "TRANSFER"
Set template = Application("templates")(TRANSFER)
End Select
End IfSet output = pool.call(Request("SVCNAME"), Null, Nothing)
Set iodata(1) = output<TABLE BORDER=1>
<TR><TD></TD><TD ALIGN=CENTER><B>Account #</B></TD>
<TD ALIGN=CENTER><B>Balance</B></TR>
<TR><TD ALIGN=RIGHT><B>From:</B></TD><TD><%=ACCOUNT_ID[0]%></TD>
<TD><%=SBALANCE[0]%></TR>
<TR><TD ALIGN=RIGHT><B>To:</B></TD><TD><%=ACCOUNT_ID[1]%></TD>
<TD><%=SBALANCE[1]%></TR>
</TABLE>path = Application("templatedir")
If (Not IsObject(output)) Or (output is Nothing) Then
Call template.evalFile(path & "\nosession.temp", Null)
Elseif output.noError() Then
Call template.eval(iodata)
Elseif output.applicationError() Then
Call template.evalFile(path & "\error.temp", iodata)
Else
'// System error
Dim errdata(0)
Set errdata(0) = Server.CreateObject("BEAWEB.TemplateData")
Call errdata(0).setValue("ERRNO", output.getError())
Call errdata(0).setValue("ERRMSG", output.getStringError())
Call template.evalFile(path & "\syserror.temp", errdata)
End If