If you choose to write your Java™ application without using Rational® Application
Developer to generate a J2C Java bean and J2EE resource, you can still
use the J2C option of Rational Application Developer to create Java data
bindings for the input and output messages of your CCI application.
After you create the Java data binding for your IMS™ input and output
messages, you can use those data bindings in a CCI application. The following
steps explain how to use the data bindings in a simple CCI application:
- From the menu bar, select File > New > Project > Java
project and click Next.
- Create a Java project named SimpleCCIApp.
- Accept all other defaults and click Finish.
- Click Yes to confirm the perspective switch
when asked to switch to the Java Perspective.
- Click OK to save the resource.
- In the Project Explorer view, expand Other Projects and
right-click the Java project named SimpleCCIApp and then select New
> Package.
- In the New Java Package wizard, in the Name field enter sample.ims and
click Finish.
- In the Package view, right-click the project SimpleCCIApp and
select Properties > Java Build Path.
- In the Projects tab, click the Add button
and select the project containing the Java data bindings that you want your CCI
application to use.
- In the Projects tab, select the project containing the IMS resource adapter
that you want to use.
If you do not have a project containing
the IMS TM
Resource Adapter that you want to use, you can import the RAR file for the IMS TM
Resource Adapter into your workspace by completing the following steps:
- Exit the Java Build path wizard.
- In the Project Explorer view, right-click on your project and select Import
> File System.
- Click Next.
- In the File System wizard, click Browse next to
the From directory field and choose your directory. You can get the
RAR files for the IMS TM Resource Adapters from the following directories:
- <RAD_install_dir>/Resource Adapters/ims for the JCA 1.0 IMS resource adapter
- <RAD_install_dir>/Resouce Adapters/ims15 for the JCA 1.5 IMS resource adapter
- Click on the box next to your directory to select it.
- Click Finish.
- In the Libraries tab, add the following JAR files to the build
path for project SimpleCCIApp by clicking the Add External
JARs button:
These JAR files are used by the Java data bindings generated by Rational Application
Developer. The version of the jar files depends on the version
of the IMS TM
Resource Adapter that you selected. For example, if you selected the IMS TM Resource
Adapter 9.1.0.1.1 and you installed the Test Environment for WebSphere® Application
Server Version 5, the jar files are located in the following directory path:
- <RAD_install_dir>/runtimes/base_v5/lib
If you selected the IMS TM Resource Adapter 9.1.0.2 and you installed the
Test Environment for WebSphere Application Server Version 6, the jar
files are located in the following directory path:- <RAD_install_dir>/runtimes/base_v6/lib
- Click OK.
- In the Package view, expand Other Projects > SimpleCCIApp,
right-click the package sample.ims, and select New
> Class.
- In the Java Class wizard, complete the following steps:
- In the name field, enter CCIApp for the
name of the new class.
- In the Which method stubs would you like to create? option,
ensure that the public static void main(String{}args) and Inherited
abstract methods check boxes are selected and click Finish.
- Edit the CCIApp.java source. Copy the following sample code and
paste into the file:
/*
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package sample.ims;
import com.ibm.connector2.ims.ico.*;
import javax.resource.cci.*;
/**
*
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class CCIApp {
public static void main(String[] args) {
Connection conn = null;
try{
IMSManagedConnectionFactory mcf = new IMSManagedConnectionFactory();
mcf.setHostName("yourHostName");
mcf.setPortNumber(new Integer(0));
mcf.setDataStoreName("yourDataStoreName");
ConnectionFactory cf = (ConnectionFactory) mcf.createConnectionFactory();
IMSConnectionSpec cSpec = new IMSConnectionSpec();
conn = cf.getConnection(cSpec);
Interaction interAction = conn.createInteraction();
IMSInteractionSpec iSpec = new IMSInteractionSpec();
iSpec.setInteractionVerb(1); // SEND_RECEIVE
iSpec.setImsRequestType(1); // TRANSACTION
iSpec.setCommitMode(1); // SEND_THEN_COMMIT
sample.ims.INPUTMSG input = new INPUTMSG();
input.setIn__ll((short) input.getSize());
input.setIn__zz((short) 0);
input.setIn__trcd("IVTNO");
input.setIn__cmd("DISPLAY");
input.setIn__name1("LAST1");
sample.ims.OUTPUTMSG output = new sample.ims.OUTPUTMSG();
interAction.execute(iSpec, input, output);
System.out.println(
"Output message is... " +
"\nMSG: " + output.getOut__msg() +
"\nNAME1: " + output.getOut__name1() +
"\nNAME2: " + output.getOut__name2() +
"\nEXTN: " + output.getOut__extn() +
"\nZIP: " + output.getOut__zip()
);
}
catch(Exception e)
{
System.out.println("Caught exception is: " + e.getMessage());
}
}
}
The CCIApp.java is a simple two-tier, non-managed Java application
program. It uses the Java data bindings, sample.ims.INPUTMSG
and sample.ims.OUTPUTMSG, that were created by the CICS/IMS Java Data
Binding wizard in Rational Application Developer. Edit CCIApp.java
and modify the values used by the setHostName(), setPortNumber(), and setDataStoreName()
statements for your environment.
- Click File > Save.
- To run your Java application, in the Project Explorer
view, expand Other Projects > SimpleCCIApp.
- Right-click CCIApp.java and select Run
> Java Application. The following information is displayed
in the Console view:
Output message is...
MSG: ENTRY WAS DISPLAYED
NAME1: LAST1
NAME2: FIRST1
EXTN: 8-111-1111
ZIP: D01/R01