 |
Task 2: Create a bean that communicates with IMS
In this section, you will create a bean that communicates with IMS using J2C. You will define whether the bean is a managed or non-managed resource, along with defining the TCP/IP address, port, and IMS datastore name.
Using the J2C Java Bean wizard
-
Start the J2C Java Bean wizard by clicking File > New > Other to open the Select a Wizard dialog, as shown in Figure 10:
Figure 10. Starting the J2C Java Bean wizard
-
Enter
j2c, select J2C Java Bean, as shown in Figure 11, and click Next:
Figure 11. Selecting the J2C Java Bean wizard
-
Select the appropriate resource adapter for the J2C Java Bean. Expand 1.5, expand
IMS TM Resource Adapter (IBM: 10.1.1), and select imsico1011, as shown in Figure 12:
Figure 12. Selecting IMS TM Resource Adapter Version 10.1.1
-
Click Next to continue.
Rational Developer for System z supports J2EE Connector Architecture Version 1.0 and Version 1.5. IMS TM Resource Adapter Version 10 is based on the newer JCA 1.5 standards, and is therefore located under the 1.5 section.
 |
Managed and non-managed connections
A managed connection runs inside a Web application server. With a managed connection, the application server provides transaction management and connection pool management, and it can send security information. In addition, managed connections allow connection information to be maintained by the system administrator. As connection information changes (the type of communications, the port, and so on), the system administrator can adjust the connection characteristics, and no Java objects need to be regenerated.
A non-managed connection is designed to run where connections management supplied by an application server is not available. The characteristics of the connection must be specified, and are hard-coded into the generated object. You can change the connection characteristics from your program, but you will need to generate your J2C code appropriately. Because non-managed connections are not always convenient to change, and they do not take advantage of the connection pooling, transaction management, and security management that are provided by an application server, it is easy to see why managed connections are recommended.
The example in this tutorial uses a managed connection to IMS.
|
|
After you have selected the resource adapter, you must provide the connection properties information. These properties will be stored in a connection factory.
This application will interact with the IMS TM Resource Adapter through an object called the connection factory. IMS connection factories are used to create pre-configured connections to the IMS transaction man
a
ger (IMS TM).
When an application uses the IMS TM Resource Adapter, it interacts with IMS using connections between the IMS TM Resource Adapter and IMS Connect that are created by the IMS TM Resource Adapter. These connections can be managed or non-managed.
-
Select Managed Connection from the Connection Properties page and click New, as shown in Figure 13.
Figure 13. New J2C Java Bean dialog
-
Make sure that WebSphere Application Server v6.1 is selected and click Next, as shown in Figure 14:
Figure 14. Selecting the server on which to deploy the IMS TM Resource Adapter
-
The New J2C Connection Factory dialog displays. Enter a new JNDI Name (for example,
PhoneBookJNDIName).
-
Make sure that TCP/IP is selected (the default) and enter the required connection information (indicated by the asterisk [*]), as shown in Figure 15:
-
Host name:
ZSERVEROS.DFW.IBM.COM
-
Port:
9999
-
Data store name:
IMSC
 |
What is JNDI?
The Java™ Naming and Directory Interface (JNDI) is an API for directory service that allows clients to discover and look up data and objects via a name. In this tutorial you will assign a unique JNDI name to your managed connection. Our J2C bean will then use this JNDI name to look up the connection on the WebSphere Application Server.
|
|
Figure 15. Specifying connection information
-
Click Finish.
-
On the Connection Properties screen, click Next to continue.
-
On the J2C Java Bean Output Properties page, enter
J2CPhoneBook as the Project Name and click New to define the project properties, as shown in Figure 16:
Figure 16. Specifying J2C Java bean output properties
-
On the New Source Project Creation page, select Web project and click Next to continue, as shown in Figure 17:
Figure 17. Selecting Web project as the project type
 |
