Creating a J2C Java bean

After you create IMS Java data bindings, you need to create a Java bean that communicates with IMS through the J2EE Connector Architecture.

This Java bean includes a method that submits a request to IMS to run the IMS transaction. This method uses the Java data bindings to build the input and output messages for the transaction. A J2C Java bean may include more than one method that runs an IMS transaction, as well as multiple data bindings for different input and output messages. The code that is generated for the J2C Java bean uses the CCI provided by the IMS resource adapter to communicate with IMS.

To create a J2C Java bean that runs an IMS transaction, complete the following steps:

  1. To start the J2C dynamic wizard, from the menu bar, select File > New > Other > J2C.
  2. Expand the J2C folder, select J2C Java bean, and click Next.
  3. In the Resource Adapters Selection page, select the version of the IMS resource adapter that you wish to use. You may select either the JCA 1.0 IMS resource adapter, IMS Connector for Java (IBM: 9.1.0.1.1) or the JCA 1.5 IMS resource adapter, IMS Connector for Java (IBM : 9.1.0.2).
  4. Click Next.
  5. In the Connection Properties page, select the Managed checkbox.
    Note: There are two options for the way in which connections are created between the IMS resource adapter, as used by your Java bean, and IMS Connect. This example is not a two-tiered application, so only a managed connection is applicable.
    • Managed connections are created by a construct of the J2EE Connector Architecture called a connection factory and are managed by the application server. Your Java bean accesses a connection factory using JNDI (Java Naming and Directory Interface). Managed connections are recommended. The IMS resource adapter and the application server's connection manager work together to efficiently manage connections by providing connection pooling, reuse, and persistence.
    • Non-managed connections are obtained directly through the IMS resource adapter, without collaboration with the application server. Non-managed connections are typically used by two-tiered applications, and are not pooled or reused. In addition, non-managed socket connections between the IMS resource adapter and IMS Connect are not persistent, incurring the additional overhead of opening and closing the socket for each use by an application.
  6. On the Connection Properties page, next to the JNDI lookup name field, click New. This defines a new server instance. To define a new server instance, the resource adapter you selected in Step 3, is deployed to the server instance. To create a new server instance in your workspace, complete the following steps:
    1. In the JNDI Lookup wizard, on the Server instance selection page, select New.
    2. In the Define a New Server page, select the type of server you wish to create; for example, WebSphere 6.0 Server. Then, click Next.
    3. In the WebSphere Server Settings page, accept the defaults.
    4. Click Finish. The resource adapter you selected in Step 3 is deployed to your server instance.
    5. On the Server instance selection page, click Next.
  7. Create and configure a J2C connection factory for the server instance you just created. The J2C Connection Factories wizard allows you to select a J2C connection factory from those that have been defined for the resource adapter you selected in Step 3. You can also provide the JNDI lookup name of a connection factory that does not yet exist and define it later. To create and configure a J2C connection factory for your server instance, complete the following steps:
    1. In the J2C Connection Factory page, enter a JNDI name for your new connection factory. For example, imsCFac.
    2. Configure your connection factory. For TCP/IP connections to IMS Connect, at minimum, provide values for the following fields:
      • In the Host name: field, enter the TCP/IP hostname of the IMS Connect that your application will use. For example: MYHOST.MYCOMPANY.COM
      • In the Port number: field, enter the port number. For example, 9999.
      • In the Data store name: field, enter the target IMS datastore. For example, IMSA.
    3. Click Finish. The server instance is started and initialized.
  8. After you have configured your server instance and your server has started, the JNDI name of the connection factory appears in the JNDI Lookup name field. Click Next.
  9. In the J2C Java Bean Output Properties page, complete the following steps:
    1. For the Java Project Name , click New.
    2. Select Java project as the project type, and click Next.
    3. In the Create a Java project page, type PhoneBookJ2CBean for the new Java project name, accept all other defaults, and then click Finish.
    4. Next to Java Package Name, click New.
    5. In the Java Package page, type sample.ims for the new Java package name and click Finish.
    6. For the Interface Name, specify PB.
    7. For the Binding Name, accept the default of PBImpl.
    8. Click Next.
  10. To create a method that runs the transaction, use the Java Methods wizard and complete the following steps:
    1. Click Add to add a Java method to your J2C Java bean.
    2. In the Add Java Method page, type runPB for the Java method name, the click Next.
    3. On the Java Method page, click Browse next to the Input type field.
    4. In the Select a data type window, prime the entry field with an asterisk (*) to view the available data types.
    5. In the Matching types field, select INPUTMSG and click OK to use the INPUTMSG data binding for the method, runPB.
    6. Next to the Output type field, click Browse.
    7. In the Select a data type window, prime the entry field with an asterisk (*) to view the available data types.
    8. In the Matching types field, select OUTPUTMSG and then click OK to use the OUTPUTMSG data binding for the method, runPB.
    9. Click Finish.
  11. The Java Methods wizard displays the new method, runPB (INPUTMSG : OUTPUTMSG) in the list of methods for the Java bean. Ensure that this method is selected.
  12. In the InteractionSpec properties for 'runPB', specify the IMSInteractionSpec values. For this example, accept all defaults, then click Finish.
You now have a J2C Java bean in project, PhoneBookJ2CBean, that you can deploy in one or more J2EE applications using different J2EE resources.
Related tasks
Creating IMS Java data bindings
Exposing InteractionSpec and ConnectionSpec properties for input as data
Exposing InteractionSpec output properties as data
Creating a web page, web service, or EJB from a J2C Java bean
Using IMS data bindings in a CCI application
Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.