302
IMS Connect IMS Connector for Java User’s Guide and Reference Version 1 Release 2 Modification 2

IMS Connector for Java User's Guide and Reference - CiteSeerX

Embed Size (px)

Citation preview

IMS Connect

IMS Connector for JavaUser’s Guide and ReferenceVersion 1 Release 2 Modification 2

���

IMS Connect

IMS Connector for JavaUser’s Guide and ReferenceVersion 1 Release 2 Modification 2

���

Edition Notice

This edition applies to IMS Connector for Java, a component of Version 1 Release 2 Modification 2 of IMS Connect(product number 5655–E51) and to all subsequent releases and modifications until otherwise indicated in neweditions.

© Copyright International Business Machines Corporation 1998, 2002. All rights reserved.US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contractwith IBM Corp.

Note!Before using this information and the product it supports, be sure to read thegeneral information under Notices.

Contents

Chapter 1. Understanding IMS Connector for Java . . . . . . . . . . . 1Prerequisites for using IMS Connector for Java . . . . . . . . . . . . . 8

VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . 8WebSphere Application Server . . . . . . . . . . . . . . . . . . 9IMS Connect . . . . . . . . . . . . . . . . . . . . . . . . . 9IMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Platform Configurations for IMS Connector for Java and IMS Connect . . . . 10IMS Connector for Java concepts and terms . . . . . . . . . . . . . . 32IMS Connector for Java conversational programming models . . . . . . 34Migrating from CCF architecture to J2EE connector architecture. . . . . . . 40

Migrating IMS Connector for Java EAB Commands to J2EE . . . . . . . 41Running a CCF Servlet in WebSphere Application Server 4.0 for Windows 42Running a CCF Servlet in WebSphere Application Server 4.0 for z/OS and

OS/390 . . . . . . . . . . . . . . . . . . . . . . . . . . 46

Chapter 2. Preparing to use IMS Connector for Java . . . . . . . . . . 53Preparing your VisualAge for Java environment . . . . . . . . . . . . . 54Preparing your WebSphere Studio environment . . . . . . . . . . . . . 58Preparing your WebSphere Application Server environment for Windows . . . 59Preparing your WebSphere Application Server environment for z/OS and

OS/390 . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

Chapter 3. Building Java applications and servlets . . . . . . . . . . 77Building CCF Java applications and servlets . . . . . . . . . . . . . . 77Building J2C Java applications and servlets . . . . . . . . . . . . . . 78Building Java applications and servlets for conversational transactions . . . . 79

Chapter 4. Building a Java application to run an IMS transaction . . . . . 81

Chapter 5. Building a Java application to run a navigator . . . . . . . . 95

Chapter 6. Building a Java application for an IMS transaction withmulti-segment output messages . . . . . . . . . . . . . . . . 109

Chapter 7. Building a Java application for an IMS transaction withmulti-segment input messages . . . . . . . . . . . . . . . . . 117

Chapter 8. Building an application to run an IMS transaction withsynchronization level confirm . . . . . . . . . . . . . . . . . 125

Chapter 9. Building the graphical user interface . . . . . . . . . . . 129

Chapter 10. Building a Java servlet to run an IMS transaction . . . . . 137

Chapter 11. Building a Web application that uses one servlet to run anIMS conversation . . . . . . . . . . . . . . . . . . . . . . 151

Chapter 12. Building a Web application that uses two servlets to run anIMS conversation . . . . . . . . . . . . . . . . . . . . . . 165

Chapter 13. Building a J2C phonebook sample application . . . . . . . 173Part 1: Building the J2C phonebook sample application . . . . . . . . . 173Part 2: Assembling the J2C phonebook sample application . . . . . . . . 188

© Copyright IBM Corp. 1998, 2002 iii

Part 2A: Assembling and deploying the J2C phonebook sample application forWindows . . . . . . . . . . . . . . . . . . . . . . . . . . 189

Part 2B: Assembling and deploying the J2C phonebook sample application forz/OS and OS/390 . . . . . . . . . . . . . . . . . . . . . . 192

Part 3: Running the J2C phonebook sample application . . . . . . . . . 196

Chapter 14. Building a J2C conversational phonebook sample application 197Part 1: Building a J2C conversational phonebook sample application 198Part 2A: Assembling and deploying the J2C conversational phonebook

sample application for Windows . . . . . . . . . . . . . . . . 210Part 2B: Assembling and deploying the J2C conversational phonebook

sample application for z/OS or OS/390 . . . . . . . . . . . . . . 214Part 3: Running the J2C conversational phonebook sample application 217

Chapter 15. Building Container-Managed and Component-ManagedTransactional EJBs to Run IMS Transactions . . . . . . . . . . . 219

Part 1: Preparing for the sample . . . . . . . . . . . . . . . . . . 220Part 2: Creating the sample. . . . . . . . . . . . . . . . . . . . 221Part 3: Packaging and Deploying the sample . . . . . . . . . . . . . 241Part 4: Running the sample . . . . . . . . . . . . . . . . . . . . 248

Appendix A. IMS INSTALL/IVP sample application . . . . . . . . . . 251

Appendix B. Using the trace and error logging facility . . . . . . . . 253Turning on the trace and error logging facility for IMS Connector for Java CCF

components. . . . . . . . . . . . . . . . . . . . . . . . . 253Turning on the trace and error logging facility for IMS Connector for Java J2C

components. . . . . . . . . . . . . . . . . . . . . . . . . 257Customizing the trace facility . . . . . . . . . . . . . . . . . . . 257Reading the error log . . . . . . . . . . . . . . . . . . . . . . 258Reading the trace log . . . . . . . . . . . . . . . . . . . . . . 259

Appendix C. Diagnosing problems related to sockets . . . . . . . . . 261Diagnosing problems related to connection pooling . . . . . . . . . . . 262If your Java application or servlet does not respond . . . . . . . . . . . 262

Appendix D. Messages and exceptions . . . . . . . . . . . . . . 263Exceptions generated by IMS Connector for Java CCF applications . . . . . 264Exceptions generated by IMS Connector for Java J2C applications . . . . . 274

Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . 287

Programming interface information . . . . . . . . . . . . . . . . 289

Trademarks and service marks . . . . . . . . . . . . . . . . . . 291

iv IMS Connector for Java User’s Guide and Reference

Chapter 1. Understanding IMS Connector for Java

IMS Connector for Java provides a way to create Java applications that can accessIMS transactions. In conjunction with the VisualAge for Java developmentenvironment, IMS Connector for Java lets you rapidly develop Java applications thatrun your transactions. With additional support from IBM WebSphere ApplicationServer, you can build and run Java servlets that access your transactions from Webpages.

IMS Connector for Java uses IMS Connect to access IMS. IMS Connect is a facilitythat runs on the host IMS machine and supports TCP/IP and Local Optioncommunication to IMS. A Java application or servlet accesses IMS OpenTransaction Manager Access (OTMA) through IMS Connect. IMS Connect acceptsmessages from its TCP/IP clients and routes them to IMS OTMA using theCross-System Coupling Facility (XCF).

IMS Connector for Java is comprised of 2 components:

v The development component of IMS Connector for Java is provided withVisualAge for Java. The VisualAge for Java Enterprise Access Builderenvironment enables you to develop Enterprise Access Builder (EAB) commands,Enterprise JavaBeans (EJBs), servlets, and Java applications that use IMSConnector for Java to access IMS transactions. VisualAge for Java also providesa WebSphere test environment that you can use to test the programs youdevelop.

v The runtime component of IMS Connector for Java is provided as a componentof IMS Connect Version 1 Release 2 (Program Number 5655-E51). The Java 2Platform (J2EE) Connector (J2C) Architecture implementation of this runtimecomponent is also referred to as the IBM WebSphere Adapter for IMS. It ispackaged as a RAR file, imsico.rar, for deployment into the J2C compliantWebSphere Application Server. The RAR file is installed to a target directory fromthe IBM IMS Connect, Version 1 Release 2.

WebSphere Application Server provides an environment in which you can run theservlets and EJBs that you develop from Web pages. WebSphere ApplicationServer is the primary runtime environment for the servlets and EJBs. In theWebSphere Application Server environment, IMS Connector for Java is alsoreferred to as the IBM WebSphere Adapter for IMS.

Related Reading: See “Prerequisites for using IMS Connector for Java” for moreinformation.

This section describes IMS Connector for Java. It includes:

v What’s New in IMS Connector for Java Version 1.2.2 (page 1)

v Overview of IMS Connector for Java (page 2)

v Java 2 Platform Enterprise Edition (J2EE) support in IMS Connector for Java(page 4)

v Sample Applications (page 6)

What’s New in IMS Connector for Java Version 1.2.2

The current release of IMS Connector for Java introduces the following:

v J2C support for WebSphere Application Server for z/OS and OS/390

© Copyright IBM Corp. 1998, 2002 1

v Global transaction (2-phase commit) support when using Local Optioncommunication in the z/OS and OS/390 environment

v Container-managed security support when using Local Option communication inthe z/OS and OS/390 environment

v Local Option support for J2C applications

Overview of IMS Connector for Java

Figure 1 shows an overview of the environments involved in developing and runningJava application programs and servlets that use IMS Connector for Java to accessIMS transactions. A Java application typically includes a graphical user interface(GUI). A Java servlet typically uses a Web browser with HTML or JSP files as theuser interface.

Figure 1. Developing Java applications and servlets using IMS Connector forJava

The steps illustrated in Figure 1 are as follows:

1. Provide your COBOL source file to VisualAge for Java’s Enterprise AccessBuilder tool. The COBOL file contains data structures for the IMS transactioninput and output messages. The COBOL file is typically the source of the IMSapplication program for the transaction. However, if your IMS applicationprogram is not written in COBOL you can represent the input and outputmessages as COBOL data structures and provide them to the EnterpriseAccess Builder tool.

2. Use the VisualAge for Java Command Editor, an Enterprise Access Builder tool,to create an Enterprise Access Builder (EAB) command. The EAB command isa composite Java bean that can be used to build either a Java servlet or astand-alone Java application program that accesses IMS transactions. A Javaservlet runs on a Java application server such as IBM’s WebSphere ApplicationServer and uses a Web browser for transaction input and output. A stand-aloneJava application does not use a Java application server and typically uses agraphical user interface (GUI) for transaction input and output. In either case,VisualAge for Java can be used to quickly build a simple Java applicationprogram to execute the IMS transaction. This program can be easily run, withinVisualAge for Java, in order to prove that the EAB command runs the IMStransaction.

3. If you are building a Java servlet to run your IMS transaction:

a. Use VisualAge for Java’s Create Servlet SmartGuide to generate HTML,JSP, and Java files for the servlet from the EAB command which youprovide to the wizard.

2 IMS Connector for Java User’s Guide and Reference

b. Deploy the HTML files, JSP files, and Java servlet files to your WebSphereApplication Server environment to enable users to access the IMStransaction from a Web browser.

VisualAge for Java provides the IBM WebSphere Test Environment that you canuse to test and debug your servlet prior to deploying it to a productionWebSphere Application Server.

4. If you are building a stand-alone Java application to run your IMS transaction:

a. Build a user interface for transaction input and output. Typically this is doneby using VisualAge for Java to build the GUI and to execute the EABcommand.

b. Deploy the Java application files to the machine on which you wish to runthe application.

Deploying stand-alone applications involves updating a CLASSPATH environmentvariable so that they can access the IMS Connector for Java runtime classes. Whendeploying applications to WebSphere Application Server, the CLASSPATHenvironment variable in updated in the deployment process. The ApplicationAssembly Tool is used to create an Enterprise Archive (EAR) file which is thendeployed to WebSphere Application Server. For more information about EAR files,see the “J2EE Modules” section in “IMS Connector for Java Concepts and Terms.”

Figures 2 and 3 show how you run either a stand-alone Java application program ora Java servlet to access your IMS transactions.

Figure 2. Running a Java application that uses IMS Connector for Java

The steps illustrated in Figure 2 are as follows:

1. Typically for Java applications, a GUI is used to provide input for the IMStransaction (1) and display the output from the IMS transaction (4).

2. The Java application accesses IMS Connector for Java via class libraries and,in the case of Local Option, a shared library.

3. IMS Connector for Java builds an OTMA message containing the transactioninput message and sends it to IMS Connect, which in turn sends it to OTMAusing XCF. OTMA passes the IMS transaction input message to IMS andreceives the IMS transaction output message from IMS. OTMA returns anOTMA message containing the transaction output message to IMS Connect,which in turn sends it to IMS Connector for Java.

4. The output of the IMS transaction is displayed by the Java application using theGUI.

Chapter 1. Understanding IMS Connector for Java 3

Figure 3. Running a servlet that uses IMS Connector for Java

The steps illustrated in Figure 3 are as follows:

1. The HTML file containing the input HTML form is displayed on the Web browser.The user provides the input data for the IMS transaction on this HTML form andpresses the ″Submit″ button (or its equivalent). WebSphere Application Serverschedules the servlet.

2. The servlet executes the EAB command, which in turn invokes IMS Connectorfor Java. If the version of WebSphere Application Server that is running theJava servlet does not include the class libraries used by the servlet, these classlibraries can be deployed to WebSphere Application Server in the form of JARfiles.

3. IMS Connector for Java builds an OTMA message and sends it to IMS Connect,which in turn sends it to OTMA using XCF. OTMA sends the IMS transactioninput message to IMS and receives the IMS transaction output message fromIMS. The IMS transaction output message is sent back to IMS Connect byOTMA. IMS Connect then sends it to the servlet using IMS Connector for Java.

4. The output of the IMS transaction is displayed on the Web browser by the Javaservlet using a JSP file.

The method used by IMS Connector for Java to send and receive OTMA messagesdepends on the runtime environment of IMS Connector for Java and IMS Connect.If both your Web server and IMS Connect are running in the same MVS image, youcan choose to use either TCP/IP or Local Option for communication between IMSConnector for Java in the servlet and IMS Connect. Otherwise, only TCP/IP can beused for communications between IMS Connector for Java and IMS Connect.

Java 2 Platform Enterprise Edition (J2EE) Support in IMS Connector for Java

IMS Connector for Java includes both a Common Connector Framework (CCF)implementation and a Java 2 Platform (J2EE) Connector (J2C) Architectureimplementation.

This release of IMS Connector for Java introduces J2C support for the z/OS andOS/390 platform. See “Prerequisites for using IMS Connector for Java” for moreinformation on getting this support.

The J2EE Connector architecture defines a standard architecture for connecting theJ2EE platform to heterogeneous Enterprise Information Systems (EISs) such asIMS. The J2C architecture uses an J2EE connector (also known as a resourceadapter), such as IMS Connector for Java. By conforming to the J2EE Connectorarchitecture, which is defined and standardized as part of the Java 2 Platform,Enterprise Edition (J2EE), the resource adapter no longer needs to be customized

4 IMS Connector for Java User’s Guide and Reference

for each J2EE application server to connect to the EIS. In addition, the J2EEConnector Architecture defines a set of standard programming interfaces thatdetermine how a J2EE application interacts with a J2EE Resource Adapter toconnect to the EIS. As a result, by using the J2EE Connector Architecture, theJ2EE applications do not require the addition of custom code to connect to differentEISs.

For more information on the J2EE architecture and its concepts, see the J2EEConnector Architecture Specification at http://java.sun.com/j2ee/download.html fordetails.

IMS Connector for Java’s implementation of the J2EE Connector Architecture willbe provided in phases. The list below is an overview of the support provided in thisrelease of IMS Connector for Java for J2C. For a list of classes provided, see “IMSConnector for Java concepts and terms.”

v Common Client Interface

IMS Connector for Java provides an implementation of the J2C Common ClientInterface (CCI).

Java clients use the CCI in the following ways:

– Using the IMS Connector for Java in conjunction with the EnterpriseApplication Integration (EAI) frameworks that are based on the CCI, such asthe Enterprise Access Builder for Transactions (EAB). This method isillustrated by the J2C samples provided in the Connector IMS Samples projectand described in “Building a J2C phonebook sample application” and “Buildinga conversational phonebook sample application.”

– Programming directly against the CCI. This method is not described in theIMS Connector for Java documentation. For more information on the J2EEprogramming model, including use of the CCI, see VisualAge for Java’s Helpby clicking Help > Concepts > Access to transaction systems >Connectors > J2EE Application Programming Model.

v Connection Management

IMS Connector for Java, in collaboration with WebSphere Application Server,provides connection pooling that is transparent to the servlet or EnterpriseJavaBean (EJB). Connection pooling implies connection reuse. For example, aconnection consisting of a TCP/IP socket between IMS Connector for Java andIMS Connect is reused for multiple transaction requests. A socket is not closedand re-opened between transaction requests.

v Error Logging and Tracing

IMS Connector for Java provides error logging and tracing through a traceLevelcontrol. Allowable values for traceLevel are defined in the interfaceIMSTraceLevelProperties. “Using the trace and error logging facility” describeshow to use WebSphere Application Server in conjunction withIMSTraceLevelProperties to control tracing and logging.

v Migration

IMS Connector for Java provides the class IMSConnectorMigrator for use byVisualAge for Java tooling to migrate Enterprise Access Builder (EAB) commandsfrom IBM’s Common Connector Framework (CCF) Architecture to Sun’s Java 2Platform, Enterprise Edition (J2EE) Connector Architecture (J2C). Information onmigration of IMS Connector for Java applications can be found in “Migrating fromCCF architecture to J2EE connector architecture.”

v Packaging and Deployment

The runtime piece of IMS Connector for Java is packaged as the ResourceAdapter Archive (RAR) file imsico.rar for deployment into the J2C compliant

Chapter 1. Understanding IMS Connector for Java 5

WebSphere Application Server. For instructions on deploying this RAR file, see“Preparing your WebSphere Application Server Environment for Windows” or“Preparing your WebSphere Application Server Environment for z/OS andOS/390.”

v Security

For WebSphere Application Server for workstation platforms, IMS Connector forJava currently supports component-managed sign-on only.

For WebSphere Application Server for z/OS and OS/390, IMS Connector for Javasupports both container and component-managed sign-on. For more informationabout the J2C security support for IMS Connector for Java, see “IMS SecurityInformation for J2C” in “IMS Connector for Java concepts and terms.”

v Supported Platforms

In this release, J2C support is provided for the following platforms:

– AIX

– z/OS and OS/390

– Solaris

– Windows

v Transaction Management

In the current release, IMS Connector for Java provides global transactionsupport known as 2-phase commit using MVS Resource Recovery Service (RRS)with WebSphere Application Server for OS/390 and z/OS.

This release of IMS Connector for Java does not provide transaction support withWebSphere Application Server on workstation platforms. For more informationabout J2C transaction support for IMS Connector for Java, see “TransactionManagement for J2C” in the “IMS Connector for Java concepts and terms.”

Generally, the process for developing J2C applications and servlets is as follows:

1. Ensure that the IMS Connector for Java RAR file (imsico.rar) has beendeployed on the WebSphere Application Server. For more information on how todeploy IMS Connector for Java to your target WebSphere Application Server,see “Preparing your WebSphere Application Server environment for Windows”or “Preparing your WebSphere Application Server Environment for z/OS andOS/390” for more information.

2. Ensure that connection factories have been created and configured for theWebSphere Application Server. For more information on how to create andconfigure connection factories, see “Preparing your WebSphere ApplicationServer environment for Windows” or “Preparing your WebSphere ApplicationServer Environment for z/OS and OS/390” for more information.

3. Import COBOL source to VisualAge for Java. See “Building a Java application torun an IMS transaction” for an example of how to complete this step and thesteps below.

4. Create a servlet or EJB using VisualAge for Java’s Enterprise tooling.

5. Create an Enterprise Application using the Application Assembly Tool (AAT).

6. Deploy the Enterprise Application to WebSphere Application Server.

7. Run the Enterprise Application in WebSphere Application Server.

Sample Applications

IMS Connector for Java provides a number of CCF and J2C sample applicationsand information about them. The following is a list of the provided samples:

v CCF samples:

6 IMS Connector for Java User’s Guide and Reference

– Building a Java application to run an IMS transaction

– Building a Java application to run a navigator

– Building a Java application for an IMS transaction with multi-segment outputmessages

– Building a Java application for an IMS transaction with multi-segment inputmessages

– Building an application to run an IMS transaction with synchronization levelconfirm

– Building the graphical user interface

– Building a Java servlet to run an IMS transaction

– Building a Web application that uses one servlet to run an IMS conversation

– Building a Web application that uses two servlets to run an IMS conversation

v J2C samples:

– Building a J2C phonebook sample application

– Building a J2C conversational phonebook sample application

– Building container-managed and component-managed transactional EJBs torun IMS transactions

Preparing to deploy J2C samples

Before you can deploy any of the J2C samples described in this documentation,you must package them into enterprise archive (EAR) and Web archive (WAR) files.To do this, use the Application Assembly Tool (AAT), provided with WebSphereApplication Server. Two AATs are available, depending on the platform on which youare deploying the samples:

v AAT for distributed platforms (such as Windows, AIX, and Solaris)

v AAT for the z/OS and OS/390 platform

The AAT for distributed platforms allows you to create EAR and WAR files.

The AAT for OS/390 and z/OS does not provide the functionality to create WARfiles. This AAT is required when creating EAR files that will be deployed on thez/OS and OS/390 platform. You can also import any EAR files that were built for thedistributed platforms into this AAT and rebuild it for a z/OS and OS/390 system.

If you don’t have an AAT for distributed platforms, you can build the WAR filesneeded to create EAR files using the JAR command provided with a JavaDevelopment Kit (JDK). See below for more information.

v AAT for distributed platforms

The AAT for distributed platforms is shipped with WebSphere Application Serverfor that specific platform. For more information on assembling an application on adistributed platform, see the IBM WebSphere Application Server InformationCenter at http://www-3.ibm.com/software/webservers/appserv/infocenter.html.

v AAT for z/OS and OS/390

The AAT for z/OS or OS/390 platforms is shipped with WebSphere ApplicationServer for that specific platform. The tool and the documentation for it are alsoavailable for download on the Web at http://www-3.ibm.com/software/webservers/appserv/zos_os390/index.html. The samples forz/OS and OS/390 described in this documentation require an additional classpathconfiguration to avoid warnings about missing classes. Add theAAT_USER_PATH variable to the list of system variables for the platform on

Chapter 1. Understanding IMS Connector for Java 7

which the AAT will be run. You should set this variable to point to the foldercontaining the JAR files that are required by the IMS Connector for Java (forexample, C:\IBMCON~1\classes\). For more information, see the section ″Noteon updating the AAT classpath″ in the AAT readme.txt file.

v Java Development Kit

Ensure that a Java Development Kit (JDK) is installed on your system. Todownload and set up JDKs, see the products and documentation available athttp://java.sun.com.

Note: You can find additional files associated with the samples in theC:\<IBM_Connectors_install_dir>\imsconn\samples directory, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory (forexample, C:\IBM Connectors).

Three subdirectories exist under the ”samples“ directory: J2C, servlets and misc.The ”J2C“ directory contains folders for J2C samples, the ”servlet“ directorycontains folders for each CCF sample and the ”misc“ directory containsmiscellaneous files relating to the samples. For more information about the files,see context.txt in the ”samples“ directory.

For the J2C samples, a pre-built EAR file is provided for you. This EAR file can beinstalled and run in WebSphere Application Server for distributed platforms (such asWindows, AIX, Solaris) and z/OS and OS/390. You can find the EAR files in the”was“ subfolder for your J2C sample.

Prerequisites for using IMS Connector for JavaThe following is a list of minimum software requirements for IMS Connector forJava:

v VisualAge for Java Enterprise Edition Version 4.0

v WebSphere Application Server (for version information, see below)

v IMS Connect Version 1 Release 2

v IMS Version 7 Release 1

To run a Java application that uses the J2C implementation of IMS Connector forJava, IMS and IMS Connect must be installed and running on your host machine.

VisualAge for JavaVisualAge for Java Enterprise Edition 4.0 is the required development environmentfor the IMS Connector for Java.

The installation of VisualAge for Java 4.0 provides you with the CCF (CommonConnector Framework) implementation of IMS Connector for Java.

To use the J2EE Connector Architecture (J2C) implementation of IMS Connector forJava, you need to add the following updates to your VisualAge for Java 4.0environment:

v VisualAge for Java Beta J2EE Connectors support is required to use the J2Csupport. Follow the instructions in “IBM Enterprise Access Builder BETA NOTES4.0” on the VisualAge for Java 4.0 Additional Features installation CD. Thisinformation is in the readme.eab file in the \extras\BetaJ2EEConnectors folder onthe Additional Features installation CD.

8 IMS Connector for Java User’s Guide and Reference

v The J2C implementation of IMS Connector for Java is provided as an update toIBM VisualAge for Java Enterprise Edition Version 4.0. This update is availableon the VisualAge Developer Domain at http://www7.software.ibm.com/vad.nsf.Once this update is applied, both the Common Connector Framework (CCF) andJ2C implementations are available when you add the IMS Connector feature toyour VisualAge for Java workbench. This feature allows you to developapplications using VisualAge for Java’s Enterprise Access Builder and the J2Cimplementation of IMS Connector for Java.

WebSphere Application ServerIMS Connector for Java using the Common Connector Framework (CCF) supportsthe following WebSphere Application Server platforms:

v AIX

v Linux for zSeries and S/390

v z/OS and OS/390

v Solaris

v Windows

The J2C implementation of IMS Connector for Java supports deployment toWebSphere Application Server on the following platforms:

v WebSphere Application Server Advanced Edition 4.0 for Windows

v WebSphere Application Server Advanced Edition 4.0 for AIX

v WebSphere Application Server Advanced Edition 4.0 for Solaris

v WebSphere Application Server V4.0.1 for z/OS and OS/390

Important: APAR PQ55873 is required for running the J2C implementation ofIMS Connector for Java on z/OS and OS/390.

IMS ConnectIBM IMS Connect Version 1 Release 2 is required to use the J2C implementation ofIMS Connector for Java.

The runtime component of IMS Connector for Java is provided as an update to theIMS Connector for Java component of the IMS Connect Version 1 Release 2product.

If you plan to use the J2C implementation of IMS Connector for Java runningWebSphere Application Server on the z/OS and OS/390 platform, the followingAPARs for IBM IMS Connect, Version 1 Release 2 (Program Number 5655-E51)are required:

v APAR PQ57192

This APAR updates the IMS Connector for Java component with J2C and2-phase commit support for WebSphere Application Server for z/OS and OS/390.It installs the IMS Connector for Java runtime component (the RAR file forWebSphere Application Server for z/OS and OS/390) to a target directory onyour system.

v APAR PQ57191

This APAR updates the IMS Connect component with 2-phase commit support tobe used by IMS Connector for Java.

Chapter 1. Understanding IMS Connector for Java 9

IMSIBM IMS Version 7 Release 1 or later is required to use IMS Connector for Java.

v APAR PQ57868

This APAR must be applied to your IMS V7.1 system if you plan to use J2C andglobal transaction (2-phase commit) support on WebSphere Application Serveron z/OS and OS/390.

Platform Configurations for IMS Connector for Java and IMS ConnectIMS Connector for Java can be deployed and configured to run on WebSphereApplication Server on various platforms. The TCP/IP and Local Optioncommunication protocols are supported for both CCF and J2C applications toconnect to IMS Connect. Additionally, using Local Option for 2-phase committransactions is supported in a z/OS and OS/390 environment. For moreinformation, see “IMS Connector for Java Concepts and Terms.”

IMS Connector for Java can be configured to run on WebSphere Application Serveron various platforms and uses TCP/IP or Local Option communication protocols toconnect to IMS Connect. The Local Option communication protocol is nowsupported for both CCF and J2C applications. In addition to TCP/IP, you can nowuse Local Option to establish communication between IMS Connector for Java andIMS Connect V1.2 for both CCF and J2C applications, provided that both IMSConnector for Java and IMS Connect exist in the same MVS image.

The following table summarizes the available communication protocols and the levelof transaction support supplied by the runtime component of IMS Connector forJava on various platforms. In this table, the heading “Platform of WebSphereApplication Server with IMS Connector for Java” refers to the fact that theWebSphere Application Server can be configured to access all of the IMSConnector for Java class libraries. See “Preparing your WebSphere ApplicationServer environment for Windows)” or “Preparing your WebSphere ApplicationServer Environment for z/OS and OS/390” for more information.

Platform of WebSphereApplication Server withIMS Connector for Java

Supported CommunicationProtocols

Transactional (2-phasecommit) Support

AIX TCP/IP (CCF and J2C) No

Linux for zSeries and S/390 TCP/IP (CCF) No

z/OS, OS/390 TCP/IP (CCF and J2C)

Local Option* (CCF and J2C)

Yes with Local Option (J2Conly)**

Solaris TCP/IP (CCF and J2C) No

Windows TCP/IP (CCF and J2C) No

Restrictions:

* To use Local Option for communication between IMS Connector for Java and IMSConnect, both IMS Connector for Java and IMS Connect must exist in the sameMVS image.

** To use Transactional (2-phase commit) support in this release, IMS Connector forJava, IMS Connect, WebSphere Application Server, and IMS must exist in the sameMVS image. Future releases of IMS Connector for Java will remove this restriction.

10 IMS Connector for Java User’s Guide and Reference

Important: Throughout this documentation, platform specific information in thesamples and examples pertains to the Windows platform. Information for all othersupported platforms is available on the IMS Connector for Java Web pages, locatedin the IMS Web site at www.ibm.com/ims. You can also find some additionalsamples and examples for non-Windows platforms on the Web. CCF examples andsamples for non-Windows platforms can be found on this Web site.

IMS Connector for Java concepts and termsThis section provides an overview of some of the concepts and terminology neededto understand IMS Connector for Java. It includes:

v Connecting with Local Option (page 11)

v Connection Management in the CCF implementation (page 12)

v Connection Management in the J2C implementation (page 14)

v EAB commands that use IMS Connector for Java (page 15)

v Enterprise JavaBeans (EJB) (page 15)

v IMS Conversations (page 16)

v IMS Messages (page 17)

v IMS Security Information (page 19)

– For CCF (page 19)

– (For J2C)

v Java Classes that are Provided with IMS Connector for Java for CCF (page 22)

v Java Classes that are Provided with IMS Connector for Java for J2C (page 27)

v J2EE Modules (page 28)

v MFS Formatting (page 29)

v Synchronization Level (page 29)

v Transaction Management for J2C (page 31)

– Global Transaction and 2-Phase commit processing

– Types of J2C transactions:

- Component-managed (or bean-managed) transactions

- Container-managed transactions

- IMS Connector for Java J2C transaction support

The information in this section pertains to IMS Connector for Java using both theCommon Connector Framework (CCF) and the Java 2 Platform Enterprise Edition(J2EE) Connector (J2C) Architecture, unless otherwise indicated.

Connecting with Local Option

IMS Connector for Java allows you to use either TCP/IP or the Local Option supportfor connections between IMS Connector for Java and IMS Connect. Local Optionprovides non-socket access to IMS transactions and data from z/OS and OS/390WebSphere Application Servers (where the servlet or Enterprise JavaBean usingIMS Connector for Java is running).

You can use Local Option in both CCF and J2C implementations of IMS Connectorfor Java.

Using Local Option in the CCF Implementation

Chapter 1. Understanding IMS Connector for Java 11

To use Local Option in the CCF implementation of IMS Connector for Java,set the Host Name property of the IMSConnectionSpec bean to LOCALHOST:ims_connect_name. The IMS Connect name is case-sensitive and must matchthe ’HWS ID’ of the target IMS Connect. Local Option will then be used forcommunication between servlets executing IMS Connector for Java EABcommands and IMS Connect. If LOCALHOST: ims_connect_name is notspecified (that is, the first ten characters of the host name are anything otherthan “LOCALHOST:”,) then IMS Connector for Java will assume that it is aTCP/IP host name and will attempt to use TCP/IP communications. Thecharacters in LOCALHOST are not case-sensitive; the ims_connect_name iscase-sensitive.

Development of EAB commands for use by servlets that use Local Option isdone on VisualAge for Java for Windows. Setup of IMS Connector for JavaLocal Option on an OS/390 machine requires deployment of an additionalclass library, the Local Option shared library libimsconn.so, which is shippedwith the IMS Connector for Java runtime component and packaged inside theimsico.rar file.

Using Local Option in the J2C Implementation

To use Local Option with J2C, define the IMS Connect name property of theIMSManagedConnectionFactory with a 1 to 8 alphanumeric character name ofthe target IMS Connect. The IMS Connect name is case-sensitive and mustmatch the ’HWS ID’ of the target IMS Connect. Local Option is then used forcommunication between IMS Connector for Java and IMS Connect. If the IMSConnect name property is not specified, IMS Connector for Java uses thevalue specified in the Hostname and Port number property and defaults tousing TCP/IP communications instead.

Setting up IMS Connector for Java Local Option for J2C on a z/OS andOS/390 machine requires deployment of an additional class library, the LocalOption shared library libimsico.so, which is shipped with the IMS Connector forJava runtime component.

Connection Management in the CCF implementation

Connection management support is a set of functions that allow the connectorframework for both CCF and J2C to automatically provide and manage connectionsto your backend enterprise information systems. Connection pooling and reuse areimportant aspects of this connection management support. Connection pooling,through the reuse of connections, is key to enhancing the performance of Javaapplications or servlets that access IMS transactions. Reuse of connectionsminimizes the overhead of connection initialization and significantly enhancesperformance.

Connection management is a feature provided by the IBM Common ConnectorFramework (CCF). CCF is a set of Java APIs that provides infrastructure serviceslike connection management, transaction services, security, and tracing facilities toJava applications and servlets. CCF currently provides two types of connectionmanager:

com.ibm.connector.internal.DefaultConnectionManagerDefaultConnectionManager is the default connection manager used by theRuntimeContext classes (specifically, RuntimeContext andJavaRuntimeContext) shipped with VisualAge for Java. It does not support

12 IMS Connector for Java User’s Guide and Reference

connection pooling. A new connection is created for each transactionrequest and the connection is disconnected when the transaction iscomplete.

com.ibm.connector.connectionmanager.ConnectionManagerConnectionManager is a ’real’ connection manager that supports connectionpooling. It maintains one or more pools of reusable connections for IMSConnect.

For TCP/IP connections, there is a separate pool of reusable connectionsfor each Hostname/Port number combination used by IMS Connector forJava.

For Local Option connections, there is a separate pool of reusableconnections for each IMS Connect used by IMS Connector for Java.

When the ConnectionManager class is used with IMS Connector for Java, aconnection with IMS Connect is obtained for each transaction request.When the request has been completed (or the last request, in the case of aconversational application, has been completed), the connection is thenreturned back to the pool to be reused by subsequent requests.

There should be one instance of the ConnectionManager class used within acomponent server (for example, WebSphere Application Server). If your componentserver supports the CCF infrastructure, a single instance connection manager wouldbe established and be accessed by the servlets using IMS Connector for Java. Ifyour component server does not support the CCF infrastructure, you can use aseparate servlet to implement a single global instance of the ConnectionManagerobject. This single instance can then be accessed by any other servlet whoseconnection manager in RuntimeContext has been set to this ConnectionManagerobject.

As a result, to ensure connection pooling is established properly in your componentserver for running your servlet requests with CCF connectors, there must be oneinstance of connection manager AND the type of connection manager being usedmust support connection pooling (for example, the typecom.ibm.connector.connectionmanager.ConnectionManager).

IMS Connector for Java has provided a sample implementation of a servlet thatstores a single global connection manager of typecom.ibm.connector.connectionmanager.ConnectionManager in the ServletContext.The source code of the servlet is in the RegisterConnectionManager servlet in thecom.ibm.connector.ims.sample.cm package included in the IMS Connector Samplefeature. This sample could be used when your component server does not supportthe CCF infrastructure or it does not use a type of connection manager thatsupports connection pooling. This sample servlet must be loaded once when thecomponent server starts to establish the connection manager. To load the sampleservlet, invoke the following URL from your web browser:http://serverhostname/servlet/com.ibm.connector.ims.sample.cm.

RegisterConnectionManager

where serverhostname is the hostname of your component server.

To access the global instance of the ConnectionManager from the ServletContext inyour servlet code, add the following sample code in the method that uses executesthe EAB command (for example, for a servlet generated by WebSphere Studio, itwill be placed in the performTask() method). This code should be placed before theexecute() method of the EAB command is called:

Chapter 1. Understanding IMS Connector for Java 13

// Access the global instance of ConnectionManager from the ServletContext.ServletConfig sc = getServletConfig();ServletContext sctx = sc.getServletContext();com.ibm.connector.connectionmanager.ConnectionManager connMgr =

(com.ibm.connector.connectionmanager.ConnectionManager)sctx.getAttribute(“CCFConnectionManager);

// Setup the Connection Manager with the RuntimeContextRuntimeContext.getCurrent().setConnectionManager(connMgr);

A sample usage of the above code can be found in the servlet examples included inthe Connector IMS Samples project of Visual Age for Java.

Note: IMS Connector for Java always uses a persistent connection (sometimesreferred to as a persistent socket) with IMS Connect. IMS Connect enforces thisconnection type for both TCP/IP socket and Local Option PC connections. WhenIMS Connector for Java is running with CCF connection pooling, the connection willbe returned to the CCF connection pool when the transaction is complete. Theconnection will remain active for reuse by another client and the connection will notbe disconnected. When IMS Connector for Java is not running with CCF connectionpooling, the connection type between IMS Connector for Java and IMS Connect isstill persistent. However, at the end of the client transaction, the connection will bedisconnected. Thus, when CCF connection pooling is not being used, theconnection is still a persistent one but has the appearance of a transactionconnection (also known as a transaction socket). In this case, IMS Connector forJava (instead of IMS Connect) disconnects the connection upon completion of eachIMS transaction request.

Connection Management in the J2C implementation

Application components using the J2C implementation of IMS Connector for Javaare targeted for the WebSphere Application Server implementation of the J2Cconnection management contract, which supports connection pooling and reuse.WebSphere Application Server’s Connection Manager maintains a connection poolfor each hostName/portNumber combination for TCP/IP connections. For LocalOption connections, a separate pool of reusable connections exist for each IMSConnect used by IMS Connector for Java.

For WebSphere Application Server for workstation platforms (like Windows, AIX,Solaris), you can configure the pooling properties for each connection pool. Forinstructions on how to edit the connection pooling properties, see the WebSphereApplication Server Advanced Edition Information Center for workstation platforms.For a description of connection pooling properties, see the VisualAge for Javadocumentation by clicking Help > Help Home Page > Reference > IBM APIs >Enterprise Access Builder for Transactions > Packagecom.ibm.connector2.spi.ConnectionPoolProperties.

When you are testing your application components in VisualAge for Java’sWebSphere Test Environment, you must run additional code in order to haveconnection pooling. For details, read the information provided for the J2EE JSP andservlet sample in the VisualAge for Java documentation by clicking Help > HelpHome Page > Samples > Enterprise Access Builder for Transactions >WebSphere Set > J2EE JSP and servlet sample.

In addition, samples of servlets that can be used when running in VisualAge forJava’s WebSphere Test Environment can be found in packagecom.ibm.ivj.eab.sample.ws.j2ee.servlet of the IBM Enterprise Access BuilderWebSphere Samples project.

14 IMS Connector for Java User’s Guide and Reference

Note: IMS Connector for Java always uses a persistent connection (sometimesreferred to as a persistent socket) with IMS Connect. IMS Connect enforces thisconnection type for both TCP/IP socket and Local Option PC connections. WhenIMS Connector for Java is running in a managed environment that supportsconnection pooling, such as WebSphere Application Server, the connection will bereturned to the connection pool when the transaction is complete. The connectionwill remain active for reuse by another client and the connection will not bedisconnected. When IMS Connector for Java is running in an environment that doesnot support connection pooling, the connection type between IMS Connector forJava and IMS Connect is still persistent. However, at the end of the clienttransaction, the connection will be disconnected. Thus, when connection pooling isnot being used, the connection is still a persistent one but has the appearance of atransaction connection (also known as a transaction socket).

EAB commands that use IMS Connector for Java

EAB commands that use IMS Connector for Java are developed with the VisualAgefor Java Command Editor. An EAB command built for IMS Connector for Java is acomposite Java bean that consists of the following:

v A Java bean (page 22) representing the input to the IMS transaction

v One or more Java beans representing the output from the IMS transaction

v An IMSConnectionSpec bean (for CCF), representing the connection betweenthe EAB command and the IMS Connect host component

v A Connection Factory Configuration object (for J2C) for specification ofconnection information.

v An IMSInteractionSpec bean containing information about the type of interactionthat the EAB command has with IMS using IMS Connect. The CCFIMSInteractionSpec also contains the name of the target IMS datastore.

v A DFSMsg bean

This bean processes potential error or status messages (DFS messages) fromIMS. These messages begin with the three characters DFS.

For the differences between building CCF and J2C EAB commands, see theVisualAge for Java documentation by clicking Help > Help Home Page >Concepts > Access to transaction systems > Enterprise Access Builder forTransactions > EAB constructs > How Commands in J2EE and CCF differ.

Enterprise JavaBeans (EJB)

The IMS Connector for Java implementation of Sun’s Java 2 Platform, EnterpriseEdition Connector (J2C) Architecture introduces the use of Enterprise JavaBeans(EJB) to build your applications. An EJB defines how server-side components arewritten and provides a standard architectural contract between the components andthe application servers and containers that manage them.

The two types of EJBs are entity beans and session beans.

Entity beanAn entity bean is an EJB that represents the data in your database directly.It handles multiple instances of that data being called by multiple clients.Entity beans do not contain business process logic. They are only used tomodel data within the database and contain functions that are used todirectly initialize, modify, or remove that data.

Chapter 1. Understanding IMS Connector for Java 15

Session beanThe bean class of session beans implement business logic. The lifetime ofa session bean is shorter than that of an entity bean. Generally, sessionbeans have the lifetime equivalent of a client session. The client sessionlasts as long as the client is connected to the application. Session beansare unique to each client. Session bean information and state are notshared between clients. The two types of session beans are statefulsession beans and stateless session beans.

Stateful session beanA stateful session bean holds a conversation that can span manymethod calls. The same bean can be used to serve all of themethod calls that come from a single client. During thisconversation, the bean holds conversational state for that client.Conversational state is information sent to or acquired by the beanthat can be referenced throughout the life of the conversation. Theconversational state of a stateful session bean is stored in the beaninstance fields.

Stateless session beanA stateless session bean holds a conversation that spans a singlemethod call. After each method call, a stateless session beanreleases any information from the previous method call andbecomes available to serve a new request.

VisualAge for Java Version 4.0 offers the EJB Development Environment featurethat helps you create EJBs.

Related Information: For more information on EJB and J2EE, see the VisualAgeDeveloper Domain at http://www7.software.ibm.com/vad.nsf. For more informationon session beans and these two types, see the IBM Redbook EJB Developmentwith VisualAge for Java for WebSphere Application Server, SG24-6144-00, availableat http://www.ibm.com/redbooks.

IMS Conversations

IMS Connector for Java Conversational Support allows customers to build Javaapplications and Web applications to access IMS conversational transactions.

A conversational IMS transaction is a transaction that is defined to IMS as beingconversational, meaning that it can be invoked repeatedly to process the individualsteps of a conversation. An IMS conversation is made up of a connected series ofclient-to-program-to-client interactions. Although multiple IMS application programsmay be involved in the processing of a conversation or even the processing of asingle interaction, only a single client can participate in a conversation. In order toparticipate in an ongoing IMS conversation, a transaction must be conversational. Inother words, it must be defined as conversational to IMS and it must conform to therequirements of IMS conversational processing. If control is passed to anonconversational program during a conversation, IMS will terminate theconversation. The IMS conversational program receives messages from the client,processes the requests and replies to the client. It also saves the intermediate datafrom the transaction in the scratch pad area (SPA). When the user enters moredata from the client, the program has access to the data it saved from the lastmessage in the SPA, and thus can continue processing the request without having

16 IMS Connector for Java User’s Guide and Reference

the user enter that data again. When the client sends a message to initiate the nextiteration of the conversation, the program uses the data in the new message alongwith the data it saved in the SPA at the end of the last iteration of the conversationas its input. In more complex conversations, different transactions can be invokedusing an immediate or deferred program switch.

Related Reading: For more information on IMS conversations in general, as wellas information on more in-depth topics such as program switching, refer to IMSConversations in Application Programming: Transaction Manager and GatheringRequirements for Conversational Processing in Application Programming: DesignGuide of the IMS books.

In a Web application that takes part in an IMS conversation, the user submits aseries of requests each of which invokes a Java servlet which in turn processes aniteration of the conversation. In fact, different servlets can be used to process theiterations of a given conversation depending on how you program the input HTMLand input/output JSP pages of the application. However, all of the servlets must usethe same connection. This is handled automatically by the connection managerwhen you use a connection manager that supports connection pooling. For eachiteration, the Java servlet receives an input request from the browser and utilizesIMS Connector for Java to send a conversational transaction request to IMS usingIMS Connect. IMS Connect then forwards the transaction request to IMS throughOTMA. IMS schedules the conversational transaction that either continues theexisting conversation or starts a new IMS conversation (if this is the first iteration ofa conversation). The IMS application processes the request and sends the outputback to the Java servlet using IMS Connect and IMS Connector for Java. The Javaservlet then loads the appropriate JavaServer Page to display the output of thatiteration to the user in the browser.

IMS Connector for Java Conversational Support provides two programming modelsfrom which to build a conversational Web application. The programming models arethe Conversational HttpSession Model and the Conversational Navigator Model.

The following commands, however, are not supported for IMS conversations thatare initiated using IMS Connector for Java Conversational Support:/EXIT*/HOLD/RELEASE

*Note: For a servlet that simulates the /EXIT command, see the packagecom.ibm.connector.ims.sample.conv.forcend.servlet in the Connector IMS Sampleproject.

IMS Messages

An EAB command for a typical IMS transaction includes Java beans that representthe IMS transaction input and output messages. These beans are constructed byVisualAge for Java’s Enterprise Access Builder by first parsing the COBOL sourceof the IMS transaction’s application program. The Enterprise Access Builder toolthen uses this information to create the transaction input and output beans thatmatch the input and output messages received and sent by that IMS applicationprogram.

The degree to which VisualAge for Java can create Java beans that accuratelyrepresent an IMS transaction’s input and output messages is limited by the way inwhich messages are defined in the COBOL application program. To overcome these

Chapter 1. Understanding IMS Connector for Java 17

limitations, if any, you can create files that contain 01 level COBOL definitions forthe input and output messages used by your COBOL IMS application program. Youcan then use these files in the Enterprise Access Builder instead of the originalCOBOL IMS application program. This technique can also be used if your IMSapplication program is not written in COBOL

Related Reading: For more information on the COBOL parser and its limitations,see the VisualAge for Java documentation. Click Help > Help Home Page >Concepts > Access to transaction systems > Enterprise Access Builder forTransactions > Limitations.

The messages sent to IMS or received from IMS by a Java application or servletusing IMS Connector for Java can be any of the following:

v IMS transaction input messages

v IMS transaction output messages

v IMS status or error messages (also called ”DFS“ messages)

v IMS commands

v IMS command output messages

IMS Connector for Java is primarily designed to handle the first three types ofmessages. IMS messages, both input and output, can consist of multiple segments.“Building a Java application for an IMS transaction with multi-segment outputmessages” and “Building a Java application for an IMS transaction withmulti-segment input messages” provide examples of how to create Javaapplications that run IMS transactions with multiple segment messages. For atransaction input or output message, no restrictions exist on the number ofsegments. The IMS Connector for Java-supplied bean, DFSMsg, supports bothsingle-segment IMS output messages and multiple-segment IMS output messagesof 22 segments or less. These ”DFS“ output messages are sent by IMS to reflectIMS errors or status changes in response to a transaction request received by IMS.They are also returned as the output response from an IMS command. While it ispossible to submit a command to IMS from a Java application or servlet using IMSConnector for Java that generates more than 22 segments of command output, thatJava application or servlet is restricted to receiving a maximum of the first 22segments of that command output.

Message segments that are sent to and received from IMS transactions alwaysbegin with a 2-byte segment length field (called LL), followed by a 2-byte field thatcontains IMS information (called ZZ). The 2-byte segment length field representsthe length of the entire message segment, including the LL and ZZ fields. The dataof the message segment follows the LL and ZZ fields. In the case of the firstsegment of the transaction’s input message, up to the first the first n+1 bytes of thedata portion of the segment contain the n-byte transaction code, followed by ablank.

COBOL definitions that represent transaction input and output message segmentsmust contain fields for the segment length, the IMS information, and the dataportions of a segment. A Java application or servlet must ”set“ the individual fieldsof a transaction input message segment before sending that segment to IMS. Thefields are set by doing the following:

v Set the individual fields of the data portion of message segments using ”set“methods. Typically values for these methods are provided by the end user usinga GUI or input HTML page. In some cases values for ”set“ methods, such as thetransaction code, can be ”hard-coded“ in the Java program.

18 IMS Connector for Java User’s Guide and Reference

v Set the segment length field (LL) to be the sum of the defined lengths of all thedata fields, plus 4. If LL is not set correctly, IMS Connector for Java might throwan exception or unpredictable results might occur, depending upon the IMSapplication program. Consider adding a method to your EAB command that usesthe getSize() method of com.ibm.record.CustomRecord to return the size of yourtransaction input message.

v Setting the IMS information field (ZZ) is optional.

Note: If your IMS application program is written in PLI, you must represent thetransaction input and output messages in COBOL in order to use the EnterpriseAccess Builder to generate Java beans for the EAB command. The COBOL datastructures are created by ”mapping“ the message data structures in the PLI IMSapplication program. The only exception is that the segment length field, LL, mustbe mapped to a COBOL definition that represents 2 bytes. When the PLITDLIinterface is used, IMS adjusts the LL field of the input message presented to theIMS application program from 2 bytes to 4 bytes, and conversely, from 4 bytes to 2bytes on output. As is normally the case for the PLITDLI interface, the segmentlength field (LLLL) is defined in the IMS application program as 4 bytes and thevalue in the LLLL field is the input message length minus 2.

IMS Security Information

The IMS logon information (user ID, password, and group name) provided to a Javaapplication or servlet is used by IMS Connector for Java for both CCF and J2Cimplementations as follows:

The user ID, password, and group name are placed in the OTMA message sent byIMS Connector for Java to the host component, IMS Connect. IMS Connect thencalls the host’s Security Authorization Facility (SAF) under control of the IMSConnect RACF state SETRACF command:

v If RACF=Y (the SETRACF ON command has been issued), the SAF is called. Ifuser authentication succeeds, the UTOKEN built by the SAF is passed on to IMSfor authorization. If user authentication fails, IMS Connect returns an error to IMSConnector for Java.

v If RACF=N (the SETRACF OFF command has been issued), the SAF is notcalled by IMS Connect. The user ID and group name are passed on to IMS forauthorization.

Four levels of authorization are available in IMS. These levels are controlled by theIMS command, /SECURE OTMA, as follows:

1. If /SEC OTMA NONE is issued, no authorization is performed.

2. If /SEC OTMA CHECK is issued, the UTOKEN or user ID and group name arepassed to the SAF to ensure the user (in the group) is authorized to execute thetransaction (or command).

3. If /SEC OTMA FULL is issued, in addition to performing CHECK levelauthorization, a user security profile is built in the MPP region for use bynon-IMS services.

4. If /SEC OTMA PROFILE is issued, the result is the same as if /SEC OTMAFULL is issued, because IMS Connector for Java sets the Security Data sectionof the OTMA message prefix for each transaction to the FULL option.

For CCF:

Chapter 1. Understanding IMS Connector for Java 19

Be sure to read the section under ”IMS Security Information (page 19)“ (above),which applies to both CCF and J2C implementations.

Relationship of IMS logon information to EAB commandsIMS logon information is set in the run-time context of a Java application or servlet.For example:com.ibm.connector.imstoc.IMSLogonInfoItems logon =

new com.ibm.connector.imstoc.IMSLogonInfoItems(runtimeContext.getLogonInfo(),cmd.getConnectionSpec());

logon.setUser(”yourUID“);logon.setPassword(”yourPwd“);logon.setGroup(”setGroup“);

Typically this is performed at the beginning of an application or servlet, and lasts forthe duration of the application or servlet. However, in some situations, it might bedesirable to change the IMS logon information within an application or servlet. Forexample, an application or servlet might run multiple transactions that belong todifferent groups. In this case, the setGroup() method must be invoked before eachexecute of an EAB command in order to set the appropriate group name for thetransaction that the command runs. This applies to both of the following cases:

v A different EAB command is used for each transaction

v The same EAB command is used for all the transactions

In certain situations the same EAB command can be used for multiple transactions.For example, multiple transactions might have the same input and output messagestructure but different transaction codes.

The IMS logon information can be changed between invocations of the execute()method for the same EAB command. This is useful if, for example, the same EABcommand is used for different transactions, and the transactions have differentgroup names.

For J2C:

Be sure to read the section under ”IMS Security Information (page 19)“ (above),which applies to both CCF and J2C implementations.

The following table summarizes the J2C security support for the current release ofIMS Connector for Java.

WebSphere Application Server with IMSConnector for Java platform

Supported Resource Authentication Type

Application(Component-managed)

Container(Container-managed)

Windows, AIX, Solaris Yes No

z/OS, OS/390 Yes Yes (with LocalOption only)

When a J2C application component requests a connection to an EnterpriseInformation System (EIS) resource (such as IMS Connect or IMS), the EIS mightrequire a sign-on to that resource. Two options are available to the J2C applicationfor managing EIS sign-on: component-managed and container-managed sign-on.

Definitions:

20 IMS Connector for Java User’s Guide and Reference

Component-managed Sign-onThe J2C application sets the res-auth deployment descriptor element to beApplication. The component code performs a programmatic sign-on to theEIS (IMS Connect/IMS) by passing the explicit security information(username, password, and groupname) to the getConnection method ofthe IMSConnectionFactory instance. To pass security information to aconnection for IMS Connect/IMS, you must use the IMSConnectionSpecclass. The component sets values for username, password, and groupnamein an instance of the IMSConnectionSpec class and provides that instanceto the getConnection method. For example:com.ibm.connector2.ims.ico.IMSConnectionSpec connSpec =

new com.ibm.connector2.ims.ico.IMSConnectionSpec();connSpec.setUserName(”yourUID“);connSpec.setPassword(”yourPwd“);connSpec.setGroupName(”yourGrp“);

Connection conn = connectionFactory.getConnection(connSpec);

If you use EAB commands in your application, you can specify the securityinformation by editing the connectionSpec property of theConnectionFactoryConfiguration property of your EAB command:

1. Edit your EAB command using the EAB Command Editor and select the″ConnectionFactoryConfiguration″ class inside the Connection folder.

2. Select the com.ibm.connector2.ims.ico.IMSConnectionSpec class for theconnectionSpec property. Then provide security information as desired.

3. Optionally, you can promote the connectionSpec property to generate asetter method for the connectionSpec property on the EAB command.Then you can invoke the setter method on the EAB command toprovide the security information.

For more information about EAB commands, please refer to the VisualAgefor Java documentation.

The security information is then sent by IMS Connector for Java to IMSConnect and IMS for the appropriate security validation. See ”IMS SecurityInformation (page 19)“ for more information.

Container-managed Sign-onThe J2C application component sets the res-auth deployment descriptorelement to be Container. The application server (WebSphere ApplicationServer) takes the responsibility of managing sign-on to the EIS (IMSConnect/IMS). The component code invokes the getConnection method onthe IMSConnectionFactory instance with no security-related parameters.The application runs with the identity associated with the current thread ofexecution set up by the application server.

Note: If the component code passes an IMSConnectionSpec instance withexplicit security information to the getConnection method on theIMSConnectionFactory instance, that security information is ignored.

Related Reading: Currently, IMS Connector for Java supportscontainer-managed sign-on for WebSphere Application Server for z/OS andOS/390 only. To set up your J2EE application with the appropriate securityidentity to use the container-managed sign-on on WebSphere ApplicationServer for z/OS and OS/390, see the document titled ”WebSphereApplication Server V4.0.1 for z/OS and OS/390: WebSphere for

Chapter 1. Understanding IMS Connector for Java 21

z/OS-supported Connectors.“ This document is available with APARPQ55873 for WebSphere Application Server V4.0.1 for z/OS and OS/390.

To download the document, go tohttp://www.ibm.com/software/webservers/appserv/zos_os390/support.html,then click Product information. At a later time, the information in thisdocument will be integrated into the WebSphere for z/OS formalpublications. To access the latest publications, go to the product librarypage at http://www.ibm.com/software/webservers/appserv/.

When the connection is successfully established, all application-level invocations tothe EIS instance using the connection occurs under the security context of theauthenticated user.

When you configure an IMSConnectionFactory you can specify default values forusername, password, and groupname (see ”Creating and Configuring a ConnectionFactory for use by the IVP“ in ”Preparing your WebSphere Application ServerEnvironment for Windows“ or ”Preparing your WebSphere Application ServerEnvironment for z/OS and OS/390“). These default values will be used for allconnections created by that connection factory and placed in the OTMA messagefor authentication and authorization by IMS Connect and IMS under the followingcircumstances:

v The J2C application specifies component-managed sign-on, but the applicationcomponent does not pass an IMSConnectionSpec instance to thegetConnection method.

v The J2C application specifies component-managed sign-on, but the applicationcomponent passes an IMSConnectionSpec instance with no security informationto the getConnection method.

Note: When any value (username, password, or groupname) in theIMSConnectionSpec instance is null, the default value from theIMSConnectionFactory is used.

v The J2C application specifies container-managed sign-on, but IMS Connector forJava does not support container-managed sign-on with the application server onthat platform.

Java Classes that are Provided by IMS Connector for Java for CCF

IMS Connector for Java provides a number of Java classes to aid you in buildingJava programs and servlets. All of these classes are in the IMS Connector for Javapackage com.ibm.connector.imstoc. Some of these classes are also Java beans.You can combine these beans into a composite bean that accesses an IMStransaction. The beans are available to VisualAge for Java’s Command Editor andVisual Composition Editor.

Definitions:

A Java bean is a reusable software component, an element of a program that mayor may not be seen by the end user at run time and is made up of one or moreJava classes. A visual Java bean is an element of a program that is seen by theend user at run time while a nonvisual bean is an element of a program that is notnecessarily seen by the end user.

1. Visual Java beans can be used to construct a graphical user interface for anEAB command. The interface can provide input to and display output from anIMS transaction. An example of a visual Java bean is a button that the userclicks to perform some action.

22 IMS Connector for Java User’s Guide and Reference

2. Nonvisual Java beans are beans which do not have visual representations atruntime. For example, all beans that are provided by IMS Connector for Javasuch as IMSConnectionSpec and IMSInteractionSpec, are nonvisual beans.

3. A composite Java bean is a Java bean that is comprised of other Java beans,either visual or nonvisual. In the context of this document, an Enterprise AccessBuilder (EAB) command is a composite bean that is constructed using theVisual Age for Java Command Editor.

For additional definitions, see the glossary in the VisualAge for Java online help.

The following classes are supplied by IMS Connector for Java:

IMSConnectionSpecThe IMSConnectionSpec bean provides information about the connectionbetween a Java program and an IMS Connect host component, as well asinformation about connection management. The IMSConnectionSpec Hostname and Port properties are specific to IMS Connector for Java, while theother properties are inherited from the Common Connector Frameworkinterface com.ibm.connector.ConnectionSpecManagementProperties.IMSConnectionSpec properties include the following:

Host nameFor a TCP/IP connection, the host name is set to the TCP/IP hostname of the machine running the IMS Connect that the EABcommand (IMS transaction) will be using.

For a connection that utilizes the Local Option of IMS Connector forJava, the host name is set to LOCALHOST: ims_connect_namewhere ims_connect_name is the IMS Connect ID (referred to in IMSConnect as ”HWS ID“) Once IMS Connect has been configured andstarted, the ims_connect_name will appear in the outstanding IMSConnect reply message on the MVS console of the host machinewhere it is running. For more information on the IMS Connect ID,see Creating the IMS Connect Configuration Member in the IMSConnect Guide and Reference.

Port The Port is a numeric value that may be used by the EABcommand for communication with IMS Connect. For a TCP/IPconnection, Port is a port used by IMS Connect on the specifiedhost machine where IMS Connect is running. For a Local Optionconnection, the Port value is not used.

IMSConvContextThe IMSConvContext bean is used to comply with the IMS Connectrequirement that the same connection is used for all iterations of an IMSconversation. A connection is a communications link, a socket in the case ofTCP/IP, and is analogous to the phone line that connects two telephonesduring a telephone conversation. IMS Connector for Java includes this classin its programming model for use by conversational Web applications. AJava application or servlet should create a single instance of theIMSConvContext class at the start of a conversation and associate thissingle instance with the connection used for the conversation. This willensure that the connection will be preserved for the lifetime of the IMS

Chapter 1. Understanding IMS Connector for Java 23

conversation and that the CCF ConnectionManager will always return thesame connection for each iteration of the IMS Conversation.

IMSConvUnboundHttpSessionCleanupIMS Connector for Java includes this class in its programming model foruse by conversational Web applications only. This class implements theHttpSessionBindingListener interface and is used to determine when theIMS conversation is unbound from the session. It then performs theappropriate cleanup.

WebSphere Application Server creates an HttpSession object to representthe HTTP session of the Web application (the connection between thebrowser and WebSphere Application Server.) An HttpSession object fires anunbound event when the associated HTTP session becomes unbound.When an HTTP session becomes unbound, the connection needs to bereturned for reuse and the IMS conversation needs to be terminated. Thiscleanup work is performed by methods of the IMSConvHttpSessionCleanupclass.

For example, an HTTP session becomes unbound when the user closesthe browser while the IMS conversation is still active. When the userprematurely exits the browser, the HTTP session associated with thebrowser eventually times out, as there is no more user interaction from thebrowser. At this point, the HttpSession object associated with the HTTPsession becomes unbound, causing an unbound event to be fired. TheIMSConvHttpSessionCleanup object receives this unbound event, which inturn triggers the calling of its valueUnbound() method. The valueUnbound()method issues a MODE_END_CONVERSATION request to end the IMSconversation and also performs any cleanup required to allow theconnection to be reused.

IMSConvHttpSessionCleanup implements the HttpSessionListener interfaceand has the following methods:

void setConvContext()Sets the IMSConvContext object of the current IMS conversation in theIMSConvHttpSessionCleanup object such that the appropriate resourcescan be cleaned up following an unbound event.

void valueUnbound()This method implements the valueUnbound() method of theHttpSessionBindingListener interface to terminate the IMS conversation andcleanup conversation resources.

IMSInteractionSpecThe IMSInteractionSpec bean provides information about the interactionbetween a Java program and a datastore. Interaction properties include:

ConvTerminatedThis property is set to TRUE if the host IMS application programends the IMS conversation. The Java application program checksthe value of this property after invocation of the execute() methodfor the EAB command, to determine whether or not theconversation has been terminated by the host. The following twomethods can be used:

24 IMS Connector for Java User’s Guide and Reference

void setConvTerminated(boolean)Sets the value of the convTerminated property. Thisproperty is set to TRUE when the conversation isterminated by the host.

boolean getConvTerminated()Gets the value of the convTerminated property. It is used bythe Java application program to determine whether or notthe conversation has been terminated by the host.

Datastore nameThe name of the target IMS datastore that is defined in the IMSConnect configuration file.

LTERM NameThe LTERM name used to override the LTERM name in the IMSapplication program I/O PCB.

Map nameAlso known as the MFS MOD name, the map name can beprovided by an IMS application program when returning the outputof a transaction. It can also be provided by IMS when returning astatus message, such as the output from a /DIS command, or anerror message. If a value for Map name is specified on input to anIMS transaction, it will be made available to the IMS applicationprogram.

Mode The type of interaction to be carried out between the Java programand the IMS datastore. The modes that are currently supportedinclude MODE_SEND_RECEIVE, MODE_ACK, MODE_NACK, andMODE_END_CONVERSATION.

Synchronization LevelSpecifies the transaction synchronization level — the way in whichthe Java client (for example, an application or servlet) and IMSinteract with respect to transaction output messages. Stated simply,the synchronization level determines whether or not the transactionoutput messages must be acknowledged either as accepted (ACK)or rejected (NACK) by the client.

For more information, see ”Synchronization Level.“ (page 29)

DFSMsgThe DFSMsg bean represents IMS status or error messages that arereturned to a Java application or servlet in response to a command or atransaction. These messages typically begin with the characters DFS. Oftentimes, DFS messages are returned to a Java application or servlet. SomeDFS messages indicate error situations, while others are returned as theoutput of IMS commands. In all cases, because OTMA is used to returnthe message, MFS formatting is not performed. However, IMS includes anMFS MOD name (Map name) with DFS messages. IMS Connector for Javachecks the MOD name field of messages that it receives from IMSConnect. If the MOD has one of the following names, the message isprocessed as a DFS message. If the name is not listed below, it isprocessed as transaction output.

Chapter 1. Understanding IMS Connector for Java 25

v DFSMO1

v DFSMO2

v DFSMO3

v DFSMO4

v DFSMO5

v DFSDSPO1

IMS Connector for Java builds a buffer containing one or more segments of a DFSmessage, up to a maximum of 22 segments. Any output data beyond the 22ndsegment is discarded. The buffer structure is as follows:

DFSLL1Two-byte length (LL) of the first segment of the output message. The length(LL) of a message segment includes the length of the LL and ZZ fields ofthe segment.

DFSZZ1Two-byte flag field (ZZ) of the first segment of the output message.

DFSDATA1The data of the first segment of the output message, blank-padded ortruncated to 119 bytes. DFSLL1 represents the length of the segmentreceived from IMS or the truncated length and, as such, is less than orequal to 123 (119 + 4).

...

...

...

DFSLL22Two-byte length (LL) of the 22nd segment of the output message. Thelength (LL) of a message segment includes the length of the LL and ZZfields of the segment.

DFSZZ22Two-byte flag field (ZZ) of the 22nd segment of the output message.

DFSDATA22The data of the 22nd segment of the output message, blank-padded ortruncated to 119 bytes. DFSLL22 represents the length of the segmentreceived from IMS or the truncated length and, as such, is less than orequal to 123 (119 + 4).

The buffer structure is used to populate a DFSMsg object. A Java program canobtain a DFS message from a DFSMsg object in the following ways:

getDFSMessage()Returns the message segments concatenated together as a singlestring.

getDFSMessageSegments()Returns a vector of the segments of the message.

In addition, the individual fields of the message segments (DFSLL1, DFSZZ1,DFSDATA1, etc.) can be accessed by a Java application or servlet.

Any of the above methods can be used by Java applications. Currently, however,WebSphere Studio does not allow selection of a method for use in displaying data

26 IMS Connector for Java User’s Guide and Reference

on a servlet’s output template. In order for a servlet to display a DFS message, theindividual fields of the DFSMsg object should be selected (DFSLL1, DFSZZ1,DFSDATA1, etc.) while in WebSphere Studio.

A composite bean that uses IMS Connector for Java should include a DFSMsgbean as well as bean(s) representing the output of the IMS transaction. VisualAgefor Java’s Enterprise Access Builder populates the appropriate output bean, basedon the data that is returned by IMS.

Related Reading: For more information on displaying a DFS message with aservlet, see ”Building a Java servlet to run an IMS transaction.“

Java Classes that are Provided by IMS Connector for Java for J2C

All classes mentioned below are in IMS Connector for Java packagecom.ibm.connector2.ims.ico. Interfaces beginning with javax.resource are part ofthe J2C architecture.

To view the Javadoc for these classes, go to VisualAge for Java and click Help >API Reference > Reference >IBM APIs > Connectors > IMS Connector.

IMS Connector for Java’s implementation of the J2C architecture will be provided inphases. Classes provided in this phase are summarized below. IMS Connector forJava uses these classes in collaboration with WebSphere Application Server toprovide connection pooling in the J2C environment. Connection pooling istransparent to the servlet or EJB.

IMS Connector for Java implements the J2C System Contracts by providing thefollowing classes. J2C interfaces are noted in parentheses:

v com.ibm.connector2.ims.ico.IMSManagedConnectionFactory(javax.resource.spi.ManagedConnectionFactory)

An IMSManagedConnectionFactory instance is a factory of bothIMSManagedConnection instances and IMSConnectionFactory instances.

v com.ibm.connector2.ims.ico.IMSManagedConnection(javax.resource.spi.ManagedConnection)

An abstract class that represents the physical connection to IMS Connect. TheIMSManagedConnection has 2 subclasses:

– com.ibm.connector2.ims.ico.IMSTCPIPManagedConnection

– com.ibm.connector2.ims.ico.IMSLocalOptionManagedConnection

An IMSTCPIPManagedConnection instance represents a TCP/IP connection toIMS Connect. An IMSLocalOptionManagedConnection instance represents aconnection using Local Option to communicate with IMS Connect.

v com.ibm.connector2.ims.ico.IMSManagedConnectionMetaData(javax.resource.spi.ManagedConnectionMetaData)

Provides information about an IMSManagedConnection.

IMS Connector for Java implements the J2C Common Client Interface (CCI) byproviding the following classes. J2C interfaces are noted in parentheses:

v Classes that represent a connection factory and an application level connection:

– com.ibm.connector2.ims.ico.IMSConnectionFactory(javax.resource.cci.ConnectionFactory)

An IMSConnectionFactory instance is a factory for IMSConnection instances.

Chapter 1. Understanding IMS Connector for Java 27

– com.ibm.connector2.ims.ico.IMSConnection(javax.resource.cci.Connection)

An IMSConnection instance is an application level handle than is used by acomponent to access IMS using IMS Connect.

– com.ibm.connector2.ims.ico.IMSConnectionSpec(javax.resource.cci.ConnectionSpec

An IMSConnectionSpec instance is used by components, when obtaining aconnection, to provide specific values for UserName, Password, andGroupName. These values are used instead of the default values provided bythe IMSConnectionFactory instance.

v Classes that enable a component to drive an interaction (specified through anInteractionSpec) with IMS using IMS Connect:

– com.ibm.connector2.ims.ico.IMSInteraction(javax.resource.cci.Interaction)

An IMSInteraction instance enables a component to interact (run atransaction) with IMS using IMS Connect.

– com.ibm.connector2.ims.ico.IMSInteractionSpec(javax.resource.cci.InteractionSpec)

An IMSInteractionSpec instance provides properties for driving the interactionwith IMS using IMS Connect.

v Classes that provide basic meta information about the IMS Connector for Javaimplementation and a connection to IMS using IMS Connect:

– com.ibm.connector2.ims.ico.IMSConnectionMetaData(javax.resource.cci.ConnectionMetaData)

Provides information about an IMSConnection.

– com.ibm.connector2.ims.ico.IMSResourceAdapterMetaData(javax.resource.cci.ResourceAdapterMetaData)

Provides information about IMS Connector for Java.

v Additional classes and interfaces provided by IMS Connector for Java are:

– IMSInteractionSpecProperties

IMSInteractionSpecProperties is an interface that defines named constantsthat are used to configure an IMSInteractionSpec instance.

– IMSTraceLevelProperties

IMSTraceLevelProperties is an interface that defines named constants that areused for controlling the level of tracing and logging that is performed by IMSConnector for Java.

– IMSConnectorMigrator

IMSConnectorMigrator is a class that is used by VisualAge for Java to migratea CCF EAB command to a J2EE EAB command.

– DFSMsg

A DFSMsg bean is used to capture ”DFS“ messages returned by IMS. For adescription of this bean, see the section ”Java Classes that are Provided forIMS Connector for Java for CCF“ (page 22) above.

J2EE Modules

A Java 2 Enterprise Edition (J2EE) application is comprised of J2EE modules.These modules are comprised of the following J2EE components:

v Enterprise beans

v Web components, specifically servlets or JavaServer Pages (JSPs)

28 IMS Connector for Java User’s Guide and Reference

v Application clients

v Applets

J2EE modules are archives: Java archive (JAR) files or Web application archive(WAR) files. A J2EE application, with all of its modules, is packaged and deliveredin an Enterprise Archive (EAR) file. An EAR file is a standard JAR file with an .earextension. You can install J2EE applications in WebSphere for z/OS and OS/390only when they are packaged in EAR files.

MFS Formatting

Transaction input and output messages that are provided to IMS through OTMAbypass online MFS processing. MFS is the online processing component in IMSthat performs message formatting, such as field padding, truncation, justification,and insertion of literal data in messages.

Currently, although VisualAge for Java includes an MFS parser, it does not supportcreating input and output record beans that are based on MFS message definitions(the MIDs and MODs in an MFS source file), and no MFS-like formatting isperformed.

When using IMS Connector for Java you need to consider any dependencies theIMS application program has on MFS online formatting and decide whether or notyou want to perform this function in your Java servlet or application.

Synchronization Level

Important: The current release of J2C implementation in IMS Connector for Javadoes not provide applications with the ability to specify synchronization level. IMSConnector for Java can use the IMS OTMA synchronization level internally tointeract with IMS OTMA and IMS Connect.

For the CCF implementation, the synchronization level can be specified for an EABcommand that runs an IMS transaction. Synchronization level determines the way inwhich IMS and the client that contains the EAB command interact. An EABcommand that runs an IMS transaction can execute with a synchronization of levelof None or Confirm.

Currently, all IMS Connector for Java interactions use the OTMA protocol CommitMode 1, also referred to as send-then-commit. Under this protocol, if thesynchronization level is Confirm, IMS sends the output message to the client andthen waits for a response from the client. It is the responsibility of the client torespond to IMS. If the synchronization level is None, IMS commits any changesmade by the IMS application without waiting for a response from the client.

Synchronization level noneWhen an EAB command uses a synchronization level of NONE, the transactionruns and IMS sends the output message to the client. Any database changes arethen committed. IMS does not require that the client send a message in responseto the transaction output message in order to commit the database changes.Synchronization level NONE is typically used for Java applications and servlets thatrun IMS transactions that browse or query host databases.

Synchronization level confirmWhen an EAB command uses the synchronization level Confirm, the transactionruns and IMS sends the output message to the client without committing any

Chapter 1. Understanding IMS Connector for Java 29

database changes. IMS does not complete the transaction until the client respondsto the transaction output message by sending a positive or negativeacknowledgment to IMS. If the client is satisfied with the transaction output, itresponds by sending a positive acknowledgment. IMS then completes thetransaction by committing the database changes, if necessary. If the client is notsatisfied with the transaction output (or does not want to continue with thetransaction for any reason) it responds by sending a negative acknowledgment. IMSthen rolls back any changes to the database.

If IMS Connect on the host encounters any errors from the Java application, it canalso send a negative acknowledgment to IMS to abort the transaction. For example,this might occur if communication with the Java application and IMS Connect is lostwhile processing the transaction.

The client application can respond to IMS in one of two ways.

1. If the coordinator object obtained from the current run-time context iscom.ibm.connector.infrastructure.NullCoordinator, the client sends a positive ornegative acknowledgement to IMS. This is done by executing a separate EABcommand with interaction mode MODE_ACK (for a positive acknowledgment) orMODE_NACK (for a negative acknowledgment) to send the appropriateacknowledgement message to IMS. Because a MODE_ACK or MODE_NACKEAB command only sends acknowledgment messages to IMS, it does notcontain any input or output beans.

2. If the coordinator object obtained from the current runtime context is notNullCoordinator, and is insteadcom.ibm.connector.infrastructure.java.JavaCoordinator, for example, then theclient invokes the commit() or rollback() method on the coordinator object,following receipt of the output message. The implementation of these methodswill, in turn, send the corresponding acknowledgement message to IMS.

In the case of an IMS conversation, different synchronization levels may be used forone or more of the iterations of the conversation. Since the conversationalprogramming model presented by IMS Connector uses a new instance of the EABcommand for each iteration of the conversation, the synchronization level must beexplicitly set for each iteration. Otherwise, the synchronization level set for thecommand at development time (usually the default, SYNC_LEVEL_NONE) will beused for the iteration.

If SYNC_LEVEL_CONFIRM is specified for a given iteration of an IMSconversation, either the commit() or rollback() method of JavaCoordinator must beexecuted following receipt of the output message for that iteration of theconversation. These messages can also be sent to IMS by creating two additionalEAB commands which would be used in a NullCoordinator environment. However, itis recommended that applications use the simpler JavaCoordinator interface. See”Building an application to run an IMS transaction with synchronization levelconfirm“ for an illustration of an application that uses an IMS nonconversationaltransaction with SYNC_LEVEL_CONFIRM. Iterations of IMS conversations that useSYNC_LEVEL_CONFIRM would be handled in a similar fashion, as far as commitand rollback processing is concerned.

Most likely the synchronization level will be the same for all iterations of the IMSconversation, in which case it would be appropriate to set it in theIMSInteractionSpec when the EAB command is developed.

A typical application scenario might be:

30 IMS Connector for Java User’s Guide and Reference

1. The application invokes a transaction EAB command with interaction modeMODE_SEND_RECEIVE and the synchronization level isSYNC_LEVEL_CONFIRM.

2. The application receives the transaction output from IMS.

3. The application performs some logic (or interacts with the end-user) to decidewhether the transaction should be completed.

4. Based on the results from the previous step, the application invokes thecommit() or rollback() methods of JavaCoordinator to respond to IMS.

5. IMS completes the transaction by committing or rolling back the databasechanges, based on the type of response (positive or negative acknowledgment)that it received.

Related Reading: For more information on building an application to run an IMStransaction with synchronization level, see ”Building an application to run an IMStransaction with synchronization level confirm.“)

Transaction Management for J2C

Global Transaction and 2-Phase commit processing

Many computer resources (for example, enterprise databases) are very critical to acompany’s work and the integrity of these resources must be guaranteed. Whenmaking changes to these protected resources, an application can group the set ofchanges into a transaction (also known as a unit of work), such that all the changesmade within a transaction are either fully completed or fully rolled back (also knownas all-or-nothing changes). There are two types of transactions: global and localtransactions.

Global TransactionA transaction is categorized as global when an external coordinator isavailable and is coordinating a transaction that could involve more than oneresource managers. The external coordinator uses the 2-phase commitprotocol to coordinate between different resource managers.

Local TransactionA local transaction is coordinated locally by the resource manager and thereis no external coordinator involved.

Related Reading: For more information about RRS and 2-phase commitprocessing, see z/OS and OS/390 MVS Programming: Resource Recovery.

IMS Connector for Java supports two types of interactions in terms of J2Ctransaction management:

v No Transaction

An IMS transaction request is submitted from a J2EE application to IMS throughIMS Connect for processing. Changes made by IMS in the processing of the IMStransaction will be committed before returning the transaction output to the J2EEapplication.

v Global Transaction

An IMS transaction request is submitted from a J2EE application to IMS throughIMS Connect for processing in the context of a global transaction. Changes madeby IMS are coordinated using the 2-phase commit protocol.

v Local Transaction

Local transaction support is not available in this release.

Chapter 1. Understanding IMS Connector for Java 31

The following table shows the J2C transaction support provided by IMS Connectorfor Java in this release:

Platform of WebSphere ApplicationServer with IMS Connector for Java

J2C Transaction Support

Windows, AIX, Solaris No transaction support

z/OS, OS/390 No transaction support when configured withTCP/IP communication

Global transaction support when configured withLocal Option*

* WebSphere Application Server, IMS, IMS Connect, and IMS Connector for Javamust exist on the same MVS image when using global transaction support.

Types of J2C transactions in your J2EE applications

The J2EE platform defines the Java Transaction API (JTA) which specifies theinterfaces between a transaction manager and other parties involved in transactionprocessing (such as the application programs, resource managers and theapplication server). Particularly, JTA defines two ways to demarcate a transaction ina J2EE application: component-managed and container-managed transaction.

Component-managed (or Bean-managed) transaction

The J2EE application uses the JTA javax.transaction.UserTransaction interfaceto demarcate a transaction boundary to a set of changes to the protectedresource or resources programmatically. Component-managed transaction canbe used in both the servlet and the EJB environment. In the case of an EJB,you sets the transaction attribute in its deployment descriptor asTX_BEAN_MANAGED.

A transaction normally begins with a UserTransaction.begin() call. When theapplication component is ready to commit the changes, it invokesUserTransaction.commit() to coordinate and commit the changes. If theapplication component prefers to rollback the transaction, it invokesUserTransaction.rollback() and all changes will be backed out. For example:// Get User Transactionjavax.transaction.UserTransaction transaction =ejbcontext.getUserTransaction();

// Start transactiontransaction.begin();

// Make changes to the protected resources.// For example, use the J2EE/CA’s CCI Interaction interface// to submit changes to an EIS system(s)interaction.execute(interactionSpec, input, output);

// Commit the transactiontransaction.commit();

Container-managed transaction

A container-managed transaction used in an EJB environment is managed bythe EJB container. The container calls the appropriate methods (such asbegin, commit or rollback) on behalf of the EJB component. The EJB specifies

32 IMS Connector for Java User’s Guide and Reference

a container-managed transaction declaratively through the transaction attributein the deployment descriptor (such as TX_REQUIRED). This declarativeapproach simplifies the programming calls in the EJB.

Related Reading: For more information the J2EE architecture and JTAspecifications, see http://java.sun.com/j2ee/docs.html for details.

IMS Connector for Java J2C transaction support

In this release, IMS Connector for Java adds support for global transactions and 2phase commit processing for WebSphere Application Server for z/OS and OS/390.This support allows J2EE application components (such as EJBs and JavaServlets) running under WebSphere Application Server for z/OS and OS/390 tosubmit IMS transaction messages in the context of global transaction and toparticipate in 2-phase commit processing. The Resource Recover Services (RRS)of z/OS or OS/390 coordinates this transaction processing. With this support,WebSphere for z/OS, RRS, and the IMS subsystem work together to makeconsistent changes to multiple protected resources.

To use this global transaction support, the following configuration is required:

v IMS Connector for Java must be configured with the Local Option communicationprotocol to process global transaction in this release. If configured with TCP/IP,IMS Connector for Java will process the requests with no transaction support.

v WebSphere Application for z/OS and OS/390, IMS Connector for Java, IMSConnect, IMS and RRS must all be running under the same MVS image forglobal transaction processing on the z/OS and OS/390 platform. This restrictionwill be lifted in the future updates of IMS Connector for Java.

When a J2EE application (such as a servlet or EJB) is running under a globaltransaction with the above configuration, the IMS transaction request is sent to IMSfor processing using the IMS OTMA synchronization level Syncpt protocol. Allchanges made to IMS will be part of a global transaction coordinated by RRS.

If the processing is not under a global transaction or if IMS Connector for Java isconfigured with no transaction processing (such as when it is configured to useTCP/IP communication), all requests to IMS are performed using the IMS OTMAsynchronization level None protocol. In this case, all changes to IMS are committedwhen the output is returned to the J2EE application.

Notes:

v Transaction support in IMS Connector for Java will be provided in phases. Futurereleases of IMS Connector for Java will provide enhanced J2C support includingXA transaction support for distributed platforms.

v IMS Connector for Java uses the RRS-Transaction support provided byWebSphere Application Server for z/OS and OS/390 in which the Localtransaction and XA transaction support as described by the J2EE ConnectorArchitecture is not supported.

Related Reading: More information about the RRS-transaction support isavailable in WebSphere Application Server for OS/390 and z/OS documentation.The document titled ”WebSphere Application Server V4.0.1 for z/OS and OS/390:WebSphere for z/OS-supported Connectors″ is available with APAR PQ55873 forWebSphere Application Server V4.0.1 for z/OS and OS/390. To download thedocument, go to the Web site athttp://www.ibm.com/software/webservers/appserv/zos_os390/support.html, thenclick ″Product information.″ At a later time, the information in this document will

Chapter 1. Understanding IMS Connector for Java 33

be integrated into the WebSphere for z/OS formal publications. To access thelatest publications, go to the product library page athttp://www.ibm.com/software/webservers/appserv/.

For information on the synchronization level protocol, see the IMS Connect Guideand Reference and the IMS Open Transaction Manager Access Guide andReference, available on the IMS Web site at (www.ibm.com/ims).

A provided sample (described in “Building Container-managed andComponent-managed Transactional EJBs to Run IMS Transactions”) demonstrateshow to build an J2EE application to access your IMS transaction using IMSConnector for Java with global transaction and 2-phase commit processing.Additional samples (such as global transactions with IMS and DB2 databases) willbecome available on the IMS Connector for Java Web page, located in the IMSWeb site at www.ibm.com/ims. Be sure to check this Web site periodically for thesesamples and supporting documentation.

IMS Connector for Java conversational programming modelsIMS Connector for Java Conversational Support provides users with twoprogramming models from which to build Java applications and Web applicationsthat iterate through the interactions of an IMS conversational program. Theprogramming models are based on the existing application model that uses IMSConnector for Java to invoke IMS transactions using IMS Connect. Applications builtfrom the programming model with CCF support use VisualAge for Java andWebSphere Studio. Applications built from the programming model with J2C supportuse VisualAge for Java and Application Assembly Tool (a WebSphere ApplicationServer tool). VisualAge for Java tools have been enhanced to help customersgenerate the record components specifically needed for generating the input andoutput messages of an IMS conversational transaction.

IMS Connector for Java provides both Common Connector Framework (CCF) andJava 2 Platform, Enterprise Edition (J2EE) Connector (J2C) architecture support forIMS conversations.

Restriction: When invoking an IMS Conversation within a global transaction with2-Phase commit processing (for example, with TX_REQUIRED), IMS OTMAsupports the execution of one iteration of an IMS Conversation only. Subsequentiteration invocations to an IMS Conversation within a global transaction will resultwith an error in IMS.

The information in this section includes the following:

v Considerations in Choosing a Model (page 35)

v Conversational HttpSession Model with CCF Support (page 35)

v Conversational HttpSession Model with J2C Support (page 38)

v Conversational Navigator Model with CCF Support (page 39)

v Conversational Navigator Model with J2C Support (page 40)

Generally, a Java application is built with a GUI interface that consists of multiplewindow panels. The user provides the input data and views the output data withinseparate panels of the same Java application when stepping through the iterationsof the IMS conversation. The Java application contains logic that utilizes Javaclasses in the IMS Connector for Java Conversational Support to invoke the IMSconversational transactions.

34 IMS Connector for Java User’s Guide and Reference

A Web application is made up of a group of application components that can beaccessed from the Web and consists of one or more Java servlets that contain theapplication logic, an HTML page which serves as the initial input page used to startthe application and one or more JSPs (Java Server Pages) for obtaining input datafrom and displaying output data to the user. The Java servlets within a Webapplication share the same servlet context. The user starts an IMS conversationaltransaction from a web browser by first providing some input data via an HTMLform. The web server then invokes the Java servlet running inside the WebSphereApplication Server. The servlet utilizes the Java classes in IMS Connector for Java(including the Conversational Support classes) to send the conversationaltransaction request and receive the transaction output via IMS Connect. The outputwill be displayed back to the user through a JSP in the web browser.

Although this documentation focuses primarily on modeling an IMS conversationwith a Web application, many of the same rules that pertain to Web applicationscan be applied to building Java applications, as well. Generally, the rules governingthe logic of a Java servlet can be applied to the logic of a Java application.Similarly, the rules governing the use of HTML and JSP pages can be applied tothe GUI interfaces of a Java application.

Considerations in Choosing a Model

You should choose the Navigator model if it is suitable for your IMS conversationsince it provides a simpler development paradigm and a more effective use ofconnections. From a development perspective, the conversational Navigator modeleliminates the need to deal with issues such as using the ″back″ button,bookmarking, browser caching or tracking the state of the IMS conversation. Inaddition, issues such as scaling, cloning, and clustering might affect your decisionof which model to use. Consult the WebSphere Application Server documentationfor a detailed discussion of these issues.

The Conversational Navigator model is suitable when a particular sequence ofinteractions representing a well defined task and the data required by all of thoseinteractions can be pre-determined. A conversational IMS application can be usedto process any number of tasks some of which may be suitable for the Navigatormodel and some of which are not. You will probably find that some small number oftasks for a given IMS conversational application can be implemented withconversational Navigators but the majority will require HttpSession based servlets.

Conversational HttpSession Model with CCF Support

IMS Connector for Java Conversational Support introduces a session-enabled Webapplication model for an IMS conversational transaction, the ConversationalHttpSession Model. A session encompasses a series of requests originating fromthe same browser to the Java servlet or servlets of a Web application. A session isanalogous to an SNA connection between a terminal user and an IMSconversational application program.

The Conversational HttpSession Model for building a Web application to invoke anIMS conversational transaction is similar to the programming model used forbuilding a Web application to invoke a non-conversational IMS transaction. Thesteps involve the use of VisualAge for Java and WebSphere Studio and are asfollows:

1. Provide your COBOL source files to VisualAge for Java to generate the inputand output Java record beans.

Chapter 1. Understanding IMS Connector for Java 35

2. Use the VisualAge for Java Command Editor to create an Enterprise AccessBuilder (EAB) command.

3. Supply the EAB command to WebSphere Studio and use WebSphere Studio togenerate a template for a Web application. Build a Web application from thetemplate using the guidelines outlined below. This process can be summarizedas follows:

a. Create additional JSP pages for the iterations.

b. Modify the JSP pages.

c. Modify the Java servlet.

The user submits a series of requests from the same browser to iterate throughdifferent interactions of an IMS Conversation. The user starts an IMS conversationaltransaction from a web browser by submitting a request to IMS to schedule (or run)a conversational transaction. The HTTP session associated with the browser isused to group the series of interactions from that browser. The conversationcontinues through any number of iterations until it is terminated, either by a useraction (i.e., the client) or by transaction program logic that directs IMS to end theconversation at the conclusion of that iteration. The conversational transaction canalso be terminated automatically by IMS Connector for Java’s classes whenever thesession-enabled Web application times out, for example, when the browser remainsidle for a specified period of time. This timeout is set using the JavaServlet APIs(the default is 30 minutes).

The JavaServlet specification provides a class, HttpSession, that is used byWebSphere Application Server to create an object associated with the HTTPsession used by the Web application. Once a session is established between thebrowser and the Java servlet, the Java servlet maintains a reference to this uniqueHttpSession object (i.e., the HttpSession object is bound to the servlet) throughoutall of the iterations for the duration of the conversation. The Java servlet uses thisunique HttpSession object to obtain information about the state of the session aswell as the state of the conversation that is running in that session.

An HttpSession object is associated with (bound to) a servlet at the start of the firstiteration of an IMS conversation. It remains bound to that servlet, or a succeedingservlet in the case of a multi-servlet Web application, until the servlet detects thateither the user has taken some action which will cause the IMS conversation to beterminated or the IMS application program has terminated the conversation.Program your servlets so that the session becomes unbound if there are any errorsencountered in the application flow. Possible errors include communication failurebetween components and abnormal termination of components. Program your Javaservlet to handle these errors appropriately. Generally, when an error occurs, yourservlet should terminate the conversation and clean up the connection resource forreuse.

For example, a browser session becomes unbound from a servlet when thebrowser times out waiting for input from the user. When this happens, the servletshould terminate the conversation and clean up the CCF connection resources. IMSConnector for Java Conversational Support provides theIMSConvHttpSessionCleanup class to capture the notification from the HttpSessionobject when the HttpSession object becomes unbound. TheIMSConvHttpSessionCleanup object instantiated by the servlet will then terminatethe conversational transaction and clean up the connection resources appropriately.

Since the HTTP protocol, which is used as the connection mechanism between theweb browser and the Java servlet, is stateless, it is often useful to bind objects to

36 IMS Connector for Java User’s Guide and Reference

the HttpSession object in order to save intermediate state data of the Webapplication. For example, you may want to save information about the currentiteration of the IMS conversation for use when the next iteration of the conversationis executed.

Another use for the HttpSession object is to save information about the connectionbeing used for a particular conversation. This is necessary since IMS Connectrequires a dedicated connection for the entire duration of an IMS conversation. Inother words, IMS Connect requires that the same connection be used for all of thecommunications between the Web application (Java servlet or servlets) and IMSConnect. Furthermore, that connection cannot be used for any othercommunications until that conversation has ended. A connection for purposes of thisdiscussion is the communications link between the Java application or servlet andIMS Connect. In a TCP/IP communications environment, this connection isrepresented as a socket.

In order to provide a mechanism for saving information about the connection beingused for an IMS conversation in the HttpSession object, IMS Connector for Javaincludes the IMSConvContext class in its Conversational HttpSession programmingmodel for conversational Web applications. This class provides a token which isstored in the HttpSession object and used to bind a particular CCF connection to aservlet that is part of an IMS Conversation. Therefore this servlet needs to create asingle IMSConvContext object at the start of each IMS conversation. This object isthen stored in the HttpSession object. The HttpSession object and therefore theIMSConvContext are then used by the CCF ConnectionManager to initially bind aconversation to a particular connection and later to ensure that the CCFConnectionManager will use that same connection for each iteration of theconversation. When the HttpSession object becomes unbound or an error occursduring the conversation, or at the end of the conversation, the IMSConvContextreference must be unbound from its connection in order to allow theConnectionManager to reuse that connection for new requests.

When the HttpSession object becomes unbound this is handled automatically by theIMSConvHttpSessionCleanup object that was instantiated in the Web applicationservlet when the conversation began. In the case of an error being detected in aservlet during a conversation, the unbinding is handled through the use of thehttpSession.invalidate() which in turn causes the IMSConvHttpSessionCleanupobject to be invoked. When a conversation ends normally, the IMSConvContextreference is unbound from its connection through the use of theRuntimeContext.getCurrent().close() method.

After the conversational transaction is completed, a new conversational ornon-conversational transaction can be run next from the client. However, if the IMSconversation is not completed, then you cannot run a new transaction with thesame connection resource.

In the Conversational HttpSession model, the application flow for an IMSconversational transaction starts when the user initiates a conversation from thebrowser. The flow continues with a series of interactions between the Webapplication and the IMS conversational application program performing the businesslogic of the application. Finally, the conversation is terminated by the user or by theIMS application program. The application flow is illustrated as follows:

Iterating in the IMS Conversation

1. The user starts an IMS conversational Web application by displaying the inputHTML page of the Web application in a Web browser.

Chapter 1. Understanding IMS Connector for Java 37

2. The user provides the initial input data of the IMS conversational transaction inthe input HTML page.

3. The Web browser sends the request with the input data to the WebSphereApplication Server, which then starts the appropriate Java servlet to process therequest.

4. The Java servlet obtains the HttpSession object and creates anIMSConvContext object which it saves in that HttpSession object for use by theCCF ConnectionManager to ensure that the same connection is usedthroughout a conversation. The servlet then invokes the execute() method of theEAB command, passing the input data received from the browser. The EABcommand uses IMS Connector for Java APIs to send the transaction request toIMS via IMS Connect.

5. IMS receives the request and schedules the IMS conversational applicationprogram. The IMS application program processes the request and the reply isreturned to the Java servlet.

6. The Java servlet populates the EAB command with the output data of the replyand loads the appropriate result JSP page to display the output data on theWeb browser. The Java servlet or the end user determines if the output datareceived is acceptable. If it is, the Java servlet invokes the commit() method ofJavaCoordinator to accept the output and commit that iteration of theconversation (by sending an ACK message to IMS Connect). Otherwise, itinvokes the rollback() method of JavaCoordinator to reject the output and backout that iteration of the conversation (by sending a NACK message to IMSConnect.)

7. The user provides the data for the second iteration on the JSP page used todisplay the output data of the first iteration, then submits the next request toIMS. This invokes the second iteration of the IMS conversational transaction.

Subsequent iterations of the conversation repeat steps 3-7 until the user or the IMSapplication program terminates the conversation. In step 4, on the second and allsubsequent iterations of the conversation, the Java servlet obtains theIMSConvContext object from its HttpSession object.

Note: The steps described above may differ when used with differentsynchronization levels. The above scenario describes an application flow withSYNC_LEVEL_CONFIRM. When used with SYNC_LEVEL_NONE, the call to theJavaCoordinator commit() or rollback() method in step 6 will not be made.

Terminating an IMS Conversation

In the IMS Connector for Java Conversational HttpSession model, an IMSconversation is typically terminated in one of two ways. For these procedures, see“Terminating a Conversation” in “Building Java applications and servlets forconversational transactions”.

Conversational HttpSession Model with J2C Support

A similar programming model is provided for using IMS Connector for Java with J2Csupport to invoke IMS conversations. In this model, you build J2C applications toaccess IMS conversational transactions.

In this Conversational HttpSession Model, a user submits a series of requests fromthe same browser to iterate through different interactions of an IMS conversation.The user starts an IMS conversation transaction from a web browser, which invokes

38 IMS Connector for Java User’s Guide and Reference

a J2C application to interact with the IMS conversation. An HttpSession object isused to group a series of browser requests and associated J2C applicationinteractions together in a session.

IMS Connect requires a dedicated connection for the duration of an IMSconversation. The conversational HttpSession model ensures that the sameconnection is used when iterating through an IMS conversation from multiplebrowser requests.

For definitions of the types of session beans, see “IMS Connector for Java conceptsand terms.”

At a high level, the following steps occur in this conversational model:

1. The user starts an IMS conversational transaction from a web browser.

2. The browser invokes a Java servlet which saves the HttpSession object in anEJB object handle.

An EJB object handle is a long-lived proxy for an EJB object. If for some reasonyou disconnect from the EJB container/server, you can use the EJB objecthandle to reconnect to your EJB object without losing the conversational statewith that bean. The EJB object handle references the stateful session beans tointeract with the IMS conversation.

3. Methods that execute different iterations of the IMS conversation build statefulsession beans. Each method normally represents a particular iteration of theIMS conversation and uses IMS J2EE Connector classes to execute theiteration of the IMS conversation. In addition, the stateful session beans keep areference to the IMS connection handle that is dedicated to the IMSconversation.

4. This connection handle will remain active for the duration of the IMSconversation. Information related to each iteration of the IMS conversation (forexample, conversation state, current iteration, intermediate data) can also besaved in the stateful session beans.

5. At the end of the IMS conversation, the close() method will be called on theconnection handle so that the connection can be reused by a new request.

Note: The conversational transaction can also end during an ejbPassivation ora HttpSession invalidation (such as a timeout). In IMS Connector for Java withthe IBM Common Connector Framework (CCF), you can clean up theconnection resources when a browser session becomes unbound using theclass IMSConvHttpSessionCleanup (shipped with IMS Connector for Java). InIMS Connector for Java with J2C support, this class is not available. The IMSJ2EE Connector Samples provides a similar solution to that class. This class isin the package com.ibm.connector2.ims.ico.sample.conv.phonebook.servlet.However, the implementation of IMSConvHttpSessionCleanup is modified for theJ2C architecture, such that the connection handle is saved instead of theIMSConvContext class. Please note that the IMSConvContext class does notexist in the IMS J2EE Connector conversational support.

Conversational Navigator Model with CCF Support

Like the conversational HttpSession model, the Conversational NavigatorProgramming Model for building a Web application to invoke an IMS conversationaltransaction is also similar to the programming model for building a Web applicationto invoke a non-conversational IMS transaction. The steps involve the use ofVisualAge for Java and WebSphere Studio and are as follows:

Chapter 1. Understanding IMS Connector for Java 39

1. Provide your COBOL source file or files to VisualAge for Java to generate theinput and output Java record beans.

2. Use the VisualAge for Java Command Editor to create an Enterprise AccessBuilder (EAB) command for each iteration of the IMS conversation.

3. Using the VisualAge for Java Visual Composition Editor, create an EABNavigator.

4. Generate a Web application using WebSphere Studio and VisualAge for Java.

5. Customize the HTML/JSP pages.

6. Modify the Java servlet

An EAB Navigator can be used to model any IMS conversation where all of thedata required for all of the interactions that make up that particular conversation isknown in advance. A conversational Navigator consists of EAB Commands and/orother Navigators linked together to form a more complex Navigator whichencapsulates all of the interactions that make up a given IMS conversation. Eachcomponent EAB Command and Navigator within the conversational Navigator isthen executed in the pre-determined order programmed into the conversationalNavigator. For example, each iteration of an IMS conversation could be modeled asan EAB command. Then, a navigator can be built to encapsulate a sequence ofEAB command iterations to model the whole IMS conversation for a particular task.

When you execute a conversational EAB Navigator, as with any other EABNavigator, it provides its input to the EAB Commands and Navigators of which it iscomprised. The output of the component EAB Commands and Navigators isavailable to the conversational Navigator to be used as output, again depending onhow the conversational Navigator is programmed.

Once a conversational Navigator has started executing, control will not be returnedto the user until all of the component EAB Commands and Navigators (whichrepresent the iterations of the conversation) have completed and the conversationhas ended. No user interaction with an EAB Navigator is possible once execution ofthe Navigator has started. There is no mechanism available to provide additionaldata to be used by subsequent Navigator components after a given Navigatorcomponent has finished execution. It is for this reason that all of the input dataneeded by each component EAB Command or Navigator must be provided to theconversational Navigator before it begins executing.

Conversational Navigator Model with J2C Support

This model remains the same as the IMS Connector for Java with CCF supportConversational Navigator model in which an EAB Navigator is used to map theiterations of the IMS conversation. An EAB Navigator can be used in J2Capplications. After the Navigator is run, all iterations of the IMS conversationaltransaction is complete. When the Navigator completes its tasks, the connectionbeing used by the Navigator is closed automatically for reuse.

Migrating from CCF architecture to J2EE connector architectureThe availability of IMS Connector for Java 1.2 marks the transition from the IBMCommon Connector Framework (CCF) architecture to Sun’s Java 2 Platform,Enterprise Edition (J2EE) Connector (J2C) architecture. This change of architectureaffects both your existing and new applications. Information on this transition can befound in VisualAge for Java’s documentation by clicking Help > Help Home Page >Concepts > Access to transaction systems > Enterprise Access Builder forTransactions > Impact of CCF to J2EE transition.

40 IMS Connector for Java User’s Guide and Reference

This section provides you with information on migrating EAB commands andNavigators, and should be used in conjunction with “Migrating IMS Connector forJava EAB Commands to J2EE” below.

Information on migrating servlets coded with the CCF architecture to the J2Carchitecture is available in the VisualAge for Java documentation in Help > HelpHome Page > Samples > Enterprise Access Builder for Transactions >WebSphere set > J2EE JSP and servlet.

If you want to run your CCF servlet in WebSphere Application Server 4.0 withoutmigrating to the J2C architecture, you can do so. The sections “Running a CCFServlet in WebSphere Application Server 4.0 for Windows” on page 42 and“Running a CCF Servlet in WebSphere Application Server 4.0 for z/OS and OS/390”on page 46 below describe how to deploy one of the CCF samples provided withan earlier release of IMS Connector for Java to WebSphere Application Server 4.0.

Migrating IMS Connector for Java EAB Commands to J2EEMigrating IMS Connector for Java EAB Commands from a CCF-based applicationto a J2EE-based application can be done using the migration tool provided withVisualAge for Java. A description of how to migrate an EAB command using thistool can be found in the VisualAge for Java documentation by clicking Help > HelpHome Page > Tasks > Accessing transaction systems > Accessing CICS, IMS,Encina, MQSeries, HOD > Getting started with Enterprise Access Builder forTransactions > Working with EAB Commands > Migrating EAB Commands toJ2EE.

This VisualAge for Java information also contains links to the migration of recordsand Navigators to J2EE. The records of an EAB command can be migrated whenyou migrate the EAB command or they can be migrated separately. The generatedrecords are backward compatible with CCF applications. In addition, the DFSMsgbean in package com.ibm.connector2.ims.ico has already been migrated.

When you migrate an IMS Connector for Java EAB command, you might receiveone or both of the following warnings:

v IVJC1604W: The property, syncLevel, could not be migrated for command_name.It has been omitted.

v IVJC1604W: The property, dataStoreName, could not be migrated forcommand_name. It has been omitted.

These warnings result from the difference in support of synchronization level anddatastore name between the CCF and J2C implementations of IMS Connector forJava.

Synchronization level is not supported

IMS Connector for Java’s CCF implementation allows you to select from twosynchronization levels (SYNC_LEVEL_CONFIRM and SYNC_LEVEL_NONE) for aniteration of a transaction. IMS Connector for Java’s J2C implementation in thisrelease does not support the specification of synchronization level for an interaction.In this release, SYNC_LEVEL_NONE, the default synchronization level, is alwaysused. Support for selecting a synchronization level will be provided in a futurerelease.

IMS datastore name is no longer an InteractionSpec property

Chapter 1. Understanding IMS Connector for Java 41

The datastore name property has been moved to theIMSManagedConnectionFactory class to be more consistent with the use of theJNDI naming service by the J2EE programming model. A connection factory for aparticular combination of hostname, port, and datastore name is deployed in theJNDI name space and used by all applications targeting that datastore using thehostname/port combination. Note, however, that only hostname and port areconsidered for the purposes of connection pooling.

Running a CCF Servlet in WebSphere Application Server 4.0 forWindows

If you are not ready to migrate your CCF application to J2C, you can still run it inWebSphere Application Server 4.0 for Windows. There are many ways to do this.These instructions show how you can do this with minimal changes, using one ofthe samples provided with an earlier release of IMS Connector for Java,com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet. This servletwas developed as a Web application (“webapp”), imsconn, for WebSphereApplication Server 3.5.

Step 1: Deploy imsconn.jar to WebSphere Application Server

Connectors that implement J2C architecture are packaged as “resource adapters.”Resource adapters are deployed in WebSphere Application Server 4.0 fordistributed platforms from a Resource Adapter Archive (RAR) file. IMS Connectorfor Java also implements IBM’s Common Connector Framework architecture. Thisimplementation is available as a Java Archive (JAR) file, imsconn.jar. To deployimsconn.jar in WebSphere Application Server 4.0 for distributed platforms, copyimsconn.jar from <ico_install_dir>/IMSICO/CCF, where <ico_install_dir> is thedirectory where you installed IMS Connector for Java to<was_install_dir>/WebSphere/AppServer/lib, where <was_install_dir> is thedirectory where you installed WebSphere Application Server 4.0.

Note: In the past it was necessary to copy ccf.jar, eablib.jar, and recjava.jar fromVisualAge for Java to a directory accessible to WebSphere Application Server. Itwas also necessary to modify the classpath used by WebSphere Application Serverto point to these JAR files as required. This in no longer necessary becauseWebSphere Application Server 4.0 for distributed platforms includes these JAR files.

Step 2: Make the Servlet Files Accessible to WebSphere Application Server4.0

Copy the contents (files and folders) from the following folder:

<vaj_install_drive>\IBM Connectors\IMSCONN\samples\servlets\phonebook

where <vaj_install_drive> is the VisualAge for Java installation directory to a folderof your choice on the target WebSphere Application Server 4.0 machine. Forexample, CCFWAS40. The CCFWAS40 folder should now contain the followingfolders and files:

v com

v theme

v DFSMsg.jsp

v Ex01Servlet.jar

v Ex01ServletHTMLError.jsp

v Ex01ServletHTMLInput.html

42 IMS Connector for Java User’s Guide and Reference

v Ex01ServletHTMLResults.jsp

Step 3: Modify the Servlet’s Input HTML

Remove the “servlet” keyword from the FORM statement of the servlet’s inputHTML, Ex01ServletHTMLInput.html. For example:

<!— <FORM METHOD=“post”ACTION=“/webapp/imsconn/servlet/com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet”

<FORM METHOD=“post”ACTION=“/webapp/imsconn/com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet”>

Step 4: Start WebSphere’s Application Assembly Tool

1. From your Windows desktop, click Start > Programs > IBM WebSphere >Application Server 4.0 > Application Assembly Tool.

2. When the “Welcome to Application Assembly Tool” appears, select Cancel.

Step 5: Create a Web Module

1. Name your Web module.

a. From the menu bar of WebSphere’s Application Assembly Tool, select File >New > Web Module.

b. Ensure that the General tab is selected and enter a Display name for yourWeb module. For example, Ex01ServletWebMod. Enter an optionaldescription of your Web module.

c. When you select the Apply you will notice that the name you chose for yourWeb module will replace the default name in the left pane of theApplication Assembler window.

2. Add files to your Web module.

a. Expand the Files folder in the left pane of the Application Assemblerwindow.

b. Right-click on the Class Files folder and select Add Files.

c. Select the Browse button beside the Root Directory or Archive entry field.If your files are in a folder (rather than an archive):

1) Locate and select the folder containing your servlet class file and itspackage directory structure. For example, select CCFWAS40.

2) Verify that the root directory (for example, CCFWAS40) appears in theFiles of Type: entry field and click the Select button.

3) You should see the files contained in the selected folder listed in theupper right pane of the Add Files window.

4) Expand the directory structure of the servlet class package foundunderneath your root directory by clickingthe plus signs next to each folder that makes up your servlet’s packagename. For example, click the plus sign next to thefollowing folders in order: com, ibm, connector, ims, sample, phonebook,servlet.

5) Select the folder at the bottom of this structure, which should contain theclass of your servlet. For example, select the servlet folder. This shouldthen display your servlet’s class in the upper right pane.

6) Select your servlet’s class (for example, Ex01Servlet.class) and click theAdd button. This should list the servlet’s package directory structure andclass name in the Selected Files: pane.

Chapter 1. Understanding IMS Connector for Java 43

7) Click OK.

8) Right-click on the Jar Files folder and select Add Files. Repeat theprocess used to add class files, but this time add the following:

v Ex01Servlet.jar

9) Right-click on the Resource Files folder and select Add Files. Repeatthe process used to add class files, but this time add the following:

v DFSMsg.jsp

v Ex01ServletHTMLError.jsp

v Ex01ServeltHTMLInput.html

v Ex01ServeltHTMLResults.jsp

v com/ibm/connector/ims/sample/phonebook/servlet/Ex01Servlet.servlet

v theme/Master.css

3. Add a Web component to your Web module.

A Web module is used to assemble servlets, JavaServer Pages, Web pages,and other static content into a single deployable unit. A Web component is aservlet or JavaServer Page. In this case, you are adding a servlet Webcomponent to your Web module, Ex01ServletWebMod.

a. Right-click on Web Components in the left pane of the ApplicationAssembler window, then select New.

b. In the New Web Component window:

1) Enter the name of your servlet in the Component name: entry field. Forexample, Ex01Servlet.

2) In the Display name: entry field, enter the name of this web componentas it will be listed in your web module. For example, Ex01Servlet.

3) Select the Servlet radio button, then select the Browse button besidethe Class name: field.

4) Locate and select your servlet class file in the WEB_INF folder. Thenclick OK.

5) In the New Web Component window, verify that the full package andclass name of the servlet are displayed in theClass name field. Click the OK button.

4. Provide your servlet’s mapping information. A servlet mapping associates aservlet with a client request by using a URL pattern.

a. Right-click Servlet Mapping in the left pane of the Application Assemblerwindow, then click New.

b. Enter /com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet in theURL pattern: entry field, then click OK. (See the statement that beginsFORM METHOD=“post” ACTION= of the file Ex01ServletHTMLInput.html.)

5. Save your Web module in a WAR file.

a. Select your Web module in the left pane of the Application Assemblerwindow. For example, select Ex01ServletWebMod.

b. Select File > Save as... from the menu of the Application Assembly Toolwindow and save your WAR file with a name you choose. For example,Ex01Servlet.war.

Step 6: Create an Enterprise Application from your Web Module

1. Select File > New > Application from the menu of the Application AssemblyTool window.

44 IMS Connector for Java User’s Guide and Reference

2. In the Display name: entry field of the right pane of the ApplicationAssembler window, enter a name for your enterprise application, then selectthe Apply button. For example, Ex01ServletApp.

3. In the left pane of the Application Assembler window, right-click on WebModules under your enterprise application, Ex01ServletApp, and selectImport.

4. Locate the WAR file for your Web module (for example, Ex01Servlet.war), selectit, then select the Open button.

5. In the Confirm values window, enter /webapp/imsconn in the Context rootentry field, then select OK.

6. Save your Enterprise application in an .ear file.

a. Select your Enterprise application in the left pane of the ApplicationAssembler window. For example, select Ex01ServletApp.

b. Select File > Save as... from the menu of the Application Assembly Toolwindow and save your .ear file with a name you choose. For example,Ex01ServletApp.ear.

7. You may now exit from the Application Assembler if you wish.

Step 7: Start the WebSphere Advanced Administrative Console

1. From your Windows desktop, click Start > Programs > IBM WebSphere >Application Server 4.0 > Start Admin Server. You must start this serverbefore you start the Administrative Console.

2. Click Start > Programs > IBM WebSphere > Application Server 4.0 >Administrator’s Console.

Step 8: Deploy your Enterprise Application

Using the instructions for “Deploying the IMS Connector for Java IVP in WebSphereApplication Server” in “Preparing your WebSphere Application Server environmentfor Windows” as a guideline, deploy your enterprise application (for example,Ex01ServletApp) to WebSphere Application Server.

Step 9: Run your Enterprise Application

Do the following in a browser of your choice:

1. In the Web address field, enter“http://localhost:9080/webapp/imsconn/Ex01ServletHTMLInput.html” (where/webapp/imsconn is the context root of your enterprise application in thisexample).

2. Provide values for the input fields as required. Values for dataStoreName,hostName, IN_CMD, IN_NAME1, IN_TRCD, and portNumber are required torun ivtno, one of the IMS INSTALL/IVP sample transactions on which thisEx01Servlet sample is based.

Values for IN_EXTN, IN_NAME1, IN_ZIP, User Name, Password, and Groupmight be required, depending on the value of IN_CMD that you entered and thesecurity settings for OTMA and IMS Connect.

Click the Submit button when you have finished entering the required values.The browser will submit a request to the application server to run Ex01Servlet.

Chapter 1. Understanding IMS Connector for Java 45

Running a CCF Servlet in WebSphere Application Server 4.0 for z/OSand OS/390

If you are not ready to migrate your CCF applications to J2C, you can continue torun it them WebSphere Application Server 4.0 for z/OS and OS/390. The followinginstructions show how to do this with minimal changes, using one of the samplesprovided with an earlier release of IMS Connector for Java,com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet. This servletwas developed as a Web application (“webapp”), imsconn, for WebSphereApplication Server 3.5.

Part 1: Assembling the Application

In this part, you will assemble your application into an enterprise archive (EAR) file.You will deploy this EAR file in the next part. This ear file contains a Web modulethat includes your HTML and JSP files and CCF servlet to run in WebSphereApplication Server for z/OS and OS/390.

To assemble your application for deployment to WebSphere Application Server forz/OS and OS/390, the Application Assembly Tool (AAT) for z/OS and OS/390 isrequired. See “Preparing to deploy the J2C Samples” section for more information.

1. Create a Web module. In this step, you will build a Web archive (WAR) file thatincludes your HTML and JSP files and CCF servlet.

If you have AAT for Windows, it is recommended that you first complete Steps 2to 5 in ““Running a CCF Servlet in WebSphere Application Server 4.0 forWindows” on page 42” to create a WAR file that contains your Web modulebefore moving on to the step. If you are planning to use tools other than theAAT for Windows to create a WAR file and import into AAT for z/OS andOS/390, make sure that you have used the appropriate values as discussed inthat section.

If you do not have tools (for example, AAT for Windows) to build a WAR file,you can build the WAR file by archiving the pieces of it (the HTML, JSP, Servletand the web.xml file) using the JAR command available with the JavaDevelopment Kit (JDK) as follows:

a. On your workstation, create a new directory (for example,c:\CCFServletWar) as the root directory for building your WAR file.

b. Create the following subdirectories under the root directory that you createdin the previous step:

v C:\CCFServletWar\WEB-INF\lib\

v C:\CCFServletWar\\WEB-INF\classes\

c. Create the web.xml file for your WAR:

1) Using a text editor, create a file named web.xml in the WEB-INF foldercreated in the previous step (for example, C:\CCFServletWar\WEB-INF\web.xml). This web.xml contains the deployment descriptorinformation for your web module.

2) Insert the following XML code into the web.xml file:<?xml version=“1.0” encoding=“UTF-8”?><!DOCTYPE web-app PUBLIC “-//Sun Microsystems,Inc.//DTD Web Application 2.2//EN”

“http://java.sun.com/j2ee/dtds/web-app_2_2.dtd”><web-app><display-name>Ex01ServletWebMod</display-name><servlet><servlet-name>Ex01Servlet</servlet-name><display-name>Ex01Servlet</display-name><servlet-class>

46 IMS Connector for Java User’s Guide and Reference

com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet</servlet-class></servlet><servlet-mapping><servlet-name>Ex01Servlet</servlet-name><url-pattern>

/com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet</url-pattern></servlet-mapping></web-app>

3) Save the web.xml file.

d. Copy the following HTML and JSP files (which are also available with thesample in the <vaj_install_dir>\IBMConnectors\IMSCONN\samples\servlets\phonebook directory) to the rootdirectory for building your WAR file (for example, c:\CCFServletWar):

v Ex01ServletHTMLInput.html

v Ex01ServletHTMLResults.jsp

v Ex01ServletHTMLError.jsp

v DFSMsg.jsp

v com/ibm/connector/ims/sample/phonebook/servlet/Ex01Servlet.servlet

v theme/Master.css

e. Modify Ex01ServletHTMLInput.html by removing the servlet keyword fromthe FORM statement. For example:<!-- <FORM METHOD=“post”ACTION=“/webapp/imsconn/servlet/com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet<FORM METHOD=“post”ACTION=“/webapp/imsconn/com.ibm.connector.ims.sample.phonebook.servlet.Ex01Servlet”>

f. Copy the directory that contains your servlet class file (for example,com\ibm\connector\ims\sample\Ex01Servlet.class) to the WEB-INF\classesdirectory under the root directory for building your WAR file (for example,c:\CCFServletWar\WEB-INF\classes).

g. Copy your support classes JAR file (for example, Ex01Servlet.jar) thatcontains your EAB command and the record beans classes to theWEB-INF\lib directory under the root directory for building your WAR file (forexample, C:\Ex01ServletWar\WEB-INF\lib).

h. Create the WAR file (for example, Ex01Servlet.war) using the jar commandas follows:

1) Using a command prompt on your workstation, navigate to the rootdirectory for building your WAR file (for example, C:\CCFServletWar\).You should files similar to the following in that directory:

v C:\CCFServletWar\Ex01ServletInput.html

v C:\CCFServletWar\Ex01ServletResults.jsp

v C:\CCFServletWar\Ex01ServletError.jsp

v C:\CCFServletWar\DFSMsg.jsp

vC:\CCFServletWar\com\ibm\connector\ims\sample\phonebook\servlet\Ex01Servlet.clas

v C:\CCFServletWar\theme\Master.css

v C:\CCFServletWar\WEB-INF\web.xml

v C:\CCFServletWar\WEB-INF\classes\com\ibm\connector\ims\sample\phonebook\servlet\

v C:\CCFServletWar\Ex01Servlet.class

v C:\CCFServletWar\WEB-INF\lib\Ex01Servlet.jar

Chapter 1. Understanding IMS Connector for Java 47

2) Create the WAR file with the name CCFServlet.war by issuing the JARcommand at the command prompt as follows:jar -cf CCFServlet.war *

The JAR command is available with your Java Development Kit (JDK)

3) Verify that the WAR file (for example, CCFServlet.war) is created in thedirectory (for example, c:\CCFServletWar).

2. In the Environment Variables on your workstation, configure the classpath forthe Application Assembly Tool for z/OS and OS/390 to use the IMS Connectorfor Java CCF classes:

a. Click Start > Settings > Control Panel.

b. Double click System in the Control Panel. In the System Propertieswindow, click the Advanced tab and click Environmental Variables...

c. Add a new system variable with the name AAT_USER_PATH and a valueC:\IBMCON~1\classes\imsconn.jar.

Note: If you have AAT for z/OS and OS/390 running on the same systemwith your VisualAge for Java environment that contains your IMS Connectorfor Java CCF code (imsconn.jar), you can find imsconn.jar in your C:\IBMConnectors\classes folder. If your AAT and VisualAge for Java with the IMSConnector for Java CCF code are running on different systems, be sure tocopy imsconn.jar to your AAT system and replace“C:\IBMCON~1\classes\imsconn.jar” value with the fully qualified path nameof your imsconn.jar file.

3. Start the Application Assembly Tool for z/OS and OS/390 by clicking Start >Programs > IBM WebSphere for z/OS > Application Assembly.

4. Right click the Applications folder and select Add from the menu. Enter thename of your application in the Display name field (for example,CCFEx01390App ). Then click Selected > Save.

5. Double click the folder of the application you just created to list the 3 componentfolders of this application. Right click the Web Apps folder and click Import. Inthe Import Web App window, click the Choose button and navigate to the CCFWeb module you created (for example, CCFServlet.war ). Select that WAR fileand click OK. Click OK again to close the Import Web App window. The webmodule (for example, Ex01ServletWebMod) associated with the selected WARfile should now appear underneath the Web Apps folder.

6. Select this new application folder and click Selected > Modify. Enter thecontext root of your application in the Context root field. The context root ofyour application should be synchronized with your servlet input HTML page (forexample, /webapp/imsconn ). Click Selected > Save.

7. Select the application folder you created in Step 4 above (for example,CCFEx01390App ). Right click it and click Validate. When the application isvalidated successfully, right click the application folder again and click Deploy.

8. You might see a message “BBO94053I Classcom.ibm.webtools.runtime.AbstractStudioServlet is not found. Do you want toimport a file into application CCFEx01390App that contains this class?” Click theNo to All button.

9. When the application is successfully deployed, right click the application folderCCFEx01390App again and click Export.... In the Export application windowthat appears, click Choose... In the Select output ear file window that appears,navigate to a directory in which you want to save your application. Give thedeployed application a file name (such as CCFEx01390.ear) in the File namefield. Click OK to close the Select output ear file window. Click OK to close theExport application window.

48 IMS Connector for Java User’s Guide and Reference

Part 2: Deploying the Application

To deploy the application to WebSphere Application Server, use the WebSphere forz/OS Administration Application.

1. Start the WebSphere for z/OS Administration Application. For example, Start >Programs > IBM WebSphere for z/OS > Administration and wait for theLogin window to appear.

2. In the dialog, enter the Bootstrap server IP name (for example, theDAEMON_IP environment variable or the name specified for the bootstrapserver’s IP address in the host file on the workstation), Port (default 900), theUserid (default CBADMIN), and the Password (default CBADMIN).

3. Click OK to login and establish connections to the servers. Wait for theWebSphere for Application Server for z/OS and OS/390 Administration windowto appear.

4. Add a new conversation:

a. Select the Conversations folder.

b. Click Selected > Add and wait for the conversation name and descriptionfields to appear.

c. In the Conversation Name text box enter the name for the newconversation (for example, CCFEx01390).

d. Click Selected > Save.

e. Wait for the completion message (for example, “BBON0515I ConversationIMSICO was added.”) to appear in the status text box above the status barin the Administration window.

5. Install the enterprise application:

a. Select the J2EE server (for example, BBOASR2) on which this applicationwill be installed. Select this server by expanding the following folders inorder: Conversations folder, the new conversation (for example,CCFEx01390), the Sysplexes folder, the sysplex in which your sample J2EEserver has been installed, and the J2EEServers folder.

b. Click Selected > Install J2EE application... and wait for its referencewindow to appear (for example, the Install J2EE application on server:BBOASR2 window).

c. Click the Browse EAR File... button and wait for the Open window toappear. Locate and select your EAR file (for example,CCFEx01390.ear).Click Open.

d. Verify that the destination and EAR file name appears in the EAR Filenametext field. Click OK and wait for the Reference and Resource Resolutionwindow to appear.

e. In the Reference and Resource Resolution dialog box:

1) On the left side of the dialog, expand the CCFEx01_WebApp.jar folderand select the J2EE application bean (for example, CCFEx01_WebApp).

2) On the right side of the dialog, click the EJB tab and click Set DefaultJNDI Path & Name. Click OK.

6. Modify the J2EE server (for example, BBOASR2) classpath by adding thefollowing:<imsconn_dir>/imsconn.jar

Modify the libpath by adding the following:<imsconn_dir>

Chapter 1. Understanding IMS Connector for Java 49

where <imsconn_dir> is the installation directory that contains the IMSConnector for Java CCF classes, namely the imsconn.jar and libimsconn.sofiles. For example, /usr/lpp/imsico/CCF.

7. Validate the new conversation you created in the previous step by selecting theconversation name (for example, CCFEx01390 ) to highlight it and clickingBuild > Validate.

8. Commit the new conversation by selecting the conversation name to highlight itand clicking Build > Commit.

9. Ensure that all preparation tasks for the new conversation are completed. Thenselect the conversation name to highlight it and click Build > Complete > AllTasks to indicate completion.

10. Activate the new conversation by selecting the conversation name to highlightit and clicking Build > Activate.

11. Configure the HTTP server for the context root of the CCF sample bymodifying the following files:

a. Ensure that the webcontainer.conf file contains the following information:Host.default_host.contextroots=/

b. Modify the httpd.conf file with the following information:Service /webapp/imsconn/* <was_dir>/WebServerPlugIn/bin/was400plugin.so:service_exit

where <was_dir> is the installation directory for WebSphere (for example,/usr/lpp/websphere)

Part 3: Starting WebSphere Application Server for z/OS and OS/390

To start WebSphere Application Server for z/OS and OS/390, follow “Step 6:Starting the server to run the IVP.” in “Preparing your WebSphere Application ServerEnvironment for z/OS and OS/390.”

Part 4: Running the Application

1. Open a Web browser and enter the following Web address:http://<servername>:<port>/webapp/imsconn/Ex01ServletHTMLInput.html

where the <servername> and <port> is the name and port number for your Webserver and the context root of your enterprise application is /webapp/imsconn inthis example.

2. Provide values for the input fields as required. Values for the following fields arerequired to run ivtno (one of the IMS INSTALL/IVP sample transactions onwhich the Ex01Servlet sample is based):

v DataStoreName

v HostName

v IN_CMD

v IN_NAME1

v IN_TRCD

v PortNumber

Values for the following fields might be required, depending on the value ofIN_CMD that you provided and on the security settings for OTMA and IMSConnect:

v IN_EXTN

v IN_NAME2

50 IMS Connector for Java User’s Guide and Reference

v IN_ZIP

v User Name

v Password

v Group

3. Click Submit when you have entered the required values. The browser thensubmits a request to the application server to run Ex01Servlet. You should seethe message “Entry was displayed.”

Chapter 1. Understanding IMS Connector for Java 51

52 IMS Connector for Java User’s Guide and Reference

Chapter 2. Preparing to use IMS Connector for Java

This topic describes how to create an environment in which you can develop andrun Java programs that use either the J2EE Connector Architecture (J2C)implementation of IMS Connector for Java or the Common Connector Framework(CCF) implementation of IMS Connector for Java. It provides installation andconfiguration information for the following products:

v VisualAge for Java Enterprise Edition 4.0

v WebSphere Application Server

See “Prerequisites for using IMS Connector for Java” for more information on theseand other prerequisites.

Information on preparing a WebSphere Studio environment pertains primarily to theearlier CCF sample, “Building a Java servlet to run an IMS transaction.”

IMS Connector for Java provides 2 types of Installation Verification Programs (IVPs)that you can run from the following environments:

v The IVP GUI, which is run in VisualAge for Java for Windows, verifies thatVisualAge for Java is correctly configured to access your IMS and IMS Connectsystem.

v The IVP Servlet, which is run in either WebSphere Application Server forWindows or WebSphere Application Server for z/OS and OS/390, verifiesWebSphere Application Server is correctly configured to access your IMS andIMS Connect system.

Each of these IVPs invoke IMS commands without requiring a host IMS application.

Preparing to Run the IMS Connector for Java IVP

To run any of the provided IVPs, verify that the following components are runningon your target host machine:

v IMS Connect Version 1.2 or higher

Ensure that the outstanding IMS Connect reply appears on the target machine’ssystem console. For example:*09.34.41 STC00156 *16 HWSC0000I *IMS CONNECT READY* ims_connect_name

Note: IMS Connect Name is referred to in IMS Connect as “HWS ID.”.

Verify that the PORT and DATASTORE are ACTIVE by entering the IMS Connectcommand VIEWHWS at the IMS Connect outstanding reply

Verify that the eyecatcher in module HWSHWS00 in the HWS RESLIB is at least“120.” For example:...HWSHWS00+0120+...

v IMS Version 7.1 or higher

Ensure that the IMS outstanding reply appears on the target machine’s systemconsole. For example:14.26.55 JOB00175 *15 DFS996I *IMS READY*

Verify that the XCF status of both the IMS and IMS Connect members is ACTIVEby entering the IMS command /DISPLAY OTMA at the outstanding IMS reply:

© Copyright IBM Corp. 1998, 2002 53

DFS000I GROUP/MEMBER XCF-STATUS USER-STATUS SECURITY SYS3DFS000I GROUPNM SYS3DFS000I -IMSMEM ACTIVE SERVER NONE SYS3DFS000I -ICONNMEM ACTIVE ACCEPT TRAFFIC SYS3DFS000I *01218/111559* SYS3

When using an IVP, you can use either the TCP/IP or Local Option communicationprotocols. If you are using TCP/IP, ensure that you can successfully “ping” thetarget host machine from your VisualAge for Java workstation. If you are usingLocal Option, ensure that IMS Connect and the IVP are running on the same MVSimage.

Complete the related tasks below to run these IVPs.á

Preparing your VisualAge for Java environmentVisualAge for Java Enterprise Edition can be used to both develop and run Javaprograms that use IMS Connector for Java to access IMS transactions. In addition,the IBM WebSphere Test Environment of VisualAge for Java can be used to testservlets and EJBs that you develop using VisualAge for Java. This sectiondescribes how you prepare your VisualAge for Java environment to use IMSConnector for Java.

Configuring VisualAge for Java

IMS Connector for Java is included with VisualAge for Java Enterprise Edition; itdoes not usually require a separate installation process. Because IMS Connectorfor Java is part of VisualAge for Java, its software prerequisites are the same asthose for VisualAge for Java.

IMS Connector for Java features both a J2EE Connector Architecture (J2C)implementation and a Common Connector Framework (CCF) implementation. Touse IMS Connector for Java perform the following steps in the order indicated:

1. Install VisualAge for Java Enterprise Edition 4.0.

Important: If you do not select the Complete installation option of VisualAge forJava, you must include the Transaction Access Builder feature in yourinstallation. If you have already installed VisualAge for Java 4.0 and an earlierversion of IMS Connector for Java you can skip this step.

The installation of VisualAge for Java 4.0 provides you with the CCF (CommonConnector Framework) implementation of IMS Connector for Java. To use theJ2C implementation of IMS Connector for Java, complete the following steps. Ifyou plan on using the CCF implementation only, your installation is complete.

2. To use the J2C implementation of IMS Connector for Java, ensure that thecomponents related to the Java 2 Platform Enterprise Edition (J2EE) ConnectorArchitecture are installed in VisualAge for Java. Instructions for installing thesecomponents can be found in file extras/BetaJ2EEConnectors/readme.eab ofVisualAge for Java’s installation media.

3. Download and install the IMS Connector for Java 1.2.2 update from theVisualAge Developer Domain at http://www7.software.ibm.com/vad.nsf.

4. Add to your VisualAge for Java workspace the VisualAge for Java features IMSConnector 1.2.2 and, optionally, IMS Connector Samples 1.2.2. The IMSConnector Samples 1.2.2 project will replace any previous versions of theproject in your VisualAge for Java workbench.

a. Start the Workbench in the VisualAge for Java IDE. Click the Start >Programs > IBM VisualAge for Java for platform > IBM VisualAge for

54 IMS Connector for Java User’s Guide and Reference

Java, where platform is the platform on which you have VisualAge for Java.If the VisualAge Welcome to VisualAge dialog box appears, click Go tothe Workbench and click OK. The IDE workbench appears.

b. From the File menu, click Quick Start.

c. In the Quick Start window, click Features on the left pane. Then, click AddFeature on the right pane and click OK.

d. Select the feature IBM EJB Development Environment 3.5.3 and click OKto add it to the VisualAge for Java workspace. This step is required.

e. Repeat the above step to add the features IMS Connector 1.2.2 and IMSConnector Samples 1.2.2. The feature IMS Connector will be added toyour workbench as project Connector IMS 1.2.2 and the feature ConnectorIMS Samples 1.2.2 will be added as project Connector IMS Samples.

Check the All Problems tab of your workbench when adding a feature to see ifadditional projects (such as the IBM Common Connector Framework, IBM CommonConnector Framework2, and J2EE Connector Architecture) need to be added inorder to resolve any problems.

After you add the IMS Connector 1.2.2 features to your VisualAge for Javaworkspace, you have access to the following:

v Connector IMS, a VisualAge for Java project that consists of four packages:

– com.ibm.connector2.ims.ico

This package includes the classes of IMS Connector for Java’s J2Cimplementation.

– com.ibm.ims.ico

This package includes the classes that implement the internal logic of IMSConnector for Java’s J2C implementation.

– com.ibm.connector.imstoc

This package includes the classes of IMS Connector for Java’s CCFimplementation. Many of the classes in this package are “support” classes,and are not used by VisualAge for Java application developers.

– com.ibm.imstoc

This package includes the classes that implement the internal logic of IMSConnector for Java’s CCF implementation. All of the classes in this packageare “support” classes, and are not used by VisualAge for Java applicationdevelopers.

The classes and methods that are used in the VisualAge for Java applicationdevelopment process are documented in the Reference section of theVisualAge for Java web help. To view this documentation, click Help >APIReference > IBM APIs > Connectors > IMS Connector

v IMS Connector for Java Online Help in HTML format. The PDF format of the IMSConnector for Java User’s Guide and Reference is available on the IMSConnector for Java Web page in the IMS Web site at www.ibm.com/ims.

v Two IMS Connector for Java IVPs (Installation Verification Programs) that youcan use to verify that a Java application using either the CCF or the J2Cimplementation of IMS Connector for Java can access IMS from within theVisualAge for Java environment. These programs are in theIMSConnIVPMainDialog class in the Connector IMS Samples project in thepackage com.ibm.connnector.ims.sample.ivp (for the CCF IVP) and in thepackage com.ibm.connector2.ims.ico.sample.ivp (for the J2C IVP).

v Two IMS Connector for Java (IVP) servlets that you can use to verify that aservlet using either the CCF or the J2C implementation of IMS Connector for

Chapter 2. Preparing to use IMS Connector for Java 55

Java can access IMS from within a WebSphere Application Server environment.The source for these programs are in the Connector IMS Samples project in thecom.ibm.connnector.ims.sample.ivp.was35.servlet (for the CCF verification)and in the package com.ibm.connector2.ims.ico.sample.ivp.servlet package(for the J2C IVP).

Important: The CCF IMS Connector for Java IVP servlet is currently providedonly with VisualAge for Java. For instructions on how to run this program in theWebSphere Application Server environment, see “Preparing your WebSphereApplication Server environment for Windows.”

The source for the J2C IMS Connector for Java IVP servlet is provided withVisualAge for Java for illustration purposes only. The runtime of the J2C IMSConnector for Java IVP servlet is included with the IMS Connector for Javaruntime component packaged with the IMS Connect product. Instructions on howto use this servlet to verify your WebSphere Application Server environment areincluded with the installation instructions for the IMS Connector for Java runtimecomponent and in “Preparing your WebSphere Application Server environmentfor Windows.”

Sample code is available to aid in the development of your Java applicationsusing either the J2C or CCF implementations of IMS Connector for Java. Thiscode is available in the Connector IMS Samples project.

Preparing to run the Installation Verification Program

See “Preparing to run the IVP servlet” in “Preparing to use IMS Connector for Java”for information on IVP prerequisites.

Using the VisualAge for Java IVP to Verify Your VisualAge for JavaEnvironment

The CCF and J2C IMS Connector for Java Installation Verification Programs (IVPs)are Java applications that are included with VisualAge for Java. You can use one ofthese IVPs to verify that a Java application that uses either the CCF or J2Cimplementation of IMS Connector for Java can run within VisualAge for Java onWindows and can successfully access the target IMS environment. The CCF IMSConnector for Java IVP sample program is contained in thecom.ibm.connector.ims.sample.ivp package in the Connector IMS Samplesproject that is added to your workbench when you add the IMS Connector Samplesfeature. The J2C IMS Connector for Java IVP sample program is contained in thecom.ibm.connector2.ims.ico.sample.ivp package in the Connector IMS Samplesproject that is added to your workbench when you add the IMS Connector Samplesfeature.

Note: The IVP is a VisualAge for Java for Windows program and therefore does notuse the Local Option connections. Instead, use TCP/IP for communication and torun the IVP.

Running the VisualAge for Java IVP

Update VisualAge for Java’s class path to point to the locations of the requiredclass libraries. Do the following:

1. Right-click the IMSICOIVPMainDialog class in packagecom.ibm.connector2.ims.ico.sample.ivp (for J2C) or theIMSConnIVPMainDialog class in package com.ibm.connector.ims.sample.ivp(for CCF), then select Properties.

56 IMS Connector for Java User’s Guide and Reference

2. Ensure that the Class path tab is selected on the Properties window and clickCompute now to compute the class path for the IVP. Click OK.

To run the IVP, select either the IMSICOIVPMainDialog class in packagecom.ibm.connector2.ims.ico.sample.ivp (for J2C) or the IMSConnIVPMainDialogclass in package com.ibm.connector.ims.sample.ivp (for CCF). From theSelected menu, click Run > Run main... The IMS Connector for Java IVP windowappears.

Because execution of the IVP causes the IMS /STA OTMA command to be sent tothe target IMS machine, you must provide values for the fields described belowbefore clicking SUBMIT.

Figure 4. The VisualAge for Java IVP GUI

Host nameThe TCP/IP host name of the machine running IMS Connect.

Port The TCP/IP port assigned to IMS Connect.

DatastoreThe Datastore ID you specified when you installed IMS Connect.

User IDThe SAF user ID to be passed to OTMA. For example, the RACF user ID.User ID may be optional depending on how you specify IMS OTMA andIMS Connect security. However, you can provide it, along with a password,if you want to verify your installation’s security configuration.

PasswordPassword can be optional (see User ID).

Group nameGroup name can be optional (see User ID).

The objective of the IVP is to receive a message from IMS in reply to the /STAOTMA command. One of two possible messages is returned, depending on thesecurity configuration of your host environment and whether the given user ID ispermitted to issue the /STA command. Either message indicates successfulexecution of the IVP:

v DFS1292E SECURITY VIOLATION

v DFS058I 17:33:32 START COMMAND COMPLETED

Chapter 2. Preparing to use IMS Connector for Java 57

This test does not verify that a particular IMS transaction can run, only that the pathto IMS is available.

If an exception is returned in response to the command, check the console window.The exception and stack trace provide diagnostic information. The following arecommon causes for IVP failure:

v Host name is misspelled or is not sufficiently qualified

v IMS Connect is not active

v Incorrect port

v Port is not active

v TCP/IP failure. Always ensure a successful “ping” prior to running the IVP

v Datastore name is incorrect or is misspelled. Datastore name must be inuppercase characters.

v Datastore is not active.

v Wrong level of IMS Connect running on the host. See “Prerequisites for usingIMS Connector for Java” for the required level of IMS Connect.

Important: If you do not compute the class path for classIMSConnIVPMainDialog as described above, the IMS Connector for Java IVPthrows an exception, indicating that one of the classes cannot be found. In somecases, the IVP might not respond.

Preparing your WebSphere Studio environmentYou can use WebSphere Studio to develop servlets that access IMS transactions.These servlets are generated from Enterprise Access Builder (EAB) commands thatuse IMS Connector for Java. This section describes what you need to do to preparefor using these commands in the WebSphere Studio environment.

Important: WebSphere Studio is required only if you are creating the CCF sample“Building a Java servlet to run an IMS transaction.” WebSphere Studio is notrequired by IMS Connector for Java. You can now create servlets using theVisualAge for Java Create Servlet SmartGuide instead of WebSphere Studio.

Installing Class Libraries

If you have both VisualAge for Java and WebSphere Studio installed on the samemachine, you must modify your WebSphere Studio’s CLASSPATH environmentvariable to point to the class libraries being installed by VisualAge for Java asfollows:

1. In WebSphere Studio, select Tools > Preferences from the menu bar.

2. Click on the Java tab and then enter the following in the Classpath field:{StudioClasspath};<VAJ_Install_dir>\eab\runtime30;

If you do not have both VisualAge for Java and WebSphere Studio installed on thesame machine, then you must install the following class libraries on the WebSphereStudio workstation to generate a servlet from an EAB command that uses IMSConnector for Java:

v IBM Common Connector Framework

v IBM Enterprise Access Builder Library

v IBM Java Record Library

v Connector IMS

58 IMS Connector for Java User’s Guide and Reference

The following steps show you where to obtain the class libraries (JAR files) andhow to set up the CLASSPATH environment variable to point to the JAR files.WebSphere Studio generates the servlet using the EAB command and these classlibraries.

In this section, the parameters represent the following:

<VAJ_install_dir>The VisualAge for Java installation directory. For example, d:\ProgramFiles\IBM\VisualAge for Java.

<IBM_Connectors_install_dir>The IBM Connectors installation directory. For example, d:\IBM Connectors.

<target_dir>The path on your WebSphere Studio workstation where the JAR files areplaced. For example, c:\imsconn.

1. Copy the following class libraries (JAR files) from their directories (indicatedbelow) to your WebSphere Studio target directory (<target_dir>):

v IBM Common Connector FrameworkFile ccf.jar is located in the <IBM_Connectors_install_dir>\classes directory.

v IBM Enterprise Access Builder LibraryFile eablib.jar is located in the <VAJ_Install_dir>\eab\runtime30 directory.

v IBM Java Record LibraryFile recjava.jar is located in the <VAJ_Install_dir>\eab\runtime30 directory.

v IMS Connector for JavaFile imsconn.jar is located in the <IBM_Connectors_install_dir>\classesdirectory.

2. Modify (or append to) your WebSphere Studio’s CLASSPATH environmentvariable for WebSphere Studio to point to the above JAR files.

Modify the CLASSPATH environment variable in WebSphere Studio by clickingTools > Preference. Click on the Java tab and enter the following in theClasspath field{StudioClasspath};<target_dir>\ccf.jar;<target_dir>\eablib.jar;<target_dir>\recjava.jar;<target_dir>\imsconn.jar;

Preparing your WebSphere Application Server environment forWindows

You can use WebSphere Application Server to run servlets that use IMS Connectorfor Java to access IMS transactions. This section describes what you need to do toprepare for using these servlets in the WebSphere Application Server environment.

Important: This section assumes that you have already installed the J2Cconnection architecture support for your WebSphere Application Server. Forinstructions on how to install this support, see the document “Installing theConnector Architecture for WebSphere Application Server (J2C)” in the WebSphereApplication Server Advanced Edition Information Center.

Note: These instructions apply to IBM WebSphere Application Server 4.0.Information for earlier versions of IBM WebSphere Application Server can be foundin earlier versions of IMS Connector for Java documentation. See the IMSConnector for Java Web page in the IMS Web site at www.ibm.com for earlierversions of the documentation.

Chapter 2. Preparing to use IMS Connector for Java 59

The runtime component of IMS Connector for Java with J2C support is provided asa component of IMS Connect Version 1 Release 2. This runtime component is alsoreferred to as the IBM WebSphere Adapter for IMS.

To prepare to run Java applications (for example, servlets or EJBs) that use theJ2C implementation of IMS Connector for Java in WebSphere Application Server,you should complete the following steps:

1. Installing the runtime component IMS Connector for Java with J2C support onthe target WebSphere Application Server

2. Deploying IMS Connector for Java with J2C support into WebSphere ApplicationServer

3. Preparing to run the Installation Verification Program (IVP)

4. Creating and Configuring a Connection Factory for use by the IVP Servlet

5. Deploying the IVP Servlet in WebSphere Application Server

6. Running the IVP Servlet to access the target IMS

Each of the above steps is described in detail below.

Step 1: Installing the runtime component IMS Connector for Java with J2Csupport on the target WebSphere Application Server

The following executable files are provided with the IMS Connector for Java runtimecomponent. Select and start the executable for the platform on which you areperforming the installation, then follow the instructions in the installation wizard.

v For AIX - select imsicosetup_aix

v For Sun Solaris - select imsicosetup_solaris

v For Windows - select imsicosetup_win.exe

Running one of these executable files will place the files listed below into a targetdirectory for later deployment in WebSphere Application Server.

Note: For AIX and Solaris you must have root authority to perform the installation.

Successful completion of the installation places the following files in directoryIMSICO/J2C of a target directory (<target_dir>) of your choice or the default targetdirectory. The default target directory is c:\Program Files for Windows platforms and/opt for the AIX and Solaris platforms.

<target_dir>/IMSICO/J2C/READMEInformation about the files in directory J2C.

<target_dir>/IMSICO/J2C/imsico.rarResource Adapter Archive file for IMS Connector for Java (J2C).

<target_dir>/IMSICO/J2C/en_US/HowTo.HTMLInformation about IMS Connector for Java.

<target_dir>/IMSICO/J2C/en_US/IMSICOIVP.HTMLInformation about the IVP.

<target_dir>/IMSICO/J2C/IVP/IMSICOIVP.earThe Enterprise Application Archive file for IMS Connector for Java’sInstallation Verification Program (IVP).

Step 2: Deploying IMS Connector for Java with J2C support into WebSphereApplication Server

60 IMS Connector for Java User’s Guide and Reference

A Resource Adapter Archive (RAR) file is used to deploy a resource adapter in anapplication server. In this case, the resource adapter is IMS Connector for Java withJ2C support.

This section describes how to deploy the IMS Connector for Java RAR file(imsico.rar) into the operational environment of WebSphere Application Server. Thissection assumes the RAR file has been installed in <target_dir>\IMSICO\J2C.

1. Start the WebSphere Advanced Administrative Console:

a. From your Windows desktop, click Start > Programs > IBM WebSphere >Application Server 4.0 > Start Admin Server. You must start this serverbefore you start the Administrative Console.

b. Click Start > Programs > IBM WebSphere > Application Server 4.0 >Administrator’s Console.

2. In the WebSphere Advanced Administrative Console, expand WebSphereAdministrative Domain by clicking the plus sign (+) next to WebSphereAdministrative Domain.

3. Click the plus sign next to Resources.

4. In the expanded directory, right-click the J2C Resources Adapters folder andclick New from the menu options to start the ″J2C Resource AdapterProperties″ dialog box.

5. In this dialog box, ensure that the General tab is selected. In the Name field,enter <Your Resource Adapter>, where <Your Resource Adapter> is the nameyou want for your Resource Adapter (for example, ″IMS J2C Connector“).

6. Click the small square to the right of the Archive file name field to start the″Install Driver″ dialog box. In this dialog, highlight the node on which you wantto install the resource adapter, then click the ″Browse″ button and locate IMSConnector for Java’s RAR file (<target_dir>\IMSICO\J2C\imsico.rar). Click theOpen button.

7. Click the Install button.

8. The archive file name should now contain the directory and name of the RARfile.

9. Click OK. When you have successfully deployed the IMS Connector for Javaresource adapter you will see a confirmation message.

Related Reading: Instructions for deploying RAR files in WebSphere ApplicationServer can also be found in the WebSphere Application Server Information Center.From the WebSphere Advanced Administrative Console, select Help > Task Helpor Help > Information Center.

Step 3: Prepare to run the Installation Verification Program (IVP)

See ”Preparing to run the IMS Connector for Java IVP“ in ”Preparing to use IMSConnector for Java“ for information on IVP prerequisites.

Restriction: Because you are using a workstation platform to run this IVP, youmust use TCP/IP to communicate with IMS Connect.

Step 4: Creating and Configuring a Connection Factory for use by the IVPServlet

This section describes how to create a Connection Factory, for use by the IVP tocreate a connection between the IVP and your IMS Connect and IMS. You mustdeploy the IMS Connector for Java RAR file before you begin this task.

Chapter 2. Preparing to use IMS Connector for Java 61

1. Create a Connection Factory:

a. In the WebSphere Advanced Administrative Console, expand the”WebSphere Administrative Domain“ directory by clicking the plus sign (+)next to it.

b. By clicking the plus signs, expand the following folders in this order:Resources, J2C Resource Adapters, and <Your Resource Adapter>,where <Your Resource Adapter> is the name you chose when youdeployed the IMS Connector for Java RAR file. For example, IMS J2CConnector.

c. Right-click the ”J2C Connection Factories“ folder under IMS J2C Connectorand click New from the menu options. This will start the ”J2C ConnectionFactory Properties“ dialog box.

d. In this dialog box, ensure that the General tab is selected. In the ”Name“field, enter a name for the connection between the IVP application and yourIMS backend system. For example, for the IVP enter ”MyIMS.“

e. For the IVP, leave the JNDI binding path field blank. This will result in adefault of ”eis/MyIMS“ being used for the JNDI binding path. Enter anoptional description for the Connection Factory.

f. Click OK. When you have successfully created the connection factory, youshould see a confirmation dialog box.

2. Configure your Connection Factory:

a. In the WebSphere Advanced Administrative Console, locate your connectionfactory in the upper-right section of the Console window (”MyIMS“ in theexample above). Click the name of your connection factory once to workwith it.

b. Click the Connections tab.

c. Specify values for each of the following connection properties. To edit aproperty, scroll down to find the Value field. Use this field to enter the valueyou want for each property. When you are done, click anywhere outside thefield to set the value.

DataStoreNameThe name of the target IMS datastore. It must match the IDparameter of the Datastore statement that is specified in the IMSConnect configuration member when IMS Connect is installed. Italso serves as the XCF member name for IMS during internal XCFcommunications between IMS Connect and OTMA. You mustreplace the default value ”myDStrNm “ with a value that is valid foryour IMS environment.

GroupNameThe default IMS group name that will be used for all connectionscreated by this Connection Factory. Whether or not you provide avalue for GroupName will depend on the level of security checkingin place for your installation. If, additionally, you wish to use the IVPto verify your installation’s security environment, and your securityenvironment requires that you use GroupName, you must replacethe default value of 8 blanks with a valid value.

HostNameThe IP address or host name of the machine running the target IMSConnect. You must replace the value ”myHostNm “ with a value thatis valid for your IMS environment.

62 IMS Connector for Java User’s Guide and Reference

PasswordThe default password that will be used for all connections created bythis Connection Factory. Whether or not you provide a value forPassword will depend on the level of security checking in place foryour installation. If, additionally, you wish to use the IVP to verifyyour installation’s security environment, you must replace the defaultvalue of 8 blanks with a valid value.

PortNumberThe number of a port used by the target IMS Connect for TCP/IPconnections (sockets). Multiple sockets can be open on a singleTCP/IP port. See ″Configuring IMS Connect″ in the IMS ConnectGuide and Reference for additional information about PortNumber.You must replace the value ”0“ with a value that is valid for your IMSenvironment.

TraceLevelLevel of information to be traced. See the Javadoc for theIMSTraceLevelProperties class or the IMS Connector for JavaUser’s Guide for a description of trace levels.

UserNameThe default security authorization facility (SAF) user name that willbe used for all connections created by this Connection Factory. Forexample, for some installations this would be the RACF user ID.Whether or not you provide a value for UserName will depend onthe level of security checking in place for your installation. If,additionally, you wish to use the IVP to verify your installation’ssecurity environment, you must replace the default value of 8 blankswith a valid value.

d. Click the Apply button to complete your command.

Step 5: Deploying the IVP Servlet in WebSphere Application Server

The IVP is packaged as an Enterprise Application Archive (EAR) file. The EAR filecontains a WebSphere Adapter Archive (WAR) file containing a servlet Webcomponent consisting of the following parts:

v IMSICOIVPServlet.class

v IMSICOIVP.jar

v IMSICOIVPServletError.jsp

v IMSICOIVPServletResults.jsp

v IMSICOIVPServletInput.html

To deploy the IVP in your WebSphere Application Server environment, do thefollowing:

1. In the WebSphere Advanced Administrative Console, deploy the IVP using theInstall Enterprise Application Wizard. Click Console > Wizards > InstallEnterprise Application. Complete the following steps in this wizard:

a. Select the Install Application (*.ear) radio button. Click ”Browse“ and selectthe EAR file for the IVP, imsicoivp.ear.

Note: These instructions assume the file imsicoivp.ear is on the nodeselected in the list associated with the Browse for the file on node field.The imsicoivp.ear file is placed in a directory of your choice as part of theinstallation process of IMS Connector for Java (for example, < targetdir>\IMSICO\J2C\ivp).

Chapter 2. Preparing to use IMS Connector for Java 63

b. Give the application a name in the ”Application Name“ field. For thisexample use the name ”IMSICOIVPApp“.

c. Click Next until you see the Mapping Resource References to Resourcespage.

d. In the Mapping Resource References to Resources page, select theresource reference, MyIMS(IMSICOIVPWar), and click Select Resource.The Select Resource dialog box appears with a list of resources defined.Select the resource MyIMS and click OK.

Note: If no resources are listed in the Select Resource dialog, you have notdeployed the RAR file and/or created a connection factory. See IMS Connectorfor Java’s HowTo.html for instructions for deploying IMS Connector for Java’sRAR file. See Step 4: Creating and Configuring the Connection Factory (page61) in this document for instructions for creating a connection factory.

e. Click Next until you see the Selecting the Virtual Hosts for WAR Modulespage.

f. In the Selecting the Virtual Hosts for WAR Modules page, select the webmodule, IMSICOIVPWar, and click Select Virtual Host. In the dialog box thatappears, select the virtual host, default_host, and click OK. (This stepchooses which server will run the servlet.) Then click Next.

g. In the Selecting the Application Server page, select the module,IMSICOIVPWar, and click the Select Server... button. In the dialog box thatopens, select the Default Server and click OK. Then click Next.

h. Verify the information displayed, then click Finish. When the command hascompleted successfully, you will see a confirmation dialog box. Click OK toclose the box.

2. Start the Default Server:

a. Click the plus (+) sign to expand the view of the WebSphereAdministrative Domain.

b. Click the plus (+) sign beside Nodes to view the nodes in the WebSphereAdministrative Domain.

c. Click the plus (+) sign to expand the view of the node that has the TCP/IPhost name of your Web server machine.

d. Click the plus (+) sign beside Application Servers to view the node’sapplication servers.

e. Right click on Default Server under the host node in the previous step, andselect Start. A dialog box displaying ”Command ’DefaultServer.start’completed successfully“ will appear when the server has been started.

Step 6: Running the IVP Servlet to access the target IMS

From a Web browser, enter the following Webaddress: http://<servername>:port/imsicoivp/IMSICOIVPServletInput.html, whereservername and port is the name and port number of your Web server machine,and imsicoivp is the context root of the WAR file.

Clicking Submit on the input form causes the IMS /STA OTMA command to besent to IMS using the properties you specified in the Connection Factory namedMyIMS.

The objective of the IVP is to receive a message from IMS in reply to the /STAOTMA command. One of two possible messages is returned, depending on thelevel of security checking in place for your installation and whether the

64 IMS Connector for Java User’s Guide and Reference

UserName/Password/GroupName is permitted to issue the /STA command. Eithermessage indicates successful execution of the IVP, since it is IMS that issues the″DFS″ message.

v DFS1292E SECURITY VIOLATION

v DFS058I 17:33:32 START COMMAND COMPLETED

The IVP does not run an IMS application program and therefore does not verify thatIMS transactions can run successfully. It only verifies that the path to IMS isavailable.

Troubleshooting IVP Failures

If the IVP does not run successfully, you should first check for information in theWebSphere Application Server logs in folder \WebSphere\AppServer\logs. This filelists exceptions and stack traces that are useful for diagnosing the failure.

In addition, the following are possible causes for IVP failure:

v The IBM WS Admin Server is not started.

v The Application Server used for the IVP (for example, default_server) is notstarted.

v The IVP’s Enterprise Application, IMSICOIVPApp, is not started. To determine thestatus of the Enterprise Application, right-click on the Enterprise ApplicationIMSICOIVPApp and select Show Status. If the status is not ”Running“ in theModule Status window, close the window then right-click on the EnterpriseApplication IMSICOIVPApp and select Start.

v Invalid data was specified when configuring the MyIMS Configuration Factory.For example:

– HostName was misspelled or was not sufficiently qualified (for TCP/IPcommunication).

– An incorrect PortNumber was specified for the target IMS Connect.

– Datastore name is invalid for the target IMS or is misspelled. Datastore namemust be in uppercase characters.

v IMS is not running.

v IMS Connect is not running.

v The IMS Connect port is not active. Use the IMS Connect command ”VIEWHWS“to determine if the port is active. Use the IMS Connect command ”OPENPORT“to activate an IMS Connect port.

v The target IMS datastore is not active. Use the IMS Connect command”VIEWHWS“ to determine if the datastore is active. Use the IMS Connectcommand ”OPENDS“ to activate a IMS datastore.

v TCP/IP failure. Always ensure a successful ”ping“ prior to running the IVP.

v The wrong level of IMS Connect is running on the host. See ”Preparing to runthe IVP“ in ”Preparing your VisualAge for Java Environment“ for the requiredlevel of IMS Connect.

Chapter 2. Preparing to use IMS Connector for Java 65

Preparing your WebSphere Application Server environment for z/OSand OS/390

The information in this section applies to the J2C implementation of IMS Connectorfor Java only and to IBM WebSphere Application Server 4.0. For information onusing the IVP in the CCF implementation or on earlier versions of IBM WebSphereApplication Server, see previous editions of the IMS Connector for Java User’sGuide and Reference, available on the IMS Connector for Java Web page in theIMS Web site at www.ibm.com/ims.

Related Reading: More information about Resource Recover Services (RRS)transaction support is available in the WebSphere Application Server for OS/390and z/OS documentation. The document titled “WebSphere Application ServerV4.0.1 for z/OS and OS/390: WebSphere for z/OS-supported Connectors″ isavailable with APAR PQ55873 for WebSphere Application Server V4.0.1 for z/OSand OS/390. To download the document, go to the Web site athttp://www.ibm.com/software/webservers/appserv/zos_os390/support.html, then click″Product information.″ At a later time, the information in this document will beintegrated into the WebSphere for z/OS formal publications. To access the latestpublications, go to the product library page athttp://www.ibm.com/software/webservers/appserv/.

To prepare to run Java applications (for example, servlets or EJBs) that use theJ2C implementation of IMS Connector for Java in WebSphere Application Server forz/OS and OS/390, you should complete the following steps:

1. Installing the runtime component IMS Connector for Java with J2C support onthe target z/OS and OS/390 system

2. Configuring IMS Connector for Java with J2C support on the target z/OS andOS/390 system

3. Preparing to run the Installation Verification Program (IVP)

4. Deploying and Configuring IMS Connector for Java as a J2EE server resourcein WebSphere Application Server for z/OS and OS/390

5. Deploying the IMS Connector for Java IVP

6. Starting the server to run the IVP

7. Running the IVP to access the target IMS

Each of the above steps is described in detail below.

Important: Before you can deploy and run the IVP servlet, the followingcomponents and configurations are required:

v WebSphere Application Server V4.0.1 or higher for z/OS and OS/390 that hasbeen tested by the supplied J2EE Web Application Installation VerificationPrograms (IVPs)

The IMS Connector for Java sample J2EE applications require a definition of aJ2EE application server and the initial modifications to the web containerconfiguration files of this server. They also require additional modifications to theenvironment variables of the HTTP server. For details, see WebSphereApplication Server V4.0.1 for z/OS and OS/390 Installation and Customization,GA22-7834.

This manual provides an example of defining a J2EE application server(BBOASR2) and creating an instance of this server (BBOASR2A) for running theWebSphere Application Server IVPs. The initial modifications to the web

66 IMS Connector for Java User’s Guide and Reference

container configuration files and HTTP server environment variables can also befound within the steps for setting up the server’s J2EE web applicationverification programs.

Additionally, be sure that you have met the prerequisites for WebSphereApplication Server described in ”Prerequisites for running IMS Connector forJava.“

v WebSphere for z/OS and OS/390 Administration application

The Administration application is packaged in a self-extracting executable filesupplied by the WebSphere Application Server for z/OS and OS/390. Thisexecutable file also provides the Operations application. Together these programsare often called the ”system management enhanced user interface“ (SMEUI). Fordetails on installing the Administration and Operations applications, seeWebSphere Application Server V4.0.1 for z/OS and OS/390 Installation andCustomization, GA22-7834.

The Administration application manages administration tasks for the WebSphereApplication Server from the terminal side and defines an IMS ConnectionFactory, creates an instance of this resource, and installs J2EE applicationsbundled within enterprise archive (EAR) files.

Step 1: Installing the runtime component IMS Connector for Java with J2Csupport on the target z/OS and OS/390 system

Using SMP, install the required APARs (APAR PQ57191 and corequisite APARPQ57192) for the IMS Connect 1.2 product on the z/OS or OS/390 system imagewhere you will start the WebSphere Application Server for z/OS and OS/390 serverfor running EJBs and servlets that use the IMS Connector for Java.

Successful completion of the installation places the following files in directory imsicoof a target directory (<target_dir>) of your choice or the default target directory. Thedefault target installation directory is /usr/lpp on the z/OS and OS/390 system.

<target_dir>/imsico/READMEInformation about the files installed for IMS Connector for Java

<target_dir>/imsico/J2C/READMEInformation about the files in the J2C directory

<target_dir>/imsico/J2C/imsico.rarResource Adapter Archive file for IMS Connector for Java (J2C)

<target_dir>/imsico/J2C/HowTo.htmlInformation about IMS Connector for Java

<target_dir>/imsico/J2C/IMSICOIVPzOS.htmlInformation about the IVP

<target_dir>/imsico/J2C/IMSICOIVPzOS.earThe Enterprise Application Archive file for IMS Connector for Java’sInstallation Verification Program (IVP)

<target_dir>/imsico/CCF/READMEInformation about the files in the CCF directory

<target_dir>/imsico/CCF/imsiconn.jarIMS Connector for Java class libraries for CCF

<target_dir>/imsico/CCF/libimsconn.soIMS Connector for Java Local Option native library for CCF

Chapter 2. Preparing to use IMS Connector for Java 67

Step 2: Configuring IMS Connector for Java with J2C support on the targetz/OS and OS/390 system

1. Create an HFS work directory that allows read, write, and execute authority.Use a meaningful name for the directory (for example: /usr/lpp/connectors).

2. In the install directory for IMS Connector for Java, look for the file imsico.rar andcopy it into the work directory you created in the previous step.

Tip: If your installation used the default directory for installing IMS Connector forJava, you will find the imsico.rar in the directory /usr/lpp/imsico/J2C.

3. Under the work directory, expand the imsico.rar file by entering the followingcommand:jar -xvf imsico.rar

Result: The expansion extracts the following files into the directory:

v imsico.jar

v libimsico.so

Note: Additional files are also extracted, but they are not used for thedeployment of the connector.

4. Use the following command to give execute permission to the imsico.jar andlibimsico.so files under the work directory:chmod ugo+x imsico.jarchmod ugo+x libimsico.so

Step 3: Preparing to run the Installation Verification Program (IVP)

See ”Preparing to run the IMS Connector for Java IVP“ in ”Preparing to use IMSConnector for Java“ for information on IVP prerequisites.

Step 4: Deploying and Configuring IMS Connector for Java as a J2EE serverresource in WebSphere Application Server for z/OS and OS/390

This section describes how to:

v Deploy IMS Connector for Java

v Create and configure a Connection Factory for IMS Connector for Java as aJ2EE server resource to your target WebSphere Application Server for z/OS andOS/390

The Connection Factory will be used by the IVP to create a connection between theIVP, your IMS Connect, and IMS.

1. Verify that the bootstrap deamon is started.

a. On the host machine display the active jobs, by entering the command:D A,L

b. If the BBODMN is not an active job displayed in the list, start the bootstrapserver by issuing the command:S BBODMN.DAEMON01

c. Verify that these messages are displayed:BBOU0016I INITIALIZATION COMPLETE FOR DAEMON DAEMON01.BBOU0020I INITIALIZATION COMPLETE FOR CB SERIES CONTROL REGION SYSMGT01.BBOU0020I INITIALIZATION COMPLETE FOR CB SERIES CONTROL REGION NAMING01.BBOU0020I INITIALIZATION COMPLETE FOR CB SERIES CONTROL REGION INTFRP01.

2. Start the Operations application and connect to the servers.

68 IMS Connector for Java User’s Guide and Reference

a. Open the Operations application. For example: click Start > Programs >IBM WebSphere for z/OS > Operations and wait for the Login window toappear.

b. Fill in the dialog with the Bootstrap server IP name (for example, theDAEMON_IP environment variable or the name specified for the bootstrapserver’s IP address in the host file on the workstation), Port (default 900),the Userid (default CBADMIN), and the Password (default CBADMIN).

c. Click OK to login and establish connections to the servers. Wait for theWebSphere for Application Server for z/OS and OS/390 Operationswindow to appear and the icons for the servers available on the hostmachine.

3. Ensure that the web server is not active:

a. On the host machine, display all active jobs by issuing the followingcommand:D A, L

b. If the web server (for example, IMWEBSRV) is an active job, issue thefollowing command to stop it:STOP IMWEBSRV

4. Ensure that the J2EE server is not active:

a. In the WebSphere Application Server for z/OS and OS/390 window,highlight the instance of the J2EE server (for example, BBOASR2A).

b. Click Selected > Stop.

Note: You also can stop the server manually by issuing the followingcommand:STOP BBOASR2.BBOASR2A

5. Start the Administration application and connect to the servers.

a. Open the Administration application. For example: click Start >Programs > IBM WebSphere for z/OS > Administration and wait for theLogin window to appear.

b. Fill in the dialog with the Bootstrap server IP name (for example, theDAEMON_IP environment variable or the name specified for the bootstrapserver’s IP address in the host file on the workstation), Port (default 900),the Userid (default CBADMIN), and the Password (default CBADMIN).

c. Click OK to login and establish connections to the servers. Wait for theWebSphere for Application Server for z/OS and OS/390 Administrationwindow to appear.

6. Add a new conversation.

a. Select the Conversations folder.

b. Under the Selected drop down menu choose Add and wait for theconversation name and description fields to appear.

c. In the Conversation Name text box enter the name for the newconversation (for example, IMSICO).

d. Click Selected > Save.

e. Wait for the completion message (for example, BBON0515I ConversationIMSICO was added.) to appear in the status text box above the status barin the Administration window.

7. Ensure that connection management is configured into the sysplex bycompleting the following steps:

a. Expand the Conversations folder (by clicking the plus sign next to it).

b. Expand the new conversation (for example, IMSICO).

Chapter 2. Preparing to use IMS Connector for Java 69

c. Expand the Sysplexes folder and highlight the sysplex name (for example,PLEX1).

d. Click Selected > Modify to update the sysplex definition.

e. Under the ”Configuration Extensions“ section of the sysplex definition,check the box labeled ”Connection Management.“

f. Click Selected > Save to save your changes.

8. Set up the IMS Connector for Java classes to be used by WebSphereApplication Server by setting up the following CLASSPATH and LIBPATHenvironment variable values. Do the following:

a. Expand the sysplex name in the conversation (for example, PLEX1).

b. Expand the J2EEServers folder and highlight the J2EE server name (forexample, BBOASR2).

c. Click Selected > Modify to update the J2EE server definition.

d. Under the Environment variable list section of the J2EE server definition,double click any environment variable (for example, the CLASSPATHvariable) to open the Environment Editing Dialog window and modify thefollowing environment variables:

v For the CLASSPATH environment variable, add the full directory namefor the file imsico.jar as noted in ”Step 2. Configuring IMS Connector forJava with J2C support on the target z/OS and OS/390 system (page68).“ To do so, complete the following steps:

1) Under the Name drop down box in the Environment Editing Dialogwindow, select the CLASSPATH variable.

2) Click the Modify button.

3) Append the full directory name for the file imsico.jar to the currentclasspath in the Variable Value textbox (for example,<current_classpath>:/usr/lpp/connectors/imsico.jar).

v For the LIBPATH environment variable, add the full name of the workdirectory that contains the libimsico.so file as noted in ”Step 2.Configuring IMS Connector for Java with J2C support on the target z/OSand OS/390 system (page 68).“ To do so, complete the following steps:

1) Under the Name drop down box in the Environment Editing Dialogwindow, select the LIBPATH variable.

2) Click the Modify button.

3) Append the work directory that contains the libimsico.so file to thecurrent libpath (for example, <current_libpath>:/usr/lpp/connectors).

e. Click OK to close the Environment Editing Dialog window (to complete theenvironment variables changes).

f. Click Selected > Save.

9. Add an IMS Connector for Java connection factory as a new J2EE ServerResource.

a. Select the J2EE Resources folder under your sysplex name (for example,PLEX1).

b. Click Selected > Add and wait for the J2EE resource description fields toappear in the right panel.

c. In the J2EE Resource Name text box, enter the name that will representan IMS connection factory resource for this example (for example, IMSRes).

d. Set the J2EE Resource type to IMSConnectionFactory.

70 IMS Connector for Java User’s Guide and Reference

e. Click Selected > Save. Wait for the completion message (for example,BBON0515I J2EE Resources IMSRes was added.) to appear in the statustext box above the status bar in the Administration window.

f. Expand the J2EE Resources folder.

g. Expand the resource name that was added (for example, IMSRes).

h. Select the J2EE Resource Instances folder.

i. Click Selected > Add and wait for the J2EE resource instance descriptionfields to appear in the right panel.

j. In the IMSConnectionFactory text box, enter the name of an instance of anIMS connection factory resource (for example, IMSRes_Instance).

k. Verify that the appropriate System name is displayed in its drop down box(for example, SY1).

l. Fill in the appropriate value for the remaining fields.

Datastore nameThe name of the target IMS datastore. It must match the IDparameter of the Datastore statement that is specified in the IMSConnect configuration member when IMS Connect is installed. Italso serves as the XCF member name for IMS during internal XCFcommunications between IMS Connect and OTMA. You mustreplace the default value ”myDStrNm “ with a value that is valid foryour IMS environment.

Datastore name is a 1 to 8 alphanumeric character name of thetarget IMS datastore defined in IMS Connect. Note: Thisinformation can be acquired by executing the nnVIEWHWS command,where nn is the response number to the IMS Connect replymessage on the host.

Group nameThe default IMS group name that will be used for all connectionscreated by this Connection Factory. Whether or not you provide avalue for GroupName will depend on the level of security checkingin place for your installation. If, additionally, you wish to use the IVPto verify your installation’s security environment, and your securityenvironment requires that you use GroupName, you must replacethe default value of 8 blanks with a valid value.

Group name is a 1 to 8 alphanumeric character value to be used asthe default group name for the user if neither the container nor theapplication provides a group name to IMS Connector for Java.

Host nameThis field is the TCP/IP host name of the target IMS Connect. Thisproperty applies only when using TCP/IP communication betweenIMS Connector for Java and IMS Connect to run the IVP.

Note: This property is ignored if the IMS Connect name property isspecified or if you are using Local Option.

IMS Connect nameThe IMS Connect name must match the ’HWS ID’ of the target IMSConnect. This property applies only when using Local Optioncommunication between IMS Connector for Java and IMS Connectto run the IVP. Fill out this field with the appropriate information. A1 to 8 alphanumeric character name of the target IMS Connect.

Note: If you are using TCP/IP, you must leave this field blank.

Chapter 2. Preparing to use IMS Connector for Java 71

LogWriter RecordingYou can either ″enable″ or ″disable″ LogWriter recording for use byIMS Connector for Java in WebSphere Application Server for z/OSand OS/390. See ”Using the trace and error logging facility“ formore information.

PasswordThe default password that will be used for all connections createdby this Connection Factory. Whether or not you provide a value forPassword will depend on the level of security checking in place foryour installation. If, additionally, you wish to use the IVP to verifyyour installation’s security environment, you must replace thedefault value of 8 blanks with a valid value.

Password is a 1 to 8 alphanumeric character value to be used asthe default password for the user if neither the container nor theapplication provides a password to IMS Connector for Java.

Port numberThis field is the TCP/IP port number of the target IMS Connect.This property applies only when using TCP/IP communicationbetween IMS Connector for Java and IMS Connect to run the IVP.

User nameThe default security authorization facility (SAF) user name that willbe used for all connections created by this Connection Factory. Forexample, for some installations this would be the RACF user ID.Whether or not you provide a value for UserName will depend onthe level of security checking in place for your installation. If,additionally, you wish to use the IVP to verify your installation’ssecurity environment, you must replace the default value of 8blanks with a valid value.

User name is a 1 to 8 alphanumeric character value to be used asthe default name for the user if neither the container nor theapplication provides a user name to IMS Connect for Java.

Trace levelLevel of information to be traced. See the Javadoc for theIMSTraceLevelProperties class or the IMS Connector for JavaUser’s Guide and Reference for a description of trace levels.

m. Click Selected > Save. Wait for the completion message (for example,BBON0515I J2EE Resource instance IMSRes_Instance was added.) toappear in the status text box above the status bar in the Administrationwindow.

Step 5: Deploying the IMS Connector for Java IVP

The IVP is packaged as an Enterprise Archive (EAR) file. An EAR file represents aJ2EE application that can be deployed in a WebSphere application server. This filecontains one Web Module and its WebSphere configuration files.

This Web Module consists of one Web Archive (WAR) file that packages itsdeployment configuration files and the following basic components:

v IMSICOIVPServlet.class

v IMSICOIVPServletError.jsp

v IMSICOIVPServletResults.jsp

v IMSICOIVPServletInput.html

72 IMS Connector for Java User’s Guide and Reference

Before you begin, you must have the IVP EAR file (IMSICOIVPzOS.ear) in adirectory of a workstation system that can be accessed by your WebSphere forz/OS Administration Application.

This IVP EAR has been installed with the IMS Connector for Java runtimecomponent on your host z/OS or OS/390 server. For more information on this, see”Step 1: Installing the runtime component IMS Connector for Java with J2C supporton the target z/OS and OS/390 system (page 67).“ You can download this IVP earfile your workstation machine. Be sure to download the IVP EAR file in binaryformat.

In the instructions below, the IVP EAR file is assumed to be the c:\Temp directory ofyour workstation.

To deploy the IVP in your WebSphere Application Server for z/OS and OS/390environment, complete the following steps in the same conversation in theWebSphere for z/OS Administration Application that you started in Step 4:Deploying and Configuring IMS Connector for Java as a J2EE server resource inWebSphere Application Server for z/OS and OS/390 (page 68).

1. Install the enterprise application.

a. Select the J2EE server on which this application will be installed (forexample, BBOASR2). Select this server by expanding the following folders inorder: Conversations folder, the conversation (for example, IMSICO), theSysplexes folder, the sysplex in which your sample J2EE server has beeninstalled (for example, PLEX1), and the J2EEServers folder.

b. Click Selected > Install J2EE application... and wait for its referencewindow to appear (for example, the Install J2EE application on server:BBOASR2 window).

c. Click the Browse EAR File... button and wait for the Open window toappear. Locate and select your EAR file (for example, select theIMSICOIVPzOS.ear file that you downloaded in the C:\Temp directory). ClickOpen.

d. Verify that the destination and EAR file name appears in the EAR Filenametext field. Click OK and wait for the Reference and Resource Resolutionwindow to appear.

e. In the Reference and Resource Resolution dialog box:

1) On the left side of the dialog, under the IMSICOIVPApp folder, expand theimsicoivp_WebApp.jar folder and select the J2EE application bean (forexample, imsicoivp_WebApp)

2) On the right side of the dialog, click the EJB tab and click ”Set DefaultJNDI Path & Name.“

3) Click the J2EE Resource tab, click the empty box under J2EEResource, then select the Connection Factory you just created for theServer (for example, IMSRes). Click OK.

2. You have now deployed IMS Connector for Java as J2EE resources. You havealso deployed the IMS Connector for Java IVP. You can complete and activatethe changes in the conversation to your WebSphere Application Server for z/OSand OS/390 with the following steps:

a. Validate the new conversation you just created in the previous step byselecting the conversation name (for example, IMSICO) to highlight it andclicking Build > Validate.

b. Commit the new conversation by selecting the conversation name tohighlight it and clicking Build > Commit.

Chapter 2. Preparing to use IMS Connector for Java 73

c. Ensure that all preparation tasks for the new conversation are completed.Then select the conversation name to highlight it and click Build >Complete > All Tasks to indicate completion.

d. Activate the new conversation by selecting the conversation name tohighlight it and clicking Build > Activate.

3. Configure the HTTP server for the context root of the IVP by modifying thefollowing files:

a. Modify the webcontainer.conf file with the following information:host.default_host.contextroots=/

b. Modify the httpd.conf file by adding the following information:Service /imsicoivp/* <was_dir>/WebServerPlugIn/bin/was400plugin.so:service_exit

where <was_dir> is the installation root directory of WebSphere ApplicationServer (for example, /usr/lpp/WebSphere).

Step 6: Starting the server to run the IVP

The following steps show how to start the Web and WebSphere Application serversto run the IVP servlet from a browser.

1. Start the J2EE server.

a. In the WebSphere Application Server for z/OS and OS/390 Operationswindow, highlight the instance of the J2EE server (for example,BBOASR2A).

b. Click Selected > Start.

c. Wait for a message indicating that the server has been issued a startcommand (for example, BBON0600I Start issued for server instanceBBOASR2A.) to appear in the status text box above the status bar in theAdministration window.

d. Click View > Refresh.

e. Wait for a green check mark to appear over the icon of the instance of theJ2EE server indicating that the server has become active.

(Note: The server can be started manually by issuing the SBBOASR2.BBOASR2A command).

2. Start the Web server.

a. Issue the command to start the Web server on the host machine. Forexample (if the default webserver setup is used)S IMWEBSRV

b. Wait for a message indicating that the Web server has completely started.For example there may be a messages similar to theseIMW3534I PID: 16777263 SERVER STARTINGIMW3536I SA 16777263 0.0.0.0:8080 * * READY

Step 7: Running the IVP to access the target IMS

1. From a Web browser, enter the following URL:http://<servername>:<port>/imsicoivp/IMSICOIVPServletInput.html

where servername and port is the name and port number for your Web servermachine and imsicoivp is the context root of the IVP Web module.

2. Click Submit on the input form. This action causes the IMS /STA OTMAcommand to be sent to IMS using the properties you specified in theConnection Factory named IMSRes.

74 IMS Connector for Java User’s Guide and Reference

The objective of the IVP is to receive a message from IMS in reply to the /STAOTMA command. One of two possible messages is returned, depending on thelevel of security checking in place for your installation and whether theUserName/Password/GroupName is permitted to issue the /STA command. Eithermessage indicates successful execution of the IVP, since it is IMS that issues the”DFS“ message.

v DFS1292E SECURITY VIOLATION

v DFS058I 17:33:32 START COMMAND COMPLETED

The IVP does not run an IMS application program, therefore it does not verify thatIMS transactions can run successfully. It only verifies that the path to IMS isavailable.

Troubleshooting IVP Failures

If an error occurs, check for information in WebSphere Application Server’s logs infolder \WebSphere\AppServer\logs. This file lists exceptions and stack traces thatare useful for diagnosing the failure.

In addition, the following are possible causes for IVP failure:

v Verify webcontainer.conf file that host.default_host.alias points to the correct IPaddress of the WebSphere Server.

v Verify webcontainer.conf file includes the appropriate context root (for example,host.default_host.contextroots=/)

v Verify httpd.conf file has the Service Directives set up for the IVP sample. (forexample, Service /imsicoivp/*/usr/lpp/websphere/WebServerPlugIn/bin/was400plugin.so:service_exit)

v The IBM Http Server is not started.

v The WebSphere Application Server used for the IVP (for example, default_server)is not started.

v Invalid data was specified when configuring the IMS Connector for JavaConfiguration Factory as J2EE Resource instance. For example:

– Incorrect IMS Connect name (for Local Option communication).

– HostName was misspelled or was not sufficiently qualified (for TCP/IPcommunication).

– An incorrect PortNumber was specified for the target IMS Connect (for TCP/IPcommunication).

– Datastore name is invalid for the target IMS or is misspelled. Datastore namemust be in uppercase characters.

v IMS is not running.

v IMS Connect is not running.

v The IMS Connect port is not active. Use the IMS Connect command VIEWHWS todetermine if the port is active. Use the IMS Connect command OPENPORT toactivate an IMS Connect port.

v The target IMS datastore is not active. Use the IMS Connect command VIEWHWSto determine if the datastore is active. Use the IMS Connect command OPENDS toactivate a IMS datastore.

v TCP/IP failure. Always ensure a successful ”ping“ prior to running the IVP.

Chapter 2. Preparing to use IMS Connector for Java 75

v The wrong level of IMS Connect is running on the host. See Prerequisites forrunning the IVP for the required level of IMS Connect.

76 IMS Connector for Java User’s Guide and Reference

Chapter 3. Building Java applications and servlets

To access IMS from a Java application or servlet, IMS and IMS Connect must beinstalled and running on the host machine.

This section describes how to build “Building CCF Java applications and servlets”and “Building J2C Java applications and servlets” on page 78 applications andservlets.

Building CCF Java applications and servletsThis section provides a high-level overview of how to build a CCF Java applicationor servlet that accesses an IMS transaction. The following steps describe how tobuild an Enterprise Access Builder (EAB) command using the Command Editor ofVisualAge for Java’s Enterprise Access Builder.

1. Create an IMSConnectionSpec object to be used for information about theconnection to IMS Connect on the host machine. Provide the followinginformation to the IMSConnectionSpec object:

v For a TCP/IP connection:

– The TCP/IP host name of the machine running IMS Connect

– The port associated with IMS Connect

v For a local connection:

– LOCALHOST: ims_connect_name, where ims_connect_name is the IMSConnect ID (the ID parameter in the HWS statement of the IMS Connectconfiguration member

– The port property is not used

For this step, IMS Connector for Java provides an IMSConnectionSpec Javabean, which can be accessed by the Enterprise Access Builder.

2. Create an IMSInteractionSpec object to be used for the interaction between theJava application or servlet and IMS. Provide the following information to theIMSInteractionSpec object:

v Type of interaction that the Java application or servlet is to have with IMS (forexample, MODE_SEND_RECEIVE and SYNC_LEVEL_NONE)

v Name of the target datastore. This is the datastore ID that is provided whenconfiguring IMS Connect on the host machine.

For this step, IMS Connector for Java provides an IMSInteractionSpec Javabean, which can be accessed by the Enterprise Access Builder.

3. Create an object to represent the input to the IMS transaction. Currently,VisualAge for Java’s Enterprise Access Builder enables you to create a COBOLRecord Type, from which an input Java record bean is created. This supportuses a COBOL 01 commarea (I/O PCB input/output area descriptor) to definethe structure of the input bean.

4. Create an object to represent the output from the IMS transaction. Currently,VisualAge for Java’s Enterprise Access Builder enables you to create a COBOLRecord Type, from which an output Java record bean is created. This supportuses a COBOL 01 commarea to define the structure of the output bean.

5. Combine the Java beans created in steps 1-4 into an Enterprise Access Builder(EAB) command using the Command Editor.

© Copyright IBM Corp. 1998, 2002 77

After you have an EAB command that corresponds to an IMS transaction, you cancreate a Java application in VisualAge for Java that runs the transaction by invokingthe execute() method of the EAB command. The execute() method performs thefollowing steps:

1. Creates a Communication object using the createCommunication method of theIMSConnectionSpec object.

2. Connects to the IMS Connect host component by invoking the Communicationobject’s connect() method.

3. Executes the request specified in the IMSInteractionSpec object by invoking theexecute() method of the Communication object.

In general, once you have an EAB command that represents an IMS transaction,you can run the IMS transaction by performing the following steps:

1. Provide the user ID, password, group name, and a ConnectionManager objectto a runtime context object.

2. Provide the input data for the IMS transaction to the EAB command by invokingthe appropriate set methods of the EAB command.

3. Invoke the execute() method of the EAB command to run the IMS transaction.

4. Display the output of the IMS transaction by using the appropriate get methodsof the EAB command to retrieve the output data.

If you want to build a servlet to run the IMS transaction, do the following:

1. Use the servlet generation wizard in the IBM WebSphere Studio to generate aservlet and associated input and output HTML and JSP files from the EABcommand. The HTML and JSP files are used to provide the input to the IMStransaction and to display the output from the IMS transaction.

2. Run the servlet using the IBM WebSphere Application Server.

Examples of these steps are presented in subsequent sections of thisdocumentation.

Related Reading: For installation and configuration information for IMS Connect,see the IMS Connect documentation at the IMS Web site: www.ibm.com/ims

Building J2C Java applications and servletsThe IMS Connector for Java implementation of Sun’s Java 2 Platform, EnterpriseEdition (J2EE) introduces the use of Enterprise JavaBeans (EJB) to build yourapplications. EJB defines how server-side components are written and provides astandard architectural contract between the components and the application serversand containers that manage them. VisualAge for Java Version 4.0 offers the EJBDevelopment Environment feature to help you create session EJBs.

VisualAge for Java Version 4.0 also provides tooling to help you create a servlet toaccess your IMS transactions. The Create Servlet SmartGuide is a wizard thatsteps you through the process of creating a servlet. You can access the servletusing a Web browser and the servlet accesses the EJB, which in turn initiates thetransaction between your browser and IMS. See the Related Task below to link toa description of how to use these tools.

Related Reading: See Chapter 1: “Enterprise JavaBeans and J2EE” the IBMRedbook EJB Development with VisualAge for Java for WebSphere ApplicationServer, SG24-6144-00, available at www.ibm.com/redbooks.

78 IMS Connector for Java User’s Guide and Reference

Building Java applications and servlets for conversational transactionsThe following steps provide a high-level overview of how a Java application orservlet that accesses an IMS conversational transaction works. You can use thisinformation along with the information in Building Java applications and servlets tobuild a Java application or servlet that accesses an IMS conversational transaction.

1. The user starts an IMS conversational Web application by displaying the inputHTML page of the Web application in a Web browser.

2. The user provides the initial input data of the IMS conversational transaction inthe input HTML page. This starts the first iteration of the IMS conversationaltransaction.

3. The Web browser sends the request with the input data to a Java servletrunning in WebSphere Application Server.

4. The Java servlet obtains the HttpSession object and creates anIMSConvContext object and IMSConvUnboundHttpSessionCleanup object. Itsets up the IMSConvContext object with the CCF ConnectionManager andsaves it in the HttpSession object. The servlet then invokes the execute()method of the EAB command, passing the input data received from the browser.The EAB command uses IMS Connector for Java APIs to send the transactionrequest to IMS via IMS Connect.

5. IMS receives the request and schedules the IMS conversational applicationprogram. The IMS application program processes the request and the reply isreturned to the Java servlet.

6. The Java servlet populates the EAB command with the output data of the replyand loads the appropriate result JSP page to display the output data on theWeb browser.

7. The Java servlet or the end user determines if the output data received isacceptable. If it is, the Java servlet invokes the commit() method ofJavaCoordinator to accept the output and commit the iteration of theconversation. Otherwise, it invokes the rollback() method of JavaCoordinator toreject the output and back out the iteration of conversation.

8. The user provides the data for the second iteration on the JSP page used todisplay the output data of the first iteration, then submits the next request toIMS. This invokes the second iteration of the IMS conversational transaction.

Subsequent iterations of the conversation repeat steps 3-8 until the user or the IMSapplication program terminates the conversation. In step 4, for second andsubsequent iterations of the conversation, the Java servlet obtains theIMSConvContext object from the unique HttpSession object.

Note: The steps described above may differ when used with differentsynchronization levels. The above scenario describes an application flow withSYNC_LEVEL_CONFIRM. When used with SYNC_LEVEL_NONE, Step 7 wouldnot be executed.

Examples of how to create Web applications that perform these similar steps fornonconversational Web applications are presented in other sections of thisdocumentation.

Terminating a Conversation

In the IMS Connector for Java conversational models, an IMS conversation istypically terminated in one of two ways:

v The client terminates the IMS conversational transaction:

Chapter 3. Building Java applications and servlets 79

1. The end user submits a request to end the IMS conversation from thebrowser.

2. The Java servlet invokes an EAB command with theMODE_END_CONVERSATION interaction mode.MODE_END_CONVERSATION is a “send only” interaction. IMSterminates the conversation. The transaction is not scheduled and nooutput message is sent back to the servlet from IMS.

3. The Java servlet should invalidate the HttpSession object and cleanup theconnection resource for reuse.

4. The servlet should also load a customized JSP page to display a messageindicating that a request was sent to IMS Connect.

Ending the conversation in this way is illustrated by the classcom.ibm.connector.ims.sample.conv.phonebook.EndConversationCommandin the Connector IMS Samples project. The EndConversationCommand classis used by the servletcom.ibm.connector.ims.sample.conv.forceend.servlet.ConvForceEndIterations.

v The IMS application program terminates the conversation:

1. The end user submits a request to IMS to run the IMS conversationaltransaction. The input message may contain a specific request toterminate the conversation. Please note that the IMS application programmay also terminate the conversation based on criteria other than thecontents of the input message.

2. IMS schedules the IMS conversational application program, the programprocesses the input message, then sends the transaction output messageback to the servlet. The OTMA message containing the transaction outputmessage contains a bit signifying that the conversation has been ended.IMS ends the conversation after sending the transaction output messageback to the servlet.

3. IMS Connector for Java receives the OTMA message and sets theboolean property in the IMSInteractionSpec to true. The EAB command ispopulated with the output data.

4. The servlet uses the getConvEnded() method of IMSInteractionSpec todetermine that the conversation has ended.

5. The Java servlet should invalidate the HttpSession object and clean up theconnection resource.

6. The servlet should also load a customized JSP page to display a messageon the Web browser indicating that the conversation was ended.

Ending the conversation in this way is illustrated by the servletcom.ibm.connector.ims.sample.conv.phonebook.servlet.ConvIterations.

80 IMS Connector for Java User’s Guide and Reference

Chapter 4. Building a Java application to run an IMStransaction

This section describes how to build an Enterprise Access Builder (EAB) commandthat uses IMS Connector for Java to run an IMS transaction. It includes descriptionsof how to create record beans that represent the input and output messages of theIMS transaction, as well as how to use the VisualAge for Java Command Editor tobuild the EAB command. The section also describes how to create and run a Javaapplication that uses an EAB command.

This example uses the IMS transaction that is described in “IMS INSTALL/IVPsample application”

This example corresponds to one of the samples included in the IMS Connect orSamples feature. The Java source relating to this example is contained in thecom.ibm.connector.ims.sample.phonebook.command package of the Connector IMSSamples project which is added to your workspace when the IMS ConnectorSamples feature is added. See “Preparing your VisualAge for Java environment” forinstructions on installing the IMS Connector Samples feature if you have not alreadydone so. By following the instructions in this section, you will create an applicationwhich is the same as the corresponding sample except that it uses different projectand package names than are used in the sample since you can’t have duplicatepackage or project names within your VisualAge environment. As a result, you willbe able to check your work against the sample, helping you to resolve anydifficulties you encounter as you progress through the steps that follow.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

Using the Enterprise Access Builder

The Enterprise Access Builder consists of frameworks and tools that allow you tocreate Java applications that access existing host applications and data. Aninteraction with a back-end system often involves sending input data to a hostapplication, which would respond with some output data. In the Enterprise AccessBuilder, this interaction is called an EAB command.

EAB commands dictate the data that is passed to and from the back-end system ina single interaction. Records are used as input and output for the EAB commands.Records define the layout of the input and output data within the back-end system.An EAB command is a composite, the main elements being connectionspecification, interaction specification, input bean, and output bean.

When constructing an EAB command, you must provide the following information:

Input dataThe input data is required by the EAB command to perform the execution.

Output dataThe output data is the result of the EAB command’s execution.

Communication informationThis information is a set of classes used to communicate with the hostsystem. A connection specification and an interaction specification definehow an EAB command communicates with a host system. You use the

© Copyright IBM Corp. 1998, 2002 81

ConnectionSpec interface to specify the connection to the host system. Youuse the InteractionSpec interface to specify to the EAB command whichprogram to call through the connection derived from ConnectionSpec.

The input of an EAB command is defined by a record bean. The output of an EABcommand is also defined by a record bean; however, there might exist multipleoutput record beans defined as candidates. An EAB command can show an entireRecordBean in its interface, or only selected record bean properties.

Using the Command Editor

The Command Editor is a tool that guides you through the steps of constructing acommand, allowing you to focus on the specific composition patterns of acommand. You can use the Command Editor to create EAB commands fromcomponents (beans) representing the input, output, and communication information.

Step 1: Creating IMS Transaction Input and Output Beans

This section describes how to create IMS transaction input and output beans thatyou can use in an EAB command that runs an IMS transaction. The steps includethe following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create a Project and Package for the Application

3. Create a COBOL Record Type Class for the IMS Transaction Input Message

4. Create a Transaction Input Record Bean

5. Create a COBOL Record Type Class for the IMS Transaction Output Message

6. Create a Transaction Output Record Bean

The COBOL source used in steps C and E of this example can be found in<IBM_Connectors_install_dir>\imsconn\samples\misc\Ex01.ccp, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

For example, d:\IBM Connectors.

Step 1A: Start the Workbench in the VisualAge for Java IDE

Click the Start icon and click Programs > IBM VisualAge for Java for Windows >IBM VisualAge for Java.

Step 1B: Create a Project and Package for the Application

This step creates a project, called Examples, that contains a package named ex01.Do the following:

1. From the Selected menu, click Add > Project. The Add Project wizardappears. Enter a name for the new project (for example, Examples), and clickFinish.

2. To add a new package to this project, ensure that the correct project is selected.Then, from the Selected menu, click Add > Package. The AddPackage wizardappears. Ensure that the correct project name is specified and that the Create anew package named: radio button is selected. Enter a name for the newpackage (for example, ex01) and click Finish.

Definition:

82 IMS Connector for Java User’s Guide and Reference

A project is a unit of organization that is used to group packages. A VisualAge forJava project is the starting point for your development work in the IDE.

Step 1C: Create a COBOL Record Type Class for the IMS Transaction InputMessage

This step parses the COBOL commarea that represents the input message for theIMS transaction, and creates a COBOL Record Type class that encapsulates theinformation in the commarea. This class will be used in Step 1D: Create aTransaction Input Record Bean to build a Java bean that represents the inputmessage. Do the following:

1. Ensure that the new package, ex01, is selected. From the Selected menu, clickTools > Enterprise Access Builder > Import COBOL to Record Type... TheImport COBOL to Record Type wizard appears.

2. On the Import COBOL to Record Type wizard, do the following:

v Enter the path and file name of the COBOL file that contains the commarearepresenting the IMS transaction input message. Click Next. The next ImportCOBOL to Record Type wizard appears, and contains a list of the availablelevel 01 commareas.

v Select the commarea representing the IMS transaction input message fromthe Available level 01 commarea list (for example, INPUT_MSG)) and add it tothe Selected commareas list by clicking the > button.

v Select the Use BigDecimal check box. This will generate the COBOL type asa BigDecimal Java type. Click Next.

v Ensure that the correct names appear in the Project Name and Packageentry fields.

v Enter a name for the new class that will represent the COBOL Record Type.For example, InMsgInfo.

v To continue to generate the record bean from this record type, ensure thatboth the Continue working with newly created record type check box andthe Create record from record type radio button are selected.

v Click Finish. A new class named InMsgInfo appears in the package namedex01 in the IDE Workbench.

The following fragment of COBOL source code is the 01 commarea for the IMStransaction input message:01 INPUT-MSG.

02 IN-LL PICTURE S9(3) COMP.02 IN-ZZ PICTURE S9(3) COMP.02 IN-TRCD PICTURE X(10).02 IN-CMD PICTURE X(8).02 IN-NAME1 PICTURE X(10).02 IN-NAME2 PICTURE X(10).02 IN-EXTN PICTURE X(10).02 IN-ZIP PICTURE X(7).

Related Reading: For more information on importing COBOL source to a recordtype, see the VisualAge for Java Enterprise Access Builder documentation.

Step 1D: Create a Transaction Input Record Bean

This step creates a record bean that represents the transaction input message fromthe COBOL Record Type class created in Step 1C: Create a COBOL Record TypeClass for the IMS Transaction Input Message. A record bean contains properties

Chapter 4. Building a Java application to run an IMS transaction 83

that map to the fields in a record in a host program. In this case, the record in thehost program is the IMS transaction input message. Do the following:

1. If both the Continue working with newly created record type check box andthe Create record from record type radio button are selected in Step 1C:Create a COBOL Record Type Class for the IMS Transaction Input Message,the Create Record from Record Type wizard appears. To manually start theCreate Record from Record Type wizard, ensure that the COBOL RecordType class, InMsgInfo, is selected. From the Selected menu, click Tools >Enterprise Access Builder > Create Record from Record Type... The CreateRecord from Record Type wizard appears.

2. On the Create Record from Record Type wizard, enter the following:

v Ensure that the correct names appear in the Project Name and Packageentry fields.

v Enter a name for the new class that will represent the input message. Forexample, InMsg.

v Click Access Method: Direct.

v Click Record Style: Custom Records.

v In Additional Options, ensure that the Generate with Notification checkbox is not selected. Do not check Use Inner Classes or Shorten Names.

v Click Next to view the next page of the Create Record from Record Typewizard. Ensure that this page shows the following values, which indicate thatthe IMS transaction input message is processed on an MVS host machine:

– Floating Point Format is IBM.

– Endian is Big Endian.

– Remote Integer Endian is Big Endian.

– Code Page is 037.

– Machine Type is MVS.

3. Click Finish on the Create Record from Record Type wizard. Two new classes,called InMsgBeanInfo and InMsg, appear in the package ex01 in the IDEWorkbench. The InMsg Java bean represents the IMS transaction inputmessage.

Notes:

Code page refers to the data of the IMS transaction. If your transaction data isother than U.S. English (code page 037), you must enter a different code pagein this field.

Ensure that all values on the Create Record from Record Type wizard havebeen accepted. That is, all of the field values should appear gray before youselect Finish.

Related Reading: For more information on additional options, see the VisualAge forJava Enterprise Access Builder documentation.

Step 1E: Create a COBOL Record Type Class for the IMS Transaction OutputMessage

Repeat the instructions in Step 1C: Create a COBOL Record Type Class for theIMS Transaction Input Message to create a class named OutMsgInfo from the 01commarea representing the IMS transaction output message.

84 IMS Connector for Java User’s Guide and Reference

The following fragment of COBOL source code is the 01 commarea for the IMStransaction output message:01 OUTPUT-MSG.

02 OUT-LL PICTURE S9(3) COMP VALUE +0.02 OUT-ZZ PICTURE S9(3) COMP VALUE +0.02 OUT-MSG PICTURE X(40) VALUE SPACES.02 OUT-CMD PICTURE X(8) VALUE SPACES.02 OUT-NAME1 PICTURE X(10) VALUE SPACES.02 OUT-NAME2 PICTURE X(10) VALUE SPACES.02 OUT-EXTN PICTURE X(10) VALUE SPACES.02 OUT-ZIP PICTURE X(7) VALUE SPACES.02 OUT-SEGNO PICTURE X(4) VALUE SPACES.

Step 1F: Create a Transaction Output Record Bean

Repeat the instructions in Step 1D: Create a Transaction Input Record Bean aboveto create classes named OutMsgBeanInfo and OutMsg. The OutMsg Java beanrepresents the IMS transaction output message.

Step 2: Creating an EAB Command Using the Command Editor

This section describes how you can create an Enterprise Access Builder (EAB)command using the VisualAge for Java Command Editor. The Command Editorguides you through the steps of constructing a command, allowing you to focus onthe specific composition patterns of a command.

For a definition of the EAB command, see “IMS Connector for Java Concepts andTerms.”

The Java source for this example can be found in the packagecom.ibm.connector.ims.sample.phonebook.command in the WorkBench. Initially,<IBM_Connectors_install_dir> is <vaj_install_drive>\IBM Connectors, where<vaj_install_drive> is the drive on which VisualAge for Java is installed.

The steps include the following:

1. Create a Command Class for the IMS Transaction

2. Promote the IMS Transaction Input Properties

3. Promote the IMS Transaction Output Properties

4. Promote the DFS Message Properties

5. Promote the Interaction Specification Properties

6. Promote the Connection Specification Properties

7. Create the Command Bean

Step 2A: Create a Command Class for the IMS Transaction

This step creates a class for the EAB command. Do the following:

1. Ensure that the package ex01 is selected. From the Selected menu, click Tools> Enterprise Access Builder > Create Command... The Create Commandwizard appears.

2. On the Create Command wizard, do the following:

a. Ensure that the correct names appear in the Project Name and Packageentry fields.

b. Enter a name for the new class that represents the EAB command (forexample, Ex01Command).

Chapter 4. Building a Java application to run an IMS transaction 85

c. Ensure that the Edit when finished check box is selected to edit theCommand class when it is created.

d. Associate a connection specification with the EAB command. Click theBrowse... button. All available ConnectionSpec classes are shown. ChooseIMSConnectionSpec and click OK.

e. Click Edit to edit the connection specification properties. Select the propertyname and specify the value as follows:

Host nameEnter the TCP/IP host name of the machine running IMS Connectthat the command (IMS transaction) will be using. If you are usingLocal Option, enter ″LOCALHOST:IMS Connect Name.″ Note thatIMS Connect Name is referred to in the IMS Connect documentationas “HWS ID”.

Port Enter the port for IMS Connect that the command (IMS transaction)will be using.

You can also provide values for the following connection properties using:

v Realm

v Connection timeout

v Maximum connections

v Minimum connections

v Reap time

v Unused timeout

See the interfacecom.ibm.connector.ConnectionSpecManagementProperties in packagecom.ibm.connector of the Enterprise Access Builder for a description ofthese properties.

f. Associate an interaction specification with the EAB command. Click theBrowse... button. All available InteractionSpec classes are shown. ChooseIMSInteractionSpec and click OK.

g. Click Edit to edit the interaction specification properties. Select the propertyname and specify the value as follows:

Datastore nameEnter the name of the target IMS datastore for this command (IMStransaction). The Datastore Name is a maximum of 8 uppercasecharacters.

LTERM NameLeave as is.

Map NameLeave as is.

Mode Leave as MODE_SEND_RECEIVE

Synchronization LevelLeave as SYNC_LEVEL_NONE

h. Click Next to use the Add Input/Output Beans wizard.

3. On the Add Input/Output Beans wizard, enter the following:

a. In the Input record bean section, ensure that the Implements IByteBuffercheck box is selected. Enter the class name of the Transaction Input bean.

86 IMS Connector for Java User’s Guide and Reference

Click the Browse... button to display a list of all available classes thatimplement IByteBuffer. Select the appropriate Type Name (InMsg) andPackage Name (ex01) and click OK.

b. Provide the Mapper class, if necessary. In this example, no additionalMapper class is needed.

c. In the Output record bean section, ensure that Select output record beansis selected. Click the Add button. A dialog box appears to enter the outputrecord bean. In this dialog box, ensure that the Implements IByteBuffercheck box is selected. Enter the class name of the Transaction Output bean. Click the Browse... button to display a list of all available classes thatimplement IByteBuffer. Select the appropriate Type Name (OutMsg) andPackage Name (ex01) and click OK.

d. Repeat the previous step to add additional output record beans, ifnecessary. In this example, repeat the previous step to add the outputrecord bean with DFSMsg as Type Name and com.ibm.connector.imstoc asthe Package Name. Provide the Mapper class, if necessary.

e. You can use Modify... or Delete to modify or delete the output record beansfrom the list.

4. Click Finish to generate the EAB command. If the Edit with finished checkbox is selected in Item 2, the new EAB command appears in the CommandEditor.

5. You can use the Command Editor to create a new command, open existingcommands, add or delete beans and properties, and promote or changeproperties. To launch an existing command with the Command Editor, ensurethat the EAB command class is selected, then select Tools > EnterpriseAccess Builder > Edit Command...

To change the bean properties with the Command Editor, do the following:

1. Select a folder icon (for example, Connector) under the command beanicon (for example, ex01.Ex01Command) in the top left pane. The beanappears in the top right pane.

2. Select the bean (com.ibm.connector.imstoc.IMSConnectionSpec) in the topright pane. The properties and their values appear in the bottom pane.

3. Select the property name that you want to change and specify the newvalue.

Related Reading: For more information on the Mapper class, see the VisualAgefor Java Enterprise Access Builder documentation.

Step 2B: Promote the IMS Transaction Input Properties

When creating a composite bean (such as the EAB command bean) you mightwant some features of beans that are embedded within it to appear in the interfaceof the composite bean. To add features of a transaction input bean to the interfaceof a composite bean, promote them to the composite’s interface by doing thefollowing:

1. In the Command Editor, select the Input folder under the ex01.Ex01Command iconin the top left pane. The input bean appears in the top right pane.

2. Select the input bean ( ex01.InMsg). The properties and their values appear inthe bottom pane.

3. Select the IN__LL property in the bottom pane with the right mouse button.Choose Promote Property on the pop-up context menu. The promoted

Chapter 4. Building a Java application to run an IMS transaction 87

property is marked with a green dot in front of the property name. By default,properties are promoted with the same name as the originating bean.

4. Repeat the previous step to promote the following properties:

v IN__ZZ

v IN__TRCD

v IN__CMD

v IN__NAME1

v IN__NAME2

v IN__EXTN

v IN__ZIP

Step 2C: Promote the IMS Transaction Output Properties

To add features of an output transaction bean to the interface of a composite bean,promote them to the composite’s interface by doing the following:

1. In the Command Editor, select the Output folder under the ex01.Ex01Commandicon in the top left pane. The output beans appear in the top right pane.

2. Select the output bean ( ex01.OutMsg). The properties and their values appearin the bottom pane.

3. Select the OUT__LL property in the bottom pane with the right mouse button.Choose Promote Property on the pop-up context menu. The promotedproperty is marked with a green dot in front of the property name. By default,properties are promoted with the same name as the originating bean.

4. Repeat the previous step to promote the following properties:

v OUT__MSG

v OUT__CMD

v OUT__NAME1

v OUT__NAME2

v OUT__EXTN

v OUT__ZIP

Step 2D: Promote the DFS Message Properties

To add features of embedded beans to the interface of a composite bean, you mustpromote them to the composite bean’s interface. In the case of the DFSMsgmessage bean, a number of options exist for promoting properties:

v Option 1

If you want to use the EAB command in a Java application program (rather thanin a Java servlet), promote either the getDFSMessage() method or thegetDFSMessageSegments() method. The method getDFSMessage returns themessage as a string of its concatenated segments. MethodgetDFSMessageSegments() returns each segment of the message as a string.

Since the Command Editor does not allow promotion of methods, you must addthe appropriate method to the EAB Command as follows:

1. Right-click on the EAB Command (for example, Ex01Command).

2. Select Add >Method... The ″Create Method″ SmartGuide appears.

3. Select the Create a new method radio button on the ″Create Method″SmartGuide, then press Next. The ″Attributes″ SmartGuide appears.

4. If the method being added is getDFSMessage():

88 IMS Connector for Java User’s Guide and Reference

a. Enter getDFSMessage in the Method Name: entry field.

b. Enter String in the Return Type: entry field.

c. Select the public radio button in Access Modifiers, then press Finish.

d. Modify the code of the newly added method by replacing the statement″return null;″ with the following statement:return getceOutputi().getDFSMessage();

where getceOutputi() is the method that returns the correspondingmessage bean.

If the method being added is getDFSMessageSegments():

1. Enter getDFSMessageSegments in the Method Name: entry field.

2. Enter java.util.Vector in the Return Type: entry field.

3. Select the public radio button in Access Modifiers, then press Finish.

4. Modify the code of the newly added method by replacing thestatement ″return null;″ with the following statement:return getceOutputi().getDFSMessageSegments()

where getceOutputi() is the method that returns the correspondingmessage bean.

v Option 2

If you want to use the EAB command to generate a Java servlet usingWebSphere Studio, promote one or more data properties of the message, ratherthan the getDFSMessage() method or the getDFSMessageSegments() method.The WebSphere Servlet Generation wizard currently only supports stringproperties for display on the output HTML.

v Option 3

Methods getDFSMessage() and getDFSMessageSegments() can still be used in.jsp pages, but must be manually coded rather than generated by WebSphereStudio.

To promote data properties of the message:

1. In the Command Editor, select the Output folder under theex01.Ex01Command icon in the top left pane. The output beans appear inthe top right pane.

2. Select the DFS message bean (com.ibm.connector.imstoc.DFSMsg). Theproperties and their values appear in the bottom pane.

3. Select, for example, the DFSDATA1 property in the bottom pane with the rightmouse button. Choose Promote Property on the pop-up context menu. Thepromoted property is marked with a green dot in front of the property name.By default, properties are promoted with the same name as the originatingbean.

Step 2E: Promote the Interaction Specification Properties

If you want your Java application or servlet to accept values for IMSInteractionSpecproperties as input, you must promote features of the embedded bean to theinterface of the EAB Command bean. For example, to provide input values forDatastore Name, do the following:

1. In the Command Editor, select the Connector folder under theex01.Ex01Command icon in the top left pane. The connector beans appear in thetop right pane.

Chapter 4. Building a Java application to run an IMS transaction 89

2. Select the IMS interaction specification bean(com.ibm.connector.imstoc.IMSInteractionSpec). The properties and their valuesappear in the bottom pane.

3. Select the Datastore name property in the bottom pane with the right mousebutton. Choose Promote Property on the pop-up context menu. The promotedproperty is marked with a green dot in front of the property name. By default,properties are promoted with the same name as the originating bean.

Step 2F: Promote the Connection Specification Properties

If you want your Java application or servlet to accept values forIMSConnectionSpec properties as input, you must promote features of theembedded bean to the interface of the EAB Command bean. For example, toprovide input values for Hostname or Port, do the following:

1. In the Command Editor, select the Connector folder under theex01.Ex01Command icon in the top left pane. The connector beans appear in thetop right pane.

2. Select the IMS connection specification bean(com.ibm.connector.imstoc.IMSConnectionSpec). The properties and theirvalues appear in the bottom pane.

3. Select the Host name property in the bottom pane with the right mouse button.Choose Promote Property on the pop-up context menu. The promotedproperty is marked with a green dot in front of the property name. By default,properties are promoted with the same name as the originating bean.

4. Repeat the previous step to promote the Port property.

Figure 7. The completed command bean as shown in the command editor

Step 2G: Create the Command Bean

90 IMS Connector for Java User’s Guide and Reference

To save the command bean, select Command > Save from the menu bar. SelectCommand > Exit Editor from the menu bar to exit the Command Editor. TheWorkbench now shows two classes associated with the EAB command:Ex01Command and Ex01CommandBeanInfo.

An EAB command that is created using the Create Command wizard and theCommand Editor can only be opened and edited using the Command Editor. AnEAB command that is created using the Visual Composition Editor must be editedusing the Visual Composition Editor. When using the Command Editor to open anEAB command that is created using the Visual Composition Editor, you areprompted to convert the command to the appropriate format for the CommandEditor. After this conversion, however, it must be edited with the Command Editor.

Step 3: Writing a Java Application to Use the EAB Command

This section demonstrates how you can use the EAB command that was created inCreating an EAB Command Using the Command Editor to create a Javaapplication. You can use the Java application to run the IMS transaction. Thisexample illustrates only basic concepts, and does not include sophisticated inputand output processing.

The steps include the following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create an Executable Class

3. Add Java Code to the Class

Java source for the EAB command that you created in Creating an EAB CommandUsing the Command Editor can be found in class Ex01Command of packagecom.ibm.connector.ims.sample.phonebook.command in the Connector IMSSamples project on your Workbench.

Step 3A: Start the Workbench in the VisualAge for Java IDE

If you are using VisualAge for Java on Windows, click the Start icon and clickPrograms > IBM VisualAge for Java for Windows > IBM VisualAge for Java. Ifthe Welcome to VisualAge dialog box appears, click Go to the Workbench andclick OK. The IDE workbench appears.

Step 3B: Create an Executable Class

1. From the Selected menu, click Add > Class. A wizard appears to request all ofthe necessary information to create a class. Do the following:

a. Ensure that the Project field contains your project name, Examples.

b. Ensure that the Package field contains your package name, ex01.

c. Click Create a new class.

d. Enter Ex01Execute in the Class name field.

e. Ensure that the Superclass is java.lang.Object.

f. Ensure that the Compose the class visually check box is not checked.

g. Click Next to continue to the next window.

2. You need to add import statements to a class that executes an EAB commandthat uses IMS Connector for Java. To include these classes as importstatements, click Add Package.... A list of available packages appears. Fromthe list, select each of the following packages, and click Add to include it in theimport statements.

Chapter 4. Building a Java application to run an IMS transaction 91

v com.ibm.connector.connectionmanager

v com.ibm.connector.imstoc

v com.ibm.connector.infrastructure

v com.ibm.connector.infrastructure.java

After adding the final one, click Close.

In addition, this example requires the following import statement for the codethat parses the command line arguments:import java.util.StringTokenizer;

You can add this line of code later or select the Add Type... button. As youenter the characters of the type in the Filter field of the Import Statementswindow (for example, ″java.util.S″), type names and package names will appear.Select the appropriate type, then select the Add button to add the importstatement.

3. Ensure that only the following fields on the ″Attributes″ SmartGuide arechecked:

v public (in modifiers section)

v Methods which must be implemented (Recommended)

v Copy constructors from superclass (Recommended)

v main(String[])

4. To generate the class, click Finish. The class appears inside the package thatyou have specified.

Step 3C: Add Java Code to the Class

Code must be added to the main() method of the Ex01Execute class to use theEAB command to run the IMS transaction. This code can be copied from the main()method of the Ex01Execute class in packagecom.ibm.connector.ims.sample.phonebook.command in the Connector IMSSamples project on your Workbench. Replace the values yourUID, yourPwd, andyourGrp with the user ID, password, and group name for your IMS environment.

In addition, the code illustrates three ways in which error or status messages fromIMS can be printed. In each case, the appropriate method or property must bepromoted to the EAB command interface.

This sample code allows you to change to a different host name, port, or datastorename at run time by supplying new values as command-line arguments. The formatof these arguments is illustrated in the comments of this code.

Step 4: Testing Your Application within VisualAge for Java

After you have successfully compiled your Java application (for example,Ex01Execute), you can test the application from within VisualAge for Java. Do thefollowing:

1. Select the class of your application and, from the Selected menu, clickProperties. The Properties window (for example, Ex01Execute) appears.

2. Ensure that the Program tab is selected and, if required, enter anycommand-line arguments in the text box under Command line arguments.Each argument is separated with a space. For example, in Writing a JavaApplication to Use the EAB Command, you enter:

92 IMS Connector for Java User’s Guide and Reference

HOSTNAME=yourhost PORT=yourportnumber DATASTORE=yourdatastorename

3. Select the Class Path tab and make sure that the Include ’.’ (dot) in classpath and Project path: check boxes are checked.

4. Click Compute Now, and click OK when the class path is computed. Thisupdates the VisualAge for Java class path to include your Java application.

5. Select the main method of your application and from the Selected menu, clickRun > Run main.... The results of running your application appear in theConsole window.

Step 5: Running Your Application Outside of VisualAge for Java

If you want to run your Java application on a workstation that does not haveVisualAge for Java installed, you must provide access on the workstation to all ofthe class libraries that the application uses. These class libraries are the same asthose that are normally part of VisualAge for Java. Do the following:

1. Ensure that JDK or JRE Version 1.2.2 or higher is installed.

2. Copy the following class libraries (.zip files) to your workstation:

IBM Common Connector FrameworkFile ccf.zip is located in the directory<IBM_Connectors_install_dir>\classes

IBM Enterprise Access Builder LibraryFile eablib.zip is located in the directory<install_dir>\eab\runtime30.

IBM Java Record LibraryFile recjava.zip is located in the directory<IBM_Connectors_install_dir> \eab\runtime30.

IMS Connector for JavaFile imsconn.zip is located in the directory<IBM_Connectors_install_dir>\classes

where <IBM_Connectors_install_dir> is the IBM Connectors installationdirectory. For example, d:\IBM Connectors.

In addition, you must create a .jar file from the .class files for your applicationand copy it to your workstation.

Your Java application might consist of one or more EAB command beans.Therefore, when you create the .jar file for your application, you must includeall of the Java beans of which the composite EAB command beans arecomprised, as well as any classes that represent the application.

3. Modify (or append to) your workstation’s CLASSPATH environment variable topoint to the above .zip and .jar files.

4. Use java.exe to run the class that corresponds to your Java application. If yourapplication requires input command-line arguments, enter:java application_class_name arg1 arg2 ...

where application_class_name is the name of the executable classcorresponding to your application and arg1 and arg2 are the command-linearguments. For example,java ex01.Ex01Execute HOSTNAME=MYHOST PORT=9999 DATASTORE=IMSA

Chapter 4. Building a Java application to run an IMS transaction 93

Note: Consider the following if you are having trouble running your applicationoutside of VisualAge for Java:

v Ensure that all class libraries (.jar and .zip files) are pointed to correctly by theCLASSPATH environment variable. A small error in CLASSPATH can result in a classnot being found. Remember that a GUI application, such as the IMS Connectorfor Java’s IVP, uses classes that may not be part of the JDK or JRE you areusing. For example, you may have to separately deploy the ″swing″ classes andpoint to them with CLASSPATH.

v Remember that, in some environments, you may have to restart the process inwhich you are running your application, after modifying CLASSPATH.

v Ensure that you correctly specify the name of your application. Keep in mindcase sensitivity and remember to qualify the name of your application by itspackage name, if applicable.

v Verify that the JAR file for your application contains all of the necessary classes.

v Depending on how you have implemented security for the operating system andJava, you might also need to ensure that the appropriate access to the JAR fileis allowed.

94 IMS Connector for Java User’s Guide and Reference

Chapter 5. Building a Java application to run a navigator

This section describes how you can create an EAB Navigator to run multiple IMStransactions. An EAB Navigator is composed of multiple EAB commands that forma more complex interaction (navigation) with a host system. This section alsodescribes how to create and run a Java application that uses an EAB Navigator.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

The process of creating and running a Java application to run two IMS transactionsis described in the following sections:

v Creating a Navigator Using the Command and Visual Composition Editors

v Writing a Java Application to Use a Navigator

v Testing the Java Application

Creating a Navigator Using the Command and Visual Composition Editors

This example illustrates how you can create an EAB Navigator command to runmultiple IMS transactions. The Navigator command is composed of othercommands that form a more complex interaction (navigation) with a host system.You construct the commands contained in the Navigator using the Command Editorand then create the complex interactions in the Navigator by interconnecting thesecommands using the Navigator’s Visual Composition Editor.

In this example, we build a Navigator command that runs two IMS transactionssequentially. This Navigator command consists of two commands. Each commandcorresponds to an IMS transaction. The Navigator command accepts input from theuser which it uses as the input to the first command. The first command executesand the output from this command is displayed by the Navigator on its outputscreen and used as the input for the second command. The Navigator thenexecutes the second command and uses the output of this command to formulatethe output which it displays on its output screen.

Definition:

An Enterprise Access Builder Navigator wraps multiple interactions with a hostsystem into what appears to the user to be a single interaction. From theoutside, a Navigator looks like an EAB command. A Navigator consists of bothEAB commands and Navigators strung together to form a more complexinteraction with the host system.

The following procedure assumes that you have thecom.ibm.connector.ims.sample.phonebook.command package on your Workbench.This will be the case if you have installed the IMS Connector Samples feature (andhave not subsequently deleted the package.)

The IMS transactions executed by both of the commands that make up theNavigator command take a single-segment input message and return asingle-segment output message.

Generally, the steps are as follows:

1. Start the Workbench in the VisualAge for Java IDE

© Copyright IBM Corp. 1998, 2002 95

2. Create a Project and Package for the Application

3. Create a Navigator Bean for Building Complex Commands

4. Set Up the Property Features

5. Create a Command Bean for the First Command

6. Create a Command Bean for the Second Command

7. Set Up the Connection Specification for the Navigator (Optional)

8. Promote Connection and InteractionSpec Property Features (Optional)

9. Save the Navigator Bean

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, see“Step 1A” of “Building a Java application to run an IMS transaction.”

Step 2: Create a Project and Package for the Application

This step creates a project, called Examples, that contains a package named ex02.

For a description of how to create a project and package, see “Step 1B” of “Buildinga Java application to run an IMS transaction.” The package used by the samplecode in this section is ex02.

Step 3: Create a Navigator Bean for Building Complex Commands

This step creates the Navigator bean, which is composed of two command beansthat correspond to the two IMS transactions. Do the following:

1. With the package ex02 selected, click the Selected menu, then click Add >Class... The Create Class wizard appears.

2. Ensure that the correct names, Examples and ex02, appear in the Project andPackage entry fields, respectively.

3. Click Create a new class and enter a name for the new Navigator commandclass (for example, Ex02Navigator).

4. To choose the superclass for class Ex02Navigator, click Browse, then selectCommunicationNavigator from the TypeNames list.

Ensure that the Compose the class visually radio button is selected and clickFinish. A new window (titled Ex02Navigator [mm/dd/yy HH:MM:SS AM/PM] in Ex02)appears with the Visual Composition tab selected.

When you execute a Navigator, the Navigator provides its input to the commandsand Navigators of which it is composed in accordance with the connections that areset up when the Navigator is created. These connections in a Navigator alsodetermine the order of execution of each EAB command or Navigator contained inthe Navigator.

For a simple Navigator, after the final interaction is carried out, the output of theindividual commands and Navigators can be used to formulate the output of theNavigator. For more complex Navigators, the output of the Navigator is determined

96 IMS Connector for Java User’s Guide and Reference

by the output of the individual commands and Navigators it contains as well ascode that can be added to the connections in the Navigator and/or code in the Javaapplication that executes the Navigator.

Step 4: Set Up the Property Features

This step creates new property features for the Navigator command. These propertyfeatures are linked to the property features of the individual commands that makeup the Navigator, which allows the input data and output results to be passedbetween the individual commands and the Navigator in accordance with theproperty-to-property connections set up in the Navigator. This enables the output ofone command to be used for the input of a subsequent command and allows theoutput of a command to be passed to the Navigator where it can be processed ifnecessary and then in turn, passed on to the application executing the Navigatorwhere it can be further processed if necessary and displayed to the user.

Create new property features for the data beans in the command bean by doing thefollowing:

1. Create Input property features:

v Input for first command:

– Select the BeanInfo tab of the Ex02Navigator bean window (located at thetop of the window that opened in the last step).

– Click Features > New Property Feature... from the pull-down menu at thetop of the screen. The New Property Feature SmartGuide appears.

– In the New Property Feature SmartGuide, enter a name in the Propertyname field for one of the promoted properties in the Ex02FirstCommand.For example, enter FIRST_CMD_IN_LL for the IN_LL property ofEx02FirstCommand.

– In the Property Type field, select the corresponding type for the property(for example, short).

– Accept the default settings for all of the other selections for this propertyfeature and click Finish. A new property feature of FIRST_CMD_IN_LLappears in the Feature section of the window.

– Repeat the above steps to create the following new features for all of theother input properties of the Ex02FirstCommand bean:

The following is Property Type short:

- FIRST_CMD_IN_ZZ (for IN_ZZ property of Ex02FirstCommand)

The following are Property Type java.lang.string:

- FIRST_CMD_IN_TRCD (for IN_TRCD property of Ex02FirstCommand)

- FIRST_CMD_IN_CMD (for IN_CMD property of Ex02FirstCommand)

- IN_NAME1 (for IN_NAME1 property of Ex02FirstCommand)

- IN_NAME2 (for IN_NAME2 property of Ex02FirstCommand)

- IN_EXTN (for IN_EXTN property of Ex02FirstCommand)

- IN_ZIP (for IN_ZIP property of Ex02FirstCommand)

v Input for second command:

Similarly, create the following new features for all of the input properties ofthe Ex02SecondCommand bean.

The following are Property Type short:

Chapter 5. Building a Java application to run a navigator 97

– >SECOND_CMD_IN_LL (for IN_LL property of Ex02SecondCommand)

– >SECOND_CMD_IN_ZZ (for IN_ZZ property of Ex02SecondCommand)

The following are Property Type java.lang.string:

– SECOND_CMD_IN_TRCD (for IN_TRCD property of Ex02SecondCommand)

– SECOND_CMD_IN_CMD (for IN_CMD property of Ex02SecondCommand)

2. Create output property features:

This step creates the following new features for all of the output properties.

The following are Property Type short:

v OUT_LL (for OUT_LL property of Ex02SecondCommand bean)

v OUT_ZZ (for OUT_ZZ property of Ex02SecondCommand bean)

The following are Property Type java.lang.string:

v OUT_MSG (for OUT_MSG property of Ex02SecondCommand bean)

v OUT_CMD (for OUT_CMD property of Ex02SecondCommand bean)

v OUT_NAME1 (for OUT_NAME1 property of Ex02SecondCommand bean)

v OUT_NAME2 (for OUT_NAME2 property of Ex02SecondCommand bean)

v OUT_EXTN (for OUT_EXTN property of Ex02SecondCommand bean)

v OUT_ZIP (for OUT_ZIP property of Ex02SecondCommand bean)

v OUT_SEGNO (for OUT_SEGNO property of Ex02SecondCommand bean)

Step 5: Create a Command Bean for the First Command

This step creates the first command bean, which represents the first IMStransaction for this example. There are multiple ways in which this command beancan be created. In this example we will “create” the Ex01FirstCommand EABcommand bean by reusing the command bean that was created in the ex01example, see Building a Java application to run an IMS transaction (Step 2.)

1. Select the Visual Composition tab of the Ex02Navigator bean window to startthe Visual Composition Editor.

2. Click the Choose Bean... icon in the tool palette and ensure that the ClassBean Type is selected. Click the Browse button for the Class name field. Inthe Pattern field, enter Ex01. A list of class names appears. Select Ex01Commandfor the Class name from the list of available classes andcom.ibm.connector.ims.sample.phonebook.command from the package name.Click OK. Enter Ex02FirstCommand in the Name field and click OK.

3. To plant the bean, move the cursor to a position in the frame window and clickthe left mouse button.

4. The following connections are needed for communication between thecommand and the Navigator:

a. UnsuccessfulExecution event connection:

These steps create an Event-to-method connection such that thereturnExecutionUnsuccessful method of the Navigator is invoked when anexecutionUnsuccessful of the Ex02FirstCommand event occurs.

v Select the Ex02FirstCommand icon and click the right mouse button.Choose Connect > Connectable Features... in the resulting pop-upwindow.

98 IMS Connector for Java User’s Guide and Reference

v Click Event and scroll down the list to choose theexecutionUnsuccessful(com.ibm.ivj.eab.command.CommandEvent) eventand click OK.

v Move the cursor to an empty area in the frame window and click the leftmouse button. Click Connectable Features.... A list in an Endconnection to [Ex02Navigator] dialog box appears.

v In the End connection dialog box, ensure that the Method radio buttonis selected. ChoosereturnExecutionUnsuccessful(com.ibm.ivj.eab.command.CommandEvent)from the scroll-down list and click OK. A new dotted-line connection iscreated.

v Select the new connection and click the right mouse button. SelectProperties from the pop-up menu, and the Event-to-method connectionproperties window appears. Click the Pass event data box and then clickOK.

The connection now becomes a solid line.

b. StartExecution event connection:

See the description in item 4a of this step to create an Event-to-methodconnection between theinternalExecutionStarting(com.ibm.ivj.eab.command.CommandEvent) eventof the Navigator and the execute(com.ibm.ivj.eab.command.CommandEvent)of Ex02FirstCommand. The execute method of Ex02FirstCommand is invokedwhen an internalExecutionStarting of the Navigator method occurs. Note thatthis step requires you to start the connection by right-clicking on an openarea in the Navigator Visual Composition window and then end theconnection by clicking on the Ex02FirstCommand icon. Be sure to click thePass event data box before clicking OK. The connection now becomes asolid line.

c. Input property connections:

The following steps create property-to-property connections between theinput properties of Ex02FirstCommand and the corresponding input propertyfeatures of the Navigator. These connections are used to propagate the userinput values from the property features of the Navigator toEx02FirstCommand.

v Place the cursor on an empty area in the frame window and click the rightmouse button. Select Connect... and a Start connection from[Ex02Navigator] dialog box appears.

v Click Property. Select the FIRST_CMD_IN_LL property from the scroll-downlist and click OK.

v Place the cursor on the Ex02FirstCommand icon and click the leftmouse button. Choose Connectable Features... An End connection to[Ex02FirstCommand] dialog box appears.

v Click Property. Select the IN_LL property from the scroll-down list andclick OK.

v A new property-to-property connection between the FIRST_CMD_IN_LLproperty of the Navigator and the IN__LL property of theEx02FirstCommand bean is created.

v Repeat the above steps to associate all of the other features of theEx02FirstCommand with the Navigator:

– FIRST_CMD_IN_ZZ > IN__ZZ

– FIRST_CMD_IN_TRCD > IN__TRCD

Chapter 5. Building a Java application to run a navigator 99

– FIRST_CMD_IN_CMD > IN__CMD

– IN_NAME1 > IN__NAME1

– IN_NAME2 > IN__NAME2

– IN_EXTN > IN__EXTN

– IN_ZIP > IN__ZIP

d. Result property connections.

This step connects the output properties of the first command with theNavigator bean so that the results can be accessed and returned to theuser. It creates property-to-property connections between the outputproperties of Ex02FirstCommand and the output property features of theNavigator. These connections are used to propagate the output values fromEx02FirstCommand to the output property features of the Navigator.Because these are result property connections and the result propertyvalues are not known until after the command has executed, it is necessaryto specify that the trigger event is a change in the value of source property.This is accomplished by selecting the result property-to-property connectionafter you have created it, right-clicking and selecting Properties and thenselecting propertyChange as the source event for all result propertyconnections. See the description in Step 5, item 4c, above to createproperty-to-property connections between the following output properties ofthe Ex02FirstCommand bean and the corresponding output propertyfeatures of the Navigator. Remember to start the result property connectionsby right-clicking on the Ex02FirstCommand icon and end them by clicking inan open area of the Navigator Visual Composition window. Be sure to selectpropertyChange for the Source event in the Property-to-propertyconnection - Properties window.

v OUT__LL > OUT_LL

v OUT__ZZ > OUT_ZZ

v OUT__MSG > OUT_MSG

v OUT__CMD > OUT_CMD

v OUT__NAME1 > OUT_NAME1

v OUT__NAME2 > OUT_NAME2

v OUT__EXTN > OUT_EXTN

v OUT__ZIP > OUT_ZIP

v OUT__SEGNO > OUT_SEGNO

Save the Ex02FirstCommand bean by clicking on Bean > Save Bean. Thiswill save the Ex02FirstCommand bean and generate the runtime codeassociated with this bean, some of which will be modified in the nextparagraph.

On your Workbench, expand the Ex02Navigator class and select theconnEtoM2 (CommandEvent) method. In the Source pane, add thefollowing code in the “user code {1}” block (after the line that reads // usercode begin {1}):System.out.println( “\nBeginning execution of Ex02FirstCommand ...” + “\n” );

This code will cause the above line to be displayed on the output screen(the Java console) right before Ex02FirstCommand is executed. Save thischange by again clicking on the connEtoM2(CommandEvent) method andthen click on Yes.

100 IMS Connector for Java User’s Guide and Reference

Step 6: Create a Command Bean for the Second Command

This step uses the Visual Composition Editor to create a second EAB commandand associate to the Navigator. Do the following:

1. Click Choose Bean... again. This time the Class Bean Type should be alreadyselected andcom.ibm.connector.ims.sample.phonebook.command.Ex01Command should behighlighted as the Class name. If so, enter Ex02SecondCommand in the Namefield and click OK. Otherwise, click Browse. In the Pattern field enterEx01Command. A list of class names appears. Choose Ex01Command (in packageex01) for the Class name from the list of available classes. Click OK. EnterEx02SecondCommand in the Name field and click OK.

2. To plant the bean, move the cursor to a position in the frame window and clickthe left mouse button.

3. The following connections are needed for communication between thiscommand, Ex02FirstCommand the Navigator:

a. UnsuccessfulExecution event connection:

This step creates an Event-to-method connection such that thereturnExecutionUnsuccessful method of the Navigator is invoked when anexecutionUnsuccessful event of Ex02SecondCommand occurs.

See the description in Step 5, item 4a to create an Event-to-methodconnection between theexecutionUnsuccessful(com.ibm.ivj.eab.command.CommandEvent) event ofEx02SecondCommand and thereturnExecutionUnsuccessful(com.ibm.ivj.eab.command.CommandEvent)method of the Navigator. Be sure to click the Pass event data box beforeclicking OK in the Event-to-method connections - Properties window.

b. ReturnSuccessfulExecution event connection:

This step creates an Event-to-method connection such that thereturnExecutionSuccessful method of the Navigator is invoked when anexecutionSuccessful event of Ex02SecondCommand occurs. See the descriptionin Step 5, item 4a to create an Event-to-method connection between theexecutionSuccessful(com.ibm.ivj.eab.command.CommandEvent) event ofEx02SecondCommand and thereturnExecutionSuccessful(com.ibm.ivj.eab.command.CommandEvent)method of the Navigator. Be sure to click the Pass event data box beforeclicking OK.

c. Execution event connection:

This step creates an Event-to-method connection to start the execution ofthe second command when the first command has executed successfully.The execute method of Ex02SecondCommand is invoked when anexecutionSuccessful event of the Ex02FirstCommand occurs.

v Select the Ex02FirstCommand icon and click the right mouse button.Choose Connect > Connectable Features... A Start connection from[Ex02FirstCommand] dialog box appears.

v Click Event. Select theexecutionSuccessful(com.ibm.ivj.eab.command.CommandEvent) eventfrom the scroll-down the list and click OK.

v Move the cursor to Ex02SecondCommand icon and click the left mousebutton. Click Connectable Features... An End connection dialog boxappears.

Chapter 5. Building a Java application to run a navigator 101

v In the End connection to [Ex02SecondCommand] dialog box, clickMethod. Choose execute(com.ibm.ivj.eab.command.CommandEvent) fromthe scroll-down list and click OK. A new dotted-line connection is created.

v Select the new connection and click the right mouse button. SelectProperties from the pop-up menu. An Event-to-method connectionproperties window appears.

v Click the Pass event data box and click OK. The connection is now asolid line.

d. Properties connections:

This step sets up the input properties for the Ex02SecondCommand bean. Inthis example, the second command takes input in the form of theSECOND_CMD_IN_TRCD and SECOND_CMD_IN_CMD which are set in the Javaapplication that runs the Navigator and also from the output of the firstcommand, in this case the OUT_NAME1 property.

Note that the properties of Ex02SecondCommand that are not set do notneed to be set in this case only because we have set upEx02SecondCommand to execute an IVTNO DISPLAY command. Had wechosen to make Ex02SecondCommand execute another ADD command, wewould have had to set the other input properties accordingly. Otherwise,those fields in the record added to the database used by IVTNO would beblank.

1) Input Properties from first command:

This step creates property-to-property connections between the outputproperties of Ex02FirstCommand and the input properties ofEx02SecondCommand. These connections are used to propagate the outputvalues from Ex02FirstCommand to Ex02SecondCommand as its input values.

v Select the Ex02FirstCommand icon and click the right mouse button.Choose Connect > Connectable Features...

v Click Property. Select OUT_NAME1 property from the scroll-down the listand click OK.

v Place the cursor to Ex02SecondCommand icon and click the leftmouse button. Click Connectable Features... An End connection to[Ex02SecondCommand] dialog box appears.

v In the End connection to [Ex02SecondCommand] dialog box, clickProperty. Select IN_NAME1 property from the scroll-down list and clickOK. Right-click the connection just created and select Properties.Select propertyChange as the source event in the resultingProperty-to-property connection - Properties window and click OK.A new connection between the OUT_NAME1 property of theEx02FirstCommand bean and the IN_NAME1 property of theEx02SecondCommand bean is created.

2) Input properties from the Navigator bean:

This step creates property-to-property connections between the inputproperty features of the Navigator and the input properties ofEx02SecondCommand. These connections are used to propagate the inputvalues from the input property features of the Navigator toEx02SecondCommand as its input values. See the description above inStep 5, item c to create property-to-property connections between thefollowing input property features of the Navigator and the inputproperties of the Ex02SecondCommand bean:

v SECOND_CMD_IN_LL > IN__LL

v SECOND_CMD_IN_ZZ > IN__ZZ

102 IMS Connector for Java User’s Guide and Reference

v SECOND_CMD_IN_TRCD > IN__TRCD

v SECOND_CMD_IN_CMD > IN__CMD

e. Result property connections:

This step connects the output properties of the second command with theNavigator bean so that the results can be accessed and returned to theuser.

It creates property-to-property connections between the output propertyfeatures of the NavigatorEx02SecondCommand and the properties ofEx02SecondCommandoutput property features of the Navigator and theproperties of Ex02SecondCommand. These connections are used to propagatethe output values from Ex02SecondCommand to the output property features ofthe Navigator. See the description in Step 5, item c to createproperty-to-property connections between the following output properties ofthe Ex02SecondCommand bean and the output property features of theNavigator: Remember to start the result property connections byright-clicking on the Ex02SecondCommand icon and end them by clicking inan open area of the Navigator Visual Composition window. Be sure to selectpropertyChange for the Source event in the Property-to-propertyconnection - Properties window.

v OUT__LL > OUT_LL

v OUT__ZZ > OUT_ZZ

v OUT__MSG > OUT_MSG

v OUT__CMD > OUT_CMD

v OUT__NAME1 > OUT_NAME1

v OUT__NAME2 > OUT_NAME2

v OUT__EXTN > OUT_EXTN

v OUT__ZIP > OUT_ZIP

v OUT__SEGNO > OUT_SEGNO

4. This step adds the DFS output message method feature of the second commandso that the Navigator bean can display the DFS message from the secondcommand.

Do the following:

a. Select the Ex02SecondCommand icon and click the right mouse button.Choose Promote Bean Features... A new window appears.

b. Ensure that the Method radio button is selected and move theGetDFSMessage() method from the left pane to the Promoted featuressection by highlighting and clicking the >> button. Click OK. A newex02SecondCommandGetDFSMessage() method is created in theEx02Navigator bean.

Save the Ex02SecondCommand bean by clicking on Bean > SaveBean. This will save the Ex02SecondCommand bean and generate theruntime code associated with this bean, some of which will be modifiedas described in the next paragraph.

On your Workbench, expand the Ex02Navigator class and select theconnEtoM5(CommandEvent) method. In the Source pane, add thefollowing code in the “user code {1}” block (after the line that reads //user code begin {1}):System.out.println( “The output from Ex02FirstCommand is: ” +

“\n” +“\nLL: ” + getOUT_LL() +

Chapter 5. Building a Java application to run a navigator 103

“\nZZ: ” + getOUT_ZZ() +“\nMSG: ” + getOUT_MSG() +“\nCMD: ” + getOUT_CMD() +“\nNAME1: ” + getOUT_NAME1() +“\nNAME2: ” + getOUT_NAME2() +“\nEXTN: ” + getOUT_EXTN() +“\nZIP: ” + getOUT_ZIP() +“\nSEGNO: ” + getOUT_SEGNO() +“\n” +“\n” +“\nBeginning execution of Ex02SecondCommand...” +“\n” );

This code will cause the above lines to be displayed on the outputscreen (the Java console) after Ex02FirstCommand has executedsuccessfully but before the start of execution of Ex02SecondCommand.Save this change by again clicking on the connEtoM5(CommandEvent)method and then click on Yes.

Step 7: Set Up the Connection Specification for the Navigator (Optional)

This step sets up a separate connection specification for the Ex02Navigator beanso that all of the EAB commands in the Navigator can use the same connectionspecification.

This is an optional step since each EAB command already has its own connectionspec. If you choose to create a connection spec in the Navigator, its attributes andmethods will override those of all EAB commands that are part of the Navigator. Dothe following:

1. In the Visual Composition Editor, click Choose Bean... again and click Browse.In the Pattern field, enter IMSConnectionSpec. A list of class names appears.Choose IMSConnectionSpec (in package com.ibm.connector.imstoc) for theClass name from the list of available classes. Click OK on this and the previouswindow.

2. To plant the bean, move the cursor to a position in the frame window and clickthe left mouse button. By default, it is assigned the name IMSConnectionSpec1.

3. To connect the bean to the Navigator, select the IMSConnectionSpec1 iconand click the right mouse button. Choose Connect > this, then move the cursorto an empty area in the frame window and click the left mouse button. SelectConnectionSpec from the Property list that appears and click OK.

4. Double click the IMSConnectionSpec1 icon to view the bean properties.Specify the bean properties as follows:

beanName

Leave as is.

Connection timeout

If you want to provide additional connection properties, see the interfacecom.ibm.connector.ConnectionSpecManagementProperties inpackage com.ibm.connector of the Enterprise Access Builder for adescription of this property.

Host name

Enter the TCP/IP host name of the machine running IMS Connect thatthe Navigator (IMS transaction) will be using.

104 IMS Connector for Java User’s Guide and Reference

Maximum connections

If you want to provide additional connection properties, see the interfacecom.ibm.connector.ConnectionSpecManagementProperties inpackage com.ibm.connector of the Enterprise Access Builder for adescription of this property.

Minimum connections

If you want to provide additional connection properties, see the interfacecom.ibm.connector.ConnectionSpecManagementProperties inpackage com.ibm.connector of the Enterprise Access Builder for adescription of this property.

Port

Enter the port for IMS Connect that the Navigator (IMS transaction) willbe using.

Reap time

If you want to provide additional connection properties, see the interfacecom.ibm.connector.ConnectionSpecManagementProperties inpackage com.ibm.connector of the Enterprise Access Builder for adescription of this property.

Unused timeout

If you want to provide additional connection properties, see the interfacecom.ibm.connector.ConnectionSpecManagementProperties inpackage com.ibm.connector of the Enterprise Access Builder for adescription of this property.

Realm

The Realm property defines a unique name for a remote target to whichthe client Java application or servlet is connecting. The Realm propertyis used by the infrastructure LogonInfo of the component server formapping security information. For example, it maps the clientinformation to the user information. The component server that supportsthe Realm property provides the appropriate value.

5. Optionally, promote the Host name and Port property features, as follows:

a. In the Visual Composition Editor, select the IMSConnectionSpec1 icon andclick the right mouse button.

b. Select Promote bean feature... A new window appears.

c. Ensure that the Property radio button is selected and move the Host nameand Port properties from the left pane to the Promoted features section byhighlighting and clicking the >> button. Then click the OK button.

Step 8: Promote InteractionSpec Property Features (Optional)

In this step you will promote the dataStoreName and DFSDATA1 bean features ofthe IMSInteractionSpec beans used by the EAB commands Ex02FirstCommandand Ex02SecondCommand to the interface of the composite Navigator bean.

This is an optional step that you would complete if you want your Java applicationor servlet to be able to dynamically accept values for and set property features ofthe IMSInteractionSpec beans used by the EAB commands in your Navigator.

Chapter 5. Building a Java application to run a navigator 105

Promote the dataStoreName and DFSDATA1 property features of theIMSInteractionSpec for each of the EAB commands in the Navigator as follows:

1. In the Visual Composition Editor, select the Ex02FirstCommand icon and clickthe right mouse button.

2. Select Promote bean feature.... A new window appears.

3. Ensure that the Property radio button is selected and move the dataStoreNameand DFSDATA1 property features from the left pane to the Promoted featuressection by highlighting each property feature, and clicking the >> button andthen clicking the OK button.

4. Repeat steps a. b. and c. to promote the dataStoreName and DFSDATA1properties of the Ex02SecondCommand bean.

Step 9: Save the Navigator Bean

Click the Bean menu and click Save Bean to save your work.

This is the final step in creating the Navigator composite command bean. You canuse this bean (Navigator) to run two IMS transactions.

Figure 8. The completed navigator bean as shown in the Visual CompositionEditor

Writing a Java Application to Use a Navigator

106 IMS Connector for Java User’s Guide and Reference

The following example illustrates how you can use the EAB Navigator created inCreating a Navigator Using the Command and Visual Composition Editors to createa Java application. You can use the Java application to run two consecutive IMStransactions.

The steps include the following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create an Executable Class

3. Add Java Code to the Class

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeBuilding a Java application to run an IMS transaction (Step 3A)

Step 2: Create an Executable Class

For the description of how to create a new executable class, see Building a Javaapplication to run an IMS transaction (Step 3B). The sample code for this sectionuses Ex02NavigatorExecute for the name of the executable class.

Step 3: Add Java Code to the Class

Code must be added to the main() method of the Ex02NavigatorExecute class touse the EAB command to run the IMS transaction. This code can be copied fromthe main() method of the Ex02NavigatorExecute class in packagecom.ibm.connector.ims.sample.phonebook.navigator in the Connector IMSSamples project on your Workbench. Place the user ID, password, and groupname to be sent to IMS in the fields “yourUID,” yourPwd,“ and ”yourGrp,“respectively.

Testing the Java Application

To test the Java application within VisualAge for Java, see Building a Javaapplication to run an IMS transaction (Step 4).

Running the Java Application

To run the Java application with the Navigator outside of VisualAge for Java, seeBuilding a Java application to run an IMS transaction (Step 5.)

Chapter 5. Building a Java application to run a navigator 107

108 IMS Connector for Java User’s Guide and Reference

Chapter 6. Building a Java application for an IMS transactionwith multi-segment output messages

This section describes how to build a Java application that processes an IMStransaction that has a single-segment input message and an output message withmultiple segments.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

This example corresponds to one of the samples included in the IMS ConnectorSamples feature. The Java source relating to this example is contained in thecom.ibm.connector.ims.sample.multisegout package of the Connector IMS Samplesproject which is added to your workspace when the IMS Connector Samples featureis added. See Preparing your VisualAge for Java environment for instructions oninstalling the IMS Connector Samples feature if you have not already done so. Byfollowing the instructions in this section, you will create an application which is thesame as the corresponding sample except that it uses different project and packagenames than are used in the sample since you can’t have duplicate package orproject names within your VisualAge environment. As a result, you will be able tocheck your work against the sample, helping you to resolve any difficulties youencounter as you progress through the steps that follow.

Note: The Java application might not be executable, because the correspondingIMS application program might not be available in all environments.

The IMS application program used with the sample code in this section isDFSDDLT0. The DFSDDLT0 script for this sample, MSOut.scr is provided in the<IBM_Connectors_install_dir> \imsconn\samples\misc.

The following stage 1 source was used in the IMS environment of this example:APPLCTN PSB=STLDDLT2, PGMTYPE=(,,2)TRANSACT CODE=SKS2, PRTY=(8,8)

The PSB and CODE values can be changed to match your IMS system definitionrequirements. The PSB requires only an I/O PCB. It does not require alternatePCBs or database PCBs.

Related Reading: For information on using DFSDDLT0, see the IMS ApplicationProgramming: Design Guide.

The processing of a multiple segment output message differs from that of a singlesegment output message in that the transaction output is represented by a classthat implements the IByteBuffer interface of the IBM Java Record Library, ratherthan a transaction output message bean created by the VisualAge for JavaEnterprise Access Builder. The IMS Connector for Java populates the byte array ofthe output class with the transaction output message. The Java application extractsthe individual segments from the byte array and uses them to set the values of theoutput segment objects. The output segment objects are created using theVisualAge for Java Enterprise Access Builder from COBOL 01 descriptors of theindividual message segments.

© Copyright IBM Corp. 1998, 2002 109

Related Reading: For information on building a Java application that processes anIMS transaction that has an input message with multiple segments and asingle-segment output message, see Building a Java application for an IMStransaction with multi-segment input messages.

A method for building a Java application for an IMS transaction with multi-segmentoutput messages is covered by the following sections:

1. Creating an EAB Command Using the Command Editor

2. Writing a Java Application to Use the EAB Command

3. Testing Your Application within VisualAge for Java

4. Running Your Application outside of VisualAge for Java

Some of the steps in the following sections are not described in detail, since theyare covered by earlier sections.

Creating an EAB Command Using the Command Editor

This section describes how you create an EAB command for an IMS transactionwith a multi-segment output message using the Command Editor.

The steps include the following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create a Project and Package for the Application

3. Create a COBOL Record Type Class for the IMS Transaction Input Message

4. Create a Transaction Input Message Record Bean

5. Create a Transaction Output Message Class that Implements IByteBuffer

6. Create COBOL Record Type Classes for the Output Message Segments

7. Create Record Beans for the Output Message Segments

8. Create a Command Class for the IMS Transaction

9. Set Up the Interaction Specification for the Command

10. Set Up the Connection Specification for the Command

11. Set Up the Command Input

12. Set Up the Command Output

13. Create the Command Bean

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeBuilding a Java application to run an IMS transaction: Step 1A.

Step 2: Create a Project and Package for the Application

For a description of this step, see Building a Java application to run an IMStransaction: Step 1B. The package used by the sample code for this section ismultisegout.

110 IMS Connector for Java User’s Guide and Reference

Step 3: Create a COBOL Record Type Class for the IMS Transaction InputMessage

For a description of how to create a COBOL Record Type class from the COBOLsource for an IMS input message, see Building a Java application to run an IMStransaction: Step 1C. The COBOL source for the input message can be found in fileMSOut.ccp in <IBM_Connectors_install_dir>\imsconn\samples\misc, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

Step 4: Create a Transaction Input Message Record Bean

For a description of how to create a transaction input message record bean from aCOBOL Record Type class, see Building a Java application to run an IMStransaction: Step 1D. The sample code for this section uses InMsg for the name ofthe input message record bean.

Step 5: Create a Transaction Output Message Class that ImplementsIByteBuffer

This step creates a class that implements the IByteBuffer interface of the packagecom.ibm.record of the IBM Java Record Library.

1. With the package multisegout selected, click the Selected menu, then selectAdd—>Class... The Create Class wizard appears.

2. Ensure that the correct names appear in the Project and Package entry fields.

3. Select the Create a new class radio button. Enter a name for the new class(for example, AllSegs), and ensure that the superclass is java.lang.Object.

4. Ensure that the Browse the class when finished and the Compose the classvisually check boxes are not checked.

5. Select the Next button. The Attributes wizard appears.

6. Enter com.ibm.record.IByteBuffer in the Which interfaces should this classimplement? list.

7. Check the public check box and the recommended check boxes under Whichmethod stubs would you like to create?.

8. Select the Finish button to create the class.

9. Modify the code generated for the class by VisualAge for Java as follows:

a. Add the following private field to the AllSegs class:private byte[] bytes;

b. Modify the checkBytes method so that it returns true instead of false.return true;

c. Modify the getBytes method so that it returns the private field bytes.return bytes;

d. Modify the setBytes method so that it sets the private field bytes.bytes = arg1;

Step 6: Create COBOL Record Type Classes for the Output MessageSegments

Chapter 6. Building a Java application for an IMS transaction with multi-segment output messages 111

For a description of how to create a COBOL Record Type class from COBOLsource, see Building a Java application to run an IMS transaction: Step 1E. Createa COBOL Record Type for each segment of the output message. The COBOLsource for the output message segments can be found in file MSOut.ccp in<IBM_Connectors_install_dir>\imsconn\samples\misc, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

Step 7: Create Record Beans for the Output Message Segments

For a description of how to create a record bean from a COBOL Record Type class,see Building a Java application to run an IMS transaction: Step 1D. Create threerecord beans, OutSeg1, OutSeg2, and OutSeg3.

Step 8: Create a Command Class for the IMS Transaction

For a description of how to create a command class, see Building a Javaapplication to run an IMS transaction: Step 2A. The command class used by thesample code for this section is MSOutCommand. After completing this step, you willbe working in the Command Editor.

Step 9: Set Up the Interaction Specification for the Command

For a description of how to set up the Interaction Specification for the command,see Building a Java application to run an IMS transaction: Step 2E. This includesadding the IMSInteractionSpec bean, connecting it to the EAB command, andpromoting the Datastore Name property.

Step 10: Set Up the Connection Specification for the Command

For a description of how to set up the Connection Specification for the command,see Building a Java application to run an IMS transaction: Step 2F. This includesadding the IMSConnectionSpec bean, connecting it to the EAB command, andpromoting the Host name and Port properties.

Step 11: Set Up the Command Input

For a description of how to set up the command input, see Writing a Javaapplication to use the EAB command. (page 113) This includes adding the InMsgbean, connecting it to the EAB command, and promoting the LL, ZZ, TRCD,DATA1, and DATA2 properties.

Step 12: Set Up the Command Output

For a description of how to set up the IMS transaction output, see Building a Javaapplication to run an IMS transaction: Step 4) In this case, the class thatimplements IByteBuffer (AllSegs) is associated with the command output. Afteradding the AllSegs bean and connecting it to the command, promote the bytesproperty of the bean.

Step 13: Create the Command Bean

For a description of how to create the composite EAB command bean, see Buildinga Java application to run an IMS transaction: Step 2G.

112 IMS Connector for Java User’s Guide and Reference

Figure 9. The completed EAB command as shown in the Visual CompositionEditor

Writing a Java Application to Use the EAB Command

This section describes how you use the EAB command created in the previoussection in a Java application. The descriptions that follow are based on the Javacode in the package com.ibm.connector.ims.sample.multisegout.

The steps include the following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create an Executable Class

3. Add Java Code to the Class

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeBuilding a Java application to run an IMS transaction: Step 3A.

Step 2: Create an Executable Class

For a description on how to create an executable class, see Building a Javaapplication to run an IMS transaction: Step 3B. The sample code for this sectionuses ExecuteMSOutCommand for the name of the executable class. In addition, theimport statements needed for the sample code are:import java.util.StringTokenizer;import java.io.*;

Step 3: Add Java Code to the Class

Chapter 6. Building a Java application for an IMS transaction with multi-segment output messages 113

Code must be added to the main() method of the ExecuteMSOutCommand classto use the EAB command to run the IMS transaction. This code can be copied fromthe main() method of the ExecuteMSOutCommand class in the packagecom.ibm.connector.ims.sample.multisegment in the Connector IMS Samplesproject on your Workbench. Replace the values yourUID, yourPwd, and yourGrp witha user ID, password, and group name, as appropriate for your IMS environment.

The code in the main method, up to and including execution of the EAB command,is similar to the Java applications discussed in earlier sections. After running theEAB command, the output of the command is retrieved using the following line:segBytes = cmd.getBytes();

This output can be either the output of the IMS transaction or a “DFS” messagefrom IMS. The method getAllSegsBytes retrieves an EBCDIC byte array. The codein the main method passes the EBCDIC byte array to the checkBytes method of theDFSMsg class to determine if the output received is a “DFS” message from IMS. If itis, the “DFS” message is printed; if not, the output is assumed to be from thetransaction, and it is also printed.

To print the “DFS” message, the aDFSMsg object must first be populated with data bypassing the EBCDIC array to the setBytes method:aDFSMsg.setBytes( segBytes );

The setBytes method converts the data from EBCDIC to UNICODE.

The code in the main method shows three methods for printing “DFS” messagesfrom IMS, as follows:

1. The individual fields of two of the segments of the message are printed using“get” methods for the fields (aDFSMsg.getDFSLL1(), aDFSMsg.getDFSZZ1(),aDFSMsg.getDFSDATA1(), etc.)

2. Method getDFSMessage returns a string that is a concatenation of the dataportion of the segments of the “DFS” message:System.out.println( “\nOutput of getDFSMessage is: ”

+ aDFSMsg.getDFSMessage() );

3. Method getDFSMessageSegments returns a vector of the data portion of thesegments of the “DFS” message, which can be used with an enumeration toprint the individual data portion of the segments of the “DFS” message:en = (aDFSMsg.getDFSMessageSegments()).elements();

System.out.println( “\nDFS Message Segments are: ” );while( en.hasMoreElements() ){

System.out.println( “\n” + en.nextElement() );}

If the output received is not a “DFS” message, it is assumed to be transactionoutput. The individual segment objects are populated by doing the following:

1. Extracting the data for a segment from the buffer containing the commandoutput (segBytes) to a byte array (buff):buff = new byte[ LL ];System.arraycopy( segBytes, srcPos, buff, dstPos, LL );

2. Using the resulting byte array as input to the setBytes method of thecorresponding segment:OutSeg2 S2 = new OutSeg2();S2.setBytes( buff );

114 IMS Connector for Java User’s Guide and Reference

The setBytes method converts the data from EBCDIC to UNICODE. The code inthe main() method also illustrates printing the data fields of the segment and addingthe segment objects to a vector.

Testing Your Application within VisualAge for Java

For a description of how to test your application within VisualAge for Java, seeBuilding a Java application to run an IMS transaction: Step 4. If you choose toexecute the application using the DFSDDLT0 script provided, the console outputshould be as follows:

OutSeg1 LL is: 16OutSeg1 ZZ is: 768OutSeg1_DATA1 is: *******M1SO1

OutSeg2 LL is: 31OutSeg2 ZZ is: 768OutSeg2_DATA1 is: ********M1SO2OutSeg2_DATA2 is: *********M2SO2

OutSeg3 LL is: 52OutSeg3 ZZ is: 768OutSeg3_DATA1 is: **********M1SO3OutSeg3_DATA2 is: ***********M2SO3OutSeg3_DATA3 is: ************M3SO3

Running Your Application outside of VisualAge for Java

For a description on running your application outside of VisualAge for Java, seeBuilding a Java application to run an IMS transaction: Step 5.

Chapter 6. Building a Java application for an IMS transaction with multi-segment output messages 115

116 IMS Connector for Java User’s Guide and Reference

Chapter 7. Building a Java application for an IMS transactionwith multi-segment input messages

This section describes how to build a Java application that processes an IMStransaction that has a multiple-segment input message and a single-segment outputmessage.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

This example corresponds to one of the samples included in the IMS ConnectorSamples feature. The Java source relating to this example is contained in thecom.ibm.connector.ims.sample.multisegin package of the Connector IMS Samplesproject which is added to your workspace when the IMS Connector Samples featureis added. See Preparing your VisualAge for Java environment for instructions oninstalling the IMS Connector Samples feature if you have not already done so. Byfollowing the instructions in this section, you will create an application which is thesame as the corresponding sample except that it uses different project and packagenames than are used in the sample since you can’t have duplicate package orproject names within your VisualAge environment. As a result, you will be able tocheck your work against the sample, helping you to resolve any difficulties youencounter as you progress through the steps that follow.

Note: The Java application might not be executable, because the correspondingIMS application program might not be available in all environments.

The IMS application program used with the sample code in this section isDFSDDLT0. The DFSDDLT0 script for this sample, MSIn.scr, can be found in<IBM_Connectors_install_dir>\imsconn\ samples\misc

The following stage 1 source was used in the IMS environment of this example:APPLCTN PSB=STLDDLT2, PGMTYPE=(,,2)TRANSACT CODE=SKS2, PRTY=(8,8)

The PSB and CODE values can be changed to match your IMS system definitionrequirements. The PSB requires only an I/O PCB. It does not require alternatePCBs or database PCBs.

Related Reading: For information on using DFSDDLT0, see the IMS ApplicationProgramming Guide.

The process for processing a multiple-segment input message differs from that of asingle-segment input message, in that the transaction input is represented by aclass that implements the IByteBuffer interface of the IBM Java Record Library,rather than a transaction input message bean created by the VisualAge for JavaRecord Generator. The Java application populates individual input segment objects,then builds the transaction input buffer. The input segment objects are created usingthe VisualAge for Java Record Generator from COBOL 01 descriptors of theindividual message segments. A method for building a Java application for an IMStransaction with multiple-segment input messages is covered in the followingsections:

1. Creating an EAB Command Using the Command Editor

2. Writing a Java Application to Use the EAB Command

© Copyright IBM Corp. 1998, 2002 117

3. Testing Your Application within VisualAge for Java

4. Running Your Application outside of VisualAge for Java

Several of the steps in the sections that follow are not described in detail, becausethey are covered in earlier sections.

Creating an EAB Command Using the Command Editor

This section describes how you create an EAB command for an IMS transactionwith a multi-segment input message using the Command Editor. The steps includethe following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create a Project and Package for the Application

3. Create COBOL Record Type Classes for the Input Message Segments

4. Create Record Beans for the Input Message Segments

5. Create a Transaction Input Message Class that Implements IByteBuffer

6. Create a COBOL Record Type Class for the IMS Transaction Output Message

7. Create a Transaction Output Message Record Bean

8. Create a Command Class for the IMS Transaction

9. Promote the IMS Transaction Input Properties

10. Promote the IMS Transaction Output Properties

11. Promote the DFS Message Properties

12. Promote the Interaction Specification Properties

13. Promote the Connection Specification Properties

14. Create the Command Bean

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeBuilding a Java application to run an IMS transaction: Step 1A.

Step 2: Create a Project and Package for the Application

For a description of this step, see Building a Java application to run an IMStransaction: Step 1B. The package used by the sample code for this section ismultisegin.

Step 3: Create COBOL Record Type Classes for the Input Message Segments

For a description of how to create a COBOL Record Type class from the COBOLsource for an IMS input message, see Building a Java application to run an IMStransaction: Step 1C. Create a COBOL Record Type for each segment of the inputmessage. The COBOL source for the input message segments can be found in fileMsIn.cpp, located in <IBM_Connectors_install_dir>\imsconn\samples\misc, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory. Forexample, d:\IBM Connectors.

Step 4: Create Record Beans for the Input Message Segments

118 IMS Connector for Java User’s Guide and Reference

For a description of how to create a record bean from a COBOL Record Type class,see Building a Java application to run an IMS transaction: Step 1D. Create fourrecord beans: InSeg1, InSeg2, InSeg3, and InSeg4.

Step 5: Create a Transaction Input Message Class that Implements IByteBuffer

This step creates a class that implements the IByteBuffer interface of the packagecom.ibm.record of the IBM Java Record Library.

1. With the package multisegin selected, click the Selected menu, then selectAdd > Class... The Create Class wizard appears.

2. Ensure that the correct names appear in the Project and Package entry fields.

3. Select the Create a new class radio button. Enter a name for the new class(for example, AllInSegs), and ensure that the superclass is java.lang.Object.

4. Ensure that the Browse the class when finished and the Compose the classvisually check boxes are not checked.

5. Select the Next button. The Attributes wizard appears.

6. Enter com.ibm.record.IByteBuffer in the Which interfaces should this classimplement? list.

7. Check the public check box and the recommended check boxes under Whichmethod stubs would you like to create?.

8. Select the Finish button to create the class.

9. Modify the code generated for the class by VisualAge for Java as follows:

a. Add the following private field to the AllInSegs class:private byte[] bytes;

b. Modify the checkBytes method so that it returns true instead of false.return true;

c. Modify the getBytes method so that it returns the private field bytes.return bytes;

d. Modify the setBytes method so that it sets the private field bytes.bytes = arg1;

Step 6: Create a COBOL Record Type Class for the IMS Transaction OutputMessage

For a description of how to create a COBOL Record Type class from the COBOLsource for an IMS output message, see Building a Java application to run an IMStransaction: Step 1E.

The COBOL source for the output message can be found in file MsIn.cpp, locatedin <IBM_Connectors_install_dir>\imsconn\samples\misc, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

Step 7: Create a Transaction Output Message Record Bean

For a description of how to create a transaction output message record bean from aCOBOL Record Type class, see Building a Java application to run an IMStransaction: Step 1F. The sample code for this section uses OutMsg for the name ofthe output message record bean.

Step 8: Create a Command Class for the IMS Transaction

Chapter 7. Building a Java application for an IMS transaction with multi-segment input messages 119

For a description of how to create a command class, see Building a Javaapplication to run an IMS transaction: Step 2A. Briefly, use the Command Editor tocreate an EAB command with name MSInCommand that includes an interactionspecification of IMSInteractionSpec, a connection specification ofIMSConnectionSpec, the AllInSegs input record bean, and output record beans ofOutMsg and DFSMsg.

Step 9: Promote the IMS Transaction Input Properties

For a description of how to promote properties of an input record bean, see Buildinga Java application to run an IMS transaction: Step 2B. In this case, promote thebytes property of the AllInSegs Input record bean.

Step 10: Promote the IMS Transaction Output Properties

For a description of how to promote properties of an output record bean, seeBuilding a Java application to run an IMS transaction: Step 2C. In this case,promote the LL, ZZ, and DATA1, properties of the OutMsg Output record bean.

Step 11: Promote the DFS Message Properties

For a description of how to promote properties of the DFSMsg output record bean,see Building a Java application to run an IMS transaction: Step 2D. In this case,promote the methods getDFSMessage and getDFSMessageSegments, as well asthe DFSDATA1 property of the DFSMsg output record bean.

Step 12: Promote the Interaction Specification Properties

For a description of how to promote properties of an interaction specification, seeBuilding a Java application to run an IMS transaction: Step 2E. In this case,promote the Datastore Name property of the IMSInteractionSpec record bean.

Step 13: Promote the Connection Specification Properties

For a description of how to promote properties of an connection specification, seeBuilding a Java application to run an IMS transaction: Step 2F. In this case,promote the Host name and Port properties of the IMSConnectionSpec recordbean.

Step 14: Create the Command Bean

For a description of how to save the command bean, see Building a Javaapplication to run an IMS transaction: Step 2G.

120 IMS Connector for Java User’s Guide and Reference

Figure 10. The completed EAB command as shown in the Command Editor

Writing a Java Application to Use the EAB Command

This section describes how you use the EAB command created in the previoussection in a Java application. The descriptions that follow are based on the Javacode in the package com.ibm.connector.ims.sample.multisegin.

The steps include the following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create an Executable Class

3. Add Java Code to the Class

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeBuilding a Java application to run an IMS transaction: Step 3A.

Step 2: Create an Executable Class

For a description on how to create an executable class, see Building a Javaapplication to run an IMS transaction: Step 3B. The sample code for this sectionuses MSInCommandExecute for the name of the executable class. In addition, theimport statements needed for the sample code are:import java.util.StringTokenizer;import java.io.*;

Step 3: Add Java Code to the Class

Chapter 7. Building a Java application for an IMS transaction with multi-segment input messages 121

Code must be added to the main() method of the MSInCommandExecute class touse the EAB command to run the IMS transaction. This code can be copied fromthe main() method of the MSInCommandExecute class in packagecom.ibm.connector.ims.sample.multisegin in the Connector IMS Samplesproject on your Workbench. Replace the values yourUID, yourPwd, and yourGrp witha user ID, password, and group name that is appropriate for your IMS environment.

The code in the main method, up to and including providing a Connection Managerfor the runtime context is similar to the Java applications that are discussed inearlier sections. Following execution of set methods for host name, port, anddatastore, each segment object is instantiated and populated with transaction inputdata as follows:multisegin.InSeg1 seg1

= (InSeg1)java.beans.Beans.instantiate(null,“multisegin.InSeg1”);

seg1.setIN__LL( (short)14 );seg1.setIN__ZZ( (short)0 );seg1.setIN__TRCD( “SKS2 ”);seg1.setIN__DATA1(“SI1M1”);

A buffer is allocated to hold the data of the individual segments, then the getBytes()method is invoked for each segment to obtain the segment data in EBCDIC. TheEBCDIC segment data is then placed in the buffer:

msgInBuff = new byte[seg1.getIN__LL() +seg2.getIN__LL() +seg3.getIN__LL() +seg4.getIN__LL()];

buff = null;srcPos = 0;dstPos = 0;buff = seg1.getBytes();totalLen = buff.length;System.arraycopy( buff, srcPos, msgInBuff, dstPos, totalLen );dstPos = dstPos + totalLen;

Finally, the buffer containing the data of the individual segments is used to populatethe AllInSegs object as follows://-------------------------------------------------------------+// Use buffer to populate input object (AllInSegs). |//-------------------------------------------------------------+cmd.setBytes( msgInBuff );

The remainder of the main method is similar to Java applications discussed earlierand includes execution of the EAB command followed by processing of the IMStransaction output.

Testing Your Application within VisualAge for Java

For a description of how to test your application within VisualAge for Java, seeBuilding a Java application to run an IMS transaction: Step 4. If you choose toexecute the application using the DFSDDLT0 script provided, the console outputshould be as follows:

Output from transaction is...LL: 8ZZ: 768DATA1: JI20

122 IMS Connector for Java User’s Guide and Reference

Running Your Application outside of VisualAge for Java

For a description on running your application outside of VisualAge for Java, seeBuilding a Java application to run an IMS transaction: Step 5.

Related Reading: For information on building a Java application that processes anIMS transaction that has a single-segment input message and an output messagewith multiple segments, see Building a Java application for an IMS transaction withmulti-segment output messages.

Chapter 7. Building a Java application for an IMS transaction with multi-segment input messages 123

124 IMS Connector for Java User’s Guide and Reference

Chapter 8. Building an application to run an IMS transactionwith synchronization level confirm

This section discusses two ways in which you can build a Java application that runsan IMS transaction with a synchronization level of Confirm.

The instructions in this section demonstrate methods in which two EAB commandsare created, in addition to the EAB command that runs the transaction. These twocommands are created with InteractionSpec modes of MODE_ACK andMODE_NACK, and are used to send positive and negative acknowledgements toIMS. This method is used when the coordinator used by the runtime context of theJava application is not coordinating; for example, if NullCoordinator is used.

The second method is used if the coordinator of the runtime context of the Javaapplication is coordinating; for example, if JavaCoordinator is used. In this case, it isrecommended that you use the commit() and rollback() methods of the coordinatorto send positive and negative acknowledgements to IMS. Instructions for thismethod are not included in this section; however, the source code is provided in theEx04ExecuteWithCoordinator class in packagecom.ibm.connector.ims.sample.phonebook.confirm in the Connector IMSSamples project on your Workbench.

For information on the synchronization level of an interaction of a command and thedifferent scenarios to build a Java application that runs an IMS transaction withsynchronization level Confirm, see IMS Connector for Java concepts and terms:Synchronization Level.

This example uses the IMS transaction that is described in the IMS INSTALL/IVPsample application, and corresponds to one of the samples included in the IMSConnector Samples feature. The Java source relating to this example is containedin the com.ibm.connector.ims.sample.phonebook.confirm package of the ConnectorIMS Samples project which is added to your workspace when the IMS ConnectorSamples feature is added. See Preparing your VisualAge for Java environment forinstructions on installing the IMS Connector Samples feature if you have not alreadydone so. By following the instructions in this section, you will create an applicationwhich is the same as the corresponding sample, with the exception that yoursample uses different project and package names than are used in the samplesince you can’t have duplicate package or project names within your VisualAgeenvironment. As a result, you will be able to check your work against the sample,helping you to resolve any difficulties you encounter as you progress through thesteps that follow.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

Creating the MODE_ACK and MODE_NACK EAB commands

The following steps create commands to run an IMS transaction withSynchronization level Confirm when usingMODE_ACK and MODE_NACK commands to send positive and negativeacknowledgements to IMS:

© Copyright IBM Corp. 1998, 2002 125

1. Start the Workbench in the VisualAge for Java IDE

2. Create a Project and Package for the Application

3. Create a Command to Execute the IMS Transaction

4. Create a Command for the MODE_ACK Interaction

5. Create a Command for the MODE_NACK Interaction

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeBuilding a Java application to run an IMS transaction: Step 1A.

Step 2: Create a Project and Package for the Application

For a description of this step, see Building a Java application to run an IMStransaction: Step 1B. The package used by the sample code for this section is ex04.

Step 3: Create a Command to Execute the IMS Transaction

This step creates a command for an IMS transaction with a synchronization level ofConfirm.

1. Create an EAB command with the name, for example, Ex04Command.

2. Edit the interaction specification properties of the command.

3. Select SYNC_LEVEL_CONFIRM for the property Synchronization Level.

Related Reading: For information on how to create and set up a command, seeBuilding a Java application to run an IMS transaction: Step 2A.

Step 4: Create a Command for the MODE_ACK Interaction

This step creates a command for the MODE_ACK interaction with IMS. TheMODE_ACK command is used to send a positive acknowledgment to IMS. Itinforms IMS that the output data has been received and tells IMS to commit thetransaction.

1. Create an EAB command with the name, for example, Ex04AckCommand.

Since the MODE_ACK command is not a transaction request, it does notcontain any user input or output data. As a result, the MODE_ACKcommand consists only of the IMSInteractionSpec andIMSConnectionSpec objects. The MODE_ACK command does not containany input or output objects.

2. Edit the interaction specification properties of the command.

Select MODE_ACK for the Mode property.

Related Reading: For information on how to create a Command class, see Buildinga Java application to run an IMS transaction: Step 2A

Step 5: Create a Command for the MODE_NACK Interaction

This step creates a command for the MODE_NACK interaction with IMS. TheMODE_NACK command is used to send a negative acknowledgment to IMS. Itnotifies IMS that the user is not satisfied with the output data, and requests IMS toroll back the transaction.

126 IMS Connector for Java User’s Guide and Reference

1. Create an EAB command with the name, for example, Ex04NackCommand.

Since the MODE_NACK command is not a transaction request, it does notcontain any user input or output data. As a result, the MODE_NACKcommand consists only of the IMSInteractionSpec andIMSConnectionSpec objects. The MODE_NACK command does notcontain any input or output objects.

2. Edit the interaction specification properties of the command.

Select MODE_NACK for the Mode property.

Writing a Java Application to Run the Transaction

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeBuilding a Java application to run an IMS transaction: Step 3A.

Step 2: Create an Executable Class

This step creates an executable class for this example.

For a description on how to create an Executable Class using the package createdin Step 2 above, see Building a Java application to run an IMS transaction: Step3B. Specify Ex04Execute as the name of the class, and a new class namedEx04Execute will be created.

Step 3: Add Java Code to the Class

Code must be added to the main() method of the Ex04Execute class to use theEAB commands to run the IMS transaction and to send positive or negativeacknowledgements to IMS. This code can be copied from the main() method of theEx04Execute class in packagecom.ibm.connector.ims.sample.phonebook.confirm in the Connector IMSSamples project on your workbench. Replace the values for user ID, password,and group name, according to your IMS environment.

Testing the Java Application

To test the Java application within VisualAge for Java, see Building a Javaapplication to run an IMS transaction: Step 4.

Running the Java Application

To run the Java application with the Navigator outside of VisualAge for Java, seeBuilding a Java application to run an IMS transaction: Step 5.

Chapter 8. Building an application to run an IMS transaction with synchronization level confirm 127

128 IMS Connector for Java User’s Guide and Reference

Chapter 9. Building the graphical user interface

This example illustrates how you can use the EAB command that you created inCreating an EAB Command Using the Command Editor to create a GUI Javaapplication. You can use the Java application to run an IMS transaction. Thisexample illustrates only basic concepts, and does not include sophisticated GUIinput and output processing.

This example corresponds to one of the samples included in the IMS ConnectorSamples feature. The Java source relating to this example is contained in thecom.ibm.connector.ims.sample.phonebook.gui package of the Connector IMSSamples project which is added to your workspace when the IMS ConnectorSamples feature is added. See Preparing your VisualAge for Java environment forinstructions on installing the IMS Connector Samples feature if you have not alreadydone so. By following the instructions in this section, you will create an applicationwhich is the same as the corresponding sample except for the fact that yourapplication will use different project and package names than those that are used inthe sample, since package or project names cannot be duplicated within yourVisualAge environment. As a result, you will be able to check your work against thesample, helping you to resolve any difficulties you encounter as you progressthrough the steps that follow.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

The steps include the following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create the Main GUI Dialog Class

3. Add the Import Statements

4. Add Connection Manager and Run-Time Context

5. Create the Main GUI Dialog Interface

6. Create a Command to Execute the IMS Transaction

7. Set Up the IMS Command

8. Finish

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeBuilding a Java application to run an IMS transaction: Step 1A. The package usedby the sample code for this section is ex03.

Step 2: Create the Main GUI Dialog Class

From the Selected menu, click Add > Class. A wizard appears to request all of thenecessary information to create a class:

1. Ensure that the Project field contains your project name, Examples.

2. Ensure that the Package field contains your package name, ex03.

3. Click Create a new class.

4. Enter Ex03MainDialog in the Class name field.

© Copyright IBM Corp. 1998, 2002 129

5. To choose the superclass for class Ex03MainDialog, click Browse, then selectJDialog from the TypeNames list.

6. Ensure that javax.swing is selected as the package name and click OK.

7. Ensure that the Compose the class visually radio button is selected.

8. Click Finish. A new window appears with the Visual Composition tab selected.

Step 3: Add the Import Statements

You need to import a number of classes when running the executable file. Add thefollowing import statements to the Ex03MainDialog class:

import com.ibm.connector.infrastructure.*;import com.ibm.connector.infrastructure.java.*;import com.ibm.connector.imstoc.*;import com.ibm.connector.connectionmanager.*;

Step 4: Add Connection Manager and Run-Time Context

This step adds the run-time context and the connection manager, which is used forthe GUI application.

Add the following statements to the Ex03MainDialog class:ConnectionManager connMgr = new ConnectionManager();

JavaRuntimeContext runtimeContext = null;

Step 5: Create the Main GUI Dialog Interface

This step builds a GUI dialog for giving the input values to the command bean thatwas created, and for displaying the output values from the command bean. TheGUI interface shown below is built using Swing components.

Figure 11. Sample GUI dialog for the IMS Phone Book Application

130 IMS Connector for Java User’s Guide and Reference

Step 6: Create a Command to Execute the IMS Transaction

This step creates an EAB command to execute an IMS transaction, as described inBuilding a Java application to run an IMS transaction: Step 2A. Name thiscommand class Ex03Command. When creating the Transaction Input/Ouput RecordBeans for the command, make sure to do the following:

v On the Create Record from Record Type wizard, select the GenerateNotification check box under Additional Options.

This ensures that appropriate notification is generated when the properties of therecord bean are updated.

This step uses the Visual Composition Editor to associate the appropriate fieldvalues of IMS command created in the previous step, Step 6: Create a Commandto Execute the IMS Transaction, with the GUI dialog to get input from the user.

1. In the Visual Composition Editor, click Choose Bean..., located beneath theSwing pull-down menu.

2. Click Browse to look through a list of available classes. In the Pattern field,enter Ex03Command. A list of class names appears.

3. Choose Ex03Command (in package ex03),for the Class name from the list ofavailable classes. Click OK on this and the previous window.

4. To plant the bean, move the cursor to a position in an empty space in the VisualComposition Editor frame window and click the left mouse button. By default, itis assigned the name Ex03Command1.

5. The following connections need to be established:

a. Set up the run-time context connection corresponding to this GUI thread.This step creates an Event-to-Code connection, such that the following blockof code is executed when the actionPerformed event of the Submit buttonoccurs (in other words, when the user clicks on the Submit button).

v Click Submit and click the right mouse button. Choose Connect >actionPerformed.

v Move the cursor to an empty area in the frame window and click the leftmouse button. Click Event-to-Code... and an Event-to-CodeConnection dialog box appears.

v In the Event-to-Code connection dialog box, replace the method withthe code below. Replace the values yourUID, yourPwd, and yourGrp withthe user ID, password, and group name for your IMS environment.

/*** Setup the runtime context and other property values to prepare* for the execution of an IMS transaction. Provide the user ID,* password and group name that will be supplied to IMS.**/public void setup(Ex03Command cmd){

//-----------------------------------------------------+// Set up the runtime context for the current thread. |//-----------------------------------------------------+if (runtimeContext == null){

runtimeContext = new JavaRuntimeContext();JavaRuntimeContext.setCurrent( runtimeContext );

Chapter 9. Building the graphical user interface 131

}//------------------------------------------------------+// Provide your environment’s values for user ID, |// password, and group name for the runtime context. |//------------------------------------------------------+IMSLogonInfoItems logon =

new IMSLogonInfoItems( runtimeContext.getLogonInfo(),cmd.getConnectionSpec() );

logon.setUser( “yourUID” );logon.setPassword( “yourPwd” );logon.setGroup( “yourGrp” );//-----------------------------------------------------+// Set Connection Manager |//-----------------------------------------------------+runtimeContext.setConnectionManager( connMgr );//-----------------------------------------------------+// Set trace level. |//-----------------------------------------------------+(JavaRASService)runtimeContext.getRASService()).setTraceLevel(

RASService.RAS_TRACE_OFF );return;

}

v Click OK. Click Yes when prompted with Text has been modified-Savechanges? dialog box. A new setup(Ex03Command cmd) method iscreated. A new connection is also created.

v This connection requires a cmd input parameter. To provide the cmdparameter and complete the connection, do the following:

1) Select the new connection and click the right mouse button.

2) Select Connect > cmd.

3) Move the cursor to the Ex03Command1 bean icon and click the leftmouse button. Click this.

b. Execute Command connection

This connection triggers the execution of the command bean when thesubmit button of the GUI is clicked:

v Select the new connection setup(Ex03Command cmd) created in theprevious step and click the right mouse button.

v Select normalResult.

v Move the cursor to the Ex03Command1 bean icon, and click the leftmouse button.

v Click Connectable Features... and an End connection dialog boxappears.

v Make sure that the Method radio button is selected. Scroll down the listto choose the execute() method and click OK. A new connection iscreated.

c. Input values property connections

This step associates the input properties of the command bean to the GUIinterface to get input from the user.

This step creates property-to-property connections between the input textfields of the GUI and the input properties of the Ex03Command1 bean.

v Select the LL text input field of the Input Section of the GUI and click theright mouse button. Select Connect > text.

v Move the cursor to select the Ex03Command1 icon and click the leftmouse button. Click Connectable Features... An End connection dialogbox appears.

v Scroll down the list of properties to choose the IN__LL and click OK.

132 IMS Connector for Java User’s Guide and Reference

v A property-to-property connection with the LL text input field on the GUIand the IN__LL property of the Ex03Command1 bean is created.

v Select the newly created connection and click the right mouse button.Select Properties.

v In the source event box, select caretUpdate.

v Click OK. This keeps the value of the IN__LL property of the commandupdated when the input text is changed.

v Repeat the steps above to associate the following text field values of theinput section of the GUI with the properties of the command bean:

– ZZ > IN__ZZ

– Tran Code > IN__TRCD

– Command > IN__CMD

– Name1 > IN__NAME1

– Name2 > IN__NAME2

– Extension > IN__EXTN

– Zip >IN__ZIP

In a property-to-property connection, the ordering of the source and targetbean affects how the property values are updated and synchronized.

d. Output values property connections

Similarly, this step associates the output property values of the commandbean with the GUI interface to display the output to the user.

See the description in Step 5, item d on how to create property-to-propertyconnections between the following output properties of the Ex03Command1bean and the output text fields in the Output section of the GUI:

v OUT__LL > LL

v OUT__ZZ > ZZ

v OUT__MSG > Message

v OUT__CMD > Command

v OUT__NAME1 > Name1

v OUT__NAME2 > Name2

v OUT__EXTN > Extension

v OUT__ZIP > Zip

In a property-to-property connection, the ordering of the source and targetbean affects how the property values are updated and synchronized. In thisstep, ensure that the property-to-property connections are created withEx03Command1 as the source bean and the GUI output text fields as thetarget bean.

e. DFS message output connection

This connection associates the output DFS message from IMS to the GUIinterface. The text value in the GUI for the DFS message is updated whenthe output bean of the command returned is a DFSMsg object.

1) Select the Ex03Command1 icon and click the right mouse button.Choose Connect > Connectable Features... A Start connection dialogbox appears.

2) Make sure that the Property radio button is selected. Scroll down thelist to choose the DFSDATA1 property and click OK.

Chapter 9. Building the graphical user interface 133

3) Move the cursor to the DFS Message TextField in the GUI and click theleft mouse button. Select text. A property-to-property connection with theDFS Message Text field and the DFSDATA1 property of theEx03Command1 is created.

4) Select the newly created connection and click on the right mouse button.Select Properties.

5) In the Source Event box, select propertyChange. Click OK. This keepsthe value of the DFS Message Text field updated when the DFSDATA1property is changed (i.e., a DFS message is returned from IMS).

f. Close run-time context connection

This connection closes the run-time context when the Close button is clickedand the GUI closes.

This step creates an Event-to-Code connection, such that the following blockof code is executed when the actionPerformed event of the Close buttonoccurs (in other words, when the user clicks on the Close button):/**

* Close the runtime context for the current thread.*/public void closeRuntimeContext(){

//-------------------------------------------------------------+// Commit resources and close the runtime context. |//-------------------------------------------------------------+if ( runtimeContext != null ){

((JavaCoordinator)runtimeContext.getCoordinator()).commit();runtimeContext.close();runtimeContext.removeCurrent();

}

//-------------------------------------+// Dispose the window. |//-------------------------------------+dispose();System.exit(0);

}

See the description in Step 5, item a on how to create an Event-to-Codeconnection between the actionPerformed event of the Close button and thecode. The code in this step does not requires any parameter.

Related Reading: For more information on property-to-property connections, seethe Visual Composition Editor documentation.

Step 8: Finish

This is the final step in creating the GUI Application.

Click the Bean menu and click Save Bean to save your work. The workbenchshows the new Ex03MainDialog class.

You can modify the handleException(Throwable) method of the Ex03MainDialogclass to print messages when exceptions occur. All trace information and exceptionsare logged to the console.

134 IMS Connector for Java User’s Guide and Reference

Figure 12. The Completed GUI application

Testing the GUI Application

To test the GUI application within VisualAge for Java, do the following:

1. Select class Ex03MainDialog and, from the Selected menu, click Properties.The Properties for Ex03MainDialog window appears.

2. Select the Class Path tab and make sure that the Include ’.’ (dot) in classpath and Project path: check boxes are checked.

3. Click Compute Now, and click OK when the class path is computed. Thisupdates the VisualAge for Java class path to include your Java application.Close the Properties for Ex03MainDialog window.

4. Modify method getEx03Command1() of class Ex03MainDialog as follows:

v Replace the value 0 in the setPortNumber method with the port number ofyour environment.

v Replace the value “YourHost” in the setHostName method with the host nameof your environment.

v Replace the value “YourDS” in the setDataStoreName method with thedatastore name of your environment.

5. Modify method setup(Ex03Command cmd) of class Ex03MainDialog as follows:

v Replace the value “yourUID” in the setUser method with the userID of yourenvironment.

v Replace the value “yourPwd” in the setPassword method with the passwordof your environment.

Chapter 9. Building the graphical user interface 135

v Replace the value “yourGrp” in the setGroup method with the group name ofyour environment.

6. Select class Ex03MainDialog and from the Selectedmenu, click Run > Runmain... Enter the desired input data. The results of running your applicationappear in the IMS Phonebook Application window.

136 IMS Connector for Java User’s Guide and Reference

Chapter 10. Building a Java servlet to run an IMS transaction

This section provides you with an example of how to use the IBM WebSphereStudio to create a Java servlet from your EAB command. This section alsodescribes how to run your servlet in a WebSphere Application Server environment.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

The process of creating and executing a servlet to run an IMS transaction iscovered in the following sections:

1. Creating a Java Servlet Using WebSphere Studio

2. Running Your Java Servlets in a WebSphere Application Server Environment

Creating a Java Servlet Using WebSphere Studio

The IBM WebSphere Studio is a comprehensive tools environment for building Webapplications. WebSphere Studio’s JavaBean wizard can be used to create a Javaservlet for the WebSphere Application Server from your IMS Connector command.

The steps include the following:

1. Configure WebSphere Studio

2. Provide Your EAB Command to WebSphere Studio

3. Start WebSphere Studio

4. Create a Project for Your Servlet

5. Start the Studio Wizard

6. Provide Input to the Studio Wizard

7. Modify the Code Generated by the Studio Wizard

Step 1: Configure WebSphere Studio

In order for WebSphere Studio to build a servlet from an Enterprise Access Buildercommand that uses IMS Connector, you must make the supporting class librariesavailable to WebSphere Studio.

Related Reading: For instructions on how to prepare your WebSphere Studioenvironment, see Preparing your WebSphere Studio environment.

Step 2: Provide Your EAB Command to WebSphere Studio

To use WebSphere Studio to build a servlet from your Enterprise Access Buildercommand, make the EAB command available to WebSphere Studio by copying itsJAR file to a target directory on your WebSphere Studio machine.

You can obtain this JAR file by exporting it from VisualAge for Java as follows:

1. Highlight the package that contains the EAB command you created (forexample, ex01).

2. Click File > Export.

3. Click Jar file and click Next.

© Copyright IBM Corp. 1998, 2002 137

4. Name your JAR file in the text box at the top of the wizard. For example,ex01.jar.

5. Ensure that both the class and beans check boxes are checked.

6. Click the Details... button of the beans check box.

7. Ensure that the check box is marked on the Projects panel.

8. Ensure that only your EAB command is marked as a bean on the Types panel(for example, Ex01Command) and click OK.

9. Click Finish to export your .jar file.

Note:

WebSphere Studio integrates with VisualAge for Java, providing quicknavigation between the two products. If you have VisualAge for Java installedand running on the same machine as your WebSphere Studio, you can easilytransfer files like Java beans, servlets and files such as .java and .classbetween the two products.

If you are using the above feature to send your EAB Command bean (forexample, ex01.Ex01Command shipped as the ex01\Ex01Command.class file)from VisualAge for Java, make sure that you also send all the related classesthat will be used by your EAB command class (for example, the ex01.InMsgand ex01.OutMsg classes) in order to compile.

For instructions on how to use this feature, see How To... > Use Studio withVisualAge in the WebSphere Studio Studio’s Guide. See also Concepts >External tool integration > Tool Integration API in VisualAge for JavaOnline Help.

Step 3: Start WebSphere Studio

Start WebSphere Studio by clicking the Start icon and click Programs > IBMWebSphere > Studio > IBM WebSphere Studio. The WebSphere Studio windowappears.

Step 4: Create a Project for Your Servlet

This step creates a project for your servlet.

If you do not yet have a WebSphere Studio project defined, select the Create anew project using: radio button, select Default Template from the scroll list andclick OK, or from the File menu, click New project. The New project windowappears. Enter a name for the new project file; for example, ex01. Choose aProject Folder, if desired. Click OK.

The steps that follow create a servlet that uses the Enterprise Access Buildercommand JAR file that was created in Step 2. This is the JAR file for the EABcommand built. In addition to creating the servlet, WebSphere Studio produces aninput HTML form for transaction input and to invoke the servlet and output JSP filesto display the results of running the transaction.

Note:

WebSphere Studio allows you to specify, for a particular Studio project, theversion of WebSphere Application Server you will be using to run your servlet.

138 IMS Connector for Java User’s Guide and Reference

Based on your selection, WebSphere Studio varies how it handles processessuch as code generation, compiling Java files, publishing, and so on.

Related Reading: For instructions for setup of the Application Server preferences,see How To... > Manage your projects > Setting the project properties in theStudio Guide for WebSphere Studio .

Step 5: Start the Studio Wizard

Select the servlet folder icon in the project tree (for example, ex01) and click Insert> File to open the Insert file dialog. Click the Use existing tab to insert yourEnterprise Access Builder command jar file (for example, ex01.jar) that you createdin Step 2: Provide Your EAB Command to WebSphere Studio.

Note:

To obtain the EAB command and the related Java classes directly fromVisualAge for Java using the integrated feature referred to in Step 2: ProvideYour EAB Command to WebSphere Studio, do the following:

1. Select the From External Source tab of the Insert File dialog box.

2. Select VisualAge for Java under the list of Providers.

3. Click the Browse button and select the Java classes to be imported. (forexample, select ex01.Ex01Command), and all its input/output beans, (forexample, ex01.InMsg, etc.). Click OK to close the window. The related files(for example, ex01/Ex01Command.class, ex01/InMsg.class, etc...) will beshown under the list of Files of the Insert File dialog box.

4. Select the files from the Files list (for example, select all the .class filesonly) and click OK to finish the import.

Related Reading: For more information on using this integrated featurebetween WebSphere Studio and VisualAge for Java, see How To... > UseStudio with VisualAge in the WebSphere Studio Studio’s Guide. See alsoConcepts > External tool integration > Tool Integration API in VisualAgefor Java’s help.

Step 6: Provide Input to the Studio Wizard

To start the Studio wizard, select your project folder (for example, ex01), then selectTools > Wizards > JavaBean Wizard from the menu.

Enter the following on each of the Studio wizard pages:

JavaBean Wizard

Under the Look in scrollbox, select the Enterprise Access Builder commandjar file (for example, ex01.jar) or the class file (for example,ex01/Ex01Command.class) that you have added to the project. Select thecommand bean name, qualifying it with the package name (for example,ex01.Ex01Command). Click Next. If you are using a JAR file and you don’tsee the JAR file, you may not have added the JAR file correctly in theprevious step. Make sure that you have inserted the JAR file in the servletfolder of your project.

Chapter 10. Building a Java servlet to run an IMS transaction 139

Markup LanguagesSelect the web application model and the markup language that will beused. Select the Servlet Model from the scroll list under What style ofcode do you want to generate?. Select HTML for the Markup Language.

Web PagesSelect the number of Web pages that you need. The Create an input pageand Create a results page check boxes are selected as default. In ourexample, we also select the Create a page for when an error occurscheck box.

Input PageThis form is used to enter the input data of your transaction. Check thefields that you want to appear on the input form. For example:

v hostName

v portNumber

v dataStoreName

v IN__CMD

v IN__EXTN

v IN__NAME1

v IN__NAME2

v IN__TRCD

v IN__ZIP

You can select a particular field and use the Change button to set initialvalues, or have more meaningful captions, or make other changes to theHTML. Click Next.

Because you typically do not present the LL and ZZ fields of an IMStransaction message to the end user, you should provide values for thesefields by modifying the servlet code. See Step 7: Modify the CodeGenerated by the Studio Wizard, Item 2-e.

Results PageThis template is used to display the output data of your transaction. Checkthe fields that you want to appear on the output template. For example:

v OUT__CMD

v OUT__EXTN

v OUT__MSG

v OUT__NAME1

v OUT__NAME2

v OUT__ZIP

v OUT__SEGNO

Note: Only the first segment of the DFS message (shown as DFSDATA1) isdisplayed in this example. You can display all of the segments of the DFSmessage by promoting the DFSDATA1..DFSDATA2 properties in your EABcommand bean. Then, you can select them in this Results Page window ofWebSphere Studio.

You can select a particular field and use the Change... button to change thecaptions. Click Next.

140 IMS Connector for Java User’s Guide and Reference

Standard Error PageSelect Use this page to display an existing error page on your Web server,or select Create a new page with the following text to let the wizardcreate one to be displayed when an error occurs. In this example, selectthe Create a new page with the following text radio button. Customizethe error text message if desired. Click Next.

MethodsSelect the execute method that has no parameters. Click Next.

SessionThis bean can be used by more than one servlet in a Web application. Youcan save this bean in the session and make it available, along with its data,for use on other Web pages within your Web site. For simplicity in thisexample, select No.

To ensure that each page has access to the correct EAB command bean,specify an alias name for the bean. For example, ex01Command. Click Next.

Finish The Servlet, Input, and Output pages are generated with the file namesshown in the Finish window. Change the names files using the Renamebutton, if desired. (For this example, change the prefix to Ex01Servlet).Click Finish to save your files and return to WebSphere Studio.

The following files are generated from your EAB command:

v An input HTML form (for example, Ex01ServletHTMLInput.html)

This is the input HTML form that is used on a web browser to provide inputdata for your IMS transaction, and to invoke the servlet.

v An output JSP page (for example, Ex01ServletHTMLResults.jsp)

This page is used on a web browser to display the output data of your IMStransaction.

v An error JSP page (for example, Ex01ServletHTMLError.jsp)

This page is used on a web browser to display error information from yourservlet.

v Java source for your servlet (for example, Ex01Servlet.java)

v A .servlet file for your servlet (for example, Ex01Servlet.servlet)

v A class file is created when you compile the Java source for your servlet. Inaddition, a master.css file is created as your style sheet.

Definitions:

v A JSP file, or JavaServer Page, is a type of file that WebSphere Studiogenerates to implement dynamic page content. JSP files can contain JavaScriptcoding, HTML tagging, and JSP tagging, and allow the WebSphere ApplicationServer to dynamically add content to your HTML pages before they are sent to arequesting browser.

You can customize a JSP file to add your own text and images usingJavaScript, HTML, or JSP tagging. This script will be included in the HTML filethat is created by the WebSphere Application Server and returned to therequesting browser.

v A .servlet file contains information that is used to configure a servlet. You canmodify a servlet’s configuration by changing the entries in its .servlet file.

Chapter 10. Building a Java servlet to run an IMS transaction 141

Step 7: Modify the Code Generated by the Studio Wizard

This step describes how you should modify the code that is generated by the Studiowizard. With the integration of WebSphere Studio and VisualAge for Java, you havethe option of editing your files in VisualAge for Java, then sending the updated filesback to the Studio. See Step 2 above for more information.

Note: The modifications presented here represent a simple servlet and do notaddress issues relating to thread safety for a servlet.

To modify the code generated by the Studio Wizard, do the following:

Modify the Generated Java Source Code for Your Servlet

1. From the list of files in the WebSphere Studio window, select the file thatcontains the Java source for your servlet (for example, Ex01Servlet.java). Fromthe Tools menu, click Edit with and select your editor (Notepad, for example)to open your file.

If asked to check-out the associated file (for example, Ex01Servlet.class), selectthe check box of the associated file. Then, click on the Check Out and Editbutton to continue.

2. Modify the performTask method as follows:

a.Ensure that the following lines are commented out as shown:

// com.ibm.connector.internal.LogonInfoItems logonInfoItems =// new com.ibm.connector.internal.LogonInfoItems(runtimeContext.getLogonInfo());// logonInfoItems.setUser(“UserID”);// logonInfoItems.setPassword(“UserPassword”);

b. After the instantiation of the ex01 command bean, for example:ex01.Ex01Command ex01Command = new ex01.Ex01Command();

add the following lines to set up the IMS LogonInfoItems class.com.ibm.connector.imstoc.IMSLogonInfoItems logon =

new com.ibm.connector.imstoc.IMSLogonInfoItems(RuntimeContext.getCurrent().getLogonInfo(),ex01Command.getConnectionSpec());

c. Set up the logon information for your transaction by either ″hard coding″ itdirectly into the Java source for your servlet, or by obtaining it from the inputHTML form for the transaction. To ″hard code″ the information, add thefollowing lines:logon.setUser(“<UserName>”);

logon.setPassword(“<Password>”);logon.setGroup(“<GroupName>”);

If you want to get the logon information from the input HTML form, modifythe input HTML form that is generated by WebSphere (for example,Ex01ServletHTMLInput.html), as described in Modify the Input HTML Pagefor Your Servlet (Optional). As replacements to the lines above, add thefollowing lines:logon.setUser(getParameter(request, “userName”, true, true, true, null));logon.setPassword(getParameter(request, “password”, true, true, true, null));logon.setGroup(getParameter(request, “group”, true, true, true, null));

d. Modify the generated code to set up the Common Connector Frameworkinfrastructure services. For example,

v Uncomment out the line

142 IMS Connector for Java User’s Guide and Reference

runtimeContext.setConnectionManager (/* global instance of the classcom.ibm.connector.connectionmanager.ConnectionManager */);

to set your global instance of the Connection manager with the currentruntime context. For more information about different types of ConnectionManager and how to set it up in your runtime environment, see IMSConnector for Java concepts and terms: Connection Management.

v Uncomment out the line((JavaRASService)runtimeContext.getRASService())

.setTraceLevel(RASService.RAS_TRACE_OFF);

to set up your desired trace level of the RAS Service.

See the comments in the generated code for more information.

Related Readings: For more information about setting up the CommonConnector Framework infrastructure, see Task > Accessing transactionsystems > Accessing CICS, IMS, Encina, MQSeries, HOD > Getting startedwith Enterprise Access Builder for Transactions > Setting up the run-timeenvironment in the VisualAge for Java Online Help.

a. Set the LL and ZZ fields prior to executing the transaction. The LL value isthe length of all input message data fields, plus 4 (for LL and ZZ).ex01Command.setIN__LL((short) <length>+4);ex01Command.setIN__ZZ((short) 0);

b. At this point, you can complete an optional step, Improving the way youtrack DFS Messages (page 144), below, which provides a more helpful wayof tracking DFS messages.

3. From the list of files in the WebSphere Studio window, select the file thatcontains the Java source for your servlet (for example, Ex01Servlet.java).

From the Project menu, click Compile to recompile your servlet after modifyingthe source.

If the Warning dialog for replacing existing .class file appears, click Yes.

Modify the Input HTML Page for Your Servlet (Optional)

If you want to obtain the logon information from the input HTML form, do thefollowing:

1. In the WebSphere Studio window, click on the project that contains theinformation for your servlet.

2. Select the file that contains the HTML source for your input page (for example,Ex01ServletHTMLInput.html) and open it for editing.

3. Add the following lines to the HTML input form so that the user can enter theuser name, password, and group name:<P>User Name<BR><INPUT TYPE=TEXT NAME=“userName” ID=“userName”></P><P>Password<BR><INPUT TYPE=“password” NAME=“password” ID=“password”></P><P>Group<BR><INPUT TYPE=TEXT NAME=“group” ID=“group”> </P>

Modify the Output JSP Page for Your Servlet (Optional)

If you modify the output JSP file for your servlet, be sure that the bean name isentered correctly. The bean name is case-sensitive. If the bean name is enteredincorrectly, an error is returned to the Web browser when WebSphere ApplicationServer attempts to run your servlet.

Chapter 10. Building a Java servlet to run an IMS transaction 143

Improving the way you track DFS Messages (Optional)

This procedure is an optional procedure. If you wish to follow it, you must do soafter you have completed Step 7e: Modify the Code Generated by the StudioWizard (page 142), above.

1. Modify the Java Servlet Generated by VisualAge for Java

a. Directly below the line executing the command beanex01Command.execute();add the following line:Object output = ex01Command.getOutput();

b. Comment out the line:callPage(getPageNameFromRequest(request), request, response);The servlet will now select the appropriate output page instead of getting itfrom the Request object.

c. Add the following code below the line you commented out in the previousstep:

if (java.beans.Beans.isInstanceOf(output,.ibm.connector.imstoc.DFSMsg.class)) {

// Call the output page indicating a DFS Message occurred:callPageNamed(“DFSMsg”, request, response);

} else if (java.beans.Beans.isInstanceOf(output, ex01.OutMsg.class)) {// Call the output page indicating successful execution:callPageNamed(“output”, request, response);

} else {// Call the generic output page which was generically created by// WebSphere Studio.callPageNamed(“error”, request, response);

}

The above code matches the output object depending on what kind ofrecord is returned. The names DFSMsg, output, and error are arbitrary, butthey must match up in the .servlet file.

2. Create a New Output JSP Page for Your Servlet

The following steps describe how to create a new JSP page, DFSMsg.jsp,which will display the DFS Message in the web browser.

a. In WebSphere Studio, select the project name (ex01). Select File > New...and ensure that the Create New tab is selected. Enter “DFSMsg.jsp” in theFile Name field and click OK.

b. Edit the newly created file DFSMsg.jsp using Studio or Notepad, forexample, and completely replace the HTML contents with the following:<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”><HTML>

<HEAD><META HTTP-EQUIV=“Content-Type” content=“text/html; charset=ISO-8859-1”><META http-equiv=“Content-Style-Type” content=“text/css”><LINK href=“/theme/Master.css” rel=“stylesheet” type=“text/css”><TITLE>DFSMsg</TITLE>

</HEAD><BODY><%@ page import=“ex01.Ex01Command” %><jsp:useBean id=“ex01Command” type=“ex01.Ex01Command” scope=“request”>

</jsp:useBean><TABLE border=“0”><TR><TD>A DFS Message has been returned:</TD></TR><TR><TD>

144 IMS Connector for Java User’s Guide and Reference

<!--METADATA type=“DynamicData” startspan<WSPX:PROPERTY property=“ex01Command.DFSDATA1”> >

<%= ex01Command.getDFSDATA1() %><!-- METADATA type=“DynamicData” endspan ></TD></TR></TABLE></BODY>

</HTML>

c. Save the file and check it in.

3. Modify the .servlet File generated by WebSphere Studio

a. In WebSphere Studio, select the .servlet file (Ex01Servlet.servlet), which isin the ex01 folder of the servlet folder. Open the file for editing (withNotepad, for example).

b. Note the <page-list> and </page-list> tags. Remove all code betweenthese tags. That is, remove the code starting with <default-page> andending with </error-page>.

4. Fill the empty space between the <page-list> and </page-list> tags with thefollowing:<page>

<page-name>DFSMsg</page-name><uri>/DFSMsg.jsp</uri>

</page><page>

<page-name>output</page-name><uri>/Ex01ServletHTMLResults.jsp</uri>

</page><page>

<page-name>error</page-name><uri>/Ex01ServletHTMLError.jsp</uri>

</page><error-page><uri>/Ex01ServletHTMLError.jsp</uri>

</error-page>

Note that the <page-name> tags contain the names DFSMsg, output, and errorexactly as specified in the Java servlet. Also note that the file names containedin <uri> tags correspond to the files in your Studio project.

Create a Web application on your WebSphere Application Server

WebSphere Application Server supports the Web application programming model inwhich the servlets are now managed, configured and deployed based on the scopeof a Web application (or Servlet group). A Web application is defined as a group ofservlets that share the same servlet context.

Web applications are rooted in the directory path<WAS_Install_Dir>\hosts\default_host\<yourWebAppName>, where<WAS_Install_Dir> is the installation directory of WebSphere Application Server (forexample, d:\WebSphere\AppServer) and <yourWebAppName> is the name thatidentifies your Web application. You must also configure the application classpath ofyour Web Application, which is<WAS_install_dir>\hosts\default_host\<yourwebappname>\servlets. All compiledresources that a servlet of a Web application uses (for example, servlet .class filesand the JAR files) should be placed in this directory. Resources in this directory areautomatically reloaded whenever the resource is updated.

Chapter 10. Building a Java servlet to run an IMS transaction 145

In addition, the non-Java resources such as .html and .jsp files will be placed in theWeb application’s document root instead of in the Web Server document root. Thepath of a Web application document root is<WAS_install_dir>\hosts\default_host\<yourwebappname>\web.

For more information on creating and configuring a Web application, refer to theConfiguring new Web applications document of the WebSphere Application Serverdocumentation.

This step helps you build a Web application called imsconn that allows you to runyour Java servlet.

1. Configure your Web application:

a. Start the Configure a Web application task wizard by clicking Console >Tasks > Configure a Web application from the WebSphereAdministrative Console menu bar.

b. In the Set Web App Name and Select System Servlets pane, set thefollowing properties:

v Specify a name for the Web application in the Web App Name field. Forexample, imsconn.

v Check the Enable File Servlet check box to enable the file servlet toserve HTML from the application server instead of the Web server.

v Check the Serve Servlets by Classname check box to serve servletsdirectory from the Web application’s servlets directory.

v Specify the JavaServer Pages (JSP) specification to use. In this example,select the Enable JSP 1.0 radio button.

c. Select the Next button.

d. Specify the servlet engine for your Web application. Click the + sign toexpand Nodes tree. Click the + sign again on the node that has the TCP/IPhost name of your Web server machine, to select the servlet engine underthe server. For example, select Default Servlet Engine.

e. Select the Next button.

f. Name the Web application and the Web path for your application.

1) Specify a name for your application in the Web Application Name field.For example, imsconn.

2) Describe the Web application. (Optional).

3) Specify the virtual host part of the Web application’s served path in theVirtual Host field. For example, default_host.

4) Specify the Web Path for the Web application in the Web ApplicationWeb Path field. For example, /webapp/imsconn.

g. Select the Next button.

h. Specify the advanced setting.

v Specify the document root for the Web application in the Document Rootfield. For example,<websphere_install_dir>\hosts\default_host\imsconn\web.

v Specify the classpath for the Web application in the Classpath forApplication field. For example,<websphere_install_dir>\hosts\default_host\imsconn\servlets.

v Specify other Web application properties or accept their default values.

i. Click the Finished button.

2. Restart your Web application:

146 IMS Connector for Java User’s Guide and Reference

a. Go to the Topology tab by selecting View > Topology from the menu bar.

b. Expand the tree under the TCP/IP host name for your machine.

c. Look for the imsconn Web application under Default Server > DefaultServlet Engine.

d. Right click the imsconn Web application and choose Restart Web App fromthe popup menu.

3. Add folders representing your Web application (imsconn) to the WebSphereApplication Server directory structure.

a. Create the Web application folder:<websphere_install_dir>\hosts\default_host\imsconn.

b. Create the Web application document root folder:<websphere_install_dir>\hosts\default_host\imsconn\web

c. Create the Web application classpath folder:<websphere_install_dir>\hosts\default_host\imsconn\servlets.

Configuring the WebSphere Studio Publishing Service

WebSphere Studio provides a publishing service that enables you to easily movethe generated HTML and .jsp pages and servlet class files to your Web server andWebSphere Application Server machine (local or remote). It also makes it easy todeploy your servlet as a Web application (as illustrated in this example). To set upthe WebSphere Studio machine for the WebSphere Studio publishing services, dothe following:

1. Start WebSphere Studio.

2. Choose a publishing stage whose files you want to publish by selecting Project> Publishing Stage > your target assembly stage (for example, Test).

3. Ensure that you are in Publishing View. To display the Publishing View, doone of the following:

a. Click View > Publishing.

b. Click the Publishing View icon on the toolbar. The Publishing View is thenshown in the right pane of WebSphere Studio.

4. You should see an icon for your target server(s) in the Publishing view. If thereis no server shown, you need to add a Server in the Publishing view of yourassembly stage. Do the following:

a. Select your assembly stage (for example, Test) in the Publishing View.

b. Click Insert > Server from the menu.

c. In the Insert Server dialog box, enter the TCP/IP hostname for your server(for example, yourHost) in the Server name field. An default server addresswould be provided (for example, http://yourHost), update the address in theServer address field if necessary.

d. A server icon (for example, http://yourHost), will be added in the PublishingView.

5. Select the Server icon of your target server in the Publishing View; for example,yourHost. Click Edit > Properties from the menu.

6. Select the method that you want to use to publish the files to your server.WebSphere Studio allows you to publish your files to the Web server using FTPor File System copy. For example, if you are publishing to a remote Web server,you might want to use FTP to move your files. If your Web server is a localmachine, you can move your files using File system copy.

To publish the files using FTP, do the following:

Chapter 10. Building a Java servlet to run an IMS transaction 147

a. In the Publishing tab of the Properties window of the server, select theFTP publish radio button.

b. Provide the FTP logon information for the Web server environment.

c. Provide the firewall information, if applicable.

To publish the files using File System copy, do the following:

a. In the Publishing tab of the Properties window of the server, select theFile system publish radio button.

b. Select the operating system on which the Application Server is running.

7. WebSphere Studio allows you to define publishing targets so that you can mapyour files in WebSphere Studio to specific directories on your Web server. Thepublishing targets specify directories on the Web server machine in which youwant to place your individual files. To setup the publishing targets, do thefollowing:

a. In the Publishing tab of the Properties window of the server, click on theTargets button.

b. Define a publishing target for the web application’s document root. Thisdirectory will contain the project’s HTML, JSP and other resource files. Bydefault, WebSphere Studio provides you with an html publishing target. Allof the files in the root directory of your WebSphere Studio project arepublished to the Web server directory specified for the html publishingtarget. You must provide the appropriate directory path for this publishingtarget. For example, <WAS_Install_Dir>\hosts\default_host\imsconn\web.

c. Define a publishing target for the web application’s servlets and Javaresources. This directory will contain the project’s Java .class files and.servlet files and/or JAR files. By default, WebSphere Studio provides youwith a servlet publishing target. All of the files in the servlet directory of yourWebSphere Studio project are published to the Web server directoryspecified for the servlet publishing target. You must provide the appropriatedirectory path for this publishing target. For example,<WAS_Install_Dir>\hosts\default_host\imsconn\servlets.

d. Click OK.

8. When publishing your servlet as a Web application, do the following:

a. Specify the Web Application Web Path in the Webapp web path field in thePublishing tab of the publishing server’s Properties window. For example,/webapp/imsconn.

b. Choose the publishing target you defined for the web application’s documentroot directory. For example, html.

c. Click OK.

Publishing to WebSphere Application Server

This step helps you publish your Web application to WebSphere Application Serverusing WebSphere Studio.

Publish Your Java Servlet To Your Web Server

1. Make sure that all your files have been checked in to save all the latestchanges. To check in a file, select the desired file and from the Project menu,select Check In.

2. You can publish the entire project or individual servers:

148 IMS Connector for Java User’s Guide and Reference

v To publish the entire project, click the right mouse button on the desiredWebSphere Studio project and select Publish whole project. Verify thesetting in the Publishing Options window, and click OK to publish the files.

v To publish a particular server in the project, do the following:

a. Ensure that you are in the Publishing View. You can switch to thePublishing View by clicking View > Publishing on the menu, or byclicking the Publishing View icon on the toolbar. The Publishing View isshown in the right pane of WebSphere Studio.

b. Click the right mouse button on the Server icon of your target server andselect Publish this Server.

c. Verify the setting in the Publishing Options window. Click OK to publishthe files.

3. If you are using FTP as your publishing mechanism, enter the port, login, andpassword information and click OK.

Running Your Java Servlets in a WebSphere Application Server Environment

This section describes how to run a Java servlet using the WebSphere ApplicationServer. To run a Java servlet, do the following:

1. Start WebSphere Application Server (you must first start the Web server, andthen start WebSphere Application Server separately)

a. To start your Web server, do the following, for example, on an IBM HTTPserver:

1) Click Start > Settings > Control Panel. Click the Services icon.

2) Select IBM HTTP Server and click Start.

3) Click Close to close the window.

b. To start the WebSphere Application Server , do the following:

1) Click Start > Settings > Control Panel. Click the Services icon. SelectIBM WS AdminServer and click Start.

2) Click Close to close the window.

3) Click Start > Programs > IBM WebSphere > Application Server >Administrator’s Console.

4) Ensure that the Topology view is displayed.

5) To switch to the Topology view, choose View > Topology from themenu bar. Click the + sign to expand the view of the WebSphereAdministrative Domain node.

6) Click on the + sign again to expand the view of the node that has theTCP/IP host name of your Web server machine.

7) Right click on Default Server under the host node in the previous step,and select Start. A dialog box displaying ″Command ’DefaultServer.start’completed successfully″ will appear when the server has been started.Click OK on the dialog box.

2. Run your Java servlet on WebSphere Application Server:

a. From a Web browser, type the following URL and press enter:

1) http://<servername>/webapp/imsconn/yourServletHTMLInput.html, where<servername> is the name of your Web server (for example,Server1.stl.ibm.com) and yourServletHTMLInput.html is the name ofthe HTML that is generated by WebSphere Studio (for example,Ex01ServletHTMLInput.html).

2) Enter the required input data for the IMS transaction.

Chapter 10. Building a Java servlet to run an IMS transaction 149

3) When the Submit button on the input form is clicked, the Java servlet isinvoked, the IMS transaction is run, and the IMS transaction output datais returned to the Web browser.

150 IMS Connector for Java User’s Guide and Reference

Chapter 11. Building a Web application that uses one servletto run an IMS conversation

This section describes how to build a Web application with one servlet that usesIMS Connector for Java to run an IMS conversation. It includes descriptions of howto create record beans that represent the input and output messages of theiterations of the IMS conversation, how to build an EAB command for theconversation using the VisualAge for Java Command Editor, how to useWebSphere Studio to create a template for the Web application, then finally how tobuild the complete Web application and use it to run the IMS conversation. Thesesteps are similar to the steps for building a nonconversational application.

This example uses the conversational IMS transaction that is described in the “IMSINSTALL/IVP sample application.”

Two of the packages in the IMS Connector Samples feature pertain to this example.Java source similar to the Java source for the EAB command of this example canbe found in the com.ibm.connector.ims.sample.conv.phonebook package of theConnector IMS Samples project. Java source similar to the Java source of theservlet for this example is contained in thecom.ibm.connector.ims.sample.conv.phonebook.servlet package of theConnector IMS Samples project. These packages are added to your workspacewhen the IMS Connector Samples feature is added. See “Preparing your VisualAgefor Java environment” for instructions on installing the IMS Connector Samplesfeature if you have not already done so.

In addition, other Web application files such as the HTML and JSP files, JAR file,the SERVLET and CLASS files in their appropriate folder(s), and a theme foldercontaining Master.css can be found in<IBM_Connectors_install_dir>\imsconn\samples\servlet\convphonebook, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory on thedrive on which VisualAge for Java is installed.

By following the instructions in this section, you will create an application which isthe same as the corresponding sample, except that it uses different project andpackage names than are used in the sample since you can’t have duplicatepackage or project names within your VisualAge environment. As a result, you willbe able to check your work against the sample, helping you to resolve anydifficulties you encounter as you progress through the steps that follow.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

Creating Input and Output Record Beans for an IMS Conversation

An IMS conversation is made up of a series of connected interactions between aclient and, in the simplest case, a single IMS application program (transaction).More complex IMS conversations can be made up of multiple IMS applicationprograms (transactions). Each interaction in the conversation is referred to as aniteration of the conversation. The input and output messages for the iterations of aconversation are often different.

© Copyright IBM Corp. 1998, 2002 151

Java record beans for an IMS conversation are created by VisualAge for Java fromthe COBOL source file(s) that contain the data structures (01 commareas) for theinput and output messages of each iteration of the IMS conversation. These file(s)are provided to VisualAge for Java’s COBOL importer. For this example, datastructures for all the iterations of the conversation are found in the single IMSapplication program, dfsiva34.mem, which can be found in<IBM_Connectors_install_dir>\imsconn\samples\misc, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

For this particular IMS conversation, the iterations of the conversation consist of thefollowing:

v The first iteration of the conversation invokes the IMS application program withan input message, which will be referred to as MI1, and returns an outputmessage, which will be referred to as MO2. The input message, MI1, isrepresented by the COBOL 01 data structure INPUT-MSG. As is the case for allIMS conversational application programs, INPUT-MSG does not map thetransaction code of the input message. The output message, MO2, isrepresented by the COBOL 01 data structure OUTPUT-AREA.

v The second and subsequent (middle) iterations of the conversation invoke theIMS application program with an input message, which will be referred to as MI2,and return the same output message as the first iteration, MO2. The inputmessage, MI2, is completely represented by the COBOL 01 data structureINPUT-MSG. The output message, MO2, is represented by the COBOL 01 datastructure OUTPUT-AREA.

v The conversation is terminated by the IMS application program on receipt of an″END command″ input message. This message is sent in response to theend-user selecting the ″END command″ radio button. The servlet detects that theIMS application program has ended the conversation using the getConvEnded()method of the IMSInteractionSpec class. The servlet then displays the final JSPpage of the conversation.

Note: The process of understanding the input and output messages of the iterationsof an IMS conversation is key to developing your Web application. If the IMStransaction has MFS source, the MSG statements, along with the NXT= keywords,can sometimes aid in this process.

The steps to build record beans representing the input and output messagespresented above include the following:

1. Start the Workbench in the VisualAge for Java IDE

2. Create a Project and Package for the IMS Conversational Input and OutputRecord Beans and EAB Command

3. Create a COBOL Record Type Class for the Initial Input Message of the IMSConversation

4. Create a Transaction Input Record Bean for the Initial Input Message

5. Create a COBOL Record Type Class for the Second Input Message

6. Create a Record Bean for the Second Input Message

7. Create a COBOL Record Type Class for the Output Message

8. Create a Record Bean for the Output Message

Step 1: Start the Workbench in the VisualAge for Java IDE

For a description of how to start the Workbench in the VisualAge for Java IDE, seeStep 1A of “Building a Java application to run an IMS transaction.”

152 IMS Connector for Java User’s Guide and Reference

Step 2: Create a Project and Package for the IMS Conversational Input andOutput Record Beans and EAB Command

For a description of this step, see Step 1B of “Building a Java application to run anIMS transaction.” Use Examples for the project name and convcmds for thepackage name.

Step 3: Create a COBOL Record Type Class for the Initial Input Message ofthe IMS Conversation

This step parses the COBOL commarea that represents the initial input message forthe IMS conversation, and creates a COBOL Record Type class that encapsulatesthe information in the commarea. This class will be used in Step 4 (page 155):Create an Input Record Bean for the Initial Input Message below to build a Javabean that represents the input message. Do the following:

1. Ensure that the new package, convcmds, is selected. From the Selected menu,click Tools > Enterprise Access Builder > Import COBOL to Record Type...The Import COBOL to Record Type wizard appears.

2. On the Import COBOL to Record Type wizard, do the following:

v Enter the path and file name of the COBOL file that contains the commarearepresenting the IMS transaction input message (dfsiva34.mem), select theAn IMS Application Program radio button, then click Next. The next windowof the Import COBOL to Record Type wizard appears, and contains a list ofthe available level 01 commareas.

3. Select the commarea representing the IMS transaction input message from theAvailable level 01 commarea list (for example, INPUT-MSG)) and add it to theSelected commareas list by clicking the > button.

4. Select the Use BigDecimal check box. This will generate the COBOL type as aBigDecimal Java type.

5. Add a transaction code field to the COBOL Record Type.

During the first iteration of a conversation, IMS Transaction Manager (IMS TM)removes the transaction code from the input message and places it in a scratchpad area (SPA) accessible to the IMS application program. The SPA is alsoused by the IMS application program to save information between iterations ofthe conversation.

The IMS application program gets the contents of the SPA with a GU call, thengets the data portion of the initial input message with a GN call. The IMSapplication program does not see the transaction code in the I/O area that itgets using the GN call, since the transaction code has already been removedfrom the initial input message by IMS TM. Hence, in an IMS conversationalapplication program, there is no 01 data structure that directly maps to the inputmessage of the first iteration. For this reason, you must indicate to theEnterprise Access Builder tool the information it needs to build a COBOLRecord Type class, and subsequently a record bean, representing the completeinitial input message.

Use the following steps to complete the initial input message by adding atransaction code field:

a. Select the Add transaction code field check box.

b. Enter the name you would like to use for the transaction code in the Fieldname field (for example, IN__TRANCD).

This is the name of the field in the generated Java record bean, and hencethe name used in the corresponding ″get″ and ″set″ methods. In this case,

Chapter 11. Building a Web application that uses one servlet to run an IMS conversation 153

IN__TRANCD was selected to be consistent with the names of the ″get″and ″set″ methods that were generated for the fields in the COBOL 01 datastructure, INPUT-MSG).

c. Select the length of the transaction code for the Length field (for example,5).

The Enterprise Access Builder tool builds the record bean for the initial inputmessage by placing the transaction code immediately following the ZZ field.A transaction code has a maximum length of 8 (EBCDIC) single-bytecharacters. If the length of the transaction code is less than 8 characters,the Enterprise Access Builder tool separates the transaction code from theinput message data by a single (EBCDIC) blank character. For example, ifthe transaction code is ″IVTCB″, you specify 5 for the Length field and thetool creates a record bean of the form:

LLZZIVTCBbData..., where

v b represents a single blank (EBCDIC) character, and

v Data... represents the portion of the initial input message represented bythe 01 COBOL data structure (e.g., INPUT-MSG), following the definitionsfor the LL and ZZ fields.

If the length of the transaction code is equal to 8 characters, the EnterpriseAccess Builder tool does not separate the transaction code from the inputmessage data. For example, if the transaction code is ″CARLOANS″, youspecify 8 for the Length field and the tool creates a record bean of the form:

LLZZCARLOANSData...

d. Enter the value of the transaction code in the Value field (for example,IVTCB).

This is optional, since you may choose to provide the value of thetransaction code at runtime, as is done in this example. Click Next.

6. Ensure that the correct names appear in the Project Name and Package entryfields.

7. Enter a name for the new class that will represent the COBOL Record Type. Forexample, MI1Type.

8. To continue to generate the record bean from this record type, ensure that boththe Continue working with newly created record type... check box and theCreate record from record type radio button are selected.

9. Click Finish. A new class named MI1Type appears in the package namedconvcmds in the IDE Workbench.

The following fragment of COBOL source code is the 01 commarea used togenerate the COBOL Record Type class for the initial input message of theconversation:01 INPUT-MSG.

02 IN-LL PICTURE S9(3) COMP.02 IN-ZZ PICTURE S9(3) COMP.02 IN-FILL PICTURE X(4).02 IN-COMMAND PICTURE X(8).02 TEMP-COMMAND REDEFINES IN-COMMAND.

04 TEMP-IOCMD PIC X(3).04 TEMP-FILLER PIC X(5).

02 IN-LAST-NAME PICTURE X(10).02 IN-FIRST-NAME PICTURE X(10).02 IN-EXTENSION PICTURE X(10).02 IN-ZIP-CODE PICTURE X(7).

154 IMS Connector for Java User’s Guide and Reference

Step 4: Create an Input Record Bean for the Initial Input Message

This step creates a record bean that represents the initial input message of the IMSconversation from the COBOL Record Type class created in Step 3 (page 153):Create a COBOL Record Type Class for the Initial Input Message of the IMSConversation above. Do the following:

1. If both the Continue working with newly created record type... check boxand the Create record from record type radio button are selected in Step 3(page 153): Create a COBOL Record Type Class for the Initial Input Message ofthe IMS Conversation, the Create Record from Record Type wizard appears.To manually start the Create Record from Record Type wizard, ensure thatthe COBOL Record Type class, MI1Type, is selected. From the Selected menu,click Tools > Enterprise Access Builder > Create Record from RecordType... The Create Record from Record Type wizard appears.

2. On the Create Record from Record Type wizard, enter the following:

v Ensure that the correct names appear in the Project Name and Packageentry fields.

v Enter a name for the new class that will represent the input message. Forexample, MI1.

v Click Access Method: Direct.

v Click Record Style: Custom Records.

v In this example, under Additional Options, Generate with Notification, UseInner Classes, and Shorten Names are not checked. Although it issometimes necessary or desirable to use one or more of these options whencreating record beans, these options are not selected in this example. Toimprove performance, deselect Generate with Notification and Use InnerClasses.

3. Click Next to view the next Create Record from Record Type wizard. Ensurethat this wizard shows the following values, which indicate that the IMStransaction input message is processed on an MVS host machine:

v Floating Point Format is IBM.

v Endian is Big Endian.

v Remote Integer Endian is Big Endian.

v Code Page is 037.

v Machine Type is MVS.

4. Click Finish on the Create Record from Record Type wizard. Two new classes,called MI1BeanInfo and MI1, appear in the package convcmds in the IDEWorkbench. The MI1 Java bean represents the initial input message of the IMSconversation.

Notes:

Code page refers to the data of the IMS transaction. If your transaction data isother than U.S. English (code page 037), you must enter a different code pagein this field.

Step 5: Create a COBOL Record Type Class for the Second Input Message

This step creates a COBOL Record Type for the input message of the second andsubsequent iterations of the conversation. It is created from the 01 COBOL data

Chapter 11. Building a Web application that uses one servlet to run an IMS conversation 155

structure, INPUT-MSG. For a description of how to create a COBOL Record Typeclass from the COBOL source for an IMS input message, see Step 1C of “Buildinga Java application to run an IMS transaction.” For this example, specify MI2Type forthe name of the COBOL Record Type class.

In this case, the input message (MI2) is completely represented by the 01 COBOLdata structure, INPUT-MSG. On the Import COBOL to Record Type wizard, youcan select either the An IMS Application Program radio button or the GenericCOBOL code radio button and you do not select the Add transaction code fieldcheck box.

The following fragment of COBOL source code is the 01 commarea used togenerate the COBOL Record Type class for the second input message of theconversation:

01 INPUT-MSG.02 IN-LL PICTURE S9(3) COMP.02 IN-ZZ PICTURE S9(3) COMP.02 IN-FILL PICTURE X(4).02 IN-COMMAND PICTURE X(8).02 TEMP-COMMAND REDEFINES IN-COMMAND.

04 TEMP-IOCMD PIC X(3).04 TEMP-FILLER PIC X(5).

02 IN-LAST-NAME PICTURE X(10).02 IN-FIRST-NAME PICTURE X(10).02 IN-EXTENSION PICTURE X(10).02 IN-ZIP-CODE PICTURE X(7).

Step 6: Create a Record Bean for the Second Input Message

This step creates a Record Bean representing the input message of the second andsubsequent iterations of the conversation. For a description of how to create arecord bean from the COBOL Record Type class, see Step 1D of “Building a Javaapplication to run an IMS transaction.” For this example, specify MI2 for the nameof the record bean. An additional class MI2BeanInfo will also be created.

Step 7: Create a COBOL Record Type Class for the Output Message

This step creates a COBOL Record Type for the output message of the first,second, (and subsequent) iterations of the conversation. It is created from the 01COBOL data structure, OUTPUT-AREA. For a description of how to create aCOBOL Record Type class from the COBOL source for an IMS output message,see Step 1E of “Building a Java application to run an IMS transaction.” For thisexample, specify MO2Type for the name of the COBOL Record Type class.

In this case, on the Import COBOL to Record Type wizard, you can select eitherthe An IMS Application Program radio button or the Generic COBOL code radiobutton, but do not select the Add transaction code field check box.

The following fragment of COBOL source code is the 01 commarea used togenerate the COBOL Record Type class for the output message of theconversation:01 OUTPUT-AREA.

02 OUT-LL PICTURE S9(3) COMP VALUE +95.02 OUT-ZZ PICTURE S9(3) COMP VALUE +0.02 OUTPUT-LINE PICTURE X(85) VALUE SPACES.02 OUTPUT-DATA REDEFINES OUTPUT-LINE.

156 IMS Connector for Java User’s Guide and Reference

04 OUT-MESSAGE PIC X(40).04 OUT-COMMAND PIC X(8).04 OUT-DATA-TYPE.

06 OUT-LAST-NAME PIC X(10).06 OUT-FIRST-NAME PIC X(10).06 OUT-EXTENSION PIC X(10).06 OUT-ZIP-CODE PIC X(7).

02 OUT-SEGMENT-NO PICTURE X(4) VALUE ’0001’.02 OUT-FILL PICTURE X(2).

Step 8: Create a Record Bean for the Output Message

This step creates a Record Bean representing the output message of the first,second, (and subsequent) iterations of the conversation. For a description of how tocreate a record bean from the COBOL Record Type class, see Step 1F of “Buildinga Java application to run an IMS transaction.” For this example, specify MO2 for thename of the record bean. An additional class MO2BeanInfo will also be created.

Building an EAB Command for the IMS Conversation

This section describes how you create the Enterprise Access Builder (EAB)command for this example’s IMS conversation using the VisualAge for JavaCommand Editor. The Command Editor guides you through the steps ofconstructing a command, allowing you to focus on the specific composition patternsof a command.

The Web application for this example is modeled using a single EAB command. ForIMS conversations, which consist of multiple interactions with an IMS applicationprogram, there may be multiple ways in which you could model your Webapplication. Possible models are:

v A single EAB command is used to represent the entire conversation.

A single EAB command bean can be used for all the iterations of an IMSconversation. Input and output record beans are created to represent allpossible input and output messages for all possible iterations of theconversation. Two approaches for associating these beans with the singleEAB command are presented below. The approach that you choose to usemay vary depending on the nature of your IMS conversation. In both cases theJava servlet determines the appropriate input bean to be used for a particulariteration of the conversation at runtime. It uses the setInput() method of theEAB command to dynamically associate the input record bean with the EABcommand at runtime.

1. Output record beans are associated with the EAB command atdevelopment time. The EAB command includes output beans for allpossible iterations of the conversation. After the input record bean hasbeen associated with the EAB command at runtime using the setInput()method, the execute() method of the EAB command is called to interactwith the IMS conversational application program, and one of the outputrecord beans provided at development time is returned. These steps arerepeated by the servlet for the duration of the conversation .

2. The output of the EAB command is represented as a single class thatreturns a byte array. Output record beans, separate from the EABcommand, are created for the all the possible iterations of theconversation. After the input record bean has been associated with theEAB command at runtime using the setInput() method, the execute()

Chapter 11. Building a Web application that uses one servlet to run an IMS conversation 157

method of the EAB command is called to interact with the IMSconversational application program, and the output of the iteration isreturned in the byte array. The servlet determines which of the outputrecord beans to populate with the bytes returned in the array. Thisdetermination could be made using, for example, the value of themapname returned in the IMSInteractionSpec of the EAB command. Thesesteps are repeated by the servlet for the duration of the conversation.

v Multiple EAB commands are used, each representing a separate iteration of theconversation.

In this scenario, a different EAB command is invoked for each iteration of theconversation. Each EAB command has input and output record beansrepresenting the input and output messages of the particular iteration itrepresents. The input and output record beans are set during development ofthe EAB command.

v A combination of the above.

The steps for creating the EAB command for this example are presented below.The EAB command is created in the same project and package as the input andoutput record beans described above.

1. Create an EAB Command Class for the IMS Conversation

2. Promote the Connection Specification Properties

3. Promote the Interaction Specification Properties

4. Promote the Output Record Bean Properties

5. Create the Command Bean

Step 1: Create an EAB Command Class for the IMS Conversation

For a description of how to create a command class, see Step 2A of “Building aJava application to run an IMS transaction.” For this particular example, the EABcommand should be created as follows:

v Use ConversationalCommand for the name of the EAB command class

v Add com.ibm.connector.imstoc.IMSConnectionSpec to the EAB command class

v Add com.ibm.connector.imstoc.IMSInteractionSpec to the EAB command class

v Add output bean convcmds.MO2 to the EAB command class

v Add output bean com.ibm.connector.imstoc.DFSMsg to the EAB command class

v Do not add an input bean to the EAB command class

Step 2: Promote the Connection Specification Properties

For a description of how to promote connection specification properties, see Step2F of “Building a Java application to run an IMS transaction.” For this particularexample, promote the following properties:

v Port

v Host name

Step 3: Promote the Interaction Specification Properties

For a description of how to promote interaction specification properties, see Step 2Eof “Building a Java application to run an IMS transaction.” For this particularexample, promote the following properties:

v Datastore name

158 IMS Connector for Java User’s Guide and Reference

v Conversation ended

Step 4: Promote the Output Record Bean Properties

For a description of how to promote output message bean properties, see Step 2Cof “Building a Java application to run an IMS transaction.” For this particularexample, promote the following properties:

v OUT__FIRST__NAME

v OUT__MESSAGE

v OUT__LAST__NAME

v OUT__EXTENSION

v OUT__ZIP__CODE

Step 5: Create the Command Bean

For a description of how to create the command bean, see Step 2G of “Building aJava application to run an IMS transaction.”

Note: For this example, the getDFSMessage() method ofcom.ibm.connector.imstoc.DFSMsg is added to the EAB command class(ConversationalCommand). For a description of adding this method see Step 2D of“Building a Java application to run an IMS transaction.”

Creating a Conversational Web application

After the EAB command bean has been built, it is exported in the form of a JARfile. The JAR file is used by WebSphere Studio to generate a template for the Webapplication, and at runtime for access to the classes of the EAB command.WebSphere Studio generates a Web application consisting of a single servlet, asingle input HTML page, a single output JSP page, and an error page. The Webapplication built by WebSphere Studio is used as a template from which to build thecomplete conversational Web application. The Web application needs to beextended significantly in order to comply with IMS Connector for Java’sConversational HttpSession programming model. This example, as well as thesample in the com.ibm.connector.ims.sample.conv.phonebook.servlet packageof the Connector IMS Samples project, are built using WebSphere Studio 3.0.2.However, a similar procedure is used for later releases of WebSphere Studio.

The following sections summarize the steps involved in developing theconversational Web application. The reader may wish to examine the files of thecorresponding sample while developing their own Web application.

Step 1: Use WebSphere Studio to Create a Web Application Template

This step is summarized in the following steps. For a detailed description of thesesteps see “Building a Java servlet to run an IMS transaction.”

1. Use VisualAge for Java to create a JAR file for the EAB command. For adescription of how to create a JAR file for an EAB command, see Step 2:Provide Your EAB Command to WebSphere Studio of “Building a Java servlet torun an IMS transaction.” When creating the JAR file, mark the classConversationalCommand as a bean.

2. In WebSphere Studio, create a project for your Web application, for exampleconvphoneserv.

Chapter 11. Building a Web application that uses one servlet to run an IMS conversation 159

3. Insert the above JAR file in the servlet folder of your project and start theJavaBean Wizard.

4. In the JavaBean Wizard, choose to create an input page, a results page, andan error page.

5. On the Input Page of the JavaBean Wizard select fields hostName,portNumber, and dataStoreName. Additional fields will be added to the inputHTML page in a later step, as well as more appropriate captions.

6. On the Results Page of the JavaBean Wizard select fields OUT__EXTENSION,OUT__FIRST__NAME, OUT__LAST__NAME, OUT__MESSAGE, andOUT__ZIP. Additional fields will be added to the output JSP page in a laterstep, as well as more appropriate captions.

7. On the Methods page of the JavaBean Wizard select the execute() method.

8. On the Session page of the JavaBean Wizard, in answer to Will you use thisbean or query on more than one page?, select the Yes, store it in the user’ssession() radio button.

9. On the Finish page of the JavaBean Wizard select the Rename... button andchoose ConvIterations as the prefix for the generated file names.

The following files are generated by WebSphere Studio and are used as a templatefor the Web application:

v ConvIterationsInput.html

v ConvIterations.java

v ConvIterationsResults.jsp

v ConvIterationsError.jsp

v ConvIterations.servlet

v Master.css, in a folder called Theme

The above Web application template must be modified extensively in order tocreate a conversational Web application. Files must be modified and new JSPpages must be added. The modified conversational Web application will consist ofthe following:

v ConvIterationsInput.html

This page will be modified to allow the user to provide the data for the inputmessage of the first iteration of the conversation, MI1.

v ConvIterationsResults.jsp

This page will be modified to display the output message of the first andsubsequent iterations of the conversation. In addition, it will be modified to allowthe user to provide the data for the input message of subsequent iterations of theconversation, MI2.

v ConvIterations.java

The Java source for the servlet will be modified, to implement the ConversationalHttpSession programming model, to be invoked by two types of request objects,and to display a page with the results of an iteration (ConvIterationsResults.jsp),a DFS message page (ConvDFSMessage.jsp), or a page for the end of theconversation (ConvEndConversation.jsp).

v ConvDFSMessage.jsp

This page will be added to the Web application. It will display any ″DFS″messages returned by IMS while the IMS conversation is running.

v ConvEndConversation.jsp

160 IMS Connector for Java User’s Guide and Reference

This page will be added to the Web application. It will display a separate pageindicating that the IMS conversation has ended.

v ConvIterationsError.jsp

This is the error page generated by WebSphere Studio. No changes are made tothis file.

v ConvIterations.servlet

This file, the servlet configuration file, will be modified to allow thecallPageNamed() method to be used to display the JSP pages described above.

v Master.css, in a folder called Theme

This is the style sheet generated by WebSphere Studio. No changes are made tothis file.

Step 2: Modify the Initial Input HTML Page, ConvIterationsInput.html

The basic structure of this page remains the same. Input fields are added for thefields of the initial input message of the IMS conversation, MI1. These fields werenot available in WebSphere Studio, since the input message is associated with theEAB command at runtime using the setInput() method. The fields added areIN__FIRST__NAME, IN__LAST__NAME, IN__EXTENSION, IN__ZIP__CODE, andIN__COMMAND. Radio buttons are used to provide a value for theIN__COMMAND field.

Template fields hostName, portNumber, and dataStoreName are kept, but newcaptions and positioning are provided. In addition, fields userID, password, andgroup are added. These 6 fields will only be provided for input on the initial HTMLpage.

A hidden field is used to indicate which page type invokes the conversationalservlet. For ConvIterationsInput.html the hidden field is indicated as follows:<input type=“hidden” name=“pageName” value=“StartPage”>

See the file ConvIterationsInput.html in<IBM_Connectors_install_dir>\imsconn\samples\servlet\convphonebook for anillustration of the modifications described in this step.

Step 3: Modify the Results JSP Page, ConvIterationsResults.jsp

The basic structure of this page must be changed from an output JSP page to acombination of an output JSP page, to display the data of the output message of aniteration (MO2), and a data input form, to accept the data for the input message ofthe next iteration (MI2). The changes are as follows:

v Change the page into a data input form by adding a <FORM></FORM> elementand Submit and Reset buttons. The <FORM> statement should invoke theconversational servlet as follows:<FORM METHOD=“post” ACTION=“/servlet/convphoneserv.ConvIterations”>

v Change the output fields to input/output fields by adding the <INPUT> tag. Thevalue of the IN__COMMAND field is input via radio buttons in the same manneras for the initial input HTML page.

v Add a hidden field to indicate which page type invokes the conversational servlet.For ConvIterationsResults.jsp the hidden field is indicated as follows:<input type=“hidden” name=“pageName” value=“MiddlePage”>

Step 4: Modify the Java Servlet, ConvIterations.java

Chapter 11. Building a Web application that uses one servlet to run an IMS conversation 161

The Java servlet generated by WebSphere Studio’s Javabean wizard contains thebasic logic to run an IMS transaction, but it must be modified as described below inorder to implement the Conversational HttpSession programming model andprocess the conversation using a single EAB command. The changes are asfollows:

v Add additional import statements to the ConvIterations class. See theConvIterations class in thecom.ibm.connector.ims.sample.conv.phonebook.servlet package of theConnector IMS Samples project for an example of the additional importstatements needed.

v Modify the performTask() method of the ConvIterations class as follows:

1. Ensure that the servlet uses a single global instance of Connection Manager.

In general, there should be a single global instance of ConnectionManagerper JVM. This example uses the RegisterConnectionManager servlet inpackage com.ibm.connector.ims.sample.cm of the Connector IMS Samplesproject. The RegisterConnectionManager servlet must be run prior to runningthis servlet, preferably when the application server is started. TheRegisterConnectionManager servlet sets the servlet context with an instanceof class com.ibm.connector.connectionmanager.ConnectionManager. Thisservlet gets that instance from the servlet context and uses it to set theservlet’s runtime context.

2. Obtain the HttpSession object.

An IMS conversation is made of a series of iterations that spans multiplerequests of the servlet. The IMS Connector for Java ConversationalHttpSession programming model uses the same HTTP session for all theiterations of a conversation. Since HTTP is a stateless protocol, it does notsave any information between one iteration and the next. However, theHttpSession object associated with the HTTP session can be used to savedata associated with the conversation between iterations of the conversation.This ensures that the execution context is set up correctly for subsequentrequests and that corresponding resources, such as the connection resource,are used appropriately.

The following shows how to obtain the HttpSession object:

// Get the HttpSession object...HttpSession httpSession = request.getSession(true);

3. Set up for the first iteration of the conversation.

a. Create a new IMSConvContext object for the new conversation and saveit in the HttpSession object for subsequent iterations. In addition, save itin the runtime context. By providing the IMSConvContext object as thesession ID for the current runtime context, you ensure that theappropriate connection is used for the current iteration of theconversation.

b. Create a cleanup helper object to be used in case the HTTP sessionbecomes unbound. Save the IMSConvContext object in the cleanuphelper object, then save the cleanup helper object in the HttpSessionobject. Sample code is:

IMSConvUnboundHttpSessionCleanup cleanupHelper =new IMSConvUnboundHttpSessionCleanup();

cleanupHelper.setConvContext( convContext );httpSession.putValue(“CleanupHelper”, cleanupHelper );

c. Instantiate the conversational EAB command bean,ConversationalCommand, and store it in the HttpSession object so it canbe accessed by called pages.

162 IMS Connector for Java User’s Guide and Reference

d. Populate an MI1 object with data from the request object passed to theservlet and use the setInput() method to associate it with the EABcommand. Most fields are populated using the getParameter() method ofthe servlet.

e. Set the EAB command’s hostName, port, and datastore properties fromthe request object and save in the HttpSession object for use in lateriterations of the conversation.

f. Set the EAB command’s userID, password, and group properties from therequest object.

4. Set up for the middle iterations of the conversation.

a. Get the existing IMSConvContext object for the conversation from theHttpSession object and save it in the runtime context.

b. Instantiate the conversational EAB command bean,ConversationalCommand, and store it in the HttpSession object so it canbe accessed by called pages.

c. Populate an MI2 object with data from the request object passed to theservlet and use the setInput() method to associate it with the EABcommand. Most fields are populated using the getParameter() method ofthe servlet.

5. Execute the EAB command. This statement is generated by WebSphereStudio.

6. Retrieve the output of the EAB command and determine the type of objectreturned. Use callPageNamed() to load the appropriate output JSP page todisplay the data.

– ConvEndConversation.jsp

The getConvEnded() method is used to determine if the IMS applicationprogram has ended the conversation. After displaying the JSP page withthe appropriate information, the HTTP Session is invalidated, and theruntime context is closed and removed from the thread.

– ConvIterationsResults.jsp

This JSP page is used to display the output of the iteration of theconversation and, at the same time, allow the user to enter new data tocontinue the conversation.

– ConvDFSMessage.jsp

When a DFS message is returned by IMS in response to a request, itmost likely indicates that the request did not complete successfully. Forexample, a DFS message is returned when the IMS application programabends. The servlet should include the appropriate logic for handling DFSmessages, and display a message to the user in the Web browser. At aminimum, the servlet should also invalidate the HTTP session, in order tofree up the connection for reuse by another request.

Note that this JSP page invokes the getDFSMessage() method on theConversationalCommand instance that was saved in the HttpSessionobject by the ConvIterations servlet. You must save the EAB commandbean (the instance of ConversationalCommand) in the HttpSession objectif you wish to use it in other than the servlet in which it was instantiated.

7. End the servlet.

Note that the code for the sample conversational servlet diverges from thetemplate generated by WebSphere Studio. Change your servlet as follows:

Chapter 11. Building a Web application that uses one servlet to run an IMS conversation 163

a. Do not close the runtime context. The close() method clears the sessionid (IMSConvContext) associated with the connection and this is neededfor the duration of the conversation.

Running the IMS Conversation

You can run the IMS conversation by running your Web application in WebSphereApplication Server or in the VisualAge for Java WebSphere Test Environment.

v For instructions on deploying and running the ConvIterations servlet inWebSphere Application Server, see “Preparing your WebSphere ApplicationServer environment for Windows” or “Preparing your WebSphere ApplicationServer Environment for z/OS and OS/390.”

v For instructions on deploying and running a Web application in VisualAge forJava, refer to Using the WebSphere Test Environment under Tasks, andWebSphere Test Environment under Concepts in VisualAge for Java’s Helppages.

In both cases, for successful execution of the Web application, ensure that theservlet com.ibm.connector.ims.sample.cm.RegisterConnectionManager is run priorto running the Web application.

If you are running the RegisterConnectionManager servlet in WebSphereApplication Server, you need to export its class file from VisualAge for Java to theappropriate WebSphere Application Server directory, then invoke it from a browseras follows:http://<servername>/servlet/com.ibm.connector.ims.sample.cm.RegisterConnectionManager

164 IMS Connector for Java User’s Guide and Reference

Chapter 12. Building a Web application that uses two servletsto run an IMS conversation

This section describes how to build a Web application with two servlets that usesIMS Connector for Java to run an IMS conversation. It illustrates an alternate wayof implementing the Conversational HttpSession programming model described inBuilding a Web application that uses one servlet to run an IMS conversation. It usesthe same IMS application program but the Web application differs in that it uses twoservlets instead of one and each servlet executes a separate EAB command. TheIMS application program the Web application runs is described in the IMSINSTALL/IVP sample application.

Two of the packages in the IMS Connector Samples feature pertain to this example.Java source similar to the Java source for the EAB commands of this example canbe found in the com.ibm.connector.ims.sample.conv.registration package of theConnector IMS Samples project. Java source similar to the Java source of theservlets for this example is contained in thecom.ibm.connector.ims.sample.conv.registration.servlet package of theConnector IMS Samples project. These packages are added to your workspacewhen the IMS Connector Samples feature is added. See Preparing your VisualAgefor Java environment for instructions on installing the IMS Connector Samplesfeature if you have not already done so.

In addition, other Web application files such as the HTML and JSP files, JAR files,the SERVLET and CLASS files in their appropriate folder(s), and a theme foldercontaining Master.css can be found in<IBM_Connectors_install_dir>\imsconn\samples\servlet\registration, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory on thedrive on which VisualAge for Java is installed.

By following the instructions in this section, you will create an application which isthe same as the corresponding sample, except that it uses different project andpackage names than are used in the sample since you can’t have duplicatepackage or project names within your VisualAge environment. As a result, you willbe able to check your work against the sample, helping you to resolve anydifficulties you encounter as you progress through the steps that follow.

Note: The examples in this section are for Windows platforms. For information onother platforms, see the IMS Connector for Java Web page located in the IMS Website at www.ibm.com/ims.

Creating Input and Output Record Beans for an IMS Conversation

Java record beans for an IMS conversation are created by VisualAge for Java fromthe COBOL source file(s) that contain the data structures (01 commareas) for theinput and output messages of each iteration of the IMS conversation. These file(s)are provided to VisualAge for Java’s COBOL importer.

For this example, data structures for all the iterations of the conversation are foundin the single IMS application program, dfsiva34.mem, which can be found in<IBM_Connectors_install_dir>\imsconn\samples\misc, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

© Copyright IBM Corp. 1998, 2002 165

For the IMS conversation of this sample, the iterations of the conversation are thesame as those described in Building a Web application that uses one servlet to runan IMS conversation: Creating Input and Output Record Beans for an IMSConversation. The record beans representing the input and output messages usedby this Web application and steps to build them are described in this section, aswell. However, you may wish to create a different package for the record beans andEAB commands of this Web application; for example, convcmds2.

Building EAB Commands for the IMS Conversation

This section describes how you create the two Enterprise Access Builder (EAB)commands for this example’s IMS conversation. For a description of the differentways in which you could model your Web application, see Building a Webapplication that uses one servlet to run an IMS conversation: Building an EABcommand for the IMS conversation.

The Web application for this example is modeled using two EAB commands:

v The first EAB command, ConversationalCommand1, models the first iteration ofthe IMS conversation. It consists of a record bean for the initial input message,MI1, a record bean for the output message, MO2, an IMSConnectionSpec object,and an IMSInteractionSpec object. This EAB command is executed by the firstservlet, ConvIterations1.

v The second EAB command, ConversationalCommand2, models subsequent(middle) iterations of the IMS conversation. It consists of a record bean for theinput message, MI2, a record bean for the output message, MO2, anIMSConnectionSpec object, and an IMSInteractionSpec object. This EABcommand is executed by the second servlet, ConvIterations2.

The steps for creating the EAB commands for this example are presented below.The EAB command is created in the same project and package as the input andoutput record beans described above.

1. Create an EAB Command Class for the IMS Conversation

2. Promote the Connection Specification Properties

3. Promote the Interaction Specification Properties

4. Promote the Input Record Bean Properties

5. Promote the Output Record Bean Properties

6. Create the Command Bean

Step 1: Create an EAB Command Class for the IMS Conversation

For a description of how to create a command class, see Building a Javaapplication to run an IMS transaction: Step 2A.

For this particular example, the first EAB command should be created as follows:

v Use ConversationalCommand1 for the name of the EAB command class

v Add com.ibm.connector.imstoc.IMSConnectionSpec to the EAB command class

v Add com.ibm.connector.imstoc.IMSInteractionSpec to the EAB command class

v Add input bean convcmds2.MI1 to the EAB command class

v Add output bean convcmds2.MO2 to the EAB command class

v Add output bean com.ibm.connector.imstoc.DFSMsg to the EAB command class

166 IMS Connector for Java User’s Guide and Reference

For this particular example, the second EAB command should be created asfollows:

v Use ConversationalCommand2 for the name of the EAB command class

v Add com.ibm.connector.imstoc.IMSConnectionSpec to the EAB command class

v Add com.ibm.connector.imstoc.IMSInteractionSpec to the EAB command class

v Add input bean convcmds2.MI2 to the EAB command class

v Add output bean convcmds2.MO2 to the EAB command class

v Add output bean com.ibm.connector.imstoc.DFSMsg to the EAB command class

Step 2: Promote the Connection Specification Properties

For a description of how to promote connection specification properties, seeBuilding a Java application to run an IMS transaction: Step 2F. For this particularexample, promote the following properties for IMSConnectionSpec in each EABcommand:

v Port

v Host name

Step 3: Promote the Interaction Specification Properties

For a description of how to promote interaction specification properties, see Buildinga Java application to run an IMS transaction: Step 2E. For this particular example,promote the following properties for IMSInteractionSpec in each EAB command:

v Datastore name

v Conversation ended

Step 4: Promote the Input Record Bean Properties

For a description of how to promote input message bean properties, see Building aJava application to run an IMS transaction: Step 2B.

For this particular example, for MI1 of ConversationalCommand1, promote thefollowing properties:

v IN__LL

v IN__FIRST__NAME

v IN__EXTENSION

v IN__LAST__NAME

v IN__ZIP__CODE

v IN__COMMAND

v IN__TRANCD

v IN__ZZ

For this particular example, for MI2 of ConversationalCommand2, promote thefollowing properties:

v IN__LL

v IN__FIRST__NAME

v IN__EXTENSION

v IN__LAST__NAME

v IN__ZIP__CODE

v IN__COMMAND

Chapter 12. Building a Web application that uses two servlets to run an IMS conversation 167

v IN__ZZ

Step 5: Promote the Output Record Bean Properties

For a description of how to promote output message bean properties, see Buildinga Java application to run an IMS transaction: Step 2C.

For this particular example, for MO2 of ConversationalCommand1 andConversationalCommand2, promote the following properties:

v OUT__FIRST__NAME

v OUT__MESSAGE

v OUT__LAST__NAME

v OUT__EXTENSION

v OUT__ZIP__CODE

Step 6: Create the Command Bean

For a description of how to create the command bean, see Building a Javaapplication to run an IMS transaction: Step 2G.

Note: For this example, the getDFSMessage() method ofcom.ibm.connector.imstoc.DFSMsg is added to the EAB command classes(ConversationalCommand1 and ConversationalCommand2). For a description ofadding this method see Building a Java application to run an IMS transaction: Step2D.

Creating a Conversational Web application

After the EAB command beans are built, they are exported in the form of a JAR file.The JAR file is used by WebSphere Studio to generate a template for the Webapplication, and at runtime for access to the classes of the EAB command.

Use VisualAge for Java to create the JAR file. For a description of how to create aJAR file for an EAB command, see Building a Java servlet to run an IMStransaction: Step 2: Provide Your EAB Command to WebSphere Studio. Whencreating the JAR file for this example, mark the classes ConversationalCommand1and ConversationalCommand2 as a beans.

The following sections summarize the steps involved in developing theconversational Web application. The reader may wish to examine the servlets inpackage com.ibm.connector.ims.sample.conv.registration.servlet of theConnector IMS Samples project while developing their own Web application.

Step 1: Use WebSphere Studio to Create a Web Application Template

WebSphere Studio does not create an exact template for this two-servlet example.However, you can create a Web application template that approximates the oneneeded for the final Web application by using the following process:

v In WebSphere Studio, create a project for your Web application, for exampleconvphonereg.

v Insert the JAR file described above in the servlet folder of your project and startthe JavaBean Wizard.

168 IMS Connector for Java User’s Guide and Reference

The next step involves making two passes through WebSphere Studio’s JavaBeanWizard. For the first pass:

v On the first page of the JavaBean Wizard, select ConversationalCommand1.

v Choose to create an input page, a results page, and an error page.

v On the Input Page of the JavaBean Wizard select fields hostName, portNumber,dataStoreName, IN__FIRST__NAME, IN__EXTENSION, IN__LAST__NAME,IN__ZIP__CODE, IN__COMMAND. Additional fields and more appropriatecaptions are added to the output JSP page later.

v On the Results Page of the JavaBean Wizard select fields OUT__EXTENSION,OUT__FIRST__NAME, OUT__LAST__NAME, OUT__MESSAGE, andOUT__ZIP. Additional fields and more appropriate captions are added to theoutput JSP page later.

v On the Methods page of the JavaBean Wizard select the execute() method.

v On the Session page of the JavaBean Wizard, in answer to Will you use thisbean or query on more than one page?, select the Yes, store it in the user’ssession() radio button.

v On the Finish page of the JavaBean Wizard select the Rename... button andchoose ConvIterations1 as the prefix for the generated file names.

For the second pass:

– On the first page of the JavaBean Wizard, select ConversationalCommand2.

– Choose to create an input page, a results page, and an error page.

– On the Input Page of the JavaBean Wizard select fields hostName,portNumber, dataStoreName, IN__FIRST__NAME, IN__EXTENSION,IN__LAST__NAME, IN__ZIP__CODE, IN__COMMAND. Additional fields andmore appropriate captions are added to the output JSP page later.

– On the Results Page of the JavaBean Wizard select fieldsOUT__EXTENSION, OUT__FIRST__NAME, OUT__LAST__NAME,OUT__MESSAGE, and OUT__ZIP. Additional fields and more appropriatecaptions are added to the output JSP page later.

– On the Methods page of the JavaBean Wizard select the execute() method.

– On the Session page of the JavaBean Wizard, in answer to Will you use thisbean or query on more than one page?, select the Yes, store it in the user’ssession() radio button.

– On the Finish page of the JavaBean Wizard select the Rename... button andchoose ConvIterations2 as the prefix for the generated file names.

The following files are generated by WebSphere Studio and are used as atemplate for the Web application:

- ConvIterations1Input.html

- ConvIterations1.java

- ConvIterations1Results.jsp

- ConvIterations1Error.jsp

- ConvIterations1.servlet

- ConvIterations2Input.html

- ConvIterations2.java

- ConvIterations2Results.jsp

- ConvIterations2Error.jsp

- ConvIterations2.servlet

- Master.css, in a folder called Theme

Chapter 12. Building a Web application that uses two servlets to run an IMS conversation 169

Step 2: Modify the Web Application Template

The Web application template must be modified extensively in order to create aconversational Web application. Files must be modified and new JSP pages mustbe added. The following summarizes the modified and new files of the two-servletconversational Web application:

v ConvIterations1Input.html

This page is modified to allow the user to provide the data for the input messageof the first iteration of the conversation, MI1. It invokes the first servlet,ConvIterations1.

Fields hostName, portNumber, dataStoreName, userID, password, and group arealso included and new captions and positioning are provided. These 6 fields areonly be provided for input on the initial HTML page.

v ConvIterations1Results.jsp

This page is modified to display the output message of the first iteration of theconversation. In addition, it is modified to allow the user to provide the data forthe input message of the next iteration of the conversation, MI2, and to invokethe second servlet, ConvIterations2.

The basic structure of this page is changed from an output JSP page to acombination of an output JSP page, to display the data of the output message ofthe first iteration (MO2), and a data input form, to accept the data for the inputmessage of the next iteration (MI2). See Building a Web application that usesone servlet to run an IMS conversation: Step 3: Modify the Results JSP Page,ConvIterationsResults.jsp for a description of changing an output JSP page to adata input form.

v ConvIterations1.java

This servlet is modified, to implement the Conversational HttpSessionprogramming model, to be invoked by a request object containing data for thefirst iteration of the conversation, and to display a page with the results of thefirst iteration (ConvIterationsResults1.jsp), a DFS message page(ConvCmd1DFSMessage.jsp), or a page for the end of the conversation,(ConvEndConversation.jsp). See Building a Web application that uses one servletto run an IMS conversation: Step 4: Modify the Java Servlet,ConvIterations.javafor a description of the type of changes that need to be madeto the servlet. The ConvIterations1 servlet only processes the first iteration of theconversation.

v ConvIterations2.java

This servlet is modified, to implement the Conversational HttpSessionprogramming model, to be invoked by a request object containing data for middleiterations of the conversation, and to display a page with the results of middleiterations (ConvIterationsResults2.jsp), a DFS message page(ConvCmd2DFSMessage.jsp), or a page for the end of the conversation,(ConvEndConversation.jsp). See Building a Web application that uses one servletto run an IMS conversation: Step 4: Modify the Java Servlet, ConvIterations.javafor a description of the type of changes that need to be made to the servlet. TheConvIterations1 servlet only processes middle iterations of the conversation.

v ConvIterations2Results.jsp

This page will be modified to display the output message a middle iteration of theconversation. In addition, it will be modified to allow the user to provide the datafor the input message of the subsequent iterations of the conversation, MI2, andto invoke the second servlet, ConvIterations2.

The basic structure of this page is changed from an output JSP page to acombination of an output JSP page, to display the data of the output message of

170 IMS Connector for Java User’s Guide and Reference

a middle iteration (MO2), and a data input form, to accept the data for the inputmessage of the next iteration (MI2). See Building a Web application that usesone servlet to run an IMS conversation: Step 3: Modify the Results JSP Page,ConvIterationsResults.jsp for a description of changing an output JSP page to adata input form.

v ConvCmd1DFSMessage.jsp

This page is added to the Web application. It is used by the first servlet,ConvIterations1, to display any ″DFS″ messages returned by IMS while the IMSconversation is running.

v ConvCmd2DFSMessage.jsp

This page is added to the Web application. It is used by the second servlet,ConvIterations2, to display any ″DFS″ messages returned by IMS while the IMSconversation is running.

v ConvEndConversation.jsp

This page is added to the Web application. It displays a separate page indicatingthat the IMS conversation has ended.

v ConvIterationsError.jsp

This is the error page generated by WebSphere Studio. No changes are made tothis file.

v ConvIterations1.servlet

This file, the servlet configuration file for the first servlet, is modified to allow thecallPageNamed() method to be used to display the JSP pages described above.

v ConvIterations2.servlet

This file, the servlet configuration file for the second servlet, is modified to allowthe callPageNamed() method to be used to display the JSP pages describedabove.

v Master.css, in a folder called Theme

This is the style sheet generated by WebSphere Studio. No changes are made tothis file.

Running the IMS Conversation

You can run the IMS conversation by running your Web application in WebSphereApplication Server or in VisualAge for Java.

v For instructions on deploying and running the servlets ConvIterations1 andConvIterations2 in WebSphere Application Server, see Preparing yourWebSphere Application Server environment for Windows.

v For instructions on deploying and running a Web application in VisualAge forJava, refer to Using the WebSphere Test Environment under Tasks, andWebSphere Test Environment under Concepts in VisualAge for Java’s Helppages.

In both cases, for successful execution of the Web application, ensure that theservlet com.ibm.connector.ims.sample.cm.RegisterConnectionManager is run priorto running the Web application.

If you are running the RegisterConnectionManager servlet in WebSphereApplication Server, you need to export its class file from VisualAge for Java to theappropriate WebSphere Application Server directory, then invoke it from a browseras follows:http://<servername>/servlet/com.ibm.connector.ims.sample.cm.RegisterConnectionManager

Chapter 12. Building a Web application that uses two servlets to run an IMS conversation 171

172 IMS Connector for Java User’s Guide and Reference

Chapter 13. Building a J2C phonebook sample application

This section describes how to create and run a phonebook sample application. Thephonebook sample uses the J2C architecture to submit transactions to an IMSdatabase system. These transactions include the commands to display, add, delete,and update records in a dummy data set.

Important: Before you start building this sample, be sure to complete the stepsdescribed in “Preparing to deploy J2C samples” (in “Understanding IMS Connectorfor Java”) and “Preparing to use IMS Connector for Java.”

The following steps are involved in creating a J2C phonebook sample:

“Part 1: Building the J2C phonebook sample application”

1. Creating IMS transaction input and output beans (page 173)

2. Creating an EAB command class for the IMS transaction (page 177)

3. Creating a sample EJB session bean (page 179)

4. Creating and modifying methods to add business logic (page 181)

5. Adding the methods to the Remote EJB Interface (page 182)

6. Generating deployed code (page 183)

7. Generating an Access Bean (page 183)

8. Creating a servlet (page 184)

9. Testing the J2C phonebook sample within VisualAge for Java (page 185)

“Part 2: Assembling the J2C phonebook sample application” on page 188

“Part 2A: Assembling and deploying the J2C phonebook sample applicationfor Windows” on page 189

1. Assembling the application in Windows (page 189)

2. Deploying the application to WebSphere Application Server for Windows (page191)

3. Starting the newly installed application (page 191)

“Part 2B: Assembling and deploying the J2C phonebook sample applicationfor z/OS and OS/390” on page 192

1. Assembling the application in z/OS and OS/390 (page 192)

2. Deploying the application to WebSphere Application Server for z/OS andOS/390 (page 195)

3. Starting WebSphere Application Server for z/OS and OS/390 (page 196)

“Part 3: Running the J2C phonebook sample application” on page 196

Note: The instructions for developing the J2C phonebook sample in this section arefor the Windows and z/Os and OS/390 platform. The J2C phonebook sampleprovided in com.ibm.connector2.ims.ico.sample.phonebook can be run on AIX,Solaris, Windows, and on the z/OS and OS/390 platform.

Part 1: Building the J2C phonebook sample applicationStep 1: Creating IMS transaction input and output Beans

© Copyright IBM Corp. 1998, 2002 173

This section describes how to create IMS transaction input and output beans thatyou can use in an EAB command that runs an IMS transaction. The steps includethe following:

1. Starting the Workbench in the VisualAge for Java IDE

2. Creating a Project and Package for the Application

3. Creating a Transaction Input Record Bean

4. Creating a Transaction Output Record Bean

Step 1A: Starting the Workbench in the VisualAge for Java IDE

Click the Start icon and click Programs > IBM VisualAge for Java for Windows >IBM VisualAge for Java.

Step 1B: Creating a Project and Package for the Application

This step creates the project and package in which you will build your application. Ifthe desired project and package already exists on your Workbench, skip to the nextstep.

1. From the Selected menu, click Add > Project. The Add Project wizardappears. Enter a name for the new project (for example, Examples), and clickFinish.

2. To add a new package to this project, ensure that the correct project is selected.Then, from the Selected menu, click Add > Package. The Add Packagewizard appears. Click the Browse... button to specify the correct project name(for example, Examples) and select the Create a new package named: radiobutton. Enter a name for the new package (for example, icoex01). If you want toadd Group Members (users who can create and release classes into yourpackage), click Next. Otherwise, click Finish.

Step 1C: Creating a Transaction Input Record Bean

The COBOL source used in this step can be found in<IBM_Connectors_install_dir>\imsconn\samples\misc\Ex01.ccp, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

In this step, you must first create a COBOL Record Type class for the IMStransaction input message. This part of the step parses the COBOL commareathat represents the input message for the IMS transaction and creates a COBOLRecord Type class that encapsulates the information in the commarea.

Then you can create a record bean that represents the transaction input messagefrom the COBOL Record Type class you created. A record bean contains propertiesthat map to the fields in a record in a host program. In this case, the record in thehost program is the IMS transaction input message.

1. Ensure that the package created in Step 1B (page 174) above (for example,icoex01) is selected. From the Selected menu, click Tools > EnterpriseAccess Builder > Import COBOL to Record Type... Wait for the ImportCOBOL to Record Type wizard to appear.

2. On the Import COBOL to Record Type wizard, do the following:

v Click the Browse... button to locate and select the file name of the COBOLfile that contains the commarea representing the IMS transaction inputmessage. In this example, select the file Ex01.ccp in theC:\<IBM_Connectors_install_dir>\imsconn\samples\misc\ directory. ClickOpen.

174 IMS Connector for Java User’s Guide and Reference

v Ensure that the Generic COBOL code radio button (under the heading“Code to be imported is:”) is selected. Click Next.

v The next window of the Import COBOL to Record Type wizard contains alist of the available level 01 commareas found in the Ex01.ccp COBOL file.Select the commarea representing the IMS transaction input message (forexample, INPUT_MSG) from the Available level 01 commarea list and click the >button to add it to the Selected commareas list. Ensure that the UseBigDecimal check box is selected. This will generate the COBOL type as aBigDecimal Java type. Click Next.

v Ensure that the correct names appear in the Project and Package entryfields.

v Enter a name for the new class that will represent the COBOL Record Type(for example, InMsgInfo).

v Ensure that both the Continue working with newly created record type...check box and the Create record from record type radio button areselected to continue to generate the record bean from this record type. ClickFinish. Wait for the Create Record from Record Type wizard to appear.

Note: You can manually start the Create Record from Record Type wizard.Ensure that the COBOL Record Type class, InMsgInfo, is selected. From theSelected menu, click Tools > Enterprise Access Builder > Create Recordfrom Record Type... Wait for the Create Record from Record Type wizardto appear.

3. Use the Create Record from Record Type wizard to create a transaction inputrecord bean. Do the following:

v Ensure that the correct names appear in the Project and Package entryfields.

v Enter a name for the new class that will represent the input message (forexample, InMsg).

v Select the Access Method: Direct radio button.

v Select the Record Style: Custom Records radio button.

v In the Additional Options section:

– Check the Generate as javax.resource.cci Record interface check box.Doing so will make the Record Bean compatible with the J2C architecture.

– Ensure that all other checkboxes are not selected.

v Click Next to view the next page of the Create Record from Record Typewizard. Ensure that the following values are set. Click the value field of anyproperty to change its value.

– Floating Point Format is IBM.

– Remote Integer Endian is Big Endian.

– Endian is Big Endian.

– Code Page is 037. The code page refers to the data of the IMStransaction. If your transaction data is something other than U.S. English(code page 037), you must enter a different code page in this field.

– Machine Type is MVS.

Ensure that all values on the Create Record from Record Type wizard havebeen accepted. That is, all of the field values should appear gray before youselect Finish.

4. Click Finish on the Create Record from Record Type wizard. The COBOLrecord type (for example, InMsgInfo), IMS transaction input message (forexample, InMsg), and the input message bean information (for example,

Chapter 13. Building a J2C phonebook sample application 175

InMsgBeanInfo) classes should now appear under the package you chose inStep 1B (page 174) (for example, icoex01) in the IDE Workbench.

Related Reading: For more information on additional options, see the VisualAge forJava Enterprise Access Builder documentation.

Step 1D: Creating a Transaction Output Record Bean

In this step, you will create a transaction output record bean using the processsimilar to that of the previous step. The COBOL source used in this step can befound in <IBM_Connectors_install_dir>\imsconn\samples\misc\Ex01.ccp, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

1. Ensure that the package created in Step 1B (page 174) above (for example,icoex01) is selected. From the Selected menu, click Tools > EnterpriseAccess Builder > Import COBOL to Record Type... Wait for the ImportCOBOL to Record Type wizard to appear.

2. On the Import COBOL to Record Type wizard, do the following:

v Click the Browse... button to locate and select the file name of the COBOLfile that contains the commarea representing the IMS transaction inputmessage. In this example, select the file Ex01.ccp in theC:\<IBM_Connectors_install_dir>\imsconn\samples\misc\ directory. ClickOpen.

v Ensure that the Generic COBOL code radio button (under the heading“Code to be imported is:” ) is selected, then click Next.

v The next window of the Import COBOL to Record Type wizard contains alist of the available level 01 commareas found in the Ex01.ccp COBOL file.Select the commarea representing the IMS transaction input message (forexample, OUTPUT_MSG) from the Available level 01 commarea list and click the> button to add it to the Selected commareas list. Ensure that the UseBigDecimal check box is selected. This will generate the COBOL type as aBigDecimal Java type. Click Next.

v Ensure that the correct names appear in the Project and Package entryfields.

v Enter a name for the new class that will represent the COBOL Record Type(for example, OutMsgInfo).

v Ensure that both the Continue working with newly created record type...check box and the Create record from record type radio button areselected to continue to generate the record bean from this record type. ClickFinish. Wait for the Create Record from Record Type wizard to appear.

3. Use the Create Record from Record Type wizard to create an transactionoutput record bean. Do the following:

v Ensure that the correct names appear in the Project and Package entryfields.

v Enter a name for the new class that will represent the input message (forexample, OutMsg).

v Select the Access Method: Direct radio button.

v Select the Record Style: Custom Records radio button.

v In the Additional Options section:

– Ensure that the Generate with Notification check box is not selected.

– Check the Generate as javax.resource.cci Record interface check box.Doing so will make the Record Bean compatible with the J2C architecture.

176 IMS Connector for Java User’s Guide and Reference

v Click Next to view the next page of the Create Record from Record Typewizard. Ensure that the following values are set. If necessary, click the valuefield of any property to change its value.

– Floating Point Format is IBM.

– Remote Integer Endian is Big Endian.

– Endian is Big Endian.

– Code Page is 037. The code page refers to the data of the IMStransaction. If your transaction data is other than U.S. English (code page037), you must enter a different code page in this field.

– Machine Type is MVS.

Ensure that all values on the Create Record from Record Type wizard havebeen accepted. That is, all of the field values should appear gray before youselect Finish.

4. Click Finish on the Create Record from Record Type wizard. The COBOLrecord type (for example, OutMsgInfo), IMS transaction output message (forexample, OutMsg), and the output message bean information (for example,OutMsgBeanInfo) classes should now appear under the package you created inStep 1B (page 174) in the IDE Workbench.

Step 2: Creating an EAB command class for the IMS transaction

This section describes how you can create an Enterprise Access Builder (EAB)command using the VisualAge for Java Command Editor. The Command Editorguides you through the steps of constructing a command, allowing you to focus onthe specific composition patterns of a command.

For a definition of the EAB command, see “IMS Connector for Java Concepts andTerms.”

The Java source for this example can be found in the packagecom.ibm.connector2.ims.ico.sample.phonebook in the VisualAge for JavaWorkBench.

1. Ensure that the package you created in Step 1B (page 174) (for example,icoex01) is selected. From the Selected menu, click Tools > EnterpriseAccess Builder > Create Command... Wait for the Create Command wizardto appear.

2. In the Create Command wizard, do the following:

a. Ensure that the correct names appear in the Project and Package entryfields.

b. Enter a name for the new class that represents the EAB command (forexample, Ex01Command).

c. Ensure that the Edit when finished check box is selected to edit theCommand class when it is created.

d. Under Connection Information, associate a connection specification with theEAB command. Click the Browse... button. All available ConnectionSpecclasses are shown. Choose ConnectionFactoryConfiguration with thepackage name com.ibm.ivj.eab.command and click OK.

e. Click Edit to edit the connection specification properties. Select the propertyname and specify the value as follows:

Chapter 13. Building a J2C phonebook sample application 177

connectionSpecThis property specifies the connection to the host system. Selectcom.ibm.connector2.ims.ico.IMSConnectionSpec from thepull-down menu.

contextFactoryNameThis property specifies the InitialContext class. JNDI performs allnaming operations relative to a context. Leave this property blank touse the default context factory.

logWriterThis property is the output data stream for logging and tracing.Specify null for this property

managedConnectionFactoryThis property sets the ManagedConnectionFactory object, which isused to manually create a ConnectionFactory object. When usedin a non-managed application (as in this sample), specify null forthis property.

res_ref_nameThis property specifies the binding name of the connection factoryobject. A binding is the association of a name with an object. TypeMyIMS.

res_typeThis property specifies the name of the connection factory. Selectjavax.resource.cci.ConnectionFactory from the pull-down menu.

f. Under InteractionSpec, associate an interaction specification with the EABcommand. Click the Browse... button. All available InteractionSpec classesare shown. Choose IMSInteractionSpec with the package namecom.ibm.connector2.ims.ico and click OK.

g. Click Next to use the Add Input/Output Beans wizard.

3. On the Add Input/Output Beans wizard, enter the following:

a. In the Input record bean section, ensure that the Implements IByteBufferand the javax.cci.record check boxes are selected. Next to theTransaction Input bean class name field, click the Browse... button todisplay a list of all available classes that implement IByteBuffer. Select theappropriate Type Name (InMsg) and Package Name (icoex01) and clickOK.

b. Provide the Mapper class, if necessary. In this example, no additionalMapper class is needed.

c. In the Output record bean section, ensure that Select output record beansis selected. Click the Add button. A dialog box appears to enter the outputrecord bean. In this dialog box, ensure that the Implements IByteBufferand javax.cci.record check boxes are selected. Next to the TransactionOutput bean class name field, click the Browse... button to display a list ofall available classes that implement IByteBuffer. Select the appropriate TypeName (OutMsg) and Package Name (icoex01) and click OK.

d. Repeat the previous step to add additional output record beans, ifnecessary. In this example, repeat the previous step to add the outputrecord bean with DFSMsg as Type Name and com.ibm.connector2.ims.icoas the Package Name. Provide the Mapper class, if necessary. In thisexample, the Mapper class is not necessary.

e. You can use Modify... or Delete to modify or delete the output record beansfrom the list.

178 IMS Connector for Java User’s Guide and Reference

4. Click Finish to generate the EAB command (for example, Ex01Command). If theEdit with finished check box is selected in Item 2, the new EAB commandappears in the Command Editor.

5. Use the Command Editor to promote the IMS Transaction Input Properties, theIMS Transaction Output Properties, and the DFS Message Property. CompleteStep 2B, Step 2C, and Step 2D in “Building a Java application to run an IMStransaction.” Follow Step 2D to promote the DFSDATA1 property.

You can use the Command Editor to create a new command, open existingcommands, add or delete beans and properties, and promote or changeproperties. To launch an existing command with the Command Editor, ensurethat the EAB command class is selected (for example, Ex01Command), then selectTools > Enterprise Access Builder > Edit Command...

Step 3: Creating a sample EJB session bean

The following describes how you can use the EAB Command you createdgenerated in Step 2 (page 177) to create a sample EJB session bean to run an IMStransaction. The EJB session bean in this example is a stateless EJB session bean.For information on the types of enterprise javabeans, see “IMS Connector for Javaconcepts and terms.”

1. If you have not previously added the IBM EJB Development Environment, IBMEnterprise Access Builder Library, IBM Enterprise Access Builder Samples, IMSConnector, IMS Connector Samples, or the IBM WebSphere Test Environmentto the Workbench, do the following (otherwise skip to the next step):

a. Select File > Quick Start. The Quick Start dialog opens.

b. Click on Features, choose Add Feature, and click OK.

c. From the list of features, select IBM Enterprise Access Builder Library,IBM Enterprise Access Builder Samples, IMS Connector, IMSConnector Samples, IBM EJB Development Environment, and IBMWebSphere Test Environment. Click OK.

For more details on adding the EJB Development Environment to the IDE,see the VisualAge for Java documentation by clicking Help > Help HomePage > Tasks > Developing EJB Components > Setting up the EJBDevelopment Environment > Loading the required features.

2. Create a new package for the EJB. Select the project in which the sample isbeing developed (for example, Examples). Select the Examples project. From theSelectedmenu, click Add > Package and wait for the Add Package SmartGuideto appear. Type in the name of the package to create (for example,icoex01ejb). If you want to add Group Members (users who can create andrelease classes into your package), click Next. Otherwise, click Finish.

3. Create the Session EJB to run an IMS transaction:

a. Click on the EJB tab on the Workbench to go to the EJB DevelopmentEnvironment.

b. EJBs are created within a EJB Group, so you must create the Group beforeyou can create an EJB. From the menu bar, select EJB > Add > EJBGroup.... Wait for the Add EJB Group SmartGuide to appear.

c. In the Add EJB Group SmartGuide, do the following:

1) Click Browse... and select the project in which the sample is beingdeveloped (for example, Examples). Click OK.

2) Ensure the radio button next to the Create a new EJB group namedfield is selected, and type the name of the group you wish to create (forexample, EJBExamples).

Chapter 13. Building a J2C phonebook sample application 179

3) Click Finish.

d. Select the newly created group (for example, EJBExamples) in the Enterprisebeans pane. From the main menu bar, select EJB > Open To > EABSession Bean Tool... to create the EJB. When prompted by the EABSession Bean dialog, ensure the Create a new EAB Session Bean radiobutton is selected and press OK. The Create EAB Session BeanSmartGuide appears.

e. In the Create EAB Session Bean section of the SmartGuide, do thefollowing:

1) Click on the Browse... button next to the Project entry field, and selectthe project in which the sample is being developed (for example,Examples). Click OK.

2) Click on the Browse... button beside the Package entry field, and selectthe package in which the sample is being developed (for example,icoex01ejb). Click OK.

3) In the Class name entry field, enter the name of the EJB to create ( forexample, Ex01Session).

4) Ensure the Edit when finished checkbox is not selected. (you canalways edit later)

5) Click on the Browse... button below the Connection information andbeside the Class name entry field.SelectConnectionFactoryConfiguration in thecom.ibm.ivj.eab.command package and click OK.

6) Click on the Edit... button to add the connection information. In theproperty window, select the property name and specify values asfollows:

connectionSpecThis property specifies the connection to the host system. Selectcom.ibm.connector2.ims.ico.IMSConnectionSpec from thepull-down menu.

contextFactoryNameThis property specifies the InitialContext class. JNDI performs allnaming operations relative to a context. To assist in finding aplace to start, the JNDI specification defines an InitialContextclass. This class is instantiated with properties that define thetype of naming service in use. Specifycom.ibm.websphere.naming.WsnInitialContextFactory forthis property.

logWriterThis property is the output data stream for logging and tracing.Specify null for this property

managedConnectionFactoryThis property sets the ManagedConnectionFactory object, whichis used to manually create a ConnectionFactory object. Whenused in a non-managed application (as in this sample), specifynull for this property.

res_ref_nameThis property specifies the binding name of the connectionfactory object. A binding is the association of a name with anobject. Type MyIMS.

180 IMS Connector for Java User’s Guide and Reference

res_typeThis property specifies the name of the connection factory.Select javax.resource.cci.ConnectionFactory from thepull-down menu.

7) Click Next. The Add Methods section of the SmartGuide appears.

f. Add methods to help your application interact with an IMS transaction. In theAdd Methods section, do the following to add a method to the EAB SessionBean:

1) Click Add.... Wait for the method information SmartGuide to appear.

2) In the Method name field, type the name of the method you are adding(for example, executeCmd).

3) Click the Use existing command: button. Click on the Browse... buttonand select the class (Ex01Command) and the package (for example,icoex01). Click OK.

4) Click OK.

5) Click Finish.

g. Ensure that the EJB remote interface (for example, Ex01Session), EJBsession bean (for example, Ex01SessionBean), and EJB home interface (forexample, Ex01SessionHome) have been added to the EJB group.

h. Right click your newly created EJB (for example, Ex01Session) under theEJB Group (for example, EJBExamples) in the Enterprise Beans panel.Select Properties from the menu. Click the Bean tab and specify the JNDIname for the BeanHome (for example, Ex01Session). You can also modifyother properties (for example, the transaction properties) of the EJB in theProperties window. Click OK.

Step 4: Creating and modifying methods to add business logic

Now you are ready to create your business methods (add, delete, display, update,and execute), using code provided in the phonebook sample found incom.ibm.connector2.ims.ico.sample.phonebook.ejb.

1. Click the Projects tab in the VisualAge for Java Workbench.

2. Select the EJB session bean class created in Step 3 (page 179) (for example,Ex01SessionBean).

3. Add an import statement to make the package created in Step 2 accessible tothe EJB. For example, insert the following line of code at the top of the textdisplayed in the source pane:import icoex01.*;

4. Save your changes by clicking Edit > Save.

5. Click the EJB tab in the VisualAge for Java Workbench.

6. In the Enterprise Beans window, expand your EJB Group (for example,EJBExamples) by clicking the + sign next to it. Then select the EJB you createdin Step 3 (page 179) (in this example, Ex01Session). In the Types pane, selectenterprise bean class (in this example, Ex01SessionBean). Click Types > Add >Method. Wait for the Create Method SmartGuide to appear.

7. In the Create Method SmartGuide, do the following:

a. Select the Create a new method radio button.

b. In the field provided, enter the following:public IByteBuffer execute(String lastName,String firstName,String zip,Stringext,String cmd) throws java.rmi.RemoteException

c. Click Finish.

Chapter 13. Building a J2C phonebook sample application 181

8. In the Source pane, replace the return null; line of code with the following:InMsg input = new InMsg();input.setIN__LL((short) 59);input.setIN__ZZ((short) 0);input.setIN__TRCD(“IVTNO”);input.setIN__NAME1(lastName);input.setIN__NAME2(firstName);input.setIN__ZIP(zip);input.setIN__EXTN(ext);input.setIN__CMD(cmd);IByteBuffer output=executeCmd(input);return output;

9. Click Edit > Save.

10. Click Types > Add > Method. Wait for the Create Method SmartGuide toappear.

11. In the Create Method SmartGuide, do the following:

a. Select the Create a new method radio button.

b. In the field provided type the following:

public IByteBuffer display(String lastName,StringfirstName,String zip,String ext) throwsjava.rmi.RemoteException

c. Click Finish.

12. In the Source pane, replace the return null; line of code with the following:IByteBuffer output = this.execute(lastName, firstName, zip, ext, “DISPLAY”);return output;

13. Click Edit > Save.

14. Repeat steps 9-12 to create additional methods. For this example, create themethods add, delete, and update. For each new method replace the methodname in Step 10b (for example, display) with the new method’s name (forexample, add, delete, or update). Be sure to replace the command sent tothe execute method (for example, “DISPLAY”) with the appropriate commandfor the method you are creating (for example, “ADD”, “DELETE”, or“UPDATE”). A servlet will use the four business methods (add, delete,display, and update) to access the sample phonebook. Note that the executemethod is only used internally and will not be added to the remote interface.

15. Ensure that there are no compilations or other errors (indicated by a red Xnext to the method or class name). If errors occur, compare the newlygenerated code with that found in the Ex01Session bean found under theIMSEJBSamples EJB group in the EJB development environment.

Step 5: Adding the methods to the EJB Remote Interface

Generating the EJB automatically builds an empty Remote Interface and a HomeInterface with a default create method. You should now add the four businessmethods you just created (display, update, add, and delete) to the Remote Interfacefor client accessibility.

1. In the VisualAge for Java workbench, click the EJB tab.

2. In the Enterprise Beans pane, expand the EJB Group (for example,EJBExamples) you created (by clicking the + sign next to it). Click on the sessionEJB (for example, Ex01Session) to select it.

3. In the Types pane, select the session bean you created (for example,Ex01SessionBean).

4. In the Members pane, select the display(String, String, String, String) method.

182 IMS Connector for Java User’s Guide and Reference

5. Click Members > Add To > EJB Remote Interface.

6. Repeat the previous step for the remaining business methods add, update, anddelete.

Step 6: Generating deployed code

To run the sample within the IDE, you must first generate the deployed code for theEJB Server which runs inside VisualAge for Java.

1. In the Enterprise Beans pane, select the session EJB (for example,Ex01Session) found in the EJB group created in Step 3 (page 179) (forexample, EJBExamples).

2. Click EJB > Generate Deployed Code.

3. An Information window should appear indicating the current phase of codegeneration. Wait for this window this close. This may take a moment.

You have successfully created the EJB needed for your phonebook sample.

Step 7: Generating an Access Bean

This step provides instructions on how to create a java bean wrapper type AccessBean. This simplifies access to the Home and Remote interfaces of your enterprisebean and allows a standard java bean approach to using your EJB.

The java bean wrapper type Access Bean is a java bean which contains a no-argconstructor and a lazy initialization technique which will instantiate your enterprisebean at the first call to one of its remote methods. This type of Access Bean isbuilt with a default JNDI name that provides to you the option to ignore the JNDIlookup process in a WebSphere run-time environment. Additionally, each accessbean class retains some class-level cache to improve performance wheninstantiating an enterprise bean. If multiple instances of an access bean use thesame home (for example, the same JNDI name and rootContext), the access beanclass only looks up the corresponding enterprise bean home once.

Related Reading: For more information on Access Beans and their various uses,go to the VisualAge for Java Help by clicking Help > Help Home Page > Concepts> EJB Development Environment > Access beans.

To create an Access bean for a particular enterprise bean, do the following:

1. In your VisualAge for Java Workbench, click the EJB tab to go to the EJBdevelopment environment.

2. In the Enterprise Beans pane, click on the session EJB (for example,Ex01Session) found within the EJB group created in Step 3 (for example,EJBExamples).

3. Click EJB > Add > Access Bean from the menu.

4. Wait for the Create Access Bean SmartGuide to appear.

5. Verify that the following the set of information displayed in the ″Select AccessBean Properties″ matches that of your specific EJB Group and enterprisebean. The following is an example:

EJB GroupEJBExamples

Enterprise beanEx01Session

Chapter 13. Building a J2C phonebook sample application 183

Access bean nameEx01SessionAccessBean

Access bean typeJava Bean Wrapper

6. Click Finish.

7. Wait for an informational message indicating that the code generation hascompleted. Click OK.

The access bean (for example, Ex01SessionAccessBean) has been generated inthe package with which the specific EJB is associated.

Re-generating an Access Bean

In many cases, an enterprise bean needs to be modified after it has been deployedand the Access Bean has been generated. This situation may require theredeployment of the EJB and the regeneration of the Access Bean.

For more information on when an enterprise bean should be redeployed go to theVisual Age documentation by clicking Help > Help Home Page > Tasks >Developing EJB Components > Setting Descriptor > Generating EJB DeployedClasses.

The redeployment of the EJB and the regeneration of the Access Bean follows thesame steps as those used to deploy an enterprise bean or to generate an AccessBean.

In some situations, an error will be produced indicating that the Access Bean doesnot match the current edition of the EJB. To fix this problem, right-click the EJB(for example Ex01SessionBean) found within a specific EJB group (for exampleEJBExamples) and click Verify.

Step 8: Creating a servlet

In this section a servlet will be created to access the EJB business methods.

1. Create a new package to contain the servlet (for example, icoex01servlet). Toadd a new package to a project:

a. Ensure that the correct project is selected (for example, Examples).

b. From the Selected menu, click Add > Package.

c. The Add Package wizard appears.

d. Click the Browse... button to specify the correct project name (for example,Examples).

e. Select the Create a new package named: radio button.

f. Enter a name for the new package (for example, icoex01servlet).

g. If you want to add Group Members (users who can create and releaseclasses into your package), click Next. Otherwise, click Finish.

2. Copy the servlet from the com.ibm.connector2.ims.ico.sample.phonebook.servletpackage.

a. Select the Ex01Servlet class under thecom.ibm.connector2.ims.ico.sample.phonebook.servlet package within the“Connector IMS Samples” project.

b. From the Selected menu, click Reorganize > Copy.

c. Wait for the Copying types window to appear.

184 IMS Connector for Java User’s Guide and Reference

d. Click the Browse... button to specify the package that the servlet code willbe copied to (for example, icoex01servlet).

e. If you wish to rename the servlet, select the Rename the copy check box.This example assumes that the servlet name (for example, Ex01Servlet)remains the same.

f. If a warning message occurs indicating that there may be problemsmanaging resource files, click OK.

g. The Ex01Servlet is now be copied to the specified servlet package (forexample, icoex01servlet).

3. Replace the following two import statements (displayed in the Source pane)import com.ibm.connector2.ims.ico.sample.phonebook.*;import com.ibm.connector2.ims.ico.sample.phonebook.ejb.*;

with import statements that access your EAB command and EJB. For example:import icoex01.*;import icoex01ejb.*;

4. From the Edit menu, click Save. This completes the generation of the servletcode.

Step 9: Testing the J2C phonebook sample within VisualAge for Java

Now you can test the servlet, EJB, and EAB command within VisualAge for Java.By testing the sample, you will ensure that it can:

v Connect to the host system

v Send and retrieve data to and from the supplied host

v Run without throwing an exception

When testing is complete, you can stop the test servers.

1. Copy the VisualAge for Java HTML and JSP files associated with the JNDIutility and phonebook example to the WebSphere test environment.

a. Locate the HTML file associated with the JNDI utility in the directory wherethe IBM Connectors for VisualAge for Java were installed (for example,C:\IBM Connectors\imscon\samples\J2C\util\vaj\JNDIDeployerInput.html).Copy this file.

b. Navigate to the VisualAge for Java WebSphere Test Environment web folder(for example, C:\Program Files\IBM\VisualAge forJava\ide\project_resources\IBM WebSphere TestEnvironment\hosts\default_host\default_app\web) and paste the HTML fileinto this directory.

c. Locate the HTML and JSP files associated with the J2C Phonebook Samplefor VAJ in the directory where the IBM Connectors for VisualAge for Javawere installed (for example, C:\IBMConnectors\imsconn\samples\J2C\phonebook\vaj\).

d. Copy all of the HTML and JSP files in this directory. For example, copy thefiles Ex01ServletInput.html, Ex01ServletError.jsp, andEx01ServletResults.jsp, and Ex01DFSMsg.jsp.

e. Navigate to the VisualAge for Java WebSphere Test Environment web folder(for example, C:\Program Files\IBM\VisualAge forJava\ide\project_resources\IBM WebSphere TestEnvironment\hosts\default_host\default_app\web) and paste the HTML andJSP files to this directory.

Chapter 13. Building a J2C phonebook sample application 185

2. Modify the phonebook example HTML and JSP files to access the newpackages.

a. Open each of the HTML and JSP files associated with the phonebookservlet that were copied to the WebSphere Test Environment web folder inthe previous step (for example, Ex01ServletInput.html, Ex01ServletError.jsp,and Ex01ServletResults.jsp).

b. Replace the text referring to thecom.ibm.connector2.ims.ico.sample.phonebook.servlet package with anicoex01servlet package equivalent (for example, replace the textcom.ibm.connector2.ims.ico.sample.phonebook.servlet.Ex01Servlet foundwithin the Ex01ServletInput.html with icoex01servlet.Ex01Servlet).Replace the text referring to thecom.ibm.connector2.ims.ico.sample.phonebook package with an icoex01package equivalent (for example, replace the textcom.ibm.connector2.ims.ico.sample.phonebook.OutMsg found in theEx01ServletResults.jsp with icoex01.OutMsg).

c. Save the modified HTML and JSP files and close any applications that referto them and any applications you used to edit them.

3. Start the WebSphere Test Environment within VisualAge for Java.

a. Start the VisualAge for Java Workbench by clicking the Start > Programs >IBM VisualAge for Java for Windows > IBM VisualAge for Java.

b. From the Workspace menu, select Tools > WebSphere Test Environment.

c. Wait for the WebSphere Test Environment Control Center window to appear.

4. Start the Servlet Engine.

a. In the Servlet Engine pane ensure that all check boxes are not selected.

b. Click the Edit Class Path... button.

c. In the Servlet Engine Class Path window click the Select All button.

d. Click OK to return to the Control Center.

e. Click the Start Servlet Engine button.

f. Wait for the status message in the lower left hand corner of the WebSphereTest Environment Control Center window to indicate that the Servlet Engineis started.

5. Start the Persistent Name Server.

a. Click the Persistent Name Server displayed under the Servers heading onthe left.

b. Click the Start Name Server button.

c. Wait for the status message in the lower left hand corner of the WebSphereTest Environment Control Center window to indicate that the PersistentName Server is started.

6. Add the EJB Group to the Server Configuration.

a. Click the EJB tab to go to the EJB Development Environment.

b. Click the new EJB Group (for example, EJBExamples).

c. In the EJB menu, click Add To > Server Configuration.

d. This should bring up the EJB Server Configuration window and highlightthe new EJB Server Configuration which contains the EJB Group you areusing (for example, EJBExamples).

7. Start the EJB Server by clicking Start Server in the Servers menu.

8. Set the JNDI Deployment properties from the browser.

186 IMS Connector for Java User’s Guide and Reference

a. Open a browser and enter the following Web address:http://localhost:8080/JNDIDeployerInput.html

b. In the browser, fill in the fields as follows:

ConnectionFactory JNDI NameThis should be the same ConnectionFactory JNDI Name specified inthe EAB Command (for example, MyIMS).

HostnameThe TCP/IP of the targeted IMS Connect.

Port NumberThe TCP/IP port number of the targeted IMS Connect.

DataStore NameThe name of the Datastore for the targeted IMS.

Enable Connection PoolingA flag set to enable or disable connection pooling in the targetedIMS Connect.

Log WriterThe output stream for logging and tracing.

Trace LevelThe level of information to be traced.

User nameThe SAF user name to be passed to OTMA. For example, theRACF user name. User name can be optional, depending on howyou specify IMS OTMA and IMS Connect security.

PasswordThe SAF password to be passed to OTMA. For example, the RACFpassword. Password can be optional, depending on how you specifyIMS OTMA and IMS Connect security.

Group The SAF group to be passed to OTMA. For example, the RACFgroup. Group can be optional, depending on how you specify IMSOTMA and IMS Connect security.

c. Click the Submit button.

d. Wait for the ConnectionFactory added to the JNDI context message toappear in the browser.

9. Access the phonebook example from a browser and add a new entry to thedatabase.

a. Open a browser and enter the Web address:http://localhost:8080/Ex01ServletInput.html

b. Fill in the provided fields.

c. Click the Add radio button.

d. Click the Submit button.

e. Wait for the results page to appear with the “Entry has been added”message.

Chapter 13. Building a J2C phonebook sample application 187

Part 2: Assembling the J2C phonebook sample applicationNow you are ready to assemble the application. In this step, you will build an EJBmodule and a Web module to comprise your application. You will create andpackage these modules into your EAR file, which is your phonebook application.The instructions in this step apply to both Windows and z/OS and OS/390platforms.

1. Export your EJB JAR file:

a. In VisualAge for Java, click the EJB tab and expand the EJB Groupcontaining your EJB (for example, EJBExamples).

b. Right-click the EJB (for example, Ex01Session) and select Export >Deployed JAR... The Export to an EJB JAR File SmartGuide appears:

c. Give your EJB JAR file a name (for example, Ex01SessionEJB.jar) in theJAR file field. Then click the Browse... button to select the directory inwhich you want to save this JAR file, then click Save. Make a note of thelocation of the JAR file because you will need to find it later. You will bereturned to the Export to an EJB JAR File SmartGuide.

d. Export only the beans and .class files by selecting the beans and .classcheckboxes. Do not export the .java files.

e. Click the .class... button. You will see the classes you have chosen toexport. In addition to those classes, select the following classes to export:

v Ex01Command

v InMsg

v OutMsg

You created these classes in “Part 1: Building the J2C phonebook sampleapplication” on page 173 above. Ensure that the classes you have selectedare from the appropriate package (for example, icoex01). Click OK.

f. Click Finish. The JAR file will be created automatically in the directoryspecified in step c above.

2. Export the servlet:

a. In VisualAge for Java, in the Projects window, select the class of the servletpackage (for example, class Ex01Servlet in package icoex01servlet),right-click it and select Export... Select the Directory radio button and clickNext.

b. In the Export to a directory SmartGuide, click the Browse... button next tothe Directory: field to select a destination directory for your servlet. Selectthe same directory that contains your exported EJB beans.

c. Select the .class checkbox and ensure that the .java checkbox is notselected.

d. Click Finish to export your servlet.

3. Export the support classes (all files related to the application) by highlightingboth the access bean class (for example, Ex01SessionAccessBean.class) andthe output transaction message class (for example, OutMsg.class). Thenright-click and select Export > .jar file and name the JAR filephonebooksupportclasses.jar.

4. If the target runtime environment for your application is WebSphere ApplicationServer for z/OS and OS/390, export all of the classes in the IBM EJB Toolsproject as follows:

a. Right click the IBM EJB Tools project in your VisualAge for Java Projectswindow and select Export...

188 IMS Connector for Java User’s Guide and Reference

b. Select the Jar file radio button and click Next.

c. In the Export to a jar file SmartGuide, provide a directory and a file name(for example, ejbtools.jar) for the JAR file and ensure that the .classcheckbox is selected.

d. Click Finish to export the classes to a JAR file.

5. Copy the HTML and JSP files with the modifications made in “Step 9: Testingthe J2C phonebook sample within VisualAge for Java” (page 185)(Ex01ServletError.jsp, Ex01DFSMsg.jsp, Ex01ServletInput.html, andEx01ServletResults.jsp) and paste them into the directory containing your JARfiles.

6. Modify the Ex01ServletInput.html file to replace the following line:<FORM METHOD=“post” ACTION=“/servlet/icoex01Servlet.Ex01Servlet”>

with the following line:<FORM METHOD=“post” ACTION=“/icoex01/Ex01Servlet”>

where /icoex01 is the context root that you will define for your Web module.

7. If you are planning to deploy and run your application in WebSphere ApplicationServer for Windows, go to “Part 2A: Assembling and deploying the J2Cphonebook sample application for Windows”. If you are planning to deploy andrun your application in WebSphere Application Server for z/OS and OS/390, goto “Part 2B: Assembling and deploying the J2C phonebook sample applicationfor z/OS and OS/390” on page 192.

Part 2A: Assembling and deploying the J2C phonebook sampleapplication for Windows

Step 1: Assembling the application in Windows

In this step, you assemble the EAR file containing your EJB and servlet which youwill run in the WebSphere Application Server for Windows environment. First, youassemble an EJB module that contains your EJB. Then assemble a Web modulethat consists of your servlet, HTML, and JSP files.

Related Reading: For information on EJB and Web modules, see the informationavailable in the IBM WebSphere Application Server Advanced Edition InformationCenter.

1. Create a J2EE application. In the Application Assembler Tool, click File > New >Application. Provide a name for the EAR file you are creating (for example,Ex01ServletApp) in the Display name: field and click Apply.

2. Create an EJB module:

a. In the Application Assembly Tool, right-click the EJB Modules folder andselect Import. In the window that appears, locate and select your JAR file.Click Open.

b. In the “Confirm values” box that opens, click OK.

c. Expand the EJB Modules folder by clicking the + next to it. Then expandthe Ex01SessionEJB folder, the Session Beans folder, and theEx01Session folder. Click Resource References and in the right pane clickthe General tab. Ensure that there is a resource reference entry with thename MyIMS.

3. Create a Web module:

Chapter 13. Building a J2C phonebook sample application 189

a. Right-click the Web Module folder and select New. In the File name: field,give your new WAR file the same file name as your EAR file (for example,Ex01Servlet.war). Enter /icoex01 in the Context root: field. Click OK.

b. Add class files, JAR files, and resource files to the new WAR file:

1) In the Application Assembler window of the AAT, expand your WAR filein the structure tree (by clicking the + sign next to it). Similarly, expandthe Files folder. You should now see three folders: Class Files, JarFiles, and Resource Files.

2) Right-click Class files and select Add files. Click the Browse... buttonto locate the root directory containing your servlet file (that you chose in“Part 2: Assembling the J2C phonebook sample application” onpage 188 above) and click Select. Select the root folder (for example,icoex01servlet), which contains the servlet class and click Add. Thenclick OK.

3) Right-click Jar files and select Add Files. Click the Browse... button tolocate the root directory containing your JAR file. Select thephonebooksupportclasses.jar and click Add. Then Click OK.

4) Right-click Resource files and select Add files. Click the Browse...button to locate the root directory containing your HTML and JSP files.Select your HTML and JSP files, then click Add. Click OK.

4. Add your servlet to the EAR file:

a. Right-click the Web Components folder and select New. A web componentis a servlet or JSP file that executes in a Web server.

b. The New Web Component window appears. Do the following:

1) In the Component name field, enter the name of the servlet (forexample, Ex01Servlet).

2) Enter the same name in the Display name field.

3) Under the Component type section, select the Servlet radio button.Click the Browse... button next to the Class name field to launch theSelect file for Class Name dialog to locate and select the servlet class.

4) In the Select file for Class Name dialog, select your servlet class file(for example, Ex01Servlet.class). Click OK. Your servlet has been addedto the EAR file.

5. Map the servlet to associate your servlet with a client request. Right-click theServlet Mapping folder and select New. In the URL pattern field, enter aforward slash and the name of your servlet (for example, /Ex01Servlet). In theServlet field, select the servlet component you just created (for example,Ex01Servlet) from the pull-down list.

6. Add the EJB Resource Reference:

a. Right-click the EJB References folder under your Web Module and selectNew from the menu. Enter a name for the EJB that your servlet willreference (for example, Ex01Session).

b. In the Link field, select the Ex01Session bean you have added in this EARfile from the pull-down menu.

c. Click the Bindings tab and enter the EJB JNDI name (for example,Ex01Session).

d. Click OK.

7. Save the EAR file by highlighting it and clicking File > Save. Specify thedirectory and name for this file (for example, Ex01Servlet.ear).

190 IMS Connector for Java User’s Guide and Reference

Step 2: Deploying the application to WebSphere Application Server forWindows

Now deploy the application you created to WebSphere Application Server.

1. Start the WebSphere Advanced Administrative Console:

a. First you must start the WebSphere Admin Server. Click Start > Programs> IBM WebSphere > Application Server V4.0AE > Start Admin Server.

b. Then start the Advanced Administrative Console. Click Start > Programs >IBM WebSphere > Application Server V4.0AE > Administrator’sConsole.

2. In the Advanced Administrative Console, select from the menu bar Console >Wizards > Install Enterprise Application. In the wizard that appears, do thefollowing:

a. In the Browse for file on node field, keep the default.

b. Select the Install Application (*.ear) radio button.

c. In the Path field, browse for the EAR file you just created (for example,Ex01Servlet.ear).

d. In the Application name field, enter a name for your application (forexample, Ex01ServletApp).

e. Click Next until you reach the “Mapping Resource References toResources” page of the wizard.

f. In the “Mapping Resource References to Resources” page, select theresource reference you want, then click the Resource Reference... buttonto choose the Connection Factory you created in “Step 2: Creating an EABcommand class for the IMS transaction” (page 177) (for example,“eis/MyIMS”).

g. Click Next until you reach the “Selecting Application Servers” page of thewizard.

h. In the “Selecting Application Servers” page, select the module containingyour application (for example, Ex01Servlet.war) to install it. Click the SelectServer button. Select an application server (for example, “Default Server”)and click OK. Then click Next.

i. The Completing the Application Installation wizard appears. Verify thatthe settings your provided are correct, then click Finish.

j. You might see the following message: “File not deployed. Do you want todeploy now?” Click Yes. Keep the default values in the Generate code fordevelopment window and click OK. When you see the message“Command ’EnterpriseApp.install’ completed successfully,” click OK.

Step 3: Starting the newly installed application

In the WebSphere Adminstrator’s Console, start your application server byright-clicking on your application server name (for example, Default Server) andselect Start from the menu. Then look in the Enterprise Applications folder tolocate the application you installed (for example, Ex01ServletApp). Highlight it,right-click it, and select Start from the menu. You should see a message statingthat the start command has completed successfully. Click OK.

When you have completed this step, go to “Part 3: Running the J2C phonebooksample application” on page 196.

Chapter 13. Building a J2C phonebook sample application 191

Part 2B: Assembling and deploying the J2C phonebook sampleapplication for z/OS and OS/390

Step 1: Assembling the application in z/OS and OS/390

In this step, you assemble the EAR file containing your EJB and servlet which youwill run in the WebSphere Application Server for z/OS and OS/390 environment.First, you assemble an EJB module that contains your EJB. Then assemble a Webmodule that consists of your servlet, HTML, and JSP files.

To assemble your application for deployment to WebSphere Application Server forz/OS and OS/390, the Application Assembly Tool for WebSphere for z/OS isrequired. See “Preparing to deploy J2C samples” for more information.

1. Start the Application Assembly Tool (AAT) for z/OS and OS/390 by clicking Start> Programs > IBM > WebSphere for z/OS > Application Assembly.

2. Create a new application. The Application Assembly Tool for z/OS and OS/390allows you to create a new EAR file or import an existing EAR that you createdusing other tools. For example, you can use the AAT for Windows to build yourJ2EE application EAR file and import this file into the AAT for z/OS and OS/390.

Recommendation: If you have AAT for Windows, you should complete “Part2A: Assembling and deploying the J2C phonebook sample application forWindows” on page 189 first to create an EAR file that contains your EJB andweb module, then continue this step. If you are using other tools to create anEAR file which you will import into AAT for z/OS and OS/390, ensure that youhave used the appropriate values as described in section “Part 2A: Assemblingand deploying the J2C phonebook sample application for Windows” onpage 189.

If you have an existing EAR file that contains your EJB and web module, do thefollowing:

a. Select the Application folder. Click Selected > Import... to import the EARfile.

b. In the Import dialog box, specify the path for the file (without the .earextension). Click Choose to select the path that contains your EAR file, thenclick OK. Your EAR file will be added under the Application folder.

c. Modify the display name as desired (for example, Ex01Servlet390App). Tomodify the display name, select the application you just imported and clickSelected > Modify. Ensure that the General tab is selected and enter avalue in the Display name field. Then click Selected > Save.

d. Skip to step 7 (page 194) below to continue assembling your application.

If you do not have an existing EAR file, create a new J2EE application:

a. Select the Application folder. Click Selected > Add.

b. Enter a Display name (for example, Ex01Servlet390App), then clickSelected > Save.

3. Create an EJB module by importing the EJB JAR file that you exported (forexample, Ex01SessionEJB.jar ) in “Part 2: Assembling the J2C phonebooksample application” on page 188 above into the J2EE application:

a. In the WebSphere for z/OS Application Assembly window for AAT, expandthe Applications folder in the structure tree (by clicking the plus sign (+) nextto it). Locate the new application you just created and expand it.

192 IMS Connector for Java User’s Guide and Reference

b. In the expanded structure tree, select the EJB Jars folder and clickSelected > Import. Click the Choose button, browse for the EJB JAR file(for example, Ex01SessionEJB.jar), then click OK.

c. Click OK.

4. Add the Resources Reference used by your EJB:

a. In the AAT, expand the EJB Jars folder by clicking the plus sign (+) next toit.

b. Expand the Session Beans folder and select your EJB (for example,Ex01Session).

c. Click the Resources tab in the right pane and click Selected > Modify...Click the Add... button to launch the Add Resource Reference dialog.

d. In the Add Resource Reference dialog, enter the following values in thefollowing fields:

v Reference Name: MyIMS

v Type: javax.resource.cci.ConnectionFactory

Note: You might want to change the values for the other fields. See theAAT for z/OS and OS/390 documentation for more information.

e. Click OK.

f. Click Selected > Save.

5. Create a Web module. The Web module for this sample consists of one webarchive (WAR) file that contains all of the HTML files, JSP files, and servletclass files associated with the EJB modules.

a. On your workstation, create a new directory (for example,c:\Ex01ServletWar) as the root directory for building your WAR file.

b. Create the following additional subdirectories under the root directory thatyou created in the previous step:c:\Ex01ServletWar\WEB-INF\lib\c:\Ex01ServletWar\WEB-INF\classes\

c. Create the web.xml file for your WAR file:

1) Using a text editor, create a file called web.xml in the WEB-INF foldercreated in the previous step (for example, C:\Ex01ServletWar\WEB-INF\web.xml). This web.xml will contain the deployment descriptorinformation for your web module.

2) Insert the following XML code into the web.xml file:<?xml version=“1.0” encoding=“UTF-8”?><!DOCTYPE web-app PUBLIC “-//Sun Microsystems,Inc.//DTD Web Application 2.2//EN” “http:<web-app><servlet><servlet-name>Ex01Servlet</servlet-name><display-name>Ex01Servlet</display-name><servlet-class>icoex01servlet.Ex01Servlet</servlet-class></servlet><servlet-mapping><servlet-name>Ex01Servlet</servlet-name><url-pattern>/Ex01Servlet</url-pattern></servlet-mapping><ejb-ref><ejb-ref-name>Ex01Session</ejb-ref-name><ejb-ref-type>Session</ejb-ref-type><home>icoex01.Ex01SessionHome</home><remote>icoex01.Ex01Session</remote><ejb-link>Ex01Session</ejb-link></ejb-ref></web-app>

3) Save the web.xml file.

Chapter 13. Building a J2C phonebook sample application 193

d. Copy the HTML and JSP files (for example, Ex01ServletInput.html,Ex01Servlet.jar) to the root directory for building your WAR file (for example,c:\Ex01ServletWar).

e. Copy the directory that contains the servlet class file (for example,icoex01servlet\Ex01Servlet.class) that you created in “Part 2: Assemblingthe J2C phonebook sample application” on page 188 to theWEB-INF\classes directory under the root directory for building your WARfile (for example, c:\Ex01ServletWar\WEB-INF\classes).

f. Copy the support classes JAR file (for example,phonebooksupportclasses.jar) that you created in “Part 2: Assembling theJ2C phonebook sample application” on page 188 to the WEB-INF\libdirectory under the root directory for building your WAR file (for example,C:\Ex01ServletWar \WEB-INF\lib).

g. Create the WAR file (for example, Ex01Servlet.war) using the JARcommand as follows:

1) Using a command prompt on your workstation, navigate to the rootdirectory you are using to build your WAR file (for example,C:\Ex01ServletWar\). You should see files similar to the following in thatdirectory:

v C:\Ex01ServletWar\Ex01ServletInput.html

v C:\Ex01ServletWar\Ex01ServletResults

v C:\Ex01ServletWar\Ex01ServletError.jsp

v C:\Ex01ServletWar\WEB-INF\web.xml

v C:\Ex01ServletWar\WEB-INF\classes\icoex01servlet\Ex01Servlet.class

v C:\Ex01ServletWar\WEB-INF\lib\phonebooksupportclasses.jar

2) Using a command prompt, create the WAR file with the nameEx01Servlet.war by issuing the JAR command in the root directory foryour WAR file (for example, c:\Ex01ServletWar), as follows:jar -cf Ex01Servlet.war *

The JAR command is available with your Java Development Kit (JDK).

3) Verify that the WAR file (for example, Ex01Servlet.war) is created in theroot directory (for example, c:\Ex01ServletWar).

h. Import the Web module into AAT for z/OS and OS/390:

1) In the WebSphere for z/OS Application Assembly window in the AAT,locate the J2EE application (for example, Ex01Servlet390App) youcreated and expand it by clicking the plus sign (+) next to it.

2) Select the Web Apps folder underneath your application folder and clickSelected > Import > Choose. Browse for the WAR file you created (forexample, Ex01Servlet.war ). Select this file and click OK.

3) Click OK.

6. Add the context root:

a. Select the Web module under the Web Apps folder you imported (forexample, Ex01Servlet.war) and click Selected > Modify.

b. Ensure that the General tab is selected. Enter the value /icoex01 in theContext root field.

c. Click Selected > Save.

7. Import the ejbtools.jar file that you created in “Part 2: Assembling the J2Cphonebook sample application” on page 188 into your web module:

194 IMS Connector for Java User’s Guide and Reference

a. Select the Web module under the Web Apps folder you have imported (forexample, Ex01Servlet.war) and click Selected > Modify.

b. Select the Files tab and click the Import... Button.

c. Select the ejbtools.jar file and click OK.

d. Click Selected > Save.

8. Validate this application:

a. Select the application (for example, Ex01Servlet390App ) and click Build >Validate.

b. Wait until the validation completes. You should see the following message:“Application Ex01Servlet390App can be deployed”

9. Export the application:

a. Select the application (for example, Ex01Servlet390App ) and click Selected> Export...

b. Choose a directory in which to save this file, provide a file name for it (forexample, Ex01Servlet390.ear ), and click OK.

Step 2: Deploying the application to WebSphere Application Server for z/OSand OS/390

1. Start the WebSphere for z/OS Administration application by clicking Start >Programs > IBM > WebSphere for z/OS > Administration. Log on to yourWebSphere Application Server with the appropriate log on information (such asthe user name and password) as described in “Preparing your WebSphereApplication Server environment for z/OS and OS/390.”

Note: This step assumes that you have deployed and configured IMSConnector for Java as a J2EE server resource in your WebSphere ApplicationServer. See “Preparing your WebSphere Application Server environment forz/OS and OS/390” for information on configuring IMS Connector for Java anddeploying your application.

2. Install the enterprise application.

a. Select the J2EE server on which this application will be installed. Select thisserver by expanding the following folders in order: Conversations folder,the new conversation, the Sysplexes folder, the sysplex in which yoursample J2EE server has been installed, and the J2EEServers folder.

b. Click Selected > Install J2EE application... and wait for its referencewindow to appear.

c. Click the Browse EAR File... button and wait for the Open window toappear. Locate and select your EAR file. Click Open.

d. Verify that the destination and EAR file name appears in the EAR Filenametext field. Click OK and wait for the Reference and Resource Resolutionwindow to appear.

e. In the Reference and Resource Resolution dialog box:

1) On the left side of the dialog, expand the Ex01SessionEJB.jar folderand select the Ex01Session Bean. Then click the J2EE Resource tab onthe right side of the dialog. In the drop-down box under the J2EEresource column, select the J2EE resource you created (for example,IMSRes).

2) On the left side of the dialog box, expand the Ex01Servlet_WebApp.jarfolder and select the Ex01Servlet_WebApp bean. Click the EJB tab onthe right side of the dialog and click the Set Default JNDI Path & Namebutton.

3) Click OK.

Chapter 13. Building a J2C phonebook sample application 195

3. Validate the new conversation you just created in the previous step by selectingthe conversation name (for example, Ex01Servlet390) to highlight it and clickingBuild > Validate.

4. Commit the new conversation by selecting the conversation name to highlight itand clicking Build > Commit.

5. Ensure that all preparation tasks for the new conversation are completed. Thenselect the conversation name to highlight it and click Build > Complete > AllTasks to indicate completion.

6. Activate the new conversation by selecting the conversation name to highlight itand clicking Build > Activate.

7. Configure the HTTP server for the context root of the Ex01Servlet by modifyingthe following files:

a. Ensure that the webcontainer.conf file contains the following information:host.default_host.contextroots=/

b. Modify the httpd.conf file with the following information:Service /icoex01/* <was_dir>/WebServerPlugIn/bin/was400plugin.so:service_exit

where <was_dir> is the installation root directory of WebSphere ApplicationServer (for example, /usr/lpp/WebSphere).

Step 3: Starting WebSphere Application Server for z/OS and OS/390

To start WebSphere Application Server for z/OS and OS/390, follow Step 6: Startingthe server to run the IVP in “Preparing your WebSphere Application ServerEnvironment for z/OS and OS/390.” When you have completed this step, go to“Part 3: Running the J2C phonebook sample application”.

Part 3: Running the J2C phonebook sample application1. Launch a Web browser. If you are working on the same machine on which the

application is installed, and enter the following Web address:http//servername:port/icoex01/Ex01ServletInput.html, where icoex01 is thecontext root and servername and port are the name and port number of yourWeb server machine.

2. In the form you see on the Web browser, enter last1 in the Last Name field.Click Submit. If you see the message “Entry was displayed” and the data recordyou requested, the application is successful.

196 IMS Connector for Java User’s Guide and Reference

Chapter 14. Building a J2C conversational phonebook sampleapplication

This section describes how to create and run a conversational phonebook sampleapplication. The conversational phonebook sample uses the J2C architecture tosubmit transactions to an IMS database system. These transactions include thecommands to display, add, delete, and update records in a dummy data set.

Important: Before you start building this sample, be sure to complete the stepsdescribed in “Preparing to deploy J2C samples” (in “Understanding IMS Connectorfor Java”) and “Preparing to Use IMS Connector for Java.”

The following steps are involved in creating a J2C phonebook sample:

“Part 1: Building a J2C conversational phonebook sample application” onpage 198

1. Creating input and output record beans for an IMS conversation (page 198)

2. Creating a sample EJB session bean (page 204)

3. Generating an Access Bean (page 205)

4. Creating and modifying methods to add business logic (page 205)

5. Adding the methods to the Remote EJB Interface (page 206)

6. Generating deployed code (page 207)

7. Generating an Access Bean (page 207)

8. Creating a servlet (page 207)

9. Testing the J2C conversational phonebook sample within VisualAge for Java(page 207)

“Part 2A: Assembling and deploying the J2C conversational phonebooksample application for Windows” on page 210

1. Assembling the application (page 210)

2. Deploying the application to WebSphere Application Server (page 213)

3. Starting the application (page 213)

“Part 2B: Assembling and deploying the J2C conversational phonebooksample application for z/OS or OS/390” on page 214

1. Assembling the application (page 214)

2. Deploying the application to WebSphere Application Server (page 215)

3. Starting WebSphere Application Server (page 217)

“Part 3: Running the J2C conversational phonebook sample application” onpage 217

1. Running the J2C conversational phonebook sample application (page 207)

Note: The instructions for developing the J2C phonebook sample in this section arefor the Windows, z/OS and OS/390 platforms. The J2C phonebook sample providedin com.ibm.connector2.ims.ico.sample.phonebook can be run on AIX, Solaris,Windows, z/OS and OS/390.

Restriction: The WebSphere for z/OS and OS/390 J2C architecture supportsnon-transactional IMS conversations only.

© Copyright IBM Corp. 1998, 2002 197

Part 1: Building a J2C conversational phonebook sample applicationStep 1: Creating input and output record beans for an IMS conversation

An IMS conversation is made up of a series of connected interactions between aclient and, in the simplest case, a single IMS application program (transaction).More complex IMS conversations can be made up of multiple IMS applicationprograms (transactions). Each interaction in the conversation is referred to as aniteration of the conversation. The input and output messages for the iterations of aconversation are often different.

For this particular IMS conversation, the iterations of the conversation consist of thefollowing:

v The first iteration of the conversation invokes the IMS application program withan input message, which will be referred to as MI1, and returns an outputmessage, which will be referred to as MO2. The input message, MI1, isrepresented by the COBOL 01 data structure INPUT-MSG. As is the case for allIMS conversational application programs, INPUT-MSG does not map thetransaction code of the input message. The output message, MO2, isrepresented by the COBOL 01 data structure OUTPUT-AREA.

v The second and subsequent (middle) iterations of the conversation invoke theIMS application program with an input message, which will be referred to as MI2,and return the same output message as the first iteration, MO2. The inputmessage, MI2, is completely represented by the COBOL 01 data structureINPUT-MSG. The output message, MO2, is represented by the COBOL 01 datastructure OUTPUT-AREA.

v The conversation is terminated by the IMS application program on receipt of an″END command″ input message. This message is sent in response to theend-user selecting the ″END command″ radio button. The servlet detects that theIMS application program has ended the conversation using the getConvEnded()method of the IMSInteractionSpec class. The servlet then displays the final JSPpage of the conversation.

Note: The process of understanding the input and output messages of the iterationsof an IMS conversation is key to developing your Web application. If the IMStransaction has MFS source, the MSG statements, along with the NXT= keywords,can sometimes aid in this process.

The steps to build record beans representing the input and output messagespresented above include the following:

1. Starting the Workbench in the VisualAge for Java IDE

2. Creating a project and package for the IMS conversational input and outputrecord beans and EAB command

3. Creating a COBOL record type class for the initial input message of the IMSconversation

4. Creating a transaction input record bean for the initial input message

5. Creating a COBOL record type class for the second input message

6. Creating a record bean for the second input message

7. Creating a COBOL record type class for the output message

8. Creating a record bean for the output message

For more information on the iterations of a conversation, see “Building a Webapplication that uses one servlet to run an IMS conversation.”

198 IMS Connector for Java User’s Guide and Reference

Step 1A: Starting the Workbench in the VisualAge for Java IDE

For instructions on how to start the Workbench in the VisualAge for Java IDE, seeStep 1A of “Building a Java application to run an IMS transaction.”

Step 1B: Creating a project and package for the IMS conversational input andoutput record beans and EAB command

For instructions on how to complete this step, see Step 1B of “Building a Javaapplication to run an IMS transaction.” For example, use the Project Examples andcreate a package named icoconvejb.

Step 1C: Creating a COBOL record type class for the initial input message ofthe IMS conversation

This step parses the COBOL commarea that represents the initial input message forthe IMS conversation, and creates a COBOL Record Type class that encapsulatesthe information in the commarea. This class will be used in Step 1D (page 201)below to build a Java bean that represents the input message. Do the following:

The COBOL source used in this step can be found in<IBM_Connectors_install_dir>\imsconn\samples\misc\dfsiva34.mem, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

1. Ensure that the package created in Step 1B (page 199) (for example,icoconvejb) is selected. From the Selected menu, click Tools > EnterpriseAccess Builder > Import COBOL to Record Type... Wait for the ImportCOBOL to Record Type wizard to appear.

2. In the Import COBOL to Record Type wizard, do the following:

a. Click the Browse... button to locate and select the file name of the COBOLfile that contains the commarea representing the IMS transaction inputmessage. In this example, select the file dfsiva34.mem in theC:\<IBM_Connectors_install_dir>\imsconn\samples\misc\ directory. ClickOpen.

b. Ensure that the An IMS Application Program radio button (under theheading “Code to be imported is:”) is selected. Click Next.

c. The next window of the Import COBOL to Record Type wizard contains alist of the available level 01 commareas found in the dfsiva34.mem file.Select the commarea representing the IMS transaction input message (forexample, INPUT-MSG) from the Available level 01 commarea list and click the> button to add it to the Selected commareas list. Ensure that the UseBigDecimal check box is selected. This will generate the COBOL type as aBigDecimal Java type. Click Next.

d. Add a transaction code field to the COBOL Record Type.

During the first iteration of a conversation, IMS Transaction Manager (IMSTM) removes the transaction code from the input message and places it in ascratch pad area (SPA) accessible to the IMS application program. The SPAis also used by the IMS application program to save information betweeniterations of the conversation.

The IMS application program gets the contents of the SPA with a GU call,then gets the data portion of the initial input message with a GN call. TheIMS application program does not see the transaction code in the I/O areathat it gets using the GN call, since the transaction code has already beenremoved from the initial input message by IMS TM. Hence, in an IMSconversational application program, there is no 01 data structure that directly

Chapter 14. Building a J2C conversational phonebook sample application 199

maps to the input message of the first iteration. For this reason, you mustindicate to the Enterprise Access Builder tool the information it needs tobuild a COBOL Record Type class, and subsequently a record bean,representing the complete initial input message.

Use the following steps to complete the initial input message by adding atransaction code field:

1) Select the Add transaction code field check box.

2) Enter the name you would like to use for the transaction code in theField name field (for example, IN__TRANCD).

This is the name of the field in the generated Java record bean, andhence the name used in the corresponding ″get″ and ″set″ methods. Inthis case, IN__TRANCD was selected to be consistent with the namesof the ″get″ and ″set″ methods that were generated for the fields in theCOBOL 01 data structure, INPUT-MSG).

3) Select the length of the transaction code for the Length field (forexample, 5).

The Enterprise Access Builder tool builds the record bean for the initialinput message by placing the transaction code immediately following theZZ field. A transaction code has a maximum length of 8 (EBCDIC)single-byte characters. If the length of the transaction code is less than 8characters, the Enterprise Access Builder tool separates the transactioncode from the input message data by a single (EBCDIC) blankcharacter. For example, if the transaction code is ″IVTCB″, you specify 5for the Length field and the tool creates a record bean of the form:

LLZZIVTCBbData..., where

v b represents a single blank (EBCDIC) character, and

v Data... represents the portion of the initial input message representedby the 01 COBOL data structure (e.g., INPUT-MSG), following thedefinitions for the LL and ZZ fields.

If the length of the transaction code is equal to 8 characters, theEnterprise Access Builder tool does not separate the transaction codefrom the input message data. For example, if the transaction code is″CARLOANS″, you specify 8 for the Length field and the tool creates arecord bean of the form:

LLZZCARLOANSData...

4) Enter the value of the transaction code in the Value field (for example,IVTCB).

This is optional, since you may choose to provide the value of thetransaction code at runtime, as is done in this example. Click Next.

3. Ensure that the correct names appear in the Project Name and Package entryfields.

4. Enter a name for the new class that will represent the COBOL Record Type. Forexample, MI1Info.

5. To continue to generate the record bean from this record type, ensure that boththe Continue working with newly created record type... check box and theCreate record from record type radio button are selected.

6. Click Finish. A new class named MI1Info appears in the package namedicoconvejb in the IDE Workbench.

200 IMS Connector for Java User’s Guide and Reference

The following fragment of COBOL source code is the 01 commarea used togenerate the COBOL Record Type class for the initial input message of theconversation:

01 INPUT-MSG.02 IN-LL PICTURE S9(3) COMP.02 IN-ZZ PICTURE S9(3) COMP.02 IN-FILL PICTURE X(4).02 IN-COMMAND PICTURE X(8).02 TEMP-COMMAND REDEFINES IN-COMMAND.

04 TEMP-IOCMD PIC X(3).04 TEMP-FILLER PIC X(5).

02 IN-LAST-NAME PICTURE X(10).02 IN-FIRST-NAME PICTURE X(10).02 IN-EXTENSION PICTURE X(10).02 IN-ZIP-CODE PICTURE X(7).

Step 1D: Creating a transaction input record bean for the initial inputmessage

1. If both the Continue working with newly created record type... check boxand the Create record from record type radio button are selected in theprevious step, the Create Record from Record Type wizard appears. Tomanually start the Create Record from Record Type wizard, ensure that theCOBOL Record Type class, MI1Info, is selected. From the Selected menu, clickTools > Enterprise Access Builder > Create Record from Record Type...The Create Record from Record Type wizard appears.

2. Use the Create Record from Record Type wizard to create an input recordbean for the initial input message. Do the following:

v Ensure that the correct names appear in the Project and Package entryfields.

v Enter a name for the new class that will represent the input message (forexample, MI1).

v Select the Access Method: Direct radio button.

v Select the Record Style: Custom Records radio button.

v In the Additional Options section:

– Ensure that the Generate with Notification and Shorten Names checkboxes are not selected.

– Check the Generate as javax.resource.cci Record interface check box.Doing so will make the Record Bean compatible with the J2C architecture.

v Click Next to view the next page of the Create Record from Record Typewizard. Ensure that the following values are set. If necessary, click the valuefield of any property to change its value.

– Floating Point Format is IBM.

– Remote Integer Endian is Big Endian.

– Endian is Big Endian.

– Code Page is 037. The code page refers to the data of the IMStransaction. If your transaction data is other than U.S. English (code page037), you must enter a different code page in this field.

– Machine Type is MVS.

Ensure that all values on the Create Record from Record Type wizard havebeen accepted. That is, all of the field values should appear gray before youselect Finish.

Chapter 14. Building a J2C conversational phonebook sample application 201

3. Click Finish on the Create Record from Record Type wizard. Two new classes,called MI1BeanInfo and MI1, appear in the package icoconvejb in the IDEWorkbench. The MI1 Java bean represents the initial input message of the IMSconversation.

Related Reading: For more information on additional options and on importingCOBOL source to record type, see the VisualAge for Java Enterprise AccessBuilder documentation.

Step 1E: Create a COBOL record type class for the second input message

This step creates a COBOL Record Type for the input message of the second andsubsequent iterations of the conversation. It is created from the 01 COBOL datastructure, INPUT-MSG. Repeat Step 1C (page 199) above, using MI2Type for thename of the COBOL Record Type class.

In this case, the input message (MI2) is completely represented by the 01 COBOLdata structure, INPUT-MSG. On the Import COBOL to Record Type wizard, youcan select either the An IMS Application Program radio button or the GenericCOBOL code radio button and you do not select the Add transaction code fieldcheck box.

The following fragment of COBOL source code is the 01 commarea used togenerate the COBOL Record Type class for the second input message of theconversation:

01 INPUT-MSG.02 IN-LL PICTURE S9(3) COMP.02 IN-ZZ PICTURE S9(3) COMP.02 IN-FILL PICTURE X(4).02 IN-COMMAND PICTURE X(8).02 TEMP-COMMAND REDEFINES IN-COMMAND.

04 TEMP-IOCMD PIC X(3).04 TEMP-FILLER PIC X(5).

02 IN-LAST-NAME PICTURE X(10).02 IN-FIRST-NAME PICTURE X(10).02 IN-EXTENSION PICTURE X(10).02 IN-ZIP-CODE PICTURE X(7).

Step 1F: Creating a record bean for the second input message

This step creates a Record Bean representing the input message of the second andsubsequent iterations of the conversation. Repeat Step 1D (page 201) above, usingMI2 for the name of the record bean. An additional class MI2BeanInfo will also becreated.

Step 1G: Creating a COBOL record type class for the output message

This step creates a COBOL Record Type (MO2Type) for the output message of thefirst, second, (and subsequent) iterations of the conversation. The COBOL sourceused in this step can be found in<IBM_Connectors_install_dir>\imsconn\samples\misc\MSOut.ccp, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory.

1. Ensure that the new package, icoconvejb, is selected. From the Selectedmenu, click Tools > Enterprise Access Builder > Import COBOL to RecordType... The Import COBOL to Record Type wizard appears.

2. On the Import COBOL to Record Type wizard, do the following:

202 IMS Connector for Java User’s Guide and Reference

v Click the Browse... button to locate and select the file name of the COBOLfile that contains the commarea representing the IMS transaction inputmessage. In this example, select the file MSOut.ccp in theC:\<IBM_Connectors_install_dir>\imsconn\samples\misc\ directory. ClickOpen.

v Under the heading “Code to be imported is:” ensure that the GenericCOBOL code radio button is selected, then click Next.

v The next window of the Import COBOL to Record Type wizard contains alist of the available level 01 commareas. Select the commarea representingthe IMS transaction input message from the Available level 01 commarea list(for example, OUTPUT-MSG) and click the > button to add it to the Selectedcommareas list. Select the Use BigDecimal check box. This will generate theCOBOL type as a BigDecimal Java type. Click Next.

3. Ensure that the correct names appear in the Project Name and Package entryfields.

4. Enter a name for the new class that will represent the COBOL Record Type. Forexample, MO2Type.

5. To continue to generate the record bean from this record type, ensure that boththe Continue working with newly created record type... check box and theCreate record from record type radio button are selected.

6. Click Finish. A new class named MO2Info appears in the package namedicoconvejb in the IDE Workbench.

Step 1H: Creating a record bean for the output message

This step creates a Record Bean (MO2) representing the output message of the first,second, (and subsequent) iterations of the conversation.

1. If both the Continue working with newly created record type... check boxand the Create record from record type radio button are selected in theprevious step, the Create Record from Record Type wizard appears. Tomanually start the Create Record from Record Type wizard, ensure that theCOBOL Record Type class, MI1Info, is selected. From the Selected menu, clickTools > Enterprise Access Builder > Create Record from Record Type...The Create Record from Record Type wizard appears.

2. Use the Create Record from Record Type wizard to create an output recordbean. Do the following:

v Ensure that the correct names appear in the Project and Package entryfields.

v Enter a name for the new class that will represent the input message. Forexample, OutMsg.

v Select the Access Method: Direct radio button.

v Select the Record Style: Custom Records radio button.

v In Additional Options:

– Ensure that the Generate with Notification and Shorten Names checkboxes are not selected.

– Check the Generate as javax.resource.cci Record interface check box.Doing so will make the Record Bean compatible with the J2C architecture.

v Click Next to view the next page of the Create Record from Record Typewizard. Ensure that the following values are set. If necessary, click the valuefield of any property to change its value.

– Floating Point Format is IBM.

Chapter 14. Building a J2C conversational phonebook sample application 203

– Remote Integer Endian is Big Endian.

– Endian is Big Endian.

– Code Page is 037. The code page refers to the data of the IMStransaction. If your transaction data is other than U.S. English (code page037), you must enter a different code page in this field.

– Machine Type is MVS.

Ensure that all values on the Create Record from Record Type wizard havebeen accepted. That is, all of the field values should appear gray before youselect Finish.

3. Click Finish on the Create Record from Record Type wizard. Two new classes,called MO2BeanInfo and MO2, appear in the package icoconvejb in the IDEWorkbench. The MO2 Java bean represents the initial output message of theIMS conversation.

Step 2: Creating a sample EJB session bean

The following describes how you can create a sample EJB session bean to run anIMS transaction. The EJB session bean in this sample is a stateful EJB sessionbean. For information on the types of enterprise javabeans, see “IMS Connector forJava concepts and terms.”

1. Start the Workbench in the VisualAge for Java IDE.

2. If you have not previously added the IBM EJB Development Environment, IBMEnterprise Access Builder Library, IBM Enterprise Access Builder Samples, IMSConnector, and/or IMS Connector Samples projects to the Workbench, do thefollowing (otherwise skip to the next step):

a. Select File > Quick Start. The Quick Start dialog opens.

b. Click on Features, choose Add Feature, and click OK.

c. From the list of features, select IBM Enterprise Access Builder Library,IBM Enterprise Access Builder Samples, IMS Connector, IMSConnector Samples, IBM EJB Development Environment, and IBMWebSphere Test Environment. Click OK.

v For more details on adding the EJB Development Environment to the IDE,please see the VisualAge for Java documentation by clicking Help > HelpHome Page > Tasks > Developing EJB Components > Setting up theEJB Development Environment > Loading the required features from theVisualAge for Java online help.

3. Create the Session EJB to run an IMS transaction:

a. Click on the EJB tab on the Workbench to go to the EJB DevelopmentEnvironment.

b. EJBs are created within an EJB group. Select the EJB group namedEJBExamples.

If you followed the steps in “Building a J2C phonebook sample application,”this group and package should already exist on your Workbench. If they donot exist, follow the instructions in steps 3 and 4 of “Step 3: Creating asample EJB session bean” in “Building a J2C phonebook sampleapplication.”

c. From the main menu bar, click EJB > Add > Enterprise Bean... to createthe EJB.

d. In the Create Enterprise Bean section of the SmartGuide, do the following:

1) Ensure that the Create a new Enterprise bean radio button is selected.

204 IMS Connector for Java User’s Guide and Reference

2) In the Bean name entry field, enter the name of the EJB to create (forexample, ConvPhoneBook).

3) Ensure that the Create a new bean class radio button is selected.

4) Click on the Browse... button next to the Project entry field, and selectthe project in which the sample is being developed (for example,Examples). Click OK.

5) Click on the Browse... button beside the Package entry field, and selectthe package in which the sample is being developed. Click OK.

6) Click Finish.

Step 3: Generating an Access Bean

This step provides instructions on how to create a Java bean wrapper type AccessBean. This simplifies access to the Home and Remote interfaces of your enterprisebean and allows a standard java bean approach to using your EJB.

The java bean wrapper type Access Bean is a java bean which contains a no-argconstructor and a lazy initialization technique which will instantiate your enterprisebean at the first call to one of its remote methods. This type of Access Bean isbuilt with a default JNDI name that provides to you the option to ignore the JNDIlookup process in a WebSphere runtime environment. Additionally, each accessbean class retains some class-level cache to improve performance wheninstantiating an enterprise bean. If multiple instances of an access bean use thesame home (for example, the same JNDI name and rootContext), the access beanclass only looks up the corresponding enterprise bean home once.

Related Reading: For more information on Access Beans and their various uses,go to the Visual Age Help by clicking Help > Concepts > EJB DevelopmentEnvironment > Access beans.

To create an Access bean for a particular enterprise bean, do the following:

1. In your VisualAge for Java Workbench, click the EJB tab to go to the EJBdevelopment environment.

2. Right-click the enterprise bean (for example, ConvPhoneBookBean) found within aspecific EJB group (for example, EJBExamples) and click Add > Access Beanfrom the menu. Wait for the Create Access Bean SmartGuide to appear.Verify that the following the set of information displayed in the ″Select AccessBean Properties″ matches that of your specific EJB Group and enterprisebean. Click Finish. The following is an example:

EJB GroupEJBExamples

Enterprise beanConvPhoneBook

Access bean nameConvPhoneBookAccessBean

Access bean typeJava Bean Wrapper

3. The access bean (for example, ConvPhoneBookAccessBean) has been generatedin the package that the specific EJB was associated with (for example,icoconvejb).

Step 4: Creating and modifying methods to add business logic

Chapter 14. Building a J2C conversational phonebook sample application 205

Now you are ready to create your business methods (add, delete, display, update,execute, end, force_end, isConvEnded ), using code provided in the conversationalphonebook sample found incom.ibm.connector2.ims.ico.sample.conv.phonebook.ejb, in the classConvPhoneBookBean.

1. Click the EJB tab in the VisualAge for Java Workbench.

2. In the Enterprise Beans window, click the + next to your EJB Group (in thisexample, EJBExamples) to expand it. Then select the EJB you just created (inthis example, ConvPhoneBook). In the Types window, select the select thecorresponding bean (in this example, ConvPhoneBookBean). Right-click it andselect Add > Method. The Create Method SmartGuide appears.

3. In the Create Method SmartGuide, select the Create a new method radiobutton. In the entry field below this radio button, provide a name for the newmethod. For example, give your display method the name display(). If youprefer to use the SmartGuide to continue creating parameters and code for thismethod, click Next. If you prefer to manually code your method, click Finish.In this example, click Finish.

4. Repeat the previous step to create the remaining methods. For this example,create the methods update(), add(), delete(), execute(), end(), force_end(),and isConvEnded(). As you create these methods and add code to them, youwill see some error messages. As you continue to create these methods andcopy the example code, these errors should become resolved.

Note that the execute method is unique from the other methods because itwon’t be accessed by the servlet directly. The other methods call the executemethod.

5. Add code to the methods you just created. Copy the code from theConvPhoneBookBean class found incom.ibm.connector2.ims.ico.sample.conv.phonebook.ejb and modify thecode to fit your application. Repeat this step for each of the following methods:

v add

v delete

v display

v update

v execute

v ejbCreate

v end

v force_end

v isConvEnded

After you modify each of these methods and save them, a copy of the originalmethod remains in the workbench. Be sure to delete these.

6. Add a new class called IMSOutputRecord in this package. Copy the code fromthe class provided incom.ibm.connector2.ims.ico.sample.conv.phonebook.ejb.

7. Ensure that no compilation errors exist (use the All Problems tab). If errorsexist, check your input statements against the import statements provided in thecom.ibm.connector2.ims.ico.sample.conv.phonebook.ejb and include anystatements that are missing from your code.

The next step is to add these methods to the EJB Remote Interface.

Step 5: Adding the methods to the EJB Remote Interface

206 IMS Connector for Java User’s Guide and Reference

Generating the EJB automatically builds an empty Remote Interface and a HomeInterface with a default create method. You should now add the seven businessmethods you just created (add, delete, display, update, end, force_end, andisConvEnded) to the Remote Interface for client accessibility.

1. In the VisualAge for Java workbench, click the EJB tab.

2. In the Enterprise Beans (left) pane, click + next to the EJB Group you created(EJBExamples) to expand it. Click on the session EJB (ConvPhoneBook) to selectit.

3. In the Types (middle) pane, click on the session bean you created(ConvPhoneBookBean) to select it.

4. In the Members (right) pane, right-click on the display() method that youcreated to select it. Right-click this method and select Add To > EJB RemoteInterface.

5. Repeat the previous step for the remaining methods update(), add(), delete(),end(), force_end(), and isConvEnded(). Do not add the execute() method tothe EJB Remote Interface because the servlet you will create will not accessthis method directly.

Step 6: Generating deployed code

To run the sample within the IDE, you must first generate the deployed code for theEJB Server which runs inside VisualAge for Java.

In the Enterprise Beans (left) pane, right-click the session EJB (ConvPhoneBook)and select EJB > Generate Deployed Code. Wait for the code to generate. Thismay take a moment. If you do not see any error messages, the code wasgenerated successfully.

You have successfully created the EJB needed for your conversational phonebooksample.

Step 7: Generating an Access Bean

Step 8: Creating a servlet

Create a package for your servlet (for example, icoconvservlet). Create yourservlet, HMTL, and JSP files based on the sample code provided. The servlet codeis in the package com.ibm.connector2.ims.ico.conv.phonebook.servlet. Be sureto copy both the ConvIterations and IMSConvUnboundHttpSessionCleanup classes.The sample HTML and JSP files are located in C:\IMSConnectors\IMSCONN\Samples\J2C\Convphonebook\vaj.

Step 9: Testing the J2C conversational phonebook sample within VisualAgefor Java

1. Copy the VisualAge for Java HTML and JSP files associated with the JNDIutility and phonebook sample to the WebSphere test environment.

a. Locate the HTML file associated with the JNDI utility in the directory wherethe IBM Connectors for VisualAge for Java were installed (for example,C:\IBM Connectors\imscon\samples\J2C\util\vaj\JNDIDeployerInput.html).Copy this file.

b. Navigate to the VisualAge for Java WebSphere Test Environment web folder(for example, C:\Program Files\IBM\VisualAge for

Chapter 14. Building a J2C conversational phonebook sample application 207

Java\ide\project_resources\IBM WebSphere TestEnvironment\hosts\default_host\default_app\web) and paste the HTML fileinto this directory.

c. Locate the HTML and JSP files associated with the J2C Phonebook Samplefor VAJ in the directory where the IBM Connectors for VisualAge for Javawere installed (for example, C:\IBMConnectors\imsconn\samples\J2C\convphonebook\vaj\).

d. Copy all of the HTML and JSP files in this directory. For example, copy thefollowing files:

v ConvIterationsInput.html

v ConvDFSMessage.jsp

v ConvEndConversation.jsp

v ConvIterationsResults.jsp

v ConvIterationsError.jsp

e. Navigate to the VisualAge for Java WebSphere Test Environment web folder(for example, C:\Program Files\IBM\VisualAge forJava\ide\project_resources\IBM WebSphere TestEnvironment\hosts\default_host\default_app\web) and paste the HTML andJSP files to this directory.

2. Modify the phonebook sample HTML and JSP files to access the newpackages.

a. Open each of the HTML and JSP files associated with the ConvIterationsservlet that were copied to the WebSphere Test Environment web folder inthe previous step.

b. Replace the text referring to thecom.ibm.connector2.ims.ico.sample.conv.phonebook.servlet package withan icoconvservlet package equivalent (for example, replace the textcom.ibm.connector2.ims.ico.sample.conv.phonebook.servlet.ConvIterationsfound within the ConvIterationsInput.html file withicoconvservlet.ConvIterations).

c. Replace the text referring to thecom.ibm.connector2.ims.ico.sample.conv.phonebook.ejb package with anicoconvejb package equivalent (for example, replace the textcom.ibm.connector2.ims.ico.sample.conv.phonebook.ejb.MO2 found in theConvIterationsResults.jsp with icoconvejb.MO2.

d. Save the modified HTML and JSP files and close any applications that referto them.

3. Start the WebSphere Test Environment within VisualAge for Java.

a. Start the VisualAge for Java Workbench by clicking the Start > Programs >IBM VisualAge for Java for Windows > IBM VisualAge for Java.

b. From the Workspace menu, select Tools > WebSphere Test Environment.

c. Wait for the WebSphere Test Environment Control Center window to appear.

4. Start the Servlet Engine.

a. In the Servlet Engine pane ensure that all check boxes are not selected.

b. Click the Edit Class Path... button.

c. In the Servlet Engine Class Path window click the Select All button.

d. Click OK to return to the Control Center.

e. Click the Start Servlet Engine button.

208 IMS Connector for Java User’s Guide and Reference

f. Wait for the status message in the lower left hand corner of the WebSphereTest Environment Control Center window to indicate that the Servlet Engineis started.

5. Start the Persistent Name Server.

a. Click the Persistent Name Server displayed under the Servers heading onthe left.

b. Click the Start Name Server button.

c. Wait for the status message in the lower left hand corner of the WebSphereTest Environment Control Center window to indicate that the PersistentName Server is started.

6. Add the EJB Group to the Server Configuration.

a. Click the EJB tab to go to the EJB Development Environment.

b. Click the new EJB Group (for example, EJB Samples).

c. In the EJB menu, click Add To > Server Configuration.

d. This should bring up the EJB Server Configuration window and highlightthe new EJB Server Configuration which contains the EJB Group you areusing (for example, EJB Samples).

7. Start the EJB Server by clicking Start Server in the Servers menu.

8. Set the JNDI Deployment properties from the browser.

a. Open a browser and enter the following Web address:http://localhost:8080/JNDIDeployerInput.html

b. In the browser, fill in the fields as follows:

ConnectionFactory JNDI NameThis should be the same ConnectionFactory JNDI Name specified inthe sample code (for example, MyIMS).

HostnameThe TCP/IP of the targeted IMS Connect.

Port NumberThe TCP/IP port number of the targeted IMS Connect.

DataStore NameThe name of the Datastore for the targeted IMS.

Enable Connection PoolingA flag set to enable or disable connection pooling in the targetedIMS Connect.

Log WriterThe output stream for logging and tracing.

Trace LevelThe level of information to be traced.

c. Click the Submit button.

d. Wait for the ConnectionFactory added to the JNDI context message toappear in the browser.

9. Access the conversational phonebook sample from a browser and add a newentry to the database.

a. Open a browser and enter the Web address:(http://localhost:8080/ConvIterationsInput.html)

b. In the form you see on the Web browser, enter last1 in the Last Name field.Ensure that the Display an entry radio button is selected. Click Submit. Ifyou see the message “Entry was displayed” and the data record you

Chapter 14. Building a J2C conversational phonebook sample application 209

requested, create a new record by entering a different last name, first name,extension, and zip code in the form. Select the Add an entry radio buttonand click Submit. The application is successful if you see the message“Entry was added.”

c. Select the End conversation radio button to end the conversation.

Part 2A: Assembling and deploying the J2C conversational phonebooksample application for Windows

Step 1: Assembling the application

Now you are ready to assemble the application using the Application Assembly Tool(AAT). In this step, you will build an EJB module and a Web module to compriseyour application. You will create and package these modules into your EAR file,which is your conversational phonebook application.

1. Determine the name of your Connection Factory in WebSphere ApplicationServer (for example, eis/MyIMS), then update the code in the ejbCreate()method of the ConvPhoneBookBean class with this Connection Factoryname. Modify the following line of code in this method:ConnectionFactory cf=(ConnectionFactory)ic.lookup(“MyIMS”);

with the JNDI name (“eis/MyIMS”) of the WebSphere Application Serverresource adapter Connection Factory.

2. Export your EJB JAR file:

a. In VisualAge for Java, click the EJB tab and select the EJB Groupcontaining your EJB (for example, EJBExamples).

b. Right-click the EJB Group and select Export > Deployed JAR... The Exportto an Deployed JAR File SmartGuide appears:

c. Give your EJB JAR file a name (for example, ConvPhoneBookEJB.jar) in theJAR file field. Then click the Browse... button to select a working directoryin which you want to save this JAR file, then click Save. Make a note of thelocation of the JAR file because you will need to find it later. You will bereturned to the Export to a Deployed JAR File SmartGuide.

d. Export only the beans and .class files by selecting the beans and .classcheckboxes. Do not export the .java files.

e. Click Finish. The JAR file will be created automatically in the directoryspecified in step c above.

3. Assemble your JAR file and convert it to an EJB 1.1 format:

a. Start the Application Assembly Tool (AAT) by clicking Start > Programs >IBM WebSphere > Application Server V4.0 AE > Application AssemblyTool. Click Cancel if you see a welcome window.

b. In AAT, click File > Open. Navigate to your JAR file (ConvPhoneBookEJB.jar)and open it.

c. In the “Please specify the dependent classpath” dialog, leave the field blankand click OK.

d. Click File > Save, then click Save to save the JAR file in the EJB 1.1format.

4. Export the servlet:

a. In VisualAge for Java, in the Projects window, select the class of the servletpackage (for example, class ConvIterations in package icoconvservlet),right-click it and select Export... Select the Directory radio button and clickNext.

210 IMS Connector for Java User’s Guide and Reference

b. In the Export to a directory SmartGuide, click the Browse... button next tothe Directory: field to select your working directory for your servlet. Selectthe same directory that contains your exported EJB beans.

c. Select the .class checkbox and ensure that the .java checkbox is notselected.

d. Click Finish to export your servlet.

5. Export the support classes (all files related to the application):

a. Select the following classes to export as a JAR file:

v ConvPhoneBookAccessBean

v IMSOutputRecord

v MI1

v MI1BeanInfo

v MI1Info

v MI2

v MI2BeanInfo

v MI2Info

v MO2

v MO2BeanInfo

v MO2Info

v IMSConvUnboundHttpSessionCleanup

Name this JAR file convsupportclass.jar.

b. Copy the JSP files that you modified in Step 9: Testing the J2Cconversational phonebook sample within VisualAge for Java (page 207) andpaste them to your working directory (which contains the other JAR files).

c. Modify the ConvIterationsInput.html and ConvIterationsResults.jsp files toreplace the following line:<FORM METHOD=“post” ACTION=“/servlet/icoconvservlet.ConvIteration”>

with the following line:<FORM METHOD=“post” ACTION=“/icoconv/ConvIterations”>

where /icoconv is the context root that you will define in step 8 below.

6. Create an EJB module. In the Application Assembler Tool, click File > New >Application. Provide a name for the EAR file you are creating (for example,ConvIterations.ear) in the Display name: field and click Apply.

7. Import the EJB JAR file into the EAR file:

a. In the Application Assembly Tool, right-click the EJB Modules folder andselect Import. In the window that appears, locate and select your JAR file.Click Open.

b. In the “Confirm values” box that opens, click OK.

c. Expand the EJB Modules folder by clicking the + next to it. Then expandthe ConvPhoneBookEJB folder, the Session Beans folder, and theConvPhoneBook folder. Click Resource References and in the right paneclick the General tab. Enter MyIMS in the Name field. Selectjavax.resource.cci.ConnectionFactory in the Type field. Then click theBindings tab and enter eis/MyIMS in the JNDI name field.

d. Click OK.

8. Add support classes to the EJB module:

Chapter 14. Building a J2C conversational phonebook sample application 211

a. From convsupportclass.jar, extract all of the classes except Manifest.mf intoyour working directory.

b. In the EJB Modules folder (under the ConvPhoneBook folder), right-clickFiles and select Add Files. Click Browse to locate and select the workingdirectory that contains the extracted classes. Click OK.

c. Select the com folder and click Add. Then click OK.

All of the support classes with the classpath have been added to the EJBmodule.

9. Create a Web module:

a. Right-click the Web Module folder and select New. In the File name: field,give your new WAR file the same file name as your EAR file (for example,ConvIterations.war). Enter “icoconv” in the Context root: field. Click OK.

b. Add class files, JAR files, and resource files to the new WAR file:

1) In the Application Assembler window of the AAT, click the + sign next toyour WAR file to expand it. Click the + sign next to Files folder toexpand it. You should see three folders: Class Files, Jar Files, andResource Files.

2) Right-click Class files and select Add files. Click the Browse... buttonto locate the root directory containing your servlet file and click Select.Select the com folder, which contains the ConvIteration.class, click Add,then click OK.

3) Right-click Jar files and select Add Files. Click the Browse... button tolocate the root directory containing your JAR files. Add theconvsupportclasses.jar.

4) Right-click Resource files and select Add Files. Add the HTML andJSP files.

10. Add your servlet to the EAR file:

a. Right-click the Web Components folder and select New. A web componentis a servlet or JSP file that executes in a Web server.

b. The New Web Component window appears. Do the following:

1) In the Component name field, enter the name of the servlet (forexample, ConvIterations).

2) Enter the same name in the Display name field.

3) Under the Component type section, select the Servlet radio button.Click the Browse... button next to the Class name field to locate andselect the servlet class ConvIterations.class.

4) Click OK. Your servlet has been added to the EAR file.

11. Map the servlet to associate your servlet with a client request. Right-click theServlet Mapping folder and select New. In the URL pattern field, enter aforward slash and the name of your servlet (for example, /ConvIterations).Enter the same servlet name in the Servlet: field. Click OK.

12. Add the EJB Resource Reference:

a. In the Web Modules, right-click EJB References and select New from themenu. Enter a name (for example, ConvPhoneBook).

b. In the Link field, select the ConvPhoneBook Bean you have added in thisEAR file from the pull-down menu.

c. Click the Bindings tab and enter the EJB JNDI name (for example,ConvPhoneBook).

d. Click OK.

13. Save the EAR file:

212 IMS Connector for Java User’s Guide and Reference

a. Highlight the EAR file you created (for example, ConvIterations.ear). ClickFile > Save.

b. Specify a directory location and name for this file.

Related Reading: For information on EJB and Web modules, see the informationavailable in the IBM WebSphere Application Server Advanced Edition InformationCenter.

Step 2: Deploying the application to WebSphere Application Server

In this step you will deploy, or install, the application you created in WebSphereApplication Server.

1. Start the WebSphere Advanced Administrative Console:

a. First you must start the WebSphere Admin Server. Click Start > Programs> IBM WebSphere > Application Server V4.0AE > Start Admin Server.

b. Then start the Advanced Administrative Console. Click Start > Programs >IBM WebSphere > Application Server V4.0AE > Administrator’sConsole.

2. In the Advanced Administrative Console, select from the menu bar Console >Wizards > Install Enterprise Application. In the wizard that appears, do thefollowing:

a. In the Browse for file on node field, keep the default.

b. Select the Install Application (*.ear) radio button.

c. In the Path field, browse for the EAR file you just created (for example,ConvIterations.ear).

d. In the Application name field, enter a name for your application (forexample, ConvIterations).

e. Click Next until you see the “Mapping Resource References to Resources”page.

f. In the “Mapping Resource References to Resources” page, select theresource reference you want, then click the Resource Reference... buttonto choose the Connection Factory you created for your server for example,MyIMS). For instructions on how to create a Connection Factory, see “Step4: Creating and Configuring a Connection Factory for use by the IVP” in“Preparing your WebSphere Application Server environment for Windows.”

g. Click Next until you see the “Selecting Application Servers” page.

h. In the “Selecting Application Servers” page, select the module containingyour application (for example, ConvIterations.war) to install it. Click theSelect Server button. Select an application server (for example, “DefaultServer”) and click OK. Then click Next.

i. The Completing the Application Installation wizard appears. Verify thatthe settings you provided are correct, then click Finish.

j. You might see the following message: “Application code necessary forinstallation has not been generated. Generate code now?” Click No.

k. Click OK when you see a message indicating that the application issuccessfully installed.

Step 3: Starting the Application

1. In the WebSphere Administrator’s Console, look in the Enterprise Applicationsfolder to locate the application you installed (for example, ConvIterations).

Chapter 14. Building a J2C conversational phonebook sample application 213

2. Highlight it this folder, right click it, and select Start from the menu. You shouldsee a message stating that the start command has completed successfully.

3. Click OK.

4. When you have completed this step, go to “Part 3: Running the J2Cconversational phonebook sample application” on page 217.

Part 2B: Assembling and deploying the J2C conversational phonebooksample application for z/OS or OS/390

Important: It is assumed that you have completed the steps in Part 2A. If you havenot, you can either complete “Part 2A: Assembling and deploying the J2Cconversational phonebook sample application for Windows” on page 210 firstor copy the sample EAR file provided in the <vaj_install_dir> (for example, C:\IBMConnectors\IMSCONN\samples\convphonebook\was\ConvIterations.ear).

If you copy the provided EAR file, be sure to modify the package name and contextroot in the Input.html and Results.jsp files. You can also extract the JAR filesdescribed in the following steps from the provided ConvIterations.ear file.

To assemble your application for deployment to WebSphere Application Server forz/OS and OS/390, the Application Assembly Tool for WebSphere for z/OS isrequired. See “Preparing to deploy J2C samples” in “Understanding IMS Connectorfor Java for more information.”

Step 1: Assembling the application in z/OS and OS/390

1. Update the ejbCreate() method of the ConvPhoneBookBean class with theConnection Factory name java:comp/env/MyIMS, where MyIMS is theResources Reference name. Then export the ConvPhoneBookEJB.jar file asdescribed in Step 1: Assembling the application (page 210) in “Part 2A:Assembling and deploying the J2C conversational phonebook sampleapplication for Windows” on page 210.

2. Export the support classes as described in step 5 (page 211) under Step 1 of“Part 2A: Assembling and deploying the J2C conversational phonebooksample application for Windows” on page 210, but in this step, name the JARfile convsupportclass390.jar. Create the folder \WEB-INF\lib\ under yourworking directory and save the JAR file in this folder.

3. Ensure that your workstation environment is correctly updated and that theApplication Assembly Tool is installed. Download this tool athttp://www.ibm.com/software/webservers/appserv/

4. Start the Application Assembly Tool (AAT) by clicking Start > Programs > IBM> WebSphere for z/OS > Application Assembly.

5. Create a new application by clicking Selected > Add. Provide a Display name(for example, ConvIterations390), then click File > Save.

6. Export all the classes in project IBM EJB Tools on VAJ and save them as a JARfile named ejbtools.jar. Save this file in the folder \WEB-INF\lib\.

7. Import the EJB JAR file you just created (for example, ConvPhoneBookEJB.jar).

a. In the Application Assembler window of the AAT, expand the Applicationsfolder in the structure tree (by clicking the + sign next to it). Locate the newapplication you just created and expand it.

b. In the expanded structure tree, highlight the EJB Jars folder by clicking it,then click Selected > Import > Choose. Browse for the JAR file youcreated (for example, ConvPhoneBookEJB.jar), select it, and click OK.

214 IMS Connector for Java User’s Guide and Reference

c. Click OK.

8. If a Confirm file import window appears prompting you to import a file thatcontains the classes required by the EJB, click Yes. Then browse forconvsupportclass390.jar, select this file, and click OK. Then click OK to closethe window.

9. Import the Web module:

a. Locate the EAR file (ConvIterations.ear) you created in step 12 of Step 1:Assembling the application (page 210) in “Part 2A: Assembling anddeploying the J2C conversational phonebook sample application forWindows” on page 210.

b. Extract the WAR (ConvIterations.war) module from the EAR file.

c. In the Application Assembler window of the AAT, select the Web Appsfolder.

d. Click Selected > Important > Choose. Browse for the WAR file(ConvIterations.war) you just created. Select this file and click OK.

e. Click OK.

10. Add the context root:

a. In the Application Assembler window of the AAT, expand the Web Appsfolder (by clicking the + sign next to it).

b. Select the WAR file (for example, ConvIterations.war) and click Selected> Modify.

c. In the Context root field, add /icoconv.

11. Import convsupportclass390.jar and ejbtools.jar into ConvIterations.war:

a. Highlight the ConvIterations.war file, click the File tab, and click Selected >Modify.

b. Click the Import... button. Navigate to the directory containingconvsupportclass390.jar. Select that JAR file and click OK.

c. In the Import file window, under the “Relative path after import” pull-downbox, select the path \WEB-INF\lib\convsupportclass390.jar and click OK.

d. Import the ejbtools.jar file in the same way.

12. Modify the Resources Reference name:

a. Expand the following folders in order: EJB Jars folder,ConvPhoneBookEJB.jar folder, and the Session Beans folder. SelectConvPhoneBook.

b. Click the Resources tab, then click Selected > Modify. Click the Addbutton, provide a name in the Reference Name field (such as MyIMS), andselect Type javax.resource.cci.ConnectionFactory Authentication isSERVLET. Click OK.

13. Validate this application:

a. Select the application name (for example, ConvIterations390) and clickBuild > Validate.

b. Wait until the validation completes. You should see the following message:″Application ConvIterations390 can be deployed.″

14. Export the application:

a. Select the application name and click Selected > Export...

b. Choose a directory in which to save this file, provide a file name (forexample, ConvIterations390.ear), and click OK.

Step 2: Deploying the application to WebSphere Application Server for z/OSand OS/390

Chapter 14. Building a J2C conversational phonebook sample application 215

Important: It is assumed that you have deployed and configured IMS Connector forJava as a J2EE server resource in your WebSphere Application Server. It is alsoassumed that you have started the server. If you have not done so, follow steps 1to 5 of “Step 4: Deploying and Configuring IMS Connector for Java as a J2EEserver resource in WebSphere Application Server for z/OS and OS/390” in“Preparing your WebSphere Application Server Environment for z/OS and OS/390”to guide you in deploying your application.

1. Add a new conversation named ConvIterations390. For detailed instructions,see step 6 of “Step 4: Deploying and Configuring IMS Connector for Java as aJ2EE server resource in WebSphere Application Server for z/OS and OS/390” in“Preparing your WebSphere Application Server Environment for z/OS andOS/390.”

2. Install the enterprise application.

a. Select the J2EE server on which this application will be installed. Select thisserver by expanding the following folders in order: Conversations folder,the new conversation, the Sysplexes folder, the sysplex in which yoursample J2EE server has been installed, and the J2EEServers folder.

b. Click Selected > Install J2EE application... and wait for its referencewindow to appear.

c. Click the Browse EAR File... button and wait for the Open window toappear. Locate and select your EAR file. Click Open.

d. Verify that the destination and EAR file name appears in the EAR Filenametext field. Click OK and wait for the Reference and Resource Resolutionwindow to appear.

e. In the Reference and Resource Resolution dialog box:

1) On the left side of the dialog, expand the ConvPhoneBookEJB.jar folderand select the ConvPhoneBook bean.

2) On the right side of the dialog, click the J2EE Resource tab, click theempty box under J2EE Resource, then select the J2EE resource youcreated for the Server in step 9 of “Step 4: Deploying and ConfiguringIMS Connector for Java as a J2EE server resource in WebSphereApplication Server for z/OS and OS/390” in “Preparing your WebSphereApplication Server Environment for z/OS and OS/390” (for example,IMSRes).

3) Expand the ConvIterations_WebApp.jar folder, select theConvIterations_WebApp bean, click the EJB tab, and click the SetDefault JNDI Path & Name button. Click OK.

3. Validate the new conversation you just created in the previous step by selectingthe conversation name (for example, ConvIterations390) to highlight it andclicking Build > Validate.

4. Commit the new conversation by selecting the conversation name to highlight itand clicking Build > Commit.

5. Ensure that all preparation tasks for the new conversation are completed. Thenselect the conversation name to highlight it and click Build > Complete > AllTasks to indicate completion.

6. Activate the new conversation by selecting the conversation name to highlight itand clicking Build > Activate.

7. Configure the HTTP server for the context root of the ConvIterationServlet bymodifying the following files:

a. Ensure that the webcontainer.conf file contains the following information:host.default_host.contextroots=/

b. Modify the httpd.conf file with the following information:

216 IMS Connector for Java User’s Guide and Reference

Service /icoconv/* /web/usr/lpp/websphere/WebServerPlugIn/bin/was400plugin.so:service_exit

Step 3: Starting WebSphere Application Server for z/OS and OS/390

To start WebSphere Application Server for z/OS and OS/390, follow “Step 6:Starting the server to run the IMS Connector for Java IVP” in “Preparing yourWebSphere Application Server Environment for z/OS and OS/390.”

Part 3: Running the J2C conversational phonebook sample applicationStep 1: Running the J2C conversational phonebook sample application

1. Launch a Web browser. Enter the following Web address:http//Servername:port/icoconv/ConvIterationsInput.html, where servernameis the name of your WebSphere server and icoconv is the context root of theConvIterations Web module.

2. In the form you see on the Web browser, enter last1 in the Last Name field.Ensure that the Display an entry radio button is selected. Click Submit. If yousee the message “Entry was displayed” and the data record you requested,create a new record by entering a different last name, first name, extension, andzip code in the form. Select the Add an entry radio button and click Submit. Theapplication is successful if you see the message “Entry was added.”

3. Select the End conversation radio button to end the conversation.

Chapter 14. Building a J2C conversational phonebook sample application 217

218 IMS Connector for Java User’s Guide and Reference

Chapter 15. Building Container-Managed andComponent-Managed Transactional EJBs to Run IMSTransactions

This section describes how to construct two transactional EJBs, container-managedand component-managed, that use IMS Connector for Java to run a single resourceglobal transaction using two-phase commit.

Important: Before you start building this sample, be sure to complete the stepsdescribed in “Preparing to deploy J2C samples” (in “Understanding IMS Connectorfor Java”) and “Preparing to Use IMS Connector for Java.”

The container-managed EJB is built with a TX_REQUIRED transaction attribute thatpasses the transaction demarcation to the container. This method of handling thetransactions gives this EJB the name container-managed.

The component-managed (or bean-managed) EJB uses the JTA UserTransactioninterface to demarcate the transactional boundaries of methods (for example, add,delete, update, and display). These methods will call upon variations of an IMStransaction (for example, IVTNO) using the EAB command and IMS transaction inputand output record beans from the J2C phonebook sample (for example,icoex01.Ex01Command,icoex01.InMsg, and icoex01.OutMsg, respectively). This typeof EJB is called component-managed or bean-managed because the transactionalboundaries are handled with the component or bean itself. Such an EJB is built witha transaction attribute value of TX_BEAN_MANAGED. This value is set to that theuser, instead of the container, specifies transactional boundaries.

The sample described in this section uses complex methods that demonstrate someof the additional capabilities supplied by the J2C architecture. Such capabilitiesinclude bundling multiple actions into a single transaction and enabling the user toroll back these actions together and treat every action as a part of a series ofactions rather than an independent step.

This sample demonstrates how to:

v Create single action container-managed and component-managed transactionalmethods (methods that perform one add, delete, update, or display commandagainst an IMS database)

v Implement multi-action methods bundled within container-managed andcomponent-managed transactions

v Create a servlet to call upon a container-managed or component-managed bean

v Generate Web and enterprise application archives (WAR and EAR files) with IMSConnection Factory J2EE resource references

v Deploy and run the application using the HTTP server and WebSphereApplication Server for z/OS and OS/390.

This sample simulates a wedding planner’s customer database (a phonebook) inwhich the wedding planner stores couples and individuals. The wedding planneruses methods such as addCouple, deleteCouple, updateCouple, and displayCouple.Each couple in the database consists of a pair of individual entries and a set ofstatus records that link each individual in the other individual in the couple. Eachmethod to add, delete, update, or display a couple is bundled into a singletransaction. This means that every aspect of a single transaction must besuccessful or the entire transaction will be rolled back. For example, the wedding

© Copyright IBM Corp. 1998, 2002 219

planner attempts to add a couple to the phonebook. If any entry required to buildthis couple fails to be added, not only does the failed entry roll back, but everyprevious attempt made to add individual components tied to that couple ortransaction are rolled back as well.

A summary of the steps in this sample are listed below:

Part 1: “Part 1: Preparing for the sample”

Part 2: Creating the sample

1. Creating output and exception classes (page 221)

2. Creating an EJB session bean from an EAB Command (page 224)

3. Setting an EJB transaction attributes (page 226)

4. Create private verification methods for the returned output (page 226)

5. Creating and modifying single-action methods to add business and transactionlogic (page 229)

6. Creating and modifying multi-action methods to add business and transactionlogic (page 232)

7. Adding the methods to the Remote EJB Interface (page 238)

8. Generating deployed code (page 238)

9. Generating an Access Bean (page 238)

10. Creating a servlet (page 238)

11. Creating a Web Archive file (page 239)

Part 3: Packaging and Deploying the sample

1. Packaging the application into a z/OS or OS/390 enterprise archive file (page241)

2. Deploying the application to the WebSphere Application Server for z/OS orOS/390 (page 245)

Part 4: Running the sample

1. Starting the Web and WebSphere Application servers (page 248)

2. Running the Sample Application (page 248)

Part 1: Preparing for the sampleTip: For each of the steps in this document, you can copy the code directly fromthe provided sample to the appropriate enterprise bean class. To copy a methodfrom the sample provided in VisualAge for Java to your sample’s class, follow thesesteps:

1. Select the method to be copied from the sample enterprise bean class(CompPhonebookBean or ContPhonebookBean) under the sample package(com.ibm.connector2.ims.ico.sample.transactional.phonebook.ejb.servletpackage) in the Connector IMS Samples project within the All Projects pane.

2. Click Selected > Reorganize > Copy. Wait for the Copying types window toappear.

3. Click the Browse... button to specify the class that the method code will becopied to (for example, icotranejb.CompPhonebookBean oricotranejb.ContPhonebookBean).

220 IMS Connector for Java User’s Guide and Reference

4. If you want to rename the method, select the Rename the copy check box.The instructions for this sample assume that the method names remain thesame

5. If a warning message occurs indicating that there might be problems managingresource files, click OK.

Important: Any of the code provided in this document can be out of date. Checkthe sample code shipped with IMS Connector for Java for a more recentimplementation of the methods within this sample.

Complete the following steps to prepare for this sample:

1. This sample uses the EAB command and IMS transaction input and outputrecord beans generated in the J2C phonebook sample (for example,icoex01.Ex01Command, icoex01.InMsg, and icoex01.OutMsg). Ensure that Steps1 and 2 from “Part 1: Building the J2C phonebook sample application” of“Building a J2C phonebook sample application” are completed prior to buildingthis sample.

2. Start the Workbench in the VisualAge for Java IDE by clicking Start >Programs > IBM VisualAge for Java for Windows > IBM VisualAge forJava.

3. Create a Project and Package for the servlet and EJBs. Create a new projector choose an existing project (for example, Examples). Add two new packages(for example, icotranejb and icotranejbservlet) to this project. For instructionson how to create a new project and a package within this project, see “Step 1B:Creating a a Project and Package for the Application” from Part 1 of “Building aJ2C phonebook sample application.”

4. Verify your EAB Command resource reference name. As a result of using anexisting EAB command and having the possibility of deploying it under variousresource reference names, it is recommended to double check this value. If anew EAB command has been created specifically for this sample, skip thisstep. The following steps show how to perform this verification:

a. Select the EAB command class (for example, Ex01Command in the packageicoex01) from the All Projects pane under the Projects tab in the VAJworkbench.

b. Click Selected > Tools > Enterprise Access Builder > Edit Command.Wait for the Command Editor window to appear.

c. Select the Connector folder under your EAB command (for example,icoex01.Ex01Command).

d. When you see thecom.ibm.ivj.eab.command.ConnectionFactoryConfiguration appear in the leftpane, select it. Wait for the list of properties and their values to appear inthe bottom pane.

e. Verify that the res_ref_name matches the initial value created with the EABcommand in “Step 2: Creating an EAB command class for the IMStransaction” of “Building a J2C phonebook sample application” (for example,MyIMS).

Part 2: Creating the sampleStep 1: Creating output and exception classes

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 221

Within the Java programming language, abnormal occurrences in an application arecaptured in classes that extend the java.lang.Exception class. In this scenario, IMSdatabase and data communication messages from the host machine (DFSMessages) can indicate that a transaction did not complete successfully. Create anexception that informs clients when this occurs. Various other transactional logicproblems should also throw an exception (for example, when an attempt is made toadd a new couple and an individual in that couple already exists). The exceptionsimply stores a string with the explanation for the transaction failure. To create anduse these exceptions easily, all of these exceptions are bundled into a single typeof exception class that indicates that the application has failed (for example,PhonebookException).

Additionally, you must construct the output class. The transactional multi-actionbusiness methods require two output buffers (for example, for the first partner andthe second partner in a couple). To simplify the output for this expansion, a newclass should be created that contains both of these buffers (for example,CoupleOutput).

The following steps describe how to construct the application exception and outputclass that will contain the set of data for a couple:

1. Construct a new exception type (for example, PhonebookException)

a. Select the package that will contain the exception class (for example,icotranejb) from the All Projects pane under the Projects tab in the VAJworkbench.

b. Click Selected > Add > Class... and wait for the Create Class SmartGuideto appear.

c. Verify that the names in the project and package fields match your selection(for example, Examples and icotranejb, respectively).

d. Enter the name of the exception (for example, PhonebookException) in theClass Name field.

e. Enter java.lang.Exception in the Superclass field to indicate that this classwill be a type of exception.

f. Click the Finish button to generate this class.

2. Construct the dual-output class (for example, CoupleOutput)

a. Select the package that will contain the output class (for example,icotranejb) from the All Projects pane under the Projects tab in the VAJworkbench.

b. Click Selected > Add > Class... and wait for the Create Class SmartGuideto appear.

c. Verify that the names in the project and package fields match your selection(for example, Examples and icotranejb, respectively).

d. Enter the name of the class that will capture the two output records (forexample, CoupleOutput) in the Class Name field.

e. Verify that java.lang.Object is specified in the Superclass field to indicatethat this class will be a new type of object.

f. Click the Next > button.

g. Next to the Add import statements: list, click the Add Type... button toimport the types of data that will be stored within this bean (for example,com.ibm.record.IByteBuffer). Wait for the Import Statement window toappear.

222 IMS Connector for Java User’s Guide and Reference

h. Enter the output type (for example, IByteBuffer) in the field provided andselect the appropriate package that contains this bean (for example,com.ibm.record) from the list of package names.

i. Click the Add button, then click Close.

j. Next to the Which interfaces should this class implement? list, click theAdd... button to import the interface that will supply this bean with a meansof persistence, or an ability to save itself in byte form and carry its databeyond one session (for example, java.io.Serializable). Wait for theImport Statement window to appear.

k. Enter the output type (for example, Serializable) in the field provided andselect the appropriate package that contains this bean (for example,java.io) from the list of package names.

l. Click the Add button, then click Close.

m. Click the Finish button to generate this class.

3. Add a set of output fields to the dual-output class:

a. Ensure that the new output class (for example, CoupleOutput) is selected.

b. Click Selected > Add > Field... and wait for the Create Field SmartGuide toappear.

c. Type the name of the instance of the first output field (for example, output1)in the Field Name: box.

d. Click the Browse... button next to the Field Type drop down box and waitfor the Field Type window to appear.

e. Enter IByteBuffer in the field provided and select the com.ibm.recordfromthe list of packages in the bottom pane.

f. Click OK.

g. Verify that the public radio button for the Access Modifiers, the Accesswith getter and setter methods checkbox, the public radio button for theGetter method, and the public radio button for the Setter method areselected.

h. Click the Finish button.

i. Repeat steps a-h to add the second output field (for example, output2).

4. Add an initializing constructor to complete the dual-output class:

a. Select the new output class (for example, CoupleOutput) from the AllProjects pane.

b. Click Selected > Add > Method... and wait for the Create MethodSmartGuide to appear.

c. Select the Create a new constructor radio button.

d. Replace the contents of the provided field with a constructor that acceptsthe two output records. For example:public CoupleOutput(IByteBuffer out1, IByteBuffer out2)

e. Click the Finish button.

f. Store the output for each individual of a couple in the body of the newconstructor method. For example, type the following lines of code betweenthe curly braces ({}) in the Source pane of the constructor added in step 4dabove to the body of the newly generated method:this.output1 = out1;this.output2 = out2;

g. Click Edit > Save to finish constructing the output type that will capture andreturn the output for a multi-action method (for example, CoupleOutput).

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 223

Step 2: Creating EJB session beans from an EAB Command

This section describes how to use Visual Age for Java EAB Session Bean tooling toconstruct an EJB session bean based on an EAB Command. For information onthe various types of enterprise javabeans, see “IMS Connector for Java conceptsand terms.”

1. If you have not previously added the IBM WebSphere Test Environment, IBMEJB Development Environment, IBM Enterprise Access Builder Library, and IMSConnector projects to the Workbench, do the following (otherwise skip to thenext step):

a. Select File > Quick Start. The Quick Start dialog opens.

b. Click on Features, choose Add Feature, and click OK.

c. From the list of features, select IBM Enterprise Access Builder Library,IMS Connector, IBM EJB Development Environment, and IBMWebSphere Test Environment. Click OK.

For more details on adding the EJB Development Environment to the IDE, seethe VisualAge for Java documentation by clicking Help > Help Home Page >Tasks > Developing EJB Components > Setting up the EJB DevelopmentEnvironment > Loading the required features.

2. Create the Session EJB to run an IMS transaction:

a. Click on the EJB tab on the Workbench to go to the EJB DevelopmentEnvironment.

b. If an EJB group already exists for this bean (for example, EJBExamples), skipto step 2 d. If not, create an EJB group by selecting EJB > Add > EJBGroup.... and wait for the Add EJB Group SmartGuide to appear. EJBs inVisual Age for Java need to be organized in EJB groups, just as classesneed to be organized in packages. To create a new EJB that is based onan EAB Command, an EJB Group must exist.

c. In the Add EJB Group SmartGuide, do the following:

1) Click Browse... and select the project in which the sample is beingdeveloped (for example, Examples). Click OK.

2) Ensure the radio button next to the Create a new EJB group namedfield is selected and type the name of the group you want to create (forexample, EJBExamples).

3) Click Finish.

d. Select the newly created group (for example, EJBExamples) in the Enterprisebeans pane. From the main menu bar, select EJB > Open To > EABSession Bean Tool... to create the EJB.

e. When prompted by the EAB Session Bean dialog, ensure the Create a newEAB Session Bean radio button is selected.

f. Click OK. Wait for the Create EAB Session Bean SmartGuide appears.

g. In the Create EAB Session Bean section of the SmartGuide, do thefollowing:

1) Click the Browse... button next to the Project entry field and select theproject in which the sample is being developed (for example,Examples). Click OK.

2) Click the Browse... button beside the Package entry field and selectthe package in which the sample is being developed (for example,icotranejb). Click OK.

224 IMS Connector for Java User’s Guide and Reference

3) In the Class name entry field, enter the name of the EJB to create (forexample, CompPhonebook).

4) Ensure the Edit when finished checkbox is not selected. You canalways edit the EAB properties of this bean later.

5) Click the Browse... button below the Connection Information headingand beside the Class name entry field.

6) Select ConnectionFactoryConfiguration in thecom.ibm.ivj.eab.command package and click OK.

7) Click the Edit button to edit the parameters of this configuration asfollows:

ConnectionSpecThis property specifies the connection to the host system.Select com.ibm.connector2.ims.ico.IMSConnectionSpecfrom the pull-down menu.

contextFactoryNameThis property specifies the InitialContext class. JNDI performsall naming operations relative to a context. To assist in findinga place to start, the JNDI specification defines an InitialContextclass. This class is instantiated with properties that define thetype of naming service in use. The InitialContext class providesalso provides the ID and password to use when connecting.Specifycom.ibm.websphere.naming.WsnInitialContextFactory forthis property.

logWriterThis property is the output data stream for logging and tracing.Specify null for this property

managedConnectionFactoryThis property sets the ManagedConnectionFactory object,which is used to manually create a ConnectionFactory object.Selectcom.ibm.connector2.ims.ico.IMSManagedConnectionFactoryfrom the pull-down menu.

res_ref_nameThis property specifies the binding name of the connectionfactory object. A binding is the association of a name with anobject. Type MyIMS.

res_typeThis property specifies the name of the connection factory.Select javax.resource.cci.ConnectionFactory from thepull-down menu.

8) Select Container from the drop down box next to the res_authlabel.

9) In the res_ref_name field specify the resource name that was used inthe construction of the EAB command (for example, MyIMS)

10) Select javax.resource.cci.ConnectionFactory from the drop downbox next to the res_type label.

11) Click the OK button to complete the configuration.

12) Click Next. The Add Methods section of the SmartGuide appears.

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 225

h. Add a method to help your application interact with an IMS transaction. Inthe Add Methods section, do the following to add a method to the EABSession Bean:

1) Click Add.... Wait for the method information SmartGuide to appear.

2) In the Method name field, type the name of the method you are adding(for example, executeCmd).

3) Click the Use existing command: button. Click on the Browse... buttonand select the class (for example, Ex01Command) and the package (forexample, icoex01). Click OK.

4) Click OK.

5) Click Finish.

i. Repeat Steps d through h for a container-managed EJB scenario (forexample, create an EAB Session Bean named ContPhonebook that is basedon the same EAB command, icoex01.Ex01Command, within the samepackage, icotranejb, and EJB group, EJBExamples).

Step 3: Setting the EJB Transaction Attributes

This step shows how to change the default transaction attribute(TX_NOT_SUPPORTED) of an EJB session bean within Visual Age for Java. Atransaction attribute is a value that indicates how a container should manage aspecific method or all of the methods within an EJB’s remote interface. For adescription on the various types of transaction attributes, see “IMS Connector forJava concepts and terms.” In this scenario, the transaction attribute for the entireEJB is changed. Thus, any business methods which are later added to the EJB’sremote interface will take on this transaction attribute.

1. Select the enterprise bean class of the EJB session bean created in theprevious step. To do so, expand the EJB Group which contains this EJB sessionbean (for example, EJBExamples). Select the EJB session bean (for example,CompPhonebook). Select the enterprise bean class from the Types pane (forexample, CompPhonebookBean).

2. Open the EJB properties window. Click EJB > Properties.

3. From the pull-down menu of the Transaction Attribute field, select how themethods of the EJB Session will be managed (for example,TX_BEAN_MANAGED).

4. Click OK to close the EJB properties window and save the new transactionattribute.

5. Repeat these steps for a container-managed EJB scenario (for example, modifythe transaction attribute of the ContPhonebookBean to be TX_REQUIRED).

Step 4: Creating private verification methods for the returned output

The business methods in this sample require verification that an action hassucceeded. In order to indicate that a method has completed successfully, twoverification methods are built. The first verification method accepts the output classand the command which created this output. It then performs a verification that noDFS messages were thrown and that the command completed successfully. If eitherof these two requirements are not met, the verification method throws an applicationexception with the DFS message DFSData1 parameter or the invalid messagereturned with the output. The second verification method is an overloaded functionof the first. This means that its method name is the same as the first verificationmethod, but it distinguishes itself with an extra input parameter, the state parameter.Within the multi-action methods it can be hard to distinguish which action failed in

226 IMS Connector for Java User’s Guide and Reference

the series. The state parameter of this verification method allows the user to enteran additional string to supply some information about where the failure occurred inthe multi-action method.

The following steps describe how to construct these two verification methods:

1. Click the Projects tab in the VisualAge for Java Workbench.

2. Select the enterprise bean class for EJB session bean created in Step 2 (page224) (for example, CompPhonebookBean, found within the Examplesproject andthe icotranejb package).

3. Add an import statement to make the package that contains the EABcommand accessible to the EJB. This command was created in “Step 2:Creating an EAB command class for the IMS transaction” of “Building a J2Cphonebook sample application.” Also add an import statement for the DFSMsgtype. For example, insert the following line of code above the text displayed inthe source pane:import icoex01.*;import com.ibm.connector2.ims.ico.DFSMsg;

4. Save this modification by clicking Edit > Save.

5. Click the EJB tab in the VisualAge for Java Workbench.

6. In the Enterprise Beans window, click the + next to your EJB Group (forexample, EJBExamples) to expand it. Then select the EJB you created in Step 2(page 224) (for example, CompPhonebook).

7. In the Types pane, select the enterprise bean class (for example,CompPhonebookBean).

8. Click Types > Add > Method. Wait for the Create Method SmartGuide toappear.

9. In the Create Method SmartGuide, do the following:

a. Select the Create a new method radio button.

b. In the field provided type the following:public void verifyOutput(IByteBuffer output, String cmd)

throws PhonebookException

c. Click Finish.

10. In the Source pane, paste the following lines of code into the body of themethod or between the curly braces ({}):

try {//If the output is null, this method throws an exception//with a string indicating it received a null outputif (output==null)

throw new PhonebookException(“NULL OUTPUT”);

//If the output is a DFS Message, this method throws// an exception with the DFS Message stringif (java.beans.Beans.isInstanceOf(output, DFSMsg.class))

throw new PhonebookException(((DFSMsg) output).getDFSDATA1());

//Otherwise this method will attempt to down cast the//output into an output message type, retrieve//the message string and trim off it’s blanks storing it//into a variable, outMsg.String outMsg = ((OutMsg) output).getOUT__MSG().trim();

//It will then determine what type of command was executed//(DISPLAY, ADD, DELETE, or UPDATE).if (cmd.equals(“DISPLAY”) || cmd.equals(“ADD”)) {

//If it was a DISPLAY or ADD command and the// output message is not “ENTRY WAS DISPLAYED” or

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 227

// “ENTRY WAS ADDED” respectively, then throw// an exception with the output message stringif (!outMsg.equals(“ENTRY WAS” + cmd + “ED”))

throw new PhonebookException(((OutMsg) output).getOUT__MSG());} else {

//If it was a DELETE or UPDATE command and the// output message is not “ENTRY WAS DELETED” or// “ENTRY WAS UPDATED” respectively, then throw// an exception with the output message stringif (!outMsg.equals(“ENTRY WAS” + cmd + “D”))

throw new PhonebookException(((OutMsg) output).getOUT__MSG());}

} catch (PhonebookException phe) {//Catch and throw all Phonebook Exceptionsthrow phe;

} catch (Exception e){//Catch any other exceptions and throw a new//PhonebookException based on what was caughtthrow new PhonebookException(e.getMessage());

}

11. Click Edit > Save. This completes the construction of the first verificationmethod.

12. Repeat steps 5-11 to create an overloaded verification method with anadditional state parameter. For example, create the empty method with thefollowing declaration:public void verifyOutput(IByteBuffer output, String cmd, String state) throws PhonebookException

Then add the following lines of code to this methods body and save yourmethod:try {

//Perform the same verification and exception handling as that shown in the overloaded//verification method without the state parameterif (output==null)

throw new PhonebookException(“NULL OUTPUT”);

if (java.beans.Beans.isInstanceOf(output, DFSMsg.class))throw new PhonebookException(((DFSMsg) output).getDFSDATA1());

String outMsg = ((OutMsg) output).getOUT__MSG().trim();

if (cmd.equals(“DISPLAY”) || cmd.equals(“ADD”)) {//If it was a DISPLAY or ADD command and the output message is not//“ENTRY WAS DISPLAYED” or “ENTRY WAS ADDED” respectively,//then throw an exception with the state string appended to the//output message string

if (!outMsg.equals(“ENTRY WAS” + cmd + “ED”))throw new PhonebookException(((OutMsg) output).getOUT__MSG() + “: ” + state);

} else {//If it was a DELETE or UPDATE command and the output message is not//“ENTRY WAS DELETED” or “ENTRY WAS UPDATED” respectively,//then throw an exception with the state string appended to the//output message stringif (!outMsg.equals(“ENTRY WAS” + cmd + “D”))

throw new PhonebookException(((OutMsg) output).getOUT__MSG() + “: ” + state);}

} catch (PhonebookException phe) {throw phe;

} catch (Exception e) {throw new PhonebookException(e.getMessage());

}

13. Repeat the above steps for the container-managed EJB (for example,ContPhonebookBean).

228 IMS Connector for Java User’s Guide and Reference

Step 5: Creating and modifying single-action methods to add business andtransaction logic

Now you are ready to create your single-action business methods (for example,add, delete, display, and update) and handle the transaction logic for these methodsusing the code provided in this document. You can also use the code found intransactional phonebook samples shipped with IMS Connector for Java, locatedunder the Connector IMS Samples project within thecom.ibm.connector2.ims.ico.sample.transactional.phonebook.ejbpackage.

1. Click the Projects tab in the VisualAge for Java Workbench.

2. Select the enterprise bean class for the component-managed EJB sessionbean (for example, CompPhonebookBean, found in the Examples project and theicotranejb package).

3. Add an import statement to the component-managed EJB to acquire the JTAtransaction demarcation methods. For example, insert the following line ofcode at the top of the text displayed in the source pane:import javax.transaction.*;

4. Click the EJB tab in the VisualAge for Java Workbench.

5. In the Enterprise Beans window, expand the EJB Group (for example,EJBExamples) and select the EJB you created in Step 2 (page 224) (forexample, CompPhonebook).

6. In the Types pane, select the enterprise bean class (for example,CompPhonebookBean).

7. Add a method that automatically populates the fields of the input record (suchas, InMsg) with the values that are passed in by the business methods toexecute the EAB command. With this method, you don’t have to manuallypopulate the fields yourself.

a. Click Types > Add > Method. Wait for the Create Method SmartGuide toappear.

b. In the Create Method SmartGuide, do the following:

1) Select the Create a new method radio button.

2) In the field provided, enter the following:

public IByteBuffer phonebookAction(String lastName,StringfirstName,String zip,String ext,String cmd) throwsPhonebookException, RemoteException

3) Click Finish.

c. In the Source pane, replace the return null; line of code with the following://Instantiate a new input message with one segment//of 59 bytes in length, an internal ZZ flag//that is set to the required 0 value for input messages,//using the IVTNO transaction, and the lastname, firstname,//zip code, extension, and transaction command entered//by the user.InMsg input = new InMsg();input.setIN__LL((short) 59);input.setIN__ZZ((short) 0);input.setIN__TRCD(“IVTNO”);input.setIN__NAME1(lastName);input.setIN__NAME2(firstName);input.setIN__ZIP(zip);input.setIN__EXTN(ext);input.setIN__CMD(cmd);

//Submit the input message to be executed

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 229

IByteBuffer output = executeCmd(input);

//Verify the outputverifyOutput(output,cmd);

//Return any valid outputreturn output;

d. Click Edit > Save.

8. Add the business methods:

a. Click the EJB tab in the VisualAge for Java Workbench.

b. In the Enterprise Beans window, click the + next to your EJB Group (forexample, EJBExamples) to expand it. Then select the EJB you created inStep 2 (page 224) (for example, CompPhonebook).

c. In the Types pane, select the enterprise bean class (for example,CompPhonebookBean).

d. Click Types > Add > Method. Wait for the Create Method SmartGuide toappear.

e. In the Create Method SmartGuide, do the following:

1) Select the Create a new method radio button.

2) In the field provided type the following:

public IByteBuffer display(String lastName,StringfirstName,String zip,String ext) throws PhonebookException,RemoteException

3) Click Finish.

f. In the Source pane, replace the return null; line of code with the followingbusiness and transactional logic. Reminder: If you are implementing thecontainer-managed EJB, see part 10 of this step):

//Instantiate a command parameter string and//set it equal to DISPLAYString cmd = “DISPLAY”;

//Instantiate the output bufferIByteBuffer output;

//Since this method has a transaction attribute of//TX_BEAN_MANAGED the bean must manage the boundaries//of any transaction it creates. Instantiate a new//user transaction to provide transaction boundary setting//methods to the bean. To do so use the session context//(information about the session in which the EJB is//instantiated) passed to the EJB from the container to//acquire a user transaction valid for that session.UserTransaction transaction = mySessionCtx.getUserTransaction();

try {//Indicate that the current thread is a new transactiontransaction.begin();

//Attempt perform the defined phonebook command using//the user supplied dataoutput = this.phonebookAction(lastName, firstName, zip, ext, cmd);

//Complete the transaction and indicate that the thread is//no longer a transactiontransaction.commit();

//Return any valid output returned from the phonebook actionreturn output;

230 IMS Connector for Java User’s Guide and Reference

} catch (Exception e) {//Catch any exceptions thrown during the transaction// processtry {

//Attempt to Roll back any changes made to the database//during the transaction and indicate that the thread//is no longer a transactiontransaction.rollback();

} catch (SystemException se) {//Catch any exceptions thrown during the transaction// roll back process and bundle them into a new// PhonebookException with the system exception appended// to the original exception that was caughtthrow new PhonebookException(e.toString() + “:EXCEPTION CAUGHT WHILEATTEMPTING TO ROLLBACK:” + se.toString();

}//If the roll back of the transaction completes successfully// catch and throw all PhonebookExceptions as isif (e instanceof PhonebookException)

throw (PhonebookException) e;//Bundle the exception caught into a PhonebookExceptionelse

throw new PhoneboookException(e.getMessage());}

g. Click Edit > Save.

h. Repeat the previous steps to create additional methods. For this sample,create the methods add, delete, and update. For each new method youcreate, replace its name (for example, display) within its declaration withthat of the new method’s name (for example, add, delete, or update).Be sure to update the command parameter value (for example, the″DISPLAY″ value for the cmd parameter) with the appropriate command forthe method you are creating (for example, ″ADD″, ″DELETE″, or ″UPDATE″).A servlet will use the four business methods (for example, add, delete,display, and update) to access the sample phonebook. Note that thephonebookAction method is only used internally and will not be added tothe remote interface.

Tip: For faster results, make all of the modifications (for example, methodname change and command change) for one specific method (for example,add) to a pre-existing method (for example, display) and save thechanges. This will result in a new method being generated with nomodifications to the pre-existing method.

9. Ensure that no compilations or other errors (indicated by a red X next to themethod or gray X next to the class name) exist. If errors occur, compare thenewly generated code with the code found in a similar sample class foundunder the IMSEJBSamples EJB group in the EJB development environment.

10. Repeat these steps for the container-managed bean, but this time add newmethod functionality that will use the setRollbackOnly method to force thecontainer (instead of the user) to roll back the transaction when an exception iscaught. The setRollbackOnly method indicates to the container that thistransaction cannot be committed and must be rolled back. For example, followthe same steps using the ContPhonebook EJB rather than the CompPhonebookEJB, but replace the business and transactional logic with the following code://Since this EJB method has a transaction attribute//of TX_REQUIRED the current thread automatically//becomes a transaction upon entering this method

//Instantiate a command parameter string and//set it equal to DISPLAYString cmd = “DISPLAY”;

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 231

//Instantiate the output bufferIByteBuffer output;try {

//Attempt to acquire the listing for the user’s input//by performing the phonebook action with the supplied dataoutput = this.phonebookAction(lastName, firstName, zip, ext, cmd);

//Return any valid output returned from the phonebook actionreturn output;

} catch (Exception e) {//Catch any exceptions thrown by the phonebook action and// indicate to the container that the transaction can have// no other outcome other than be rolled backmySessionCtx.setRollbackOnly();

//Catch and throw all PhonebookExceptions as is.if (e instanceof PhonebookException)

throw (PhonebookException) e;//Bundle the exception caught into a PhonebookExceptionelse

throw new PhonebookException(e.getMessage());}

Step 6: Creating and modifying multi-action methods to add business andtransaction logic

Now you are ready to create your multi-action business methods (for example,addCouple, deleteCouple, displayCouple, and updateCouple) and handle thetransaction logic for these methods, using the code provided in this document. Youcan also use the code found in the transactional phonebook samples shipped withIMS Connector for Java (located under the Connector IMS Samples project withinthe com.ibm.connector2.ims.ico.sample.transactional.phonebook.ejbpackage).Because the logic for displaying a couple differs from that of adding, deleting, orupdating it (database modification methods), the step for creating the displaymethod is described separately.

1. Click the EJB tab in the VisualAge for Java Workbench.

2. In the Enterprise Beans window, click the + next to your EJB Group (forexample, EJBExamples) to expand it. Then select the EJB you created in Step 2(page 224) (for example, CompPhonebook).

3. In the Types pane, select the enterprise bean class (for example,CompPhonebookBean).

4. Add a method that automatically populates the fields of the input record (suchas, InMsg) with the values that are passed in by the business methods toexecute the EAB command. With this method, you don’t have to manuallypopulate the fields yourself. Notice that this method is an overloaded version ofthe method constructed for the previous step. In this case, the state parameteris passed to accept information pertaining to the mutli-action method beingperformed.

a. Click Types > Add > Method. Wait for the Create Method SmartGuide toappear.

b. In the Create Method SmartGuide, do the following:

1) Select the Create a new method radio button.

2) In the field provided, enter the following:

public IByteBuffer phonebookAction(String lastName, StringfirstName, String zip, String ext, String cmd, String state)throws PhonebookException, RemoteException

232 IMS Connector for Java User’s Guide and Reference

3) Click Finish.

c. In the Source pane, replace the return null; line of code with the following://Instantiate a new input message with one segment//of 59 bytes in length, an internal ZZ flag//that is set to the required 0 value for input messages,//using the IVTNO transaction, and the lastname, firstname,//zip code, extension, and transaction command entered//by the user.InMsg input = new InMsg();input.setIN__LL((short) 59);input.setIN__ZZ((short) 0);input.setIN__TRCD(“IVTNO”);input.setIN__NAME1(lastName);input.setIN__NAME2(firstName);input.setIN__ZIP(zip);input.setIN__EXTN(ext);input.setIN__CMD(cmd);

//Submit the input message to be executedIByteBuffer output = executeCmd(input);

//Verify that the output is valid for the command supplied//and use the state information for a more descriptive//invalid output messageverifyOutput(output,cmd,state);

//Return any valid outputreturn output;

d. Click Edit > Save.

5. Create the multi-action transactional methods that will modify the database forthe component-managed EJB (for example, CompPhonebook).

a. Click the EJB tab in the VisualAge for Java Workbench.

b. In the Enterprise Beans window, click the + next to your EJB Group (forexample, EJBExamples) to expand it. Then select the EJB you created inStep 2 (page 224) (for example, CompPhonebook).

c. In the Types pane, select the enterprise bean class (for example,CompPhonebookBean).

d. Click Types > Add > Method. Wait for the Create Method SmartGuide toappear.

e. In the Create Method SmartGuide, do the following:

1) Select the Create a new method radio button.

2) In the field provided, enter the following:

public CoupleOutput addCouple(String lastName1,StringfirstName1,String zip1,String ext1,String lastName2,StringfirstName2,String zip2,String ext2) throwsPhonebookException, RemoteException

3) Click Finish.

f. In the Source pane, replace the return null; line of code with the followingbusiness and transactional logic. If you are implementing thecontainer-managed EJB, refer to part 9 of this step. The following logic addsthe two individuals to the database, then constructs two more entries thatcontain a name that is the hashcode of the lastname of the individual thatthe couple status record represents. For example, John Doe would have acouple status record created for him under the number that is produced bygenerating a hashcode from his last name, Doe. A hashcode is a unique

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 233

number that can be generated for a specific object using the hashcodefunction. The couple status record stores the name of the partner for theindividual for which that status applies.

//Instantiate a command parameter string and//set it equal to ADDString cmd = “ADD”;

//Instantiate the output buffersIByteBuffer output1 = null;IByteBuffer output2 = null;

//Instantiate strings that will be used for//the status hashcode for each individualString hashcode1, hashcode2;

//Use the same transaction demarcation technique//as the single action version of this methodUserTransaction transaction = mySessionCtx.getUserTransaction();try {

//Indicate that the current thread is a new transactiontransaction.begin();

//Attempt to perform the command for the first input individual//by performing the phonebook action with the supplied dataoutput1 = this.phonebookAction(lastName1,firstName1,zip1,ext1,cmd,“FIRST INDIVIDUAL”);

//Change the last name of the first individual to upper case//for a consistent hash codelastName1 = lastName1.toUpperCase();

//Acquire the hashcode of the last name for the first individualint h = lastName1.hashCode();

//Allow ease of use when converting the hashcode to a string by ensuring//that it is positiveif (h < 0) h = 0 - h;

//Store the string value of the haschode for//the first individualhashcode1 = String.valueOf(h);

//Attempt to perform the command for the status record of the first individual//by performing the phonebook action with the hashcode of the individual’s//last name and a truncated version of the data for the matching recordphonebookAction(hashcode1, lastName2, zip1, ext1, cmd, “FIRST COUPLE STATUS”);

//Repeat the previous steps for the second individualoutput2 = this.phonebookAction(lastName2,firstName2,zip2,ext2,cmd,“SECOND INDIVIDUAL”);

lastName2 = lastName2.toUpperCase();h = lastName2.hashCode();if (h < 0) h = 0 - h;hashcode2 = String.valueOf(h);phonebookAction(hashcode2, lastName1, zip2, ext2, cmd, “SECOND COUPLE STATUS”);

transaction.commit();

//Return any valid output in the form of a CoupleOutputreturn new CoupleOutput(output1, output2);

} catch (Exception e) {//Use the same exception handling technique as that of the single action//version of this command

234 IMS Connector for Java User’s Guide and Reference

try {transaction.rollback();

} catch (SystemException se) {throw new PhonebookException(

e.toString()+ “: EXCEPTION CAUGHT WHILE ATTEMPTING TO ROLLBACK: ”+ se.toString());

}//If the roll back of the transaction completes successfully//catch and throw all PhonebookExceptions as is.if (e instanceof PhonebookException)

throw (PhonebookException) e;//bundle the exception caught into a PhonebookExceptionelse

throw new PhonebookException(e.getMessage());}

g. Click Edit > Save.

h. Repeat the previous steps to create additional multi-action methods that willmodify the database. For this sample, create the methods updateCoupleand deleteCouple. For each new method replace its name (for example,addCouple) within its declaration with that of the new method’s name (forexample, updateCouple or displayCouple). Be sure to update the commandparameter value (for example, the ″ADD″ value of the cmd parameter) with theappropriate command for the method you are creating (for example,″UPDATE″ or ″DELETE″). A servlet will use the four business methods (forexample, add, delete, display, and update) to access the samplephonebook. (Note that the phonebookAction method is only used internallyand will not be added to the remote interface).

6. Add the multi-action method that will display the couple.

a. Click the EJB tab in the VisualAge for Java Workbench.

b. In the Enterprise Beans window, click the + next to your EJB Group (forexample, EJBExamples) to expand it. Then select the EJB you created inStep 2 (page 224) (for example, CompPhonebook).

c. In the Types pane, select the enterprise bean class (for example,CompPhonebookBean).

d. Add a method that automatically populates the fields of the input record(such as, InMsg) with the values that are passed in by the businessmethods to execute the EAB command. With this method, you don’t have tomanually populate the fields yourself.

e. Click Types > Add > Method. Wait for the Create Method SmartGuide toappear. In the Create Method SmartGuide, do the following:

1) Select the Create a new method radio button.

2) In the field provided, enter the following:

public CoupleOutput displayCouple(String lastName1,StringfirstName1,String zip1,String ext1) throwsPhonebookException, RemoteException

3) Click Finish.

7. In the Source pane, replace the return null; line of code with the followingbusiness and transactional logic. If you are implementing thecontainer-managed EJB, see part 9 of this step. The following logic firstacquires the specified individual from the database. It then uses the hashcodefunction to generate the name of this individual’s couple status and obtain thestatus record. From the status record, it pulls out the name of the individualthat is associated with the first individual. It then pulls out the information forthe second individual and bundles the two individuals into the multi-output class.

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 235

//Instantiate similar variables as those found in//the addCouple method, but initialize the//hashcode and last name’s for the individual’s//status recordString cmd = “DISPLAY”;IByteBuffer output1 = null;IByteBuffer output2 = null;IByteBuffer coupleStatus1 = null;String hashcode1 = “”;String lastName2 = “”;

//Use the same transaction demarcation technique//as the single action version of this methodUserTransaction transaction = mySessionCtx.getUserTransaction();try {

transaction.begin();

//Search for and acquire the listing for the first individualoutput1 =

phonebookAction(lastName1, firstName1,zip1, ext1, cmd, “FIRST INDIVIDUAL”);

//Obtain the hashcode for the first individual’s last namelastName1 = lastName1.toUpperCase();int h = lastName1.hashCode();if (h < 0) h = 0 - h;hashcode1 = String.valueOf(h);

//Search for and acquire the status record for the first individualcoupleStatus1 =phonebookAction(hashcode1, “”, “”, “”, cmd, “FIRST COUPLE STATUS”);

//Obtain the last name of the individual that is the partner of the firstlastName2 = ((OutMsg) coupleStatus1).getOUT__NAME2();

//Search for and acquire the listing for the second individualoutput2 = phonebookAction(lastName2, “”, “”, “”, cmd, “SECOND INDIVIDUAL”);

transaction.commit();return new CoupleOutput(output1, output2);

} catch (Exception e) {//Use the same exception handling technique as that of the single action// version of this commandtry {

transaction.rollback();} catch (SystemException se) {

throw new PhonebookException(e.toString() + “: ROLLBACK FAILED: ” + se.toString());

}//If the roll back of the transaction completes successfully//catch and throw all PhonebookExceptions as is.if (e instanceof PhonebookException)

throw (PhonebookException) e;//Bundle the exception caught into a PhonebookExceptionelse

throw new PhonebookException(e.getMessage());}

8. Click Edit > Save.

9. Repeat all of the parts to this step for the container-managed bean, but this timeadd new method functionality to take advantage of the setRollbackOnlymethod in order to force the container (instead of the user) to rollback thetransaction. For example, follow the same steps using the ContPhonebook EJBrather than the CompPhonebook EJB, but replace the business and transactionallogic for the database modification methods with the following code:

236 IMS Connector for Java User’s Guide and Reference

//Perform the same function as that for the component managed//addCouple method, but use the container managed transaction//handling technique found in the single action version of this method//within this EJBString cmd = “ADD”;IByteBuffer output1 = null;IByteBuffer output2 = null;IByteBuffer coupleStatus1 = null;IByteBuffer coupleStatus2 = null;String hascode1, hashcode2;try {

output1 = this.phonebookAction(lastName1, firstName1,zip1, ext1, cmd, “FIRST INDIVIDUAL”);

output1 = this.phonebookAction(lastName2, firstName2,zip2, ext2, cmd, “FIRST INDIVIDUAL”);

lastName1 = lastName1.toUpperCase();int h = lastName1.hashCode();if (h < 0) h = 0 - h;lastName2 = lastName2.toUpperCase();hashcode1 = String.valueOf(h);h = lastName2.hashcode();if (h < 0) h = 0 - h;hashcode2 = String.valueOf(h);phonebookAction(hashcode1, lastName2, zip1, ext1, cmd, “FIRST COUPLE STATUS”);phonebookAction(hashcode2, lastName1, zip2, ext2, cmd, “SECOND COUPLE STATUS”);return new CoupleOutput(output1, output2);

} catch (Exception e) {mySessionCtx.setRollbackOnly();//catch and throw all PhonebookExceptions as is.if (e instanceof PhonebookException)

throw (PhonebookException) e;//Bundle the exception caught into a PhonebookExceptionelse

throw new PhonebookException(e.getMessage());}

Replace the display methods logic with the following code://Perform the same function as that for the component managed//displayCouple method, but use the container managed transaction//handling technique found in the single action version of this method//within this EJBString cmd = “DISPLAY”;IByteBuffer output1 = null;IByteBuffer output2 = null;IByteBuffer coupleStatus1 = null;String hashcode1 = “”;String lastName2 = “”;try {

output1 = this.phonebookAction(lastName1, firstName1,zip1, ext1, cmd, “FIRST INDIVIDUAL”);

lastName1 = lastName1.toUpperCase();int h = lastName1.hashCode();if (h<0) h=0-h;hashcode1 = String.valueOf(h);coupleStatus1 = phonebookAction(hashcode1,“”,“”,“”,cmd,“FIRST COUPLE STATUS”);lastName2 = ((OutMsg) coupleStatus1).getOUT__NAME2();output2 = phonebookAction(lastName2, “”, “”, “”, cmd, “SECOND INDIVIDUAL”);return new CoupleOutput(output1, output2);

} catch (Exception e) {mySessionCtx.setRollbackOnly();//Catch and throw all PhonebookExceptions as isif (e instanceof PhonebookException)

throw (PhonebookException) e;

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 237

//Bundle the exception caught into a PhonebookExceptionelse

throw new PhonebookException(e.getMessage());}

Step 7: Adding the methods to the EJB Remote Interfaces

Add a declaration for each of the business methods (for example, add, delete,update, display, addCouple, deleteCouple, updateCouple, and displayCouple)to the EJB remote interfaces (for example, CompPhonebook and ContPhonebook).These methods are found within the enterprise bean classes (for example,CompPhonebookBean and ContPhonebookBean) created in the steps above. Forinstructions on how to add methods to the EJB Remote Interface, see to “Step 5:Adding the methods to the EJB Remote Interface” of “Building a J2C phonebooksample application.”

Step 8: Generating deployed code

To run the sample, you must first generate the deployed code for the EJB sessionbeans (for example, CompPhonebookandContPhonebook). These beans are found inthe EJB group you created earlier (for example, EJBExamples). For instructions onhow to generate the deployed code, see “Step 6: Generating deployed code” of“Building a J2C phonebook sample application.”

Step 9: Generating Access Beans

Generate access beans (for example, CompPhonebookAccessBeanandContPhonebookAccessBean) for the EJB session beans (for example,CompPhonebookandContPhonebook). These beans are found in the EJB group youcreated earlier (for example, EJBExamples). For instructions on how to generate anaccess bean see “Step 7: Generating an Access Bean” of “Building a J2Cphonebook sample application.”

Step 10: Creating a servlet

This step uses the sample code provided to create a servlet that takes the user’sinput data from the HTML page and makes the appropriate method call based onthis data. The servlet then parses the output data returned from the selectedmethod and invokes the appropriate output JSP page (CoupleServletError.jsp orCoupleServletResults.jsp).

1. Copy the servlet from thecom.ibm.connector2.ims.ico.sample.transactional.phonebook.ejb.servletpackage.

a. Select the TranServlet class under thecom.ibm.connector2.ims.ico.sample.transactional.phonebook.ejb.servletpackage within the All Projects pane.

b. From the Selected menu, click Reorganize > Copy. Wait for the Copyingtypes window to appear.

c. Click the Browse... button to specify the package to which the servlet codewill be copied (for example, icotranejbservlet).

d. If you wish to rename the servlet, select the Rename the copy check box.These instructions assume that the servlet name (for example, TranServlet)remains the same.

e. If a warning message occurs indicating that there might be problemsmanaging resource files, click OK.

238 IMS Connector for Java User’s Guide and Reference

f. The TranServlet is now copied to the specified servlet package (forexample, icotranejbservlet).

2. Replace the following two import statements (displayed in the Source pane)import com.ibm.connector2.ims.ico.sample.phonebook.*;import com.ibm.connector2.ims.ico.sample.transactional.phonebook.ejb.*;

with import statements that access your EAB command and EJB. For example:import icoex01.*;import icotranejb.*;

From the Edit menu, click Save. This completes the generation of the servletcode.

Step 11: Creating a Web Archive File

The web module for this sample consists of one web archive (WAR) file thatcontains all of the HTML files, JSP files, and servlet class files associated with theEJB Modules. To create this web archive file, the jar command from the JavaDevelopment Kit (JDK) is used.

Perform the following steps to construct your WAR file :

1. Build the WAR file directory structure by creating the classes and library pathsfor your servlet and supporting classes (for example,C:\TranPhonebook\TranPhonebook_war\WEB-INF\classes andC:\TranPhonebook\TranPhonebook_war\WEB-INF\lib).

2. Create the web.xml file for your WAR. Using a text editor, create a file calledweb.xml in the WEB-INF folder created in the previous step (for example,C:\TranPhonebook\TranPhonebook_war\WEB-INF\web.xml).

3. Insert the deployment descriptor information pertaining to your WAR file. Forexample, insert the following XML code into the web.xml file. You can alsocopy the web.xml file associated with the J2C conversational phonebooksample in the directory in which IMS Connector for Java was installed (forexample, C:\IBM Connectors\IMSCONN\samples\J2C\tranphonebook\was\).

<?xml version=“1.0” encoding=“UTF-8”?><!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application2.2//EN” “http://java.sun.com/j2ee/dtds/web-app_2_2.dtd”><web-app><servlet><servlet-name>CoupleServlet</servlet-name><display-name>CoupleServlet</display-name><servlet-class>icotranejbservlet.CoupleServlet</servlet-class></servlet><servlet-mapping><servlet-name>CoupleServlet</servlet-name><url-pattern>/CoupleServlet</url-pattern></servlet-mapping><ejb-ref><ejb-ref-name>CompPhonebook</ejb-ref-name><ejb-ref-type>Session</ejb-ref-type><home>icotranejb.CompPhonebookHome</home><remote>icotranejb.CompPhonebook</remote><ejb-link>CompPhonebook</ejb-link></ejb-ref><ejb-ref><ejb-ref-name>ContPhonebook</ejb-ref-name><ejb-ref-type>Session</ejb-ref-type><home>icotranejb.ContPhonebookHome</home>

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 239

<remote>icotranejb.ContPhonebook</remote><ejb-link>ContPhonebook</ejb-link></ejb-ref></web-app>

4. Save the file.

5. Copy the HTML and JSP files from the provided sample and place them intothe WAR file directory.

a. Locate the HTML and JSP files associated with the J2C TransactionalPhonebook Sample in the directory where the IBM Connectors forVisualAge for Java were installed (for example, C:\IBMConnectors\IMSCONN\samples\J2C\tranphonebook\was\).

b. Copy all of the HTML and JSP files in this directory (for example, copy thefiles CoupleServletError.jsp, CoupleServletInput.html, andCoupleServletResults.jsp).

c. Navigate into the WAR file directory (for example,C:\TranPhonebook\TranPhonebook_war\) and paste all of the files copied inthe previous step to this directory.

6. Locate and modify any references in the HTML and JSP files that point to filesother than those used in this sample.

a. Modify all of the package references in the CoupleServletError.jsp fromcom.ibm.connector2.ims.ico.sample.transactional.phonebook.ejb.servlet

toicotranejbservlet

b. Modify the package reference in the CoupleServletResults.jsp fromcom.ibm.connector2.ims.ico.sample.phonebook

toicoex01

7. Export the servlet class file.

a. Expand the servlet project and package created for this sample (forexample, the Examples project and the icotranejbservlet package).

b. Select the servlet class you created in Step 10: Creating a servlet (page238) (for example, CoupleServlet).

c. Click Selected > Export..., then select the Directory radio button.

d. Click Next.

e. In the Directory field, enter the WAR file classes directory (for example,C:\TranPhonebook\TranPhonebook_war\WEB-INF\classes).

f. Ensure that the .class checkbox is selected and deselect all other checkboxes.

g. Click Finish.

8. Export the supporting classes of the servlet to a JAR file.

a. Click the Projects tab in the VisualAge for Java Workbench.

b. Select the supporting files:

1) Expand the EAB command project and package you created for thissample (for example, the Examples project and the icoex01 package).

2) Click the output message record class (for example, OutMsg).

3) Expand the project and package you created for the EJBs earlier. Forexample, expand the Examples project and the icotranejb package.

4) Highlight all of the following supporting files:

240 IMS Connector for Java User’s Guide and Reference

v PhonebookException

v CoupleOutput

v CompPhonebookAccessBean

v ContPhonebookAccessbean

5) Highlight the IBM EJB Tools project also, ensuring that the files aboveremain highlighted. You will export these files together.

Tip: To avoid adding the IBM EJB Tools project to every servletdeployed on your server, consider packaging the IBM EJB Tools projectin a jar file of its own and storing it on the host machine. Then, appendthe jar file’s location and name to the existing classpath of the serveron which the servlets will be deployed.

c. Click Selected > Export..., then select the Jar file radio button.

d. Click Next.

e. Click the Browse... button and locate the WAR file library directory inwhich the JAR file will be saved (for example,C:\TranPhonebook\TranPhonebook_war\WEB-INF\lib).

f. Type the name of the JAR file that will be created in this directory in FileName: field (for example, servletsupport.jar).

g. Click the Save button.

h. Ensure that the file name with its directory extension is now displayed inthe JAR file field (for example, C:\TranPhonebook\TranPhonebook_war\WEB-INF\lib\servletsupport.jar).

i. Ensure that the .class checkbox is selected. Deselect all other checkboxes.

j. Click Finish.

9. Open a command prompt on your workstation.

10. Navigate to the WAR file directory (for example,C:\TranPhonebook\TranPhonebook_war\).

11. Create the WAR file by issuing the JAR command shipped with the J2EEplatform. For example, issue the following command in the command line:jar -cf TranPhonebook.war *

This completes the creation of your WAR file.

12. Navigate into the WAR file directory and verify that the WAR file (for example,TranPhonebook.war) has been created.

Part 3: Packaging and Deploying the sampleStep 1: Packaging the application into a z/OS or OS/390 enterprise archive file

In this sample, you are constructing one enterprise application that consists of oneweb module and two enterprise java beans. This enterprise application is bundled inan enterprise archive (EAR) file, which is the standard packaging format. Use theApplication Assembly Tool (AAT) provided by WebSphere for z/OS or OS/390 tobuild this package. The following steps describe how to construct an EAR file forthis sample:

1. Export the component-managed EJB:

a. Click on the EJB tab on the VAJ Workbench to go to the EJB DevelopmentEnvironment.

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 241

b. Select the enterprise bean class of the component-managed EJB sessionbean (for example, CompPhonebook) which can be found (if not already listedin the Enterprise Beans pane) by expanding the EJB group created for thisbean (for example, EJBExamples).

c. Under the EJB drop down menu, select Export > Deployed JAR...andwait for the Export to Deployed JAR file SmartGuide to appear.

d. Click the Browse... button. In the file selection window, locate and enterthe directory in which the JAR file will be saved (for example,C:\TranPhonebook).

e. Type the name of the JAR file in the File Name: field (for example,CompPhonebook_deployed.jar).

f. Click the Save button.

g. Verify that the file name with its directory extension is now displayed in theJAR file: field (for example,C:\TranPhonebook\CompPhonebook_deployed.jar).

h. Verify that the beans and .class checkboxes are selected. Deselect allother checkboxes.

i. Click Finish.

2. Export the container-managed EJB by repeating the previous step for theremaining EJB session bean (for example, ContPhonebook).

3. Export the EJB supporting classes:

a. Click the Projects tab in the VisualAge for Java Workbench.

b. Select the EJB supporting classes. For example:

1) Expand the EAB command project created earlier (for example, expandExamples).

2) Select the EAB command package created earlier (for example, selectthe icoex01 package found within this project).

3) While ensuring the EAB command package remains highlighted,expand the project and package created for the EJBs in thepreparation of this sample (for example, expand the Examples projectand the icotranejb package).

4) Selecting the remaining supporting classes (for example,PhonebookException andCoupleOutput), ensuring that the EABcommand package remains highlighted. You will export the supportingclasses and the package together.

c. Click Selected > Export...

d. Click the Jar file radio button underneath the Select and exportdestination.

e. Click Next.

f. Click the Browse... button. In the file selection window, locate and enter thedirectory in which the JAR file will be saved (for example,C:\TranPhonebook).

g. Type the name of the JAR file that will be created in this directory in theFile Name: field (for example, supportingclasses.jar).

h. Click the Save button.

i. Verify that the file name with its directory extension is now displayed in theJAR file: field (for example, C:\TranPhonebook\supportingclasses.jar).

j. Verify that the .class checkbox is selected. Deselect all other checkboxes.

k. Click Finish.

242 IMS Connector for Java User’s Guide and Reference

4. Start the Application Assembly Tool by clicking Start > Programs > IBMWebSphere for z/OS > Application Assembly.

5. Add a new application with the supporting classes to the application treedisplayed in the tool:

a. Select the Applications folder

b. Click Selected > Add.

c. In the Display Name text field under the General tab, enter the name ofthe enterprise application (for example, TranPhonebook).

d. Click the Files tab.

e. Click the Import... button and wait for the Import file window to appear.

f. Click the Choose... button and wait for the Select file to import window toappear.

g. Locate and select the supporting classes JAR file. (for example,C:\TranPhonebook\supportingclasses.jar)

h. Click OK to exit the Select file to import window.

i. Click OK to exit the Import file window.

j. Click Selected > Save.

6. Add the EJB JAR files to the new enterprise application:

a. Expand the Applications folder.

b. Expand the enterprise application added in the previous step (for example,TranPhonebook)

c. Select the Ejb Jars folder.

d. Click Selected > Import... and wait for the Import ejb jar window toappear.

e. Click the Choose... and wait for the Select ejb jar file to import windowto appear.

f. Locate and select the component managed JAR file (for example,C:\TranPhonebook\CompPhonebook_deployed.jar)

g. Click OK to exit the Select ejb jar file to import window.

h. Click OK to exit the Import ejb jar window. Wait for the completionmessage (for example, “BBO94001I Ejb jar CompPhonebook_deployed.jarwasimported”) to appear in the status text box above the status bar in theAAT.

i. When the JAR file has been imported successfully, repeat these steps toimport the container-managed JAR file. (for example,C:\TranPhonebook\ContPhonebook_deployed.jar)

7. Add the web archive to the new enterprise application:

a. Expand the Applications folder.

b. Expand the enterprise application (for example, TranPhonebook)

c. Select the Web Apps folder.

d. From the Selected drop down menu choose Import... and wait for theImport web app window to appear.

e. Click the Choose... and wait for the Select war file to importwindow toappear.

f. Locate and select the component managed JAR file (for example,C:\TranPhonebook\TranPhonebook_war\TranPhonebook.war)

g. Click OK to exit the Select ejb jar file to import window.

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 243

h. Click OK to exit the Import ejb jar window. Wait for the completionmessage (for example, “BBO94000I Web app TranPhonebook.war wasimported”) to appear in the status text box above the status bar in theAAT.

8. Add resource references to the enterprise java beans:

a. Expand the Applications folder.

b. Expand the enterprise application (for example, TranPhonebook)

c. Expand the Ejb Jars folder.

d. Expand the component-managed deployed .jar file (for example,CompPhonebook_deployed.jar).

e. Expand the Session Beans folder.

f. Select the component-managed EJB session bean (for example,CompPhonebook).

g. Click the Resources tab.

h. Click Selected > Modify.

i. Click the enabled Add... button under the Resources tab and wait for theAdd resource reference window to appear.

j. In the Reference Name drop down box enter the resource reference name(for example, MyIMS).

k. Click the down arrow of the Type drop down box and selectjavax.resource.cci.ConnectionFactory.

l. Ensure that the Authentication drop down box displays the Containervalue.

m. Ensure that the Connection Management drop down box displays theDefault value.

n. Click OK.

o. Click Selected > Save.

p. Repeat these steps for the container-managed deployed .jar file andsession bean (for example, ContPhonebook_deployed.jar andContPhonebook, respectively).

9. Supply a servlet context root:

a. Expand the Applications folder.

b. Expand the enterprise application (for example, TranPhonebook)

c. Expand the Web Apps folder.

d. Select the web archive file you imported earlier (for example,TranPhonebook.war).

e. Click the General tab.

f. Click Selected > Modify.

g. In the Context root field, enter the context root of the servlet (for example,/imsicotran). The context root of the servlet is located in the ACTIONparameter for the FORM on the input HTML page for the servlet. A callmade upon the servlet is a combination of the servlet context root andservlet mapping name specified in the web.xml file for the web archive (forexample, /imsicotran/CoupleServlet).

h. Click Selected > Save.

10. Validate the enterprise application:

a. Expand the Applications folder.

b. Select the enterprise application (for example, TranPhonebook).

244 IMS Connector for Java User’s Guide and Reference

c. Click Build > Validate. Wait for the completion message (for example,“BBO94008I Application TranPhonebook can be deployed”) to appear in thestatus text box above the status bar in the AAT.

11. Deploy the enterprise application:

a. Expand the Applications folder.

b. Select the enterprise application (for example, TranPhonebook).

c. Click Build > Deploy. Wait for the completion message (for example,“BBO94009I Application TranPhonebook was deployed”) to appear in thestatus text box above the status bar in the AAT.

12. Export the enterprise application into an enterprise archive:

a. Expand the Applications folder.

b. Select the enterprise application (for example, TranPhonebook).

c. Click Selected > Export... and wait for the Export application window toappear.

d. Click the Choose... button and wait for the Select output ear file windowto appear.

e. Locate the directory to which you want to export the application (forexample, C:\TranPhonebook).

f. Verify that the File name field displays the name of the EAR file in whichthe application will be bundled (for example, TranPhonebook).

g. Click OK to exit the Select output ear file window.

h. Ensure that the WebSphere for z/OS Version 4.0 compatible checkbox isselected.

i. Click OK to exit the Export application window.

j. Wait for the completion message (for example, “BBO94010I ApplicationTranPhonebook was exported to EAR file”) to appear in the status text boxabove the status bar in the AAT.

Step 2: Deploying the application to the WebSphere Application Server forz/OS or OS/390

Follow these steps to deploy the enterprise archive file to the WebSphereApplication Server for z/OS or OS/390 using its Administration application.

1. Add a new conversation (for example, TranPhonebook) using the WebSphereApplication Server for z/OS and OS/390 SMEUI tooling. For instructions on howto do this, follow steps 1 to 6 of “Step 4: Deploying and Configuring IMSConnector for Java as a J2EE server resource in WebSphere Application Serverfor z/OS and OS/390” in “Preparing your WebSphere Application ServerEnvironment for z/OS and OS/390.”

2. Install the enterprise application.

a. Select the J2EE server on which this application will be installed (forexample, BBOASR2). Select this server by expanding the following folders inorder: Conversations folder, the new conversation (for example,TranPhonebook), the Sysplexes folder, the sysplex in which your sampleJ2EE server has been installed (for example, PLEX1), and the J2EEServersfolder.

b. Click Selected > Install J2EE application... and wait for its referencewindow to appear (for example, the Install J2EE application on server:BBOASR2 window).

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 245

c. Click the Browse EAR File... button and wait for the Open window toappear. Locate and select your EAR file (for example, select theTranPhonebook.ear file in the C:\TranPhonebook directory). Click Open.

d. Verify that the destination and EAR file name appears in the EAR Filenamefield (for example, C:\TranPhonebook\TranPhonebook.ear). Click OK and waitfor the Reference and Resource Resolution window to appear.

e. In the Reference and Resource Resolution window:

1) On the left side of the window, expand the component-manageddeployed JAR file folder (for example, CompPhonebook_deployed.jar)and select the component-managed EJB (for example, CompPhonebook).

2) On the right side of the window, click the J2EE Resource tab.

3) From the pull-down menu under the J2EE Resource table columnheading, select the appropriate J2EE resource for thecomponent-managed EJB in this sample (for example,IMSICOTRAN_resource).

4) Expand the container-managed deployed JAR file folder (for example,ContPhonebook_deployed.jar) and select the container-managed EJB(for example, ContPhonebook).

5) Click the J2EE Resource tab.

6) From the pull-down menu under the J2EE Resource table columnheading, select the appropriate J2EE resource for thecontainer-managed EJB in this sample (for example,IMSICOTRAN_resource).

7) Expand the web application JAR file folder (for example,CoupleServlet_WebApp.jar) and select the web application (forexample, CoupleServlet_WebApp).

8) Click the EJB tab.

9) Click the Set Default JNDI Path & Name button.

10) Click OK to finish the installation of the EAR file on the selected J2EEserver. Wait for the completion message (for example, “BBON0470IEAR file TranPhonebook_resolved.ear has been successfully installedon server BBOASR2”) to appear in the status text box above the statusbar in the Administration window.

3. Validate the conversation.

a. Expand the Conversations folder.

b. Select the new conversation (for example, TranPhonebook)

c. Click Build > Validate. Wait for the completion message (for example,“BBON0442I Conversation TranPhonebook is valid”) to appear in the statustext box above the status bar in the Administration window.

4. Commit the conversation.

a. Expand the Conversations folder.

b. Select the new conversation (for example, TranPhonebook)

c. Click Build > Commit.

d. Wait for the Confirm Commit window to appear and click on the Yes buttonto confirm.

e. Wait for the completion message (for example, “BBON0444I ConversationTranPhonebook was committed”) to appear in the status text box above thestatus bar in the Administration window.

5. Confirm that the WebSphere for z/OS Host Instructions have been completed.

a. Expand the Conversations folder.

246 IMS Connector for Java User’s Guide and Reference

b. Select the new conversation (for example, TranPhonebook).

c. Click Build > Instructions... to view the set of instructions that need to becompleted prior to activating the conversation.

Note: In many scenarios, these tasks only need to be performed once forthe bootstrap server’s initial conversation.

d. Click Build > Complete > All Tasks.

e. Wait for the Confirm Complete window to appear. Click the Yes button toconfirm.

f. Wait for the completion message (for example, “BBON0484I All taskscomplete”) to appear in the status text box above the status bar in theAdministration window.

6. Activate the new conversation.

a. Expand the Conversations folder.

b. Select the new conversation (for example, TranPhonebook).

c. Click Build > Activate.

d. Wait for the Confirm Activate Conversation window to appear. Click theYes button to confirm.

e. Wait for the completion message (for example, “BBON0449I ConversationTranPhonebook was activated”) to appear in the status text box above thestatus bar in the Administration window:

7. Verify that the webcontainer for the specified J2EE server is configured for theservlet’s context root.

a. In the OMVS shell on the host machine, navigate to the control file directoryfor the selected server. For example,cd /WebSphere390/CB390/controlinfo/envfile/sysplex/BBOASR2A

where sysplex is your sysplex name (for example, PLEX1).

b. Open the webcontainer.conf file located in this directory for editing.

c. Ensure that the host.default_host.contextroots parameter is set to acceptall context root. If this parameter is set this way, the value would only be asingle forward slash. If the parameter is not set this way (that is, it is set tobe a series of context roots), append this sample’s servlet context root to theparameter. For example, either modify the parameter to be like the following:host.default_host.contextroots=/

or append the following context root declarations to the end of the value forthis parameter. For example,host.default_host.contextroots=existing_value,/imsicotran,/imsicotran/*

where the existing_value was the value that this parameter was set toupon first opening the webcontainer.conf file.

d. Save and close the configuration file.

8. In the JVM properties, set the classloader mode to be application mode. Thisstep ensures that the CoupleOutput class used to deliver the output to theservlet is the same type used by the EJB.

a. In the OMVS shell on the host machine, navigate to the control file directoryfor the selected server. For example,cd /WebSphere390/CB390/controlinfo/envfile/sysplex/BBOASR2A

where sysplex is your sysplex name (for example, PLEX1).

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 247

b. Open the jvm.properties file for editing and add the following line to thebeginning of this file:com.ibm.ws390.server.classloadermode = 2

c. Save and close the properties file.

9. Configure the Web server for the servlet’s context root.

a. In the OMVS shell on the host machine, navigate to the Web server’sconfiguration file directory. For example (if the default Web server setup isused):cd /etc

10. Open the httpd.conf file located in this directory for editing.

11. Append a service statement for the servlet context root of this sample to theexisting list of service statements.

a. Locate the block of service statements.

b. Copy one line from this block.

c. Add a new line at the end of the service statement block with the copiedcontents.

d. Replace the servlet context value in the new line with the servlet contextfor this sample.

For example, you should see something like this:Service /webapp/examples/*/web/usr/lpp/WebSphere/WebServerPlugIn/bin/was400plugin.so:service_exitService /PolicyIVP/*/web/usr/lpp/WebSphere/WebServerPlugIn/bin/was400plugin.so:service_exitService /imsicotran/*/web/usr/lpp/WebSphere/WebServerPlugIn/bin/was400plugin.so:service_exit

The Service statement provides the Web server with the ability to recognizeany URL received with the new servlet’s context root as its starting stringand pass the URL over to the plugin environment.

e. Save and close the configuration file.

Part 4: Running the sample1. Start WebSphere Application Server for z/OS and OS/390 by follow “Step 6:

Starting the server to run the IVP” in “Preparing your WebSphere ApplicationServer Environment for z/OS and OS/390.”

2. Run the sample application by opening a browser (for example, Netscape orInternet Explorer) and entering the URL of the servlet’s input HTML page. Forexample,http://server_ip_name:port/imsicotran/CoupleServletInput.html

where the server_ip_name and port values are those specified in thehost.default_host.alias parameter in the webcontainer.conf file for theWebSphere application server.

3. Provide data in the fields provided on the web page. For example, enter thefollowing information for the first individual:Last Name: TEST1First Name: TEST1Extension: 1-1111Zip Code: 11111

Provide the following information for the second individual:

248 IMS Connector for Java User’s Guide and Reference

Last Name: TEST2First Name: TEST2Extension: 2-2222Zip Code: 22222

4. Select the desired function to be performed using the data provided. Forexample, select the Add radio button under the Select a command for acouple heading.

5. Select the type of transaction handling to be used. For example, select theContainer radio button under the Select the type of transaction managementheading.

6. Click the Submit button to submit the data for processing.

7. Wait for the result JSP or error JSP page to appear. The results page shouldappear with the message “Entry has been added.”

8. Submit various combinations of input to the JSP or HTML pages.

Note: Be cautious of deleting an individual from the couple phonebook. Firstverify that the individual is not part of a couple. If that individual is a part of acouple, delete the couple rather than the individual to avoid leaving invalidstatus records. The method for deleting an individual can be enhanced toperform this check by performing the displayCouple method and verifying thatthe exception that is thrown indicates that the first individual’s couple statusrecord is not found.

Chapter 15. Building Container-Managed and Component-Managed Transactional EJBs to Run IMS Transactions 249

250 IMS Connector for Java User’s Guide and Reference

Appendix A. IMS INSTALL/IVP sample application

Some of the Java applications and servlets in the Connector IMS Samples projectuse transactions that are part of the IMS INSTALL/IVP Sample Applications. Thetwo transactions that are used are IVTNO, a nonconversational transaction, andIVTCB, a conversational transaction. If these transactions are not installed on yourIMS system, contact your IMS system administrator to have them installed. TheINSTALL/IVP Sample Application is packaged and shipped with IMS. Thesetransactions, as they are used in this documentation, have the followingcharacteristics:

v The IVTNO transaction is nonconversational and the IVTCB transaction isconversational.

v The transaction codes are IVTNO (nonconversational) and IVTCB(conversational).

v The IMS INSTALL/IVP Sample Application transactions, both conversational andnonconversational, accept a single-segment input message and return asingle-segment output message.

v The IMS INSTALL/IVP Sample Application transactions support ADD, DISPLAY,and DELETE commands for working with entries in a phone book database.

Typically, you first add an entry to the database using the ADD command. You mustprovide values for all of the fields of the single-segment IMS transaction inputmessage, including LL and ZZ. You can do this by invoking the appropriate “set”methods of the EAB command. For example:cmd.setIN__LL( (short) ((InMsg)cmd.getInput()).getSize() );cmd.setIN__ZZ( (short)0 );cmd.setIN__TRCD( “IVTNO” );cmd.setIN__CMD( “ADD” );cmd.setIN__NAME1( “Bond” );cmd.setIN__NAME2( “James” );cmd.setIN__EXTN( “1234” );cmd.setIN__ZIP( “99000” );

You must always provide the correct LL value. Each IMS message segment (eitherinput or output) begins with a 2-byte segment length (LL) field, followed by a 2-byteflag (ZZ) field. The ZZ field can be set to zero on input, but the input value for LLmust be the sum of the defined lengths of the input fields plus 4 (corresponding tothe length of the entire message, i.e., the sum of the lengths of the input fields plusthe lengths of the LL and ZZ fields.) For more information on using the getSize()method to determine a value for LL, see “IMS Messages” in “IMS Connector forJava concepts and terms.”

After an entry is added to the database, you can display it by using the DISPLAYcommand, as follows:cmd.setIN__LL( (short) ((InMsg)cmd.getInput()).getSize() );cmd.setIN__ZZ( (short)0 );cmd.setIN__TRCD( “IVTNO” );cmd.setIN__CMD( “DISPLAY” );cmd.setIN__NAME1( “Bond” );cmd.setIN__NAME2( “” );cmd.setIN__EXTN( “” );cmd.setIN__ZIP( “” );

The names of the actual “set” methods in the examples will vary, depending uponthe names of the corresponding transaction input and output message beans.

© Copyright IBM Corp. 1998, 2002 251

The examples in other sections of the documentation illustrate this database indifferent states. For instance, some sections assume that the entry being displayedhas been previously added to the database.

The COBOL source for the input and output messages of the nonconversationaltransaction can be found in<IBM_Connectors_install_dir>\imsconn\samples\misc\Ex01.cpp, where<IBM_Connectors_install_dir> is the IBM Connectors installation directory. Forexample, d:\IBM Connectors.

The COBOL source for the input and output messages of the conversationaltransaction can be found in \imsconn\samples\misc\dfsiva34.mem.

252 IMS Connector for Java User’s Guide and Reference

Appendix B. Using the trace and error logging facility

Turning on the trace and error logging facility for IMS Connector forJava CCF components

The trace and error logging facility is implemented by the RASService interfaceclass. It consists of two different output streams. All trace information is logged tothe trace output stream, and the errors and exceptions are logged to the erroroutput stream. The levels of trace information that are logged are as follows:

RAS_TRACE_OFFNo trace information is logged. This is the default trace level.

RAS_TRACE_ERROR_EXCEPTIONOnly errors and exceptions are logged.

RAS_TRACE_ENTRY_EXITEntry and exit of methods, as well as errors and exceptions are logged.

RAS_TRACE_INTERNALThe internal state of a connector object, as well as entry and exit ofmethods, errors, and exceptions are logged.

RAS_TRACE_INTERNAL_NATIVEDisplays most of the information, including the internal state of other objectsused by the connector and all the information in the above trace levels.

You can set the trace level in your code by using the JavaRASServiceimplementation class. Replacing the DefaultRASService with the JavaRASServiceallows for control of the error and trace reporting mechanisms. To change to useJavaRASService, you need to execute the following code:com.ibm.connector.infrastructure.java.JavaRASService ras =

new com.ibm.connector.infrastructure.java.JavaRASService();runtimeContext.setRASService(ras);

Note: JavaRASService is the default implementation class of the RASService forthe JavaRuntimeContext class. Therefore, you do not need to implement the abovecode if you are using JavaRuntimeContext in your application.

The following sample code sets the trace level of the JavaRASService trace facilityto log the entry and exit of each method:((com.ibm.connector.infrastructure.java.JavaRASService)runtimeContext.getRASService())

.setTraceLevel(com.ibm.connector.infrastructure.RASService.RAS_TRACE_ENTRY_EXIT );

Errors are always logged to the error log stream.

Related Reading: For information on the methods of thecom.ibm.connector.infrastructure.RASService interface, see its Javadocinformation.

© Copyright IBM Corp. 1998, 2002 253

Turning on the trace and error logging facility for IMS Connector forJava J2C components

Turning on tracing and logging is a two step process. The first step involvesenabling tracing of the IMS Connector for Java components in the applicationserver. The second step sets the desired trace level for a particular ConnectionFactory. These steps are provided for workstation platforms and OS/390 and z/OSplatforms.

For WebSphere Application Server on workstation platforms:

Step 1: Enabling the tracing and logging in the IMS Connector for Java J2Ccomponents

A similar process is used to enable tracing in other components of the applicationserver.

1. In the left pane of the WebSphere Advanced Administrative Console, select theapplication server for which you wish to enable tracing. For example, selectDefault Server in the tree:

v WebSphere Administrative Domain

– Nodes

- <your_node>

v Application Servers

– Default Server

2. In the right pane, select the Services tab.

3. In the Service list, select the Trace Service entry, then click the EditProperties... button.

4. In the resulting Trace Service window:

a. Enter the desired trace specification value in the Trace specification entryfield. For example:

com.ibm.connector2.ims.*=all=enabled

This trace string specifies that tracing is enabled for all classes contained inpackages whose name begins with “com.ibm.connector2.ims.” This tracewill cause all IMS Connector for Java J2C code to be traced at the tracelevel specified in the Connection Factory (see the next step.) Note thattracing will occur in both IMS Connector packages(“com.ibm.connector2.ims” and “com.ibm.ims.ico”) even when only oneof the packages has been specified. This occurs because the tracingstatements in both packages key off of the same LogWriter.

The trace specification can be modified or extended to include packagesand classes of other components. If you click the ... button at the right endof the Trace specification field, you will bring up a Trace window in whichyou can graphically select the components and groups for which you wish toenable (or disable) tracing.

b. Optionally you can select the Specify radio button of the Trace output filefield and enter a file of your choice to which to log trace events.

c. See the Help associated with the Trace Service window for additionalinformation.

d. Select the OK button.

5. In the right pane of WebSphere’s Administrative Console, select the Applybutton.

254 IMS Connector for Java User’s Guide and Reference

Step 2: Setting the desired trace level for the Connection Factory you want totrace

This trace level will apply to all connections created by the Connection Factory.

1. In the left pane of the WebSphere Advanced Administrative Console, select J2CConnection Factories for the IMS Connector for Java J2C Resource Adapter.For example, select Default Server in the tree:

v WebSphere Administrative Domain

– Resources

- J2C Resource Adapters

v IMS J2C Connector

– J2C Connection Factories

2. In the list of Connection Factories at the top of the right pane, select theConnection Factory you wish to trace, then select the Connections tab.

3. In the list of properties, scroll down to and select the TraceLevel property.

4. To provide a value for the TraceLevel property, scroll down to find the Valuefield. Use this field to enter the value for the property. For the list of possiblevalues for the Trace level property, see the “IMS Connector for Java J2CTraceLevel Properties” section below. When you are done, click anywhereoutside the field to set the value.

5. Click the Apply button to complete your command.

For WebSphere Application Server for z/OS and OS/390:

A J2C resource adapter such as IMS Connector for Java uses a LogWriter to logthe tracing and logging information. LogWriter is a character output stream createdby an application server. In WebSphere Application Server for z/OS and OS/390,the LogWriter output is written to its tracing and logging stream. Enabling tracingand logging for IMS Connector for Java J2C components involves two steps. First,enable WebSphere Application Server tracing for the LogWriter output. Second,enable the creation of a LogWriter instance that can be used by IMS Connector forJava for logging.

Step 1: Enabling the tracing and logging in the IMS Connector for Java J2Ccomponents

1. In the jvm.properties for your WebSphere Application Server, be sure to specifya trace options file as follows:com.ibm.ws390.trace.settings=YourFileName

where YourFileName is the fully qualified name of your trace file (for example,/WebSphere390/CB390/controlinfo/envfile/PLEX1/BBOASR2A/trace.dat).

2. In the trace options file you specified in the previous step, enable WebSphereApplication Server with the LogWriter output by adding the trace string asfollows:com.ibm.ws390.logwriter.*=all=enabled

3. Enable IMS Connector for Java tracing output by adding the following tracestring in the trace option file:com.ibm.connector2.ims.ico.*=all=enabled

Note: This trace string specifies tracing to be enabled for all classes containedin packages whose name begins with “com.ibm.connector2.ims.ico.” This tracewill cause all IMS Connector for Java J2C code to be traced at the trace level

Appendix B. Using the trace and error logging facility 255

specified in the Connection Factory (see Step 2. Setting the desired trace levelfor the Connection Factory you want to trace (page 257)) Note that tracing willoccur in both IMS Connector packages (″com.ibm.connector2.ims.ico″ and″com.ibm.ims.ico″) even when only one of the packages has been specified.This occurs because the tracing statements in both packages key off of thesame LogWriter.

4. Save both the jvm.properties file and your trace file.

To enable the creation of a LogWriter instance to be used by IMS Connector forJava to record the log and trace data, do the following:

1. Before starting, stop the J2EE server of your WebSphere Application Server.

2. Ensure that the Bootstrap deamon server of your WebSphere Application Serveris up and running.

3. Start the WebSphere for z/OS Administration Application:

a. From your Windows desktop, click the Start button. Select Programs > IBMWebSphere for z/OS > Administration.

b. In the Login window, provide values for your Bootstrap server IP name, Port,Userid, and Password.

c. Click OK to start connecting to your server.

4. Create a new conversation for running the WebSphere Application Server onz/OS and OS/390:

a. Locate the WebSphere Application Server for z/OS and OS/390Administration window.

b. Right click the Conversations folder and select Add from the menu. Typeyour conversation name (for example, IMSICOSetTraceOn) theConversation name field, then click Selected > Save.

5. Enable the LogWriter Recording for your IMS Connector for Java ConnectionFactory Instance:

a. When the new conversation is added, expand the conversation hierarchy (byclicking the + signs) down to the specific sysplex (for example, PLEX1).Expand this sysplex, then expand the J2EE Resource folder.

b. Select the J2EE resource for which you want to enable tracing. This J2EEResource refers to the IMS Connector for Java Connection Factory resource(for example, MyIMS) for connecting to IMS. Expand this J2EE Resource.

Note: If you do not have an IMS Connector for Java Connection Factoryresource created, follow the instructions in the “Creating and andConfiguring the Connection Factory in WebSphere for z/OS and OS/390”step in the “Preparing your WebSphere Application Server environment forz/OS and OS/390” to create the ConnectionFactory resource.

c. Expand the J2EE Resource Instances folder. Select the correspondingConnection Factory Resource instance (for example, MyIMS_Instance1).The list of properties of the resource instance will be displayed in the rightpanel.

d. Click Selected > Modify.

e. In the list of properties, scroll down to the LogWriter Recording property andselect enable in the drop down box. When enable is specified, a LogWriterinstance will be created by WebSphere Application Server for use by IMSConnector for Java to write the logging and tracing information intoWebSphere Application Server’s logging and tracing stream. If disable isselected, no LogWriter will be created.

f. Click Selected > Save.

256 IMS Connector for Java User’s Guide and Reference

Step 2: Setting the desired trace level for the Connection Factory you want totrace

This trace level will apply to all connections created by the Connection Factory. Toset the desired trace level for the Connection Factory of IMS Connector for Java, dothe following: (continuing from 4f in Step 1)

1. Setting the desired value of the TraceLevel property of IMS Connector for Java:

a. Select the same Connection Factory Resource (for example,MyIMS_Instance1) instance you modified in the previous step.

b. Click Selected > Modify.

c. In the list of properties, select the Trace level property.

d. Enter the value of the Trace level property you desired.

For the list of possible values for the Trace level property, see IMSConnector for Java J2C TraceLevel Properties (page 257) below.

e. Click Selected > Save.

2. Activate the conversation for the changes to enable tracing and logging:

a. Validate the new conversation you just created in the previous step byselecting the conversation name (for example, IMSICOSetTraceOn) tohighlight it and clicking Build > Validate.

b. Commit the new conversation by selecting the conversation name tohighlight it and clicking Build > Commit.

c. Ensure that all preparation tasks for the new conversation are completed.Then select the conversation name to highlight it and click Build >Complete > All Tasks to indicate completion.

d. Activate the new conversation by selecting the conversation name tohighlight it and clicking Build > Activate.

3. Start the J2EE Server.

IMS Connector for Java J2C TraceLevel Properties

The possible values for the TraceLevel property are:

Value IMSTraceLevelProperties Description

0 RAS_TRACE_OFF No tracing or logging is to occur.

1 RAS_TRACE_ERROR_EXCEPTION Log errors and exceptions only.

2 RAS_TRACE_ENTRY_EXIT Log TraceLevel 1 plus entry and exit of important methods.

3 RAS_TRACE_INTERNAL Log TraceLevel 2 plus the contents of the buffers sent to and receivedfrom IMS Connect. In most cases, this trace level is used for problemdetermination.

Customizing the trace facilityImportant: The information in this section refers to the CCF implementation of IMSConnector for Java.

By default, the RASService sends the trace log to the System.out stream, andsends the error log to the System.err stream. You can use thecom.ibm.connector.infrastructure.java.JavaRASService class to direct the error or

Appendix B. Using the trace and error logging facility 257

trace log to a different output stream (such as a file). The JavaRASService classprovides the following methods to customize the output stream of the error andtrace that the connector uses:public void setErrorStream(java.io.OutputStream param1)Set the output stream of the error log

public void setTraceStream(java.io.OutputStream param1)Set the output stream of the trace log

Related Reading: For information on the methods ofcom.ibm.connector.infrastructure.java.JavaRASService class, see the Javadocinformation for the class.

For information on using the trace facility in the WebSphere Application Serverenvironment, see the WebSphere Application Server documentation.

For information on using the trace facility in the J2C implementation of IMSConnector for Java, see “Using the trace and error logging facility.”

Reading the error logWhen an exception occurs, the exception information and a printstack of theexception is sent to the error log stream. The following is an example of the errorlog:com.ibm.connector.CommunicationException:HWSJ003E: [email protected]() error.Fails to connect to Host name [CSDMEC15],Port [9999]. [java.net.SocketException: Connection timed out]

java.net.SocketException: Connection timed outjava.lang.Throwable(java.lang.String)java.lang.Exception(java.lang.String)java.io.IOException(java.lang.String)java.net.SocketException(java.lang.String)void java.net.PlainSocketImpl.socketConnect(java.net.InetAddress, int)void java.net.PlainSocketImpl.doConnect(java.net.InetAddress, int)void java.net.PlainSocketImpl.connectToAddress(java.net.InetAddress, int)void java.net.PlainSocketImpl.connect(java.net.InetAddress, int)java.net.Socket(java.net.InetAddress, int, java.net.InetAddress, int, boolean)java.net.Socket(java.lang.String, int)void com.ibm.connector.imstoc.IMSAdapter.connect()void com.ibm.connector.imstoc.IMSConnection.connect()void com.ibm.connector.imstoc.IMSCommunication.connect()void com.ibm.ivj.eab.command.CommandCommunicationPrimitive.

beforeExecute(com.ibm.ivj.eab.command.CommandEvent)void com.ibm.ivj.eab.command.CommunicationCommand.

connEtoM1(com.ibm.ivj.eab.command.CommandEvent)void com.ibm.ivj.eab.command.CommunicationCommand.

beforeInternalExecution(com.ibm.ivj.eab.command.CommandEvent)void com.ibm.ivj.eab.command.Command.

fireBeforeInternalExecution(com.ibm.ivj.eab.command.CommandEvent)void com.ibm.ivj.eab.command.Command.

execute(com.ibm.ivj.eab.command.CommandEvent)void com.ibm.ivj.eab.command.Command.execute()void com.ibm.ivj.eab.command.CommunicationCommand.execute()void JTCV36.JTCV36Execute.main(java.lang.String [])

This information consists of the error message of the exception and the printstackinformation of the exception. First, it shows the exception that is being thrown(com.ibm.connector.CommunicationException: in the example above).

258 IMS Connector for Java User’s Guide and Reference

The sample then shows the message number and the method that throws thisexception (HWSJ003E:[email protected]() ),along with the corresponding error message (Fails to connect to Hostname[CSDMEC15], Port[9999]). Each exception message is identified by amessage number (such as HWSJ003E). If an exception message is shown inbrackets [] at the end of the error message (such as [java.net.SocketException:Connection timed out]), it shows the information of the base native exception that iscaught and re-thrown according to the Common Connection Frameworkspecification.

If a base native exception is caught and re-thrown by the connector, the printstackinformation reflects the printstack information of the base native exception. Forspecific exception details, see the Javadoc of the particular exception class.

Reading the trace logDepending on the trace level that is set, the trace log can contain differentinformation:

RAS_TRACE_ERROR_EXCEPTION

The information at this level is similar to that in the error log. See Reading the ErrorLog for more information.

RAS_TRACE_ENTRY_EXIT

At this level, the trace log shows the entry and exit of a method, such as thefollowing:--> [[email protected]()]

The right-arrow symbol (—>) represents the entry of a method. The left-arrowsymbol (<—) represents the exit of a method. All the information within the sectionof a —> and a <— of the same method shows all of the execution call stack withinthat method.

A double arrow symbol (<—>) indicates that the method has been entered andexited. No specific information within the method is logged. The name before the @sign shows the class name. The alphanumeric number after the @ sign shows thehash code of the class. The name after the ’.’ of the hash code shows the methodname.

RAS_TRACE_INTERNAL

At this level, the internal state of an object and other important information aredumped to the trace log. The dump of an object normally starts with the name ofthe class to be dumped in brackets []. This is similar to the entry/exit, as shownabove, but without any symbol at the beginning. It looks similar to the following:[com.ibm.connector.imstoc.communication@1c27]

Each field value of the class is shown.

The OTMA messages ″Buffer to send:″ and ″Buffer received:″ are sent to andreceived from IMS Connect. If you understand the structure of these OTMAmessages, you can examine the information in the buffers containing these inputand output messages to help diagnose problems. An example of a problem that can

Appendix B. Using the trace and error logging facility 259

be diagnosed by examining a buffer is when the output record bean of the EABcommand doesn’t match the data being returned by the IMS application program.

RAS_TRACE_INTERNAL_NATIVE

At this level, more information about the internal state of other objects being usedby the connector are dumped tothe trace log. The dump format of the object is similar to theRAS_TRACE_INTERNAL trace level.

260 IMS Connector for Java User’s Guide and Reference

Appendix C. Diagnosing problems related to sockets

If the IMS Connect environment appears to be suspended or if the Java applicationor servlet (using a valid host name and port for the target IMS Connect system)fails to make a connection to that IMS Connect system, you might have reached themaximum number of sockets. The number of sockets that can exist between a Javaclient (a Java application or servlet) and the host component, IMS Connect, iscontrolled by two parameters that need to be synchronized. These parameters arethe following:

MAXSOCThe maximum number of sockets for an IMS Connect port. MAXSOCapplies to all of the ports associated with an instance of IMS Connect.MAXSOC is displayed in the MAXSOC field of the IMS Connect commandVIEWHWS. The default value for MAXSOC is 50.

Important: The value displayed in the MAXSOC field reflects one socketdedicated to Listen State and the remainder available for connections. Forexample, if MAXSOC is 50, only 49 can be used by connections from Javaclients (Java applications or servlets).

Example: If a particular host machine has a single instance of IMS Connectwith 2 ports, and if MAXSOC is 50, each port can have 49 sockets(connections) from Java clients, yielding a maximum of 98 sockets into theIMS Connect instance.

When the MAXSOC limit is reached, IMS Connect enters a wait state, fromwhich it returns at regular time intervals to check for available sockets. Ifthe Java applications or servlets are not releasing their sockets, yourenvironment can appear to be suspended. If this situation occurs, take oneof the following actions:

v Consider increasing the maximum number of sockets to 2000. Themaximum connections would then be 1999.

Related Reading: For information on increasing the maximum socketvalue, see the section on configuring IMS Connect in the IMS Connectdocumentation at http://www-4.ibm.com/software/data/db2imstools/.

v Make sockets available by cancelling one or more of the Javaapplications or servlets that are holding sockets to the particular IMSConnect.

v Avoid setting the value of the disconnectedCommunication property tofalse using the setDisconnectCommunication method of thecom.ibm.ivj.eab.command.CommunicationCommand class. If thedisconnectedCommunication property is false, the communicationremains connected after execution.

Maximum connectionsA property of the IMSConnectionSpec class that specifies the maximumnumber of connections (sockets) registered with the connection manager forthe host name and port of the associated IMSConnectionSpec. In the caseof the “real” connection manager(com.ibm.connector.connectionmanager.ConnectionManager), a pool ofconnections is kept for each host name and port combination. Therefore,Maximum connections determines the maximum number of connectionsfor a pool.

After the Maximum connections number is reached, no new connectionsare created. The NoConnectionAvailableException is thrown.

© Copyright IBM Corp. 1998, 2002 261

Recommendation: When synchronizing Maximum connections and MAXSOC, itis strongly recommended that Maximum connections be less than or equal toMAXSOC.

Diagnosing problems related to connection poolingIf the number of connections used by your Java application or servlet iscontinuously increasing, such that the connections are not reused by newtransaction requests nor released at the end of transaction executions, you may nothave connection pooling established appropriately in your environment. Forinformation about connection pooling, see the connection management informationin “IMS Connector for Java Concepts and Terms.”

If your Java application or servlet does not respondIn some situations, a Java application or servlet might not respond, which usuallymeans that it has sent a message to the host system and is waiting for a reply. Forexample, this situation can occur when a transaction input message is sent to IMS,but a message processing region is not available to process the transaction. In thiscase, the input message is placed on the IMS message queue, and remains thereuntil a message region is available to process it. The Java application or servletwaits for a reply.

If you do not want your Java application to wait for such a reply, change the defaulttimeout value in the configuration member of IMS Connect. Change the value of theTIMEOUT parameter in the TCP/IP statement to a value greater than 0. Setting thetimeout value to something greater than 0 will cause IMS Connect to close thesocket to the Java application if it does not receive a response from IMS within thespecified time. The TIMEOUT value is specified in hundredths of seconds. Forexample, a TIMEOUT value of 1000 specifies a 10 second timeout.

The Java application receives the exception message HWSJ029E in CCF andICO0005E in J2C. The connection will not be available for reuse. When the IMSapplication program completes and returns the output message to IMS Connect,IMS Connect will display the message HWSD0252W with service code NFNDSVTon the console (because the connection is not available to return the message tothe Java application).

Related Reading: For more information on IMS Connect, see the IMS Connectdocumentation at http://www-4.ibm.com/software/data/db2imstools.

262 IMS Connector for Java User’s Guide and Reference

Appendix D. Messages and exceptions

While you develop Java programs that use IMS Connector for Java, you mightencounter situations in which your program throws exceptions. Some of theseexceptions are thrown by IMS Connector for Java, while others are thrown by otherclass libraries (such as the IBM Common Connector Framework or the Java classlibraries) that your program uses.

This section provides information on:

v “Exceptions generated by IMS Connector for Java CCF applications” onpage 264

v “Exceptions generated by IMS Connector for Java J2C applications” on page 274

An example of an exception that is thrown by Java is:java.lang.NoClassDefFoundError: com/ibm/connector/infrastructure/java/JavaRuntimeContext

A common cause for this exception is an incomplete class path. When testing yourapplication in the VisualAge for Java development environment, ensure that youcompute the class path using the Class path tab of the Properties window for yourapplication.

Related Reading:

v For information on exceptions that are thrown from other class libraries, see theJavadoc information for the specific class library.

v For information on exceptions related to Local Option support, see IBM IMSConnect User’s Guide and Reference. Some exceptions are thrown based onIMS, IMS OTMA or IMS Connect errors returned by IMS Connect. Forinformation on IMS OTMA and IMS Connect errors, see IBM IMS OpenTransaction Manager Access Guide and IBM IMS Connect User’s Guide andReference, respectively. For information on IMS errors, see IBM IMS Messagesand Codes.

The following terms, in italics in the message descriptions that follow, are replacedby specific values at runtime.

hostnameThe TCP/IP host name of the machine that is running IMS Connect.

innermethodnameThe name of the method that originally throws this exception. Thisexception has been caught by IMS Connector for Java and is beingre-thrown to another exception, according to the Common ConnectorFramework specification.

lengthThe length of the data.

libraryFileNameThe Local Option native library file name.

llvalueThe value of LL.

maxlengthThe maximum valid length of the data.

© Copyright IBM Corp. 1998, 2002 263

methodnameThe name of the method that is throwing this exception.

mode The type of interaction between IMS Connector for Java and the IMSConnect component on the host (as defined in the interactionspec).

nativeMethodNameThe Local Option native method name.

portnumberThe port number that is assigned to IMS Connect.

propertynameThe name of the property.

propertyvalueThe value of the property.

reasoncodeThe reason code that is returned by IMS Connect.

rectypeThe type of the record.

returncodeThe return code, formatted in decimal, that is returned by IMS Connect.

sensecodeThe sense code, formatted in decimal, that is returned from IMS OTMA.

socketexceptionThe socket exception.

source_exceptionThe exception thrown when the error first occurred in an internal method.

source_methodnameThe internal method in which the error first occurred.

state The internal state of IMS Connector for Java.

Exceptions generated by IMS Connector for Java CCF applicationsThe following exception messages are produced by applications built using the IMSConnector for Java Common Connector Framework (CCF) class libraries when anerror condition is detected.

HWSJ001E

com.ibm.connector.imstoc.IMSTOCResourceException:HWSJ001E: methodname error.IMS Connect returned error:RETCODE=[returncode],REASONCODE=[reasoncode].

Explanation: An error code has been returned by IMS Connect on the host.

User Action: For diagnostic information on the return code (returncode) andreason code (reasoncode) values, see the IMS Connect Messages and Codesmanual.

HWSJ002E

264 IMS Connector for Java User’s Guide and Reference

com.ibm.connector.imstoc.IMSTOCResourceException:HWSJ002E: methodname error.IMS returned error:SENSECODE=[sensecode].REASONCODE=[otmareasoncode].

Explanation: A NAK error message has been returned from IMS OTMA.

User Action: Related Reading: For diagnostic information on the sense code(sensecode) and OTMA reason code (otmareasoncode) values of the NAKmessage, see the IMS OTMA Guide and Reference.

HWSJ003E

com.ibm.connector.CommunicationException:HWSJ003E: methodname error.Failed to connect to Host name[hostname], Port [portnumber].[socketexception].

Explanation: socketexception is one of the following:[java.net.UnknownHostException: hostname]Hostname is invalid. Check the spelling of the Host name, and use the fullyqualified path for Host name. Correct the application, if necessary.[java.net.SocketException: Connection refused] One of the followingoccurred:

v Port number is invalid.

v The IMS Connect host component with the specified host name is down.

v TCP/IP restarted without canceling and restarting IMS Connect (HWS) onthe host machine, or issuing stopport followed by openport.

Take the following actions:

v Verify that the port number for IMS Connect on the host with the specifiedhost name.

v Start IMS Connect (HWS) on the host machine.

v Do one of the following:

– Cancel and restart the IMS Connect component on the host machine.

– Issue stopport dddd, followed by openport dddd, where dddd is theport number for IMS Connect.

[java.net.SocketException: Connection timed out] One of the followingoccurred:

v The machine with the specified host name is inaccessible on the TCP/IPnetwork.

v TCP/IP on the host system is down.

Take the following actions:

v Ensure that the host machine is accessible from the TCP/IP network. Verifyby issuing the ping command to the host machine.

v Restart TCP/IP on the host and do one of the following:

– Cancel and restart the IMS Connect component on the host machine.

Appendix D. Messages and exceptions 265

– Issue stopport dddd, followed by openport dddd, where dddd is theport number for IMS Connect.

HWSJ004E

com.ibm.connector.CommunicationException:HWSJ004E: methodname error.Failed to close the connection.[socketexception]

Explanation: The connection failed to close. The connection with the host hasbeen reset, or the TCP/IP connection is down.

User Action: Refer to the socketexception for more details for the cause offailure. Restart IMS Connect and TCP/IP on the host, if appropriate.

HWSJ005E

com.ibm.connector.CommunicationException:HWSJ005E: methodname error.Failed to send the data.[socketexception]

Explanation: Failed to write to a socket to send the transaction message toIMS Connect on the host. The connection with the host has been reset or theTCP/IP connection is down.

User Action: Refer the socketexception for more details of the failure. RestartIMS Connect and TCP/IP on the host, if appropriate.

HWSJ006E

com.ibm.connector.NotConnectedException:HWSJ006E: methodname error.The connection resource is notconnected.

Explanation: An application programming error occurred while attempting toexecute a transaction. The connection has not been established.

User Action: Correct the application program.

HWSJ007E

com.ibm.connector.AlreadyConnectedException:HWSJ007E: methodname error.The connection resource is alreadyconnected.

Explanation: An application programming error occurred while attempting toconnect to IMS Connect on the host. The connection has already beenestablished.

266 IMS Connector for Java User’s Guide and Reference

User Action: Correct the application program.

HWSJ008E

java.lang.IllegalArgumentException:HWSJ008E: methodname error.The property [propertyname] exceededmaximum length.Length is [length],maximum length is [maxlength].

Explanation: An application programming error occurred. The property valueis invalid (the length exceeded the maximum value).

User Action: Verify the property value. The length must be less than themaximum length value. Correct the application program.

HWSJ009E

java.lang.IllegalArgumentException:HWSJ009E: methodname error.The [propertyname] property value[propertyvalue] is invalid.

Explanation: An application programming error occurred. The property valueis invalid.

User Action: Verify the property value. Correct the application program.

Related Reading: For a list of supported values for property, see theVisualAge for Java documentation by clicking Help > Help Home Page >Reference > IBM Tool APIs > Connectors > IMS Connect.

HWSJ010E

java.lang.IllegalArgumentException:HWSJ010E: methodname error.The input record type is invalid.The type currently supported is[rectype].

Explanation: An application programming error occurred. The type of inputrecord bean is invalid.

User Action: Verify the type of input record bean. The record type of the inputbean must be rectype. Correct the application program.

HWSJ011E

java.lang.IllegalArgumentException:HWSJ011E: methodname error.The output record type is invalid.The type currently supported is[rectype].

Appendix D. Messages and exceptions 267

Explanation: An application programming error occurred. The type of outputrecord bean is invalid.

User Action: Verify the type of output record bean. The record type of theoutput bean must be rectype. Correct the application program.

HWSJ012E

com.ibm.connector.BadInvOrderException:HWSJ012E: methodname error.Protocol violation.The connection resource is inan inappropriate state [state]for the execution [execution].

Explanation: An application programming error occurred during the orderedsequence of methods invocation of an interaction with IMS Connect on thehost. Connector is in an inappropriate state for the requested execution. Apossible cause might be that command.execute() is called beforecommunication.connect().

User Action: Correct the application program. Correct the execution flow:communication.connect() > communication.execute() >communication.disconnect()

Related Reading: For the suggested execution flow, see the VisualAge forJava documentation by clicking Help > Help Home Page > Reference > IBMTool APIs > Connectors > IMS Connect.

HWSJ013E

com.ibm.connector.BadInvOrderException:HWSJ013E: methodname error.Protocol violation.The Interaction Mode [mode]is not allowed for thecurrent state [state].

Explanation: An application programming error occurred in the orderedsequence of methods invocation of an interaction with IMS Connect on thehost. The execution of the command with the specified interaction mode is notallowed in the state. A possible cause might be the execution of the secondinteraction of a command with the synchronization level ofSYNC_LEVEL_CONFIRM (as specified in the IMSConnectionSpec bean)without previously executing an ACK or NACK command to reply to IMSConnect on the host for the first interaction.

For example, (1st interaction) command.execute() > (2nd interaction)command.execute() ... An ACK or NACK command is an EAB command withinteraction mode MODE_ACK or MODE_NACK.

User Action: Correct the application program. Correct the execution flow tothe following: (1st interaction) command.execute() > ackCommand.execute (to

268 IMS Connector for Java User’s Guide and Reference

reply to IMS Connect on the host as it is waiting for a response because ofthe synchronization level of Confirm) > (2nd interaction) command.execute()

Related Reading: For suggested execution flow, see the VisualAge for Javadocumentation by clicking Help > Help Home Page > Reference > IBM ToolAPIs > Connectors > IMS Connect.

HWSJ014E

com.ibm.connector.ResourceException:HWSJ014E: methodname error.The connection resource is inan invalid state [state].

Explanation: An application programming error occurred. The value of thestate field is invalid.

User Action: Correct the application program.

Related Reading: For the valid values of state, see the VisualAge for Javadocumentation by clicking Help > Help Home Page > Reference > IBM ToolAPIs > Connectors > IMS Connect.

HWSJ015E

java.lang.IllegalArgumentException:HWSJ015E: methodname error.This was an error in building theOTMA message. [exception]

Explanation: The exception is one of the following:

vcom.ibm.imstoc.IMSException:HWSJ501E: innermethodname error.The LL value of the input message is incorrect.

The LL value of the input message is incorrect. Ensure that the LL value ofthe input object that is provided by the application program matches the reallength of the message data. Correct the application program.

vcom.ibm.imstoc.IMSException:HWSJ502E: innermethodname error.The input byte array is not pure DBCS.There is an odd number of bytes.

The input byte array is not pure DBCS. An odd number of bytes exists.Ensure that this exception is being handled properly in your applicationprogram. See the exception for the specific cause of the error.

v For other exception types that are not listed above, see the exception of thespecific cause of the error. An error building the OTMA message for theinteraction request occurred. Ensure that the values provided by theapplication program are valid for building the interaction request. Correct theapplication program.

HWSJ016E

Appendix D. Messages and exceptions 269

com.ibm.connector.ResourceException:HWSJ016E: methodname error.Two phase commit is not supported.

Explanation: An application programming error occurred while attempting touse two-phase commit to coordinate the transaction. Currently, two-phasecommit is not supported.

User Action: Use IMSConnection.commitOnePhase(). Correct the applicationprogram.

As suggested in the IMS Connector for Java User’s Guide, the applicationimplementation should invoke the Coordinator.commit() in order to commit aconnection. If the application is using the original Coordinator class from CCF,the IMSConnection.commitOnePhase() method is automatically invoked.Therefore, this exception is not thrown. However, if the application uses themethod (IMSConnection.commit()) directly to commit the connection, thisexception is thrown.

HWSJ017E

com.ibm.connector.TransactionRolledBack:HWSJ017E: methodname error.An exception occurred during commit.Transaction was rolled back andthe connection will be closed[exception].

Explanation: An exception occurred while attempting to commit thetransaction. This exception notifies the application program that the transactionhas been rolled back and that the connection is closed.

Definition: A connection is marked as dirty when severe exceptions, such ascommunications or protocol violations, occur during the execution.

User Action: Ensure that this exception is handled properly by the applicationprogram. See the exception for the specific causes of the error.

HWSJ018E

HWSJ018E: methodname error.An exception occurred whileattempting to close the dirty connection[socketexception].

Explanation: An exception has occurred while attempting to close the dirtyconnection. This warning message is normally displayed after anotherexception is shown during the execution of the command.

Definition: A connection is marked as dirty when severe exceptions, such ascommunications or protocol violations, occur during the execution.

User Action: See the socketexception for the specific cause of the exception.Because this is a warning message, no specific action is needed. However, if

270 IMS Connector for Java User’s Guide and Reference

the exception impacts the subsequent execution of the application program,ensure that the application can handle the situation properly.

HWSJ019E

com.ibm.connector.ResourceException:HWSJ019E: methodname error.Resource is registered with thecoordinator.

Explanation: An application programming error occurred. The connectionresource is still registered with the Coordinator while preparing the connectionto be reused.

User Action: Verify that the managed connection has been unregistered withthe Coordinator by invoking commit()/rollback() before reusing the connectionin the application program. Correct the application program.

HWSJ021E

com.ibm.connector.ResourceException:HWSJ021E: methodname error.Attempted to execute on a dirtyconnection.

Explanation: An application programming error occurred while attempting toexecute or commit on a dirty connection.

Definition: A connection is marked as dirty when severe exceptions, such ascommunications or protocol violations, occur during the execution.

If the application program attempts to commit on a dirty connection, thisexception notifies the application program that the transaction has been rolledback.

User Action: Correct the application program. Ensure that this exception ishandled properly in the application program. Do not perform any furtherexecution using a dirty connection.

HWSJ022E

com.ibm.connector.TransactionRolledBack:HWSJ022E: methodname error.Attempted to commit on a dirtyconnection.

Explanation: An application programming error occurred while attempting tocommit on a dirty connection.

Definition: A connection is marked as dirty when severe exceptions, such ascommunications or protocol violations, occur during the execution.

User Action: Correct the application program. Ensure that this exception ishandled properly by the application program. Do not perform any furtherexecution using a dirty connection.

Appendix D. Messages and exceptions 271

HWSJ024E

java.lang.IllegalArgumentException:HWSJ024E: methodname error.Invalid segment length (LL) of [llvalue]in input object.

Explanation: The segment length LL of the input object is invalid.

User Action: Verify that the segment length LL in the segment messagematches the real length of the segment. Correct the application program.

HWSJ025E

java.lang.IllegalArgumentException:HWSJ025E: methodname error.Invalid segment length (LL) of [llvalue]in OTMA message.

Explanation: The segment length LL of the OTMA message is invalid whileprocessing the output transaction message from IMS.

User Action: Verify that the transaction output message that is being sentback from the IMS transaction is correct. Verify that the segment length LL inthe OTMA message that is received is valid and matches the real length of thesegment. Correct the application program.

HWSJ026E

java.lang.IllegalArgumentException:HWSJ026E: methodname error.There was an error in processing theoutput message. [exception]

Explanation: An error occurred while processing the output message that isreceived from IMS. The output message that is sent from the IMS transactionmight be invalid.

User Action: Verify that the output message that is sent from the IMStransaction is valid. See the exception for the specific cause of the error.Correct the application program.

HWSJ027E

java.lang.IllegalArgumentException:HWSJ027E: methodname error.An error occurred when completingthe interaction request. [exception]

Explanation: An error occurred while completing the interaction request of thecommand. For example, the connection with IMS Connect on the host mightbe down while completing the interaction. The interaction request might ormight not be completed successfully.

User Action: Ensure that this exception is handled properly by the applicationprogram. See the exception for the specific cause of the error.

272 IMS Connector for Java User’s Guide and Reference

HWSJ028E

com.ibm.connector.TransactionRolledBack:HWSJ028E: methodname error.An exception occurred duringrollback. [exception]

Explanation: An exception occurred while attempting to perform a roll back onthe transaction. The connection is closed.

User Action: Ensure that this exception is handled properly by the applicationprogram. See the exception for the specific cause of the error.

HWSJ029E

com.ibm.connector.CommunicationException:HWSJ029E: methodname error.A communication error occurred whilereceiving the output message. [exception].

Explanation: Failed to read the output message from the socket. One of thefollowing may have occurred:

v The client on IMS Connect was closed. (For example, the IMS ConnectSTOPCLNT command was issued).

v The connection with the host has been reset or the TCP/IP connection isdown.

v The output message is incomplete or corrupted.

Definition: A connection is marked as dirty when severe exceptions, such ascommunications or protocol violations, occur during the execution.

User Action: Refer to the exception for more details of the failure. The “dirty”connection will be closed and will not be reused. A new connection will becreated for the next request.

HWSJ030E

java.lang.lllegalArgumentException:HWSJ030E: methodname error.errortext1 error: errortext2.

Explanation: An error has been detected by IMS Connector for Java duringLocal Option processing. This is a generic exception that may apply to avariety of different error conditions.

User Action: An invalid argument was supplied to one of the Local Optionprocessing classes. For example, if the IMS Connect name supplied in thehostname property of IMSConnectionSpec is null or blanks, this exceptionwould be thrown. Examine the argument identified in the message error textand verify that it is a valid value for the property that it represents. In theabove example, errortext2 would be ″IMS Connect name is null.″ You wouldneed to ensure that the IMS_connect_name portion of theIMSConnectionSpec hostname property is set to the correct value.

Appendix D. Messages and exceptions 273

Exceptions generated by IMS Connector for Java J2C applicationsThe following exception messages are produced by applications built with the Java2 Platform, Enterprise Edition (J2EE) Connector Architecture (J2C) class librarieswhen an error condition is detected.

ICO0001E

javax.resource.spi.EISSystemException:ICO0001E: methodname error.IMS Connect returned error:RETCODE=[returncode], REASONCODE=[reasoncode].[source_methodname: source_exception]

Explanation: IMS Connect returned an error. The connection in error will notbe reused.

User Action: For diagnostic information on the return code (returncode) andreason code (reasoncode) values, see the IMS Connect Messages and Codesmanual.

ICO0002E

javax.resource.spi.EISSystemException:ICO0002E: methodname error.IMS OTMA returned error:SENSECODE=[sensecode], REASONCODE=[otmareasoncode].[source_methodname: source_exception]

Explanation: IMS OTMA returned a NAK error.

User Action: Related Reading: For diagnostic information on the sense code(sensecode) and OTMA reason code (otmareasoncode) values of the NAKerror, see the IMS OTMA Guide and Reference.

ICO0003E

javax.resource.spi.CommException:ICO0003E: methodname error.Failed to connect to host [hostname],port [portnumber].[java_exception]

Explanation: IMS Connector for Java was unable to connect to the host andport combination. java_exception indicates the reason for the failure toconnect. For additional information see User Action: below.

User Action: Examine java_exception to determine the reason for the failureto connect to the host. Some suggested actions to take, based on the value ofjava_exception are:

v java.net.UnknownHostException: hostname The host name you specifiedwhen configuring the Connection Factory used by your application is invalidor your application specified an invalid host name. Check the spelling of thehost name. You may have to use the fully qualified path for host name.

274 IMS Connector for Java User’s Guide and Reference

v java.net.ConnectException: Connection refused One of the followingoccurred:

– The port number is invalid. Ensure that you are using a valid portnumber for the target IMS Connect (indicated by hostname).

– The specified port is stopped. Use the IMS Connect command,OPENPORT dddd, where dddd is the specified port number, to start theport.

– IMS Connect on the specified host machine is not running. Start IMSConnect (HWS) on the host machine.

– TCP/IP restarted without canceling and restarting IMS Connect orissuing STOPPORT followed by OPENPORT on the host machine.

v java.io.InterruptedIOException: Operation timed out

One of the following occurred:

– The machine with the specified host name is inaccessible on the TCP/IPnetwork. Ensure that the host machine is accessible from the TCP/IPnetwork. Verify by issuing the ping command to the specified hostmachine. Enter the ping command on the machine on which IMSConnector for Java is running.

– TCP/IP on the host system is down. Restart the TCP/IP on the host anddo one of the following:

- Cancel and restart the IMS Connect component on the host machine.

- Issue the IMS Connect command STOPPORT dddd, then issue thecommand OPENPORT dddd, where dddd is the port number for IMSConnect.

ICO0005E

javax.resource.spi.CommException:ICO0005E: methodname error.A communication error occurred while sending or receiving the IMSmessage.[java_exception]

Explanation: IMS Connector for Java was unable to successfully complete asend and receive interaction with the target host. java_exception indicates thereason for the failure to complete the interaction. For additional informationsee User Action: below.

User Action: Examine java_exception to determine the reason for the failureto connect to the host. Some suggested actions to take, based on the value ofjava_exception are:

v java.io.EOFException

The client sees this exception when the timeout specified in the IMSConnect configuration causes it to expire before receiving a response fromIMS. The connection in error will not be reused. This exception typicallyhappens when there is no region available in IMS to run the transaction toprocess the client’s request. If this is the case, ensure that an appropriateregion is started and available to process work. It can also happen if theIMS application program associated with the transaction is stopped. If this isthe case, use the IMS command /START PROGRAM to start the IMSapplication program.

Appendix D. Messages and exceptions 275

A client also receives this exception if it tries to use a previously activeclient (for example, a connection from the pool) for which an IMS ConnectSTOPCLNT command has been issued.

v java.net.SocketException: socket closed

A client might receive this exception after an IMS Connect STOPCLNTcommand has been issued.

v java.net.SocketException: Connection reset by peer

A client would receive this exception if the client uses a previously workingconnection but TCP/IP on the host has gone down.

ICO0006E

javax.resource.ResourceException:ICO0006E: methodname error.The value provided for DataStoreName is null or an empty string.

Explanation: The method indicated in methodname was invoked using anempty DatastoreName parameter.

User Action: Provide a valid DatastoreName parameter. In a managedenvironment, the DatastoreName is specified when you are configuring aConnection Factory to be used by WebSphere Application Server. In anon-managed environment, the DatastoreName is specified in your Javaapplication.

ICO0007E

javax.resource.NotSupportedException:ICO0007E: methodname error.The [propertyName] property value [propertyValue] is not supported.

Explanation: The value propertyValue specified for the propertypropertyName is not supported.

User Action: Provide a supported value for the named property. For example,certain values of the InteractionVerb property of the InteractionSpec class thatare be defined by the J2C architecture might not be supported by this releaseof IMS Connector for Java.

ICO0008E

javax.resource.ResourceException:ICO0008E: methodname error.The value [propertyValue] of the [propertyName] property exceeds themaximum allowable length of [maxPropertyLength].

Explanation: The length of the value propertyValue supplied for propertypropertyName exceeds maxPropertyLength, the maximum length allowed forvalues of property propertyName.

User Action: Provide a value for the named property which does not exceedmaxPropertyLength.

ICO0009E

276 IMS Connector for Java User’s Guide and Reference

javax.resource.ResourceException:ICO0009E: methodname error.The [propertyName] property value [propertyValue] is invalid.

Explanation: The value propertyValue specified for the propertypropertyName is not valid.

User Action: Provide a value which is valid for the named property. Validvalues for the InteractionVerb property of the InteractionSpec class of IMSConnector for Java are listed in the Javadoc for the IMSInteractionSpec class.See the VisualAge for Java documentation by clicking Help > API Reference> IBM APIs > Connectors > IMS Connector > Packagecom.ibm.connector2.ims.ico > methodsetInteractionVerb of classIMSInteractionSpec.

ICO0010E

javax.resource.spi.IllegalStateException:ICO0010E: methodname error.Method invoked on invalid IMSConnection instance.

Explanation: The method indicated in methodname was invoked on an invalidIMSConnection instance.

User Action: The named method was most likely issued on anIMSConnection instance that was already closed. Ensure that theIMSConnection instance is not already closed before you attempt to use it orclose it.

ICO0011E

javax.resource.spi.IllegalStateException:ICO0011E: methodname error.Method invoked on invalid IMSInteraction instance.

Explanation: The method indicated in methodname was invoked on an invalidIMSInteraction instance.

User Action: The named method was most likely issued on an IMSInteractioninstance that was already closed. Ensure that the IMSInteraction instance isnot already closed before you attempt to use it or close it.

ICO0012E

javax.resource.ResourceException:ICO0012E: methodname error.The value provided for HostName is null or an empty string.

Explanation: The method indicated in methodname was invoked using amnull or empty HostName parameter.

User Action: Provide a valid HostName parameter. In a managedenvironment, the property value is specified when you are configuring aConnection Factory to be used by WebSphere Application Server. In anon-managed environment, the property value is specified in your Javaapplication.

Appendix D. Messages and exceptions 277

ICO0013E

javax.resource.ResourceException:ICO0013E: methodname error.ConnectionManager is null.

Explanation: The method indicated in methodname was invoked. Theapplication server invoked the createConnectionFactory method of theIMSManagedConnectionFactory class with a null ConnectionManager object.

User Action: Provide a valid HostName parameter. This form of thecreateConnectionFactory method is used in a managed environment. It isnot typically invoked by a client program. Contact the service personnel foryour application server.

ICO0014E

javax.resource.ResourceException:ICO0014E: methodname error.Input record contains no data.

Explanation: The method indicated in methodname was invoked with an inputrecord that contained no data.

User Action: Verify that the input record that you provide is not empty.

ICO0015E

ResourceAdapterInternalExceptionICO0015E: methodname error.Unexpected error encountered while processing the OTMA message.[java_exception]

Explanation: An unexpected internal error was encountered while processingthe OTMA message.

User Action: Contact your IBM service representative.

ICO0017E

ResourceAdapterInternalExceptionICO0017E: methodname error.Invalid value provided for TraceLevel.

Explanation: An invalid trace level was specified.

User Action: Specify a valid trace level. Optionally, this exception can beignored due to the fact that the default trace level will be used for thisconnection factory. In this case, the connection factory is still usable but thetrace level will be the default trace level. For valid trace level values, see theVisualAge for Java documentation by clicking Help > API Reference > IBMAPIs > Connectors > IMS Connector > Packagecom.ibm.connector2.ims.ico > interface IMSTraceLevelProperties.

ICO0018E

278 IMS Connector for Java User’s Guide and Reference

javax.resource.ResourceException:ICO0018E: methodname error.The value provided for PortNumber is null.

Explanation: The method indicated in methodname was invoked using a nullPortNumber.

User Action: Provide a valid PortNumber parameter. In a managedenvironment, the property value is specified when you are configuring aConnection Factory to be used by WebSphere Application Server. In anon-managed environment, the property value is specified in your Javaapplication.

ICO0024E

javax.resource.ResourceException:ICO0024E: methodname error.Invalid segment length (LL) of [llvalue] in input object.[java_exception]

Explanation: The input message provided by the Java program for the IMSapplication program contains a value for its segment length which is eithernegative, 0, or greater than the number of bytes of data in the messagesegment.

User Action: Provide the correct value for the segment length of the inputmessage.

ICO0025E

javax.resource.IllegalArgumentException:ICO0025E: methodname error.Invalid segment length (LL) of [{1}] in OTMA message.

Explanation: The output message provided by the IMS application programcontains a value for its segment length which is either negative, 0, or greaterthan the number of bytes of data in the message segment. The outputmessage provided by the IMS application program is contained in the OTMAmessage.

User Action: Ensure that your IMS application program provides valid lengthsfor the segments of its output message.

ICO0026E

javax.resource.ResourceException:ICO0026E: methodname error.An error was encountered while processing the IMS message.[source_methodname:source_exception]

Explanation: An error occurred while processing the IMS transaction input oroutput message. source_exception provides additional information regardingthe cause of the error.

Appendix D. Messages and exceptions 279

User Action: Examine source_exception for additional information regardingthe cause of the error. Some suggested actions to take, based on the value ofsource_exception are:

v java.io.IOException

Error preparing input or output record. Ensure that the objects you areproviding to IMS Connector for Java for use as the IMS transaction inputand output are defined properly for the J2C architecture. For example,ensure that they implement the interfaces javax.resource.cci.Record andjavax.resource.cci.Streamable. This is done for you when you useVisualAge for Java’s Enterprise Access Builder to create you input andoutput records.

v com.ibm.ims.ico.IMSConnResourceException

The OTMA message containing the IMS transaction output messagecontained an invalid length field (i.e., LLLL was <= 0). If this error continuesto occur after verifying that your IMS application program is returning a validoutput message, contact your IBM service representative.

ICO0031E

javax.resource.spi.IllegalStateException:ICO0031E: methodname error.Protocol violation. The Interaction Verb [interactionverb] is not allowed forthe current state [state].[java_exception]

Explanation: The action attempted has resulted in a protocol violation. Forexample, a protocol violation would occur if your Java program is not inconversation, but you attempt an interaction with IMS using theSYNC_END_CONVERSATION value for the InteractionVerb property of anIMSInteractionSpec instance.

User Action: Ensure that you are using an appropriate value for theInteractionVerb property of IMSInteractionSpec.

ICO0033E

javax.resource.NotSupportedException:ICO0033E: methodname error.XAResource interface not supported.

Explanation: XA Transactions are currently not supported by IMS Connectorfor Java.

User Action: Ensure that your Java application uses classes and methodsthat are appropriate for the level of support currently provided by IMSConnector for Java.

ICO0034E

javax.resource.NotSupportedException:ICO0034E: methodname error.Auto-commit not supported.

Explanation: Auto-commit is currently not supported by IMS Connector forJava.

280 IMS Connector for Java User’s Guide and Reference

User Action: Ensure that your Java application uses classes and methodsthat are appropriate for the level of support currently provided by IMSConnector for Java.

ICO0035E

javax.resource.NotSupportedException:ICO0035E: methodname error.Local Transaction not supported.

Explanation: Local Transactions are not currently supported by IMSConnector for Java.

User Action: Ensure that your Java application uses classes and methodsthat are appropriate for the level of support currently provided by IMSConnector for Java.

ICO0037E

javax.resource.NotSupportedException:ICO0037E: methodname error.ResultSet not supported.

Explanation: ResultSets are currently not supported by IMS Connector forJava.

User Action: Ensure that your Java application uses classes and methodsthat are appropriate for the level of support currently provided by IMSConnector for Java.

ICO0039E

javax.resource.spi.IllegalStateException:ICO0039E: methodname error.IMS Connect returned error:Not in CONNECT state.

Explanation: The sequence of interactions between IMS Connector for Javaand IMS Connect is invalid. The current state of the interaction is not theCONNECT state as it needs to be at this point in the interaction.

User Action: Contact your IBM service representative.

ICO0040E

javax.resource.NotSupportedException:ICO0040E: methodname error.IMSConnector does not support this version of execute method.

Explanation: IMS Connector for Java does not currently support the form ofthe execute method that takes two input parameters and returns an object oftype javax.resource.cci.Record.

User Action: Use the form of the execute method in class IMSInteraction withthe following signature:boolean execute(InteractionSpec, Record input, Record output)

Appendix D. Messages and exceptions 281

ICO0041E

javax.resource.ResourceException:ICO0041E: methodname error.Invalid interactionSpec specified [interactionSpec].

Explanation: An invalid InteractionSpec object was passed to the executemethod of class com.ibm.connector2.ims.ico.IMSInteraction.

User Action: Verify that they InteractionSpec object you passed to theexecute method of class com.ibm.connector2.ims.ico.IMSInteraction is oftype com.ibm.connector2.ims.ico.IMSInteractionSpec.

ICO0042E

javax.resource.ResourceException:ICO0042E: methodname error.Input is not of type Streamable.

Explanation: The input object provided to the execute method of the classcom.ibm.connector2.ims.ico.IMSInteraction was either null or did notimplement the interface javax.resource.cci.Streamable.

User Action: Ensure that you are providing a valid input object to the executemethod. For example, ensure that it implements the interfacesjavax.resource.cci.Record and javax.resource.cci.Streamable. This is donefor you when you use VisualAge for Java’s Enterprise Access Builder to createyour input record.

ICO0043E

javax.resource.ResourceException:ICO0043E: methodname error.Output is not of type Streamable.

Explanation: The output object provided to the execute classcom.ibm.connector2.ims.ico.IMSInteraction was either null or did notimplement the interface javax.resource.cci.Streamable.

User Action: Ensure that you are providing a valid output object to theexecute method. For example, ensure that it implements the interfacesjavax.resource.cci.Record and javax.resource.cci.Streamable. This is donefor you when you use VisualAge for Java’s Enterprise Access Builder to createyour output record.

ICO0044E

javax.resource.NotSupportedException:ICO0044E: methodname error.RecordFactory is not supported by IMS Connector for Java.

Explanation: RecordFactory is currently not supported by IMS Connector forJava.

282 IMS Connector for Java User’s Guide and Reference

User Action: Ensure that your Java application uses classes and methodsthat are appropriate for the level of support currently provided by IMSConnector for Java.

ICO0045E

javax.resource.NotSupportedException:ICO0045E: methodname error.Invalid type of ConnectionRequestInfo.

Explanation: An invalid ConnectionRequestInfo object was passed to an IMSConnector for Java method.

User Action: Contact the service personnel for your application server.

ICO0049E

javax.resource.NotSupportedException:ICO0049E: methodname error.The security credentials passed to getConnection do not match existingsecurity credentials.

Explanation: The security credentials in the request do not match the securitycredentials of the IMSManagedConnection instance that was being used toprocess the request.

User Action: Contact your IBM service representative.

ICO0054E

javax.resource.ResourceException:ICO0054E: methodname error.Invalid ConnectionSpec.

Explanation: IMS Connector for Java was unable to cast the connectionSpecprovided for this connection to type IMSConnectionSpec. While the CommonClient Interface will accept a connectionSpec object for any supportedconnector, IMS Connector for Java will only work with an IMSConnectionSpecor a derivative of IMSConnectionSpec as its connectionSpec.

User Action: Ensure that the connectionSpec used in your application is anIMSConnectionSpec or inherits from IMSConnectionSpec.

ICO0055E

javax.resource.ResourceException:ICO0055E: methodname error.Failed to cast the connection object to IMSConnection.

Explanation: IMS Connector for Java was unable to cast the connectionobject allocated by the ConnectionManager for this connection to typeIMSConnection. IMS Connector for Java will only work with an IMSConnectionor a derivative of IMSConnection as its connection object. This error might bethe result of a problem with the ConnectionManager.

User Action: Please contact your IBM service representative.

Appendix D. Messages and exceptions 283

ICO0057E

javax.resource.spi.IllegalStateException:ICO0057E: methodname error.Invoked with invalid connection handle.

Explanation: The application is in an illegal state: the connection handle(IMSConnection instance) used for this interaction is not valid. This could notoccur if the application attempted to use a connection handle for a previouslyused connection or the handle for the wrong connection if the application hasmore than one connection open.

User Action: Ensure that the application is using the currently validIMSConnection instance for that connection.

ICO0060E

java.lang.UnsatisfiedLinkError:ICO0060E: methodname error.Error loading Local Option native library: libname=libraryFileName.[source_exception].

Explanation: The Local Option native library cannot be found in one of thedirectory listed in the libpath.

User Action: Verify the LIBPATH environment variable and en sure that theLocal Option native library exists in one of the directories listed in the libpath.If you are using IMS Connector for Java with WebSphere Application Serverfor z/OS and OS/390, ensure that the full name of the directory that containsthe Local Option native library file is defined in the LIBPATH environmentvariable for your J2EE server. For more information, see “Preparing yourWebSphere Application Server environment for z/OS and OS/390.”

ICO0061E

javax.resource.ResourceException:ICO0061E: methodname error.Local Option runs only in z/OS and OS/390.

Explanation: You can use Local Option to communicate with IMS Connectonly if your application using IMS Connector for Java is running on the z/OSor OS/390 platform.

User Action: Ensure that your application using IMS Connector for Java isrunning on the z/OS or OS/390 platform. If you plan to run your application ona workstation platform, correct your application to use TCP/IP communication.

ICO0062E

javax.resource.ResourceException:ICO0062E: methodname error.Error loading Local Option native method: libfilename=libraryFileName,methodname=nativeMethodName. [source_exception].

Explanation: The Local Option native method cannot be found.

284 IMS Connector for Java User’s Guide and Reference

User Action: Verify that you have the correct level of the IMS Connector Javasuch that the correct level of the Local Option native library is being installedon your system. See “Prerequisites for using IMS Connector for Java” formore information.

ICO0063E

javax.resource.spi.ResourceAdapterInternalException:ICO0063E: methodname error.Exception thrown in native method. [source_exception].

Explanation: An internal error occurred in the Local Option native library.

User Action: Contact your IBM service representative.

ICO0064E

javax.resource.spi.SecurityException:ICO0064E: methodname error.Invalid security credential.

Explanation: The security credential provided by WebSphere ApplicationServer is invalid. There is no appropriate security credential available for useby IMS Connector for Java.

User Action: Ensure that you have the correct level of WebSphere ApplicationServer for z/OS and OS/390 installed. See the “Prerequisites for using IMSConnector for Java” section for details.

ICO0065E

javax.resource.spi.SecurityException:ICO0065E: methodname error.Error obtaining credential data from the securitycredential.[source_exception].

Explanation: There is an error in obtaining the credential data from thesecurity credential provided by WebSphere Application Server.

User Action: Ensure that you have the correct level of WebSphere ApplicationServer for z/OS and OS/390 installed. See the “Prerequisites for using IMSConnector for Java” section for details.

ICO0066E

javax.resource.ResourceException:ICO0066E: methodname error.Error loading WebSphere Application Server Transaction Manager.[source_exception].

Explanation: An error occurred when accessing the Transaction Manager ofthe WebSphere Application Server for processing the transaction request.

User Action: Ensure that you have the correct level of WebSphere ApplicationServer for z/OS and OS/390 installed. See the “Prerequisites for using IMSConnector for Java” section for details.

Appendix D. Messages and exceptions 285

ICO0068E

javax.resource.ResourceException:ICO0068E: methodname error.Error obtaining the transaction object. [source_exception].

Explanation: An error occurred while obtaining the transaction objectassociated with your transaction request provided by WebSphere ApplicationServer.

User Action: Ensure that you have the correct level of WebSphere ApplicationServer for z/OS and OS/390 installed. See the “Prerequisites for using IMSConnector for Java” section for details.

ICO0069E

javax.resource.spi.ResourceAllocationException:ICO0069E: methodname error.Error obtaining RRS transaction context token. [source_exception].

Explanation: An unexpected internal error occurred while obtaining an RRStransaction context token for processing the global transaction.

User Action: Ensure that you have the correct level of IMS Connect, IMSConnector for Java and WebSphere Application Server for z/OS and OS/390installed. See the “(Prerequisites for using IMS Connector for Java)” sectionfor details.

286 IMS Connector for Java User’s Guide and Reference

Notices

Note to U.S. Government Users Restricted Rights — Use, duplication or disclosurerestricted by GSA ADP Schedule Contract with IBM Corp.

This information was developed for products and services offered in the U.S.A. IBMmay not offer the products, services, or features discussed in this document in othercountries. Consult your local IBM representative for information on the products andservices currently available in your area. Any reference to an IBM product,program, or service is not intended to state or imply that only that IBM product,program, or service may be used. Any functionally equivalent product, program, orservice that does not infringe any IBM intellectual property right may be usedinstead. However, it is the user’s responsibility to evaluate and verify the operationof any non-IBM product, program, or service.

IBM may have patents or pending patent applications covering subject matterdescribed in this document. The furnishing of this document does not give you anylicense to these patents. You can send license inquiries, in writing, to:

IBM Director of LicensingIBM CorporationNorth Castle DriveArmonk, NY 10504-1785U.S.A.

For license inquiries regarding double-byte (DBCS) information, contact the IBMIntellectual Property Department in your country or send inquiries, in writing, to:

IBM World Trade Asia CorporationLicensing2-31 Roppongi 3-chome, Minato-kuTokyo 106, Japan

The following paragraph does not apply to the United Kingdom or any othercountry where such provisions are inconsistent with local law:INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THISPUBLICATION “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIESOR CONDITIONS OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESSFOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of expressor implied warranties in certain transactions, therefore, this statement may not applyto you.

This information could include technical inaccuracies or typographical errors.Changes are periodically made to the information herein; these changes will beincorporated in new editions of the publication. IBM may make improvements and/orchanges in the product(s) and/or the program(s) described in this publication at anytime without notice.

Any references in this information to non-IBM Web sites are provided forconvenience only and do not in any manner serve as an endorsement of thoseWeb sites. The materials at those Web sites are not part of the materials for thisIBM product and use of those Web sites is at your own risk.

© Copyright IBM Corp. 1998, 2002 287

IBM may use or distribute any of the information you supply in any way it believesappropriate without incurring any obligation to you.

Licensees of this program who wish to have information about it for the purpose ofenabling: (i) the exchange of information between independently created programsand other programs (including this one) and (ii) the mutual use of the informationwhich has been exchanged, should contact:

Lab DirectorIBM Canada Ltd.1150 Eglinton Avenue EastToronto, Ontario M3C 1H7Canada

Such information may be available, subject to appropriate terms and conditions,including in some cases, payment of a fee.

The licensed program described in this document and all licensed material availablefor it are provided by IBM under terms of the IBM Customer Agreement, IBMInternational Program License Agreement or any equivalent agreement between us.

Information concerning non-IBM products was obtained from the suppliers of thoseproducts, their published announcements or other publicly available sources. IBMhas not tested those products and cannot confirm the accuracy of performance,compatibility or any other claims related to non-IBM products. Questions on thecapabilities of non-IBM products should be addressed to the suppliers of thoseproducts.

This information contains examples of data and reports used in daily businessoperations. To illustrate them as completely as possible, the examples may includethe names of individuals, companies, brands, and products. All of these names arefictitious and any similarity to the names and addresses used by an actual businessenterprise is entirely coincidental.

COPYRIGHT LICENSE:

This information contains sample application programs in source language, whichillustrates programming techniques on various operating platforms. You may copy,modify, and distribute these sample programs in any form without payment to IBM,for the purposes of developing, using, marketing or distributing application programsconforming to the application programming interface for the operating platform forwhich the sample programs are written. These examples have not been thoroughlytested under all conditions. IBM, therefore, cannot guarantee or imply reliability,serviceability, or function of these programs. You may copy, modify, and distributethese sample programs in any form without payment to IBM for the purposes ofdeveloping, using, marketing, or distributing application programs conforming toIBM’s application programming interfaces.

Each copy or any portion of these sample programs or any derivative work, mustinclude a copyright notice as follows:

(C) (your company name) (year). Portions of this code are derived from IBM Corp.Sample Programs. (C) Copyright IBM Corp. 1997, 2000. All rights reserved.

288 IMS Connector for Java User’s Guide and Reference

Programming interface information

Programming interface information is intended to help you create applicationsoftware using this program.

General-use programming interfaces allow the customer to write applicationsoftware that obtain the services of this program’s tools.

However, this information may also contain diagnosis, modification, and tuninginformation. Diagnosis, modification and tuning information is provided to help youdebug your application software.

Warning: Do not use this diagnosis, modification, and tuning information as aprogramming interface because it is subject to change.

© Copyright IBM Corp. 1998, 2002 289

290 IMS Connector for Java User’s Guide and Reference

Trademarks and service marks

The following terms are trademarks of International Business Machines Corporationin the United States, or other countries, or both:

v AIX

v AS/400

v DB2

v CICS

v CICS/ESA

v IBM

v IMS

v Language Environment

v MQSeries

v Network Station

v OS/2

v OS/390

v OS/400

v RS/6000

v S/390

v VisualAge

v VTAM

v WebSphere

Lotus, Lotus Notes and Domino are trademarks or registered trademarks of LotusDevelopment Corporation in the United States, or other countries, or both.

Tivoli Enterprise Console and Tivoli Module Designer are trademarks of TivoliSystems Inc. in the United States, or other countries, or both.

Encina and DCE Encina Lightweight Client are trademarks of Transarc Corporationin the United States, or other countries, or both.

Java and all Java-based trademarks and logos are trademarks or registeredtrademarks of Sun Microsystems, Inc. in the United States and other countries.

ActiveX, Microsoft, SourceSafe, Visual C++, Visual SourceSafe, Windows, WindowsNT, Win32, Win32s and the Windows logo are trademarks or registered trademarksof Microsoft Corporation in the United States, or other countries, or both.

UNIX is a registered trademark in the United States and other countries licensedexclusively through X/Open Company Limited.

Intel and Pentium are trademarks of Intel Corporation in the United States, or othercountries, or both.

Other company, product, and service names, which may be denoted by a doubleasterisk(**), may be trademarks or service marks of others.

© Copyright IBM Corp. 1998, 2002 291

292 IMS Connector for Java User’s Guide and Reference

Readers’ Comments — We’d Like to Hear from You

IMS ConnectIMS Connector for JavaUser’s Guide and ReferenceVersion 1 Release 2 Modification 2

Overall, how satisfied are you with the information in this book?

Very Satisfied Satisfied Neutral Dissatisfied Very DissatisfiedOverall satisfaction h h h h h

How satisfied are you that the information in this book is:

Very Satisfied Satisfied Neutral Dissatisfied Very DissatisfiedAccurate h h h h h

Complete h h h h h

Easy to find h h h h h

Easy to understand h h h h h

Well organized h h h h h

Applicable to your tasks h h h h h

Please tell us how we can improve this book:

Thank you for your responses. May we contact you? h Yes h No

When you send comments to IBM, you grant IBM a nonexclusive right to use or distribute your comments in anyway it believes appropriate without incurring any obligation to you.

Name Address

Company or Organization

Phone No.

Readers’ Comments — We’d Like to Hear from You����

Cut or FoldAlong Line

Cut or FoldAlong Line

Fold and Tape Please do not staple Fold and Tape

Fold and Tape Please do not staple Fold and Tape

NO POSTAGENECESSARYIF MAILED IN THEUNITED STATES

BUSINESS REPLY MAILFIRST-CLASS MAIL PERMIT NO. 40 ARMONK, NEW YORK

POSTAGE WILL BE PAID BY ADDRESSEE

IBM CorporationDepartment HHX/H1555 Bailey AvenueSAN JOSE CAU. S. A.95141-1003

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

__

_

����

Printed in the United States of Americaon recycled paper containing 10%recovered post-consumer fiber.