Why Web project?
The J2C wizard gives you a choice between creating a Java, Web, or EJB project. Choose Web project because you will be creating a Web interface for your J2C bean in the form of a simple JSP component and as a Web Service (see optional Task 4).
Web projects hold all of the Web resources that you create and use to develop your Web applications.
|
|
-
On the New Dynamic Web Project page shown in Figure 18:
-
In Project contents, leave Use default checked.
-
For the Target Runtime, select WebSphere Application Server v6.1 as the server.
-
Leave the Configurations setting as <custom>.
-
Select the Add Project to an EAR check box. Allow the wizard to add "EAR" to your EAR project name. Web projects and EAR projects must have different names.
-
Click Finish to create the Dynamic Web Project.
Figure 18. Specifying the target runtime and EAR membership for the Web project
Rational Developer for System z will now complete the creation of the J2EE components that support the J2C bean. Notice that both a dynamic Web project and an EJB project have been added to your work space.
Also, now that the supporting projects are created, the J2C Java Bean wizard returns to define the J2C bean Output Properties.
-
On the J2C Java Bean Output Properties page, leave the project name as J2CPhoneBook
. Enter the following required fields (respect the upper/lower case) as shown in Figure 19:
-
Package Name:
sample.ims
-
Interface Name:
PhoneBook
Notice that PhoneBookImpl in the Implementation Name field will be created for you once the Interface Name is supplied.
Figure 19. Specifying the package name and interface name
-
Click Next to continue.
-
From the Java Methods page, click the Add button to add a Java method to the sample.ims package defined in the previous page.
-
From the Add Java Methods page, enter runPhoneBook as the Java Method Name:
Figure 20. Adding a Java method
-
Click Next to Continue. This Java method will be added to the sample.ims package that was defined previously.
What’s Next
You have just started creating a Java method that will provide translation between COBOL data that IMS can understand and Java data types suitable for Java EE applications. Next, you will import a COBOL copybook for the IVTNO transaction. The wizard will parse the copybook and identify input and output fields. It will then generate translation code that will provide the mapping between COBOL and Java. As elsewhere in this tutorial, all the work is done by the Rational Developer for System z tooling, and no manual coding is required.
Now you will create the input and output data mappings between COBOL and Java. In this step you will import the data definitions from the Ex01.cbl (COBOL) copybook.
-
Click New next to the Input type to create the input mappings for the
runPhoneBook Java method as shown in Figure 21:
Figure 21. Creating a new input type
-
From the Data Import page, accept the default COBOL to Java mapping.
-
Click the Browse button and find the file C:\IMS PhoneBook\IMSPHBK.cpy as shown in Figure 22. Click Open to accept it:
Figure 22. Selecting the COBOL to Java mapping and the COBOL file
-
Click Next to continue.
-
The Importer page opens, allowing you to define the appropriate COBOL Import Parameter settings. Default settings are for the Win32 platform.
-
From the Platform list, select z/OS. The code page and other parameter settings will correctly change for the z/OS platform.
-
You can press the Advanced>> button to observe the other parameter settings for COBOL. However, do not change any of these advanced settings for this tutorial.
-
Click Query to select the appropriate input data from the IMSPHBK.cpy COBOL file as shown in Figure 23:
Figure 23. Specifying the COBOL import parameter settings
The COBOL program IMSPHBK.cpy contains the following Data structures in the Linkage Section: INPUT-MSG and OUTPUT-MSG. Notice that Rational Developer for System z inspected the IMSPHBK.cpy COBOL program and provided the data areas to map to the input record.
-
Select the INPUT-MSG data structure to map this data area to the input record, as shown in Figure 24, and then click Next to continue:
Figure 24. Selecting the input data structure
-
The Import page displays. Notice that you can change the generation style and data bindings. Accept the default generation style and data bindings.
-
Click Finish to generate the INPUTMSG Java class for the input mapping:
Figure 25. Specifying the data binding information for input messages
The Add Java Method page redisplays. Notice that the Input type has been defined with the INPUTMSG Java class.
-
Click New to define the output type, as shown in Figure 26:
Figure 26. Creating an output type
You must now create the Output type, repeating similar actions that you already performed for the Input type.
-
From the Data Import page, accept the default COBOL to Java mapping.
-
Click Browse and select the C:\IMS PhoneBook\IMSPHBK.cpy file again, as shown in Figure 27.
-
Click Open to accept it.
Figure 27. Selecting the COBOL to Java mapping and the COBOL file
-
Click Next to continue.
-
The Importer page opens, in which you define the appropriate COBOL Import Parameter settings, as shown in Figure 28. Default settings are for the Win32 platform.
-
Select z/OS as the platform. The code page and other parameter settings will correctly change for the z/OS platform.
-
Click Query to select the appropriate input data from the IMSPHBK.cpy COBOL file:
Figure 28. Specifying the COBOL import parameter settings
-
Select the OUTPUT-MSG as the data structure for the output type, as shown in Figure 29, and then click Next to continue:
Figure 29. Specifying the output data structure
-
Accept the default generation style and data bindings. Click Finish to generate the OUTPUTMSG Java class, as shown in Figure 30:
Figure 30. Specifying the data binding information for output messages
-
The Add Java Method page should now be defined with an Input type: INPUTMSG and
an Output type: OUTPUTMSG, as shown in Figure 31.
-
Click Next to continue to the Java method summary page:
Figure 31. Both input type and output type are defined
-
The Java method summary page should look like that shown in Figure 32:
Figure 32. Summary for the Java method
-
Click Finish to complete the Java method creation.
-
The New J2C Java Bean Wizard displays and summarizes the Java method that you just created for this J2C Java bean, as shown in Figure 33. You can insert additional Java methods in the same manner.
-
Click Next to continue.
Figure 33. New J2C Java Bean wizard Java methods summary page
-
The Deployment Information page displays, as shown in Figure 34. From here you could complete the J2C Java bean generation. However, Rational Developer for System z provides additional generation capabilities (Web page, Web service, or EJB) to consume this J2C Java bean.
-
Select the Create a Web Page, Web Service, or EJB from the J2C bean check box. More options will become available, as shown in Figure 34.
-
Select Simple
JSP.
-
Click Next to continue:
Figure 34. Specifying the J2EE resource type for deployment
The JavaServer Pages
(JSP) technology enables you to generate dynamic web content (such as HTML, DHTML, XHTML, and XML files) to include in a Web application. JSP files are one way that the product implements server-side dynamic page content. JSP files allow a Web server, such as WebSphere Application Server, to add content dynamically to your HTML pages before they are sent to a requesting browser.
EJB (Enterprise JavaBeans) and Web Services are other powerful architectures that can interface with your J2C bean. Web services are covered in the optional Task 4 of this tutorial.
-
From the Simple JSP Creation dialog, enter
myJSPs for the JSP folder name and click Finish to complete the simple JSP, as shown in Figure 35:
Figure 35. Creating a JSP folder
Notice that after clicking Finish, the Rational Developer for System z workspace opens up the PhoneBookImpl.java file. This is the implementation of the mapping between COBOL and Java. It contains the runPhoneBook() method, as well as other generated methods. It also contains the reference to the JNDI name PhoneBookJNDIName, which is used to look up the Managed Connection factory that we created. The connection information (along with the input data) is passed to the IMS TM Resource Adapter, which in turn calls IMS.
-
Expand Java Resources: src > sample.ims under the J2CPhoneBook project, as shown in Figure 36. Take a moment and look at the generated components in the Project Explorer. The myJSPs folder contains the newly generated JSPs that will be used to test our J2C bean implementation.
Figure 36. J2CPhoneBook project in the Project Explorer and the PhoneBookImp.java file
|  |