Skip to main content

Exposing a CICS program as a Web service using IBM Rational Application Developer

A step-by-step guide to using the J2C tooling in RAD

Dan McGinnes (mcginnes@uk.ibm.com), IT Specialist, IBM
Dan McGinnes is an IT specialist working in the Pan-EMEA WebSphere services group, with previous experience in the CICS TS and CICS TG development teams.

Summary:  IBM Rational Application Developer v6.0.0.1 provides new tooling to simplify the creation of J2EE applications that use the J2EE Connector Architecture to access applications running on legacy systems. This article will start with a simple CICS program, and show how basic wizards can be used to expose the program as a Web service running on IBM WebSphere Application Server. It will also cover some of the pitfalls encountered on the way. This will be useful to people wishing to use their legacy CICS applications in a Service-Oriented Architecture.

Date:  18 Oct 2005
Level:  Introductory
Activity:  703 views

Why use the IRAD J2C tooling?

The IBM® Rational® Application Developer (IRAD) tooling greatly simplifies the process of accessing a CICS® program as a Web service. This article will demonstrate how a CICS program can be exposed as a Web service without writing a single line of code, and how the use of a few simple wizards can greatly speed up development time when integrating your legacy programs in a Service-Oriented Architecture.


Prerequisites

This example uses the following levels of software:

  • IBM® Rational® Software Architect v6.0.0.1 (IRSA). IRAD v6.0.0.1 is also supported
  • IBM® WebSphere® Application Server v6 (test environment shipped with IRSA)
  • CICS Transaction Gateway v6
  • CICS Transaction Server v3.1

In addition, the following runtime combinations are supported:

Table 1. Supported runtime combinations
WebSphere Application ServerCICS Transaction Gateway resource adapterCICS Transaction GatewayCICS Transaction Server
v5.0.x distributed with Cumulative Fix 5.0.2.8 and Integration Edition RunTime Fixes for 5.0V5.1 (JCA 1.0)V5.1, V6 (remote mode only)V1.3, V2.2, V2.3, V3.1
V5.0.x z/OS with W502023 (PTF UK00329)V5.1 (JCA 1.0)V5.1, V6 (remote mode only)V1.3, V2.2, V2.3, V3.1
V5.1.x distributed with Integration Edition RunTime Fixes for 5.1V5.1 (JCA 1.0)V5.1, V6 (remote mode only)V1.3, V2.2, V2.3, V3.1
V5.1.x z/OS with: W510205 (PTF UK0028)V5.1 (JCA 1.0)V5.1, V6 (remote mode only)V1.3, V2.2, V2.3, V3.1
V6V5.1 (JCA 1.0), V6 (JCA 1.5)V5.1, V6 (remote mode only if using V5.1 Resource Adapter)V1.3, V2.2, V2.3, V3.1

This article assumes that the CICS Transaction Gateway has already been installed and configured to connect to the target CICS Transaction Server. For more information on this task refer to the CICS Transaction Gateway v6 documentation. You will also need to have a copy of the ec01.ccp sample that comes supplied with the CICS Transaction Gateway on your workstation. This is a very simple program that receives a commarea, populates it with the current date and time on the CICS server, and returns it.


Overview

This article will show you how to create a J2C Bean, and a Java™ Data Binding that will be used to call the CICS Transaction Gateway, which in turn will access the CICS Transaction Server. You will also expose the J2C Bean as a Web Service Endpoint, which will receive Simple Object Access Protocol (SOAP) requests. All the artifacts you create will run on WebSphere Application Server. Figure 1 illustrates all the pieces and how they fit together.


Figure 1. Overview of solution
Creating a Dynamic Web project

Create the projects

The first step is to create projects in to which you can put your Web application. You will create an enterprise archive (EAR) project, which you can deploy into WebSphere, and within that a Dynamic Web Project to hold the Web service and Java components that will be created.

  1. From the Java™ 2 Platform, Enterprise Edition (J2EE™) perspective, create a new EAR project called EC01EAR, with J2EE version 1.4 and Target server WebSphere Application Server v6.
  2. Create a new Dynamic Web Project (EC01Web) in EC01EAR, and fill in as shown in Figure 2.

Figure 2. Creating a Dynamic Web project
Creating a Dynamic Web project
  1. Click Finish, and do not switch to the Web perspective when asked.

Create Java Data Binding

You will use wizards to create a mapping from a COBOL structure to a Java object, and vice-versa. This is necessary because the COBOL executing on CICS is expecting a COBOL record structure, in EBCDIC, whereas our Web application will manipulate Java objects in ASCII.

Specifying the codepage conversion

If you do not currently have a DFHCNV entry set up in CICS for program EC01, then you should select Platform = z/OS. This means the code page conversion from ASCII to EBCDIC and vice versa will be done by the Java Data Binding generated.
You may already have a DFHCNV installed in CICS, used by existing applications, which will do the codepage conversion for this program. If this is the case then you may not want to break existing applications, so leave DFHCNV as it is, and select the platform as Win32.

  1. Under Dynamic Web Projects, right-click EC01Web and select New -> Other. In the select a Wizard dialog, under J2C select CICS/IMS Java Data Binding and click Next.
  2. On the Data Import screen, in the Choose mapping field select COBOL to Java. Next to COBOL file select the location of your ec01.ccp file. (C:\Program Files\IBM\IBM CICS Transaction Gateway\samples\server\ec01.ccp). Click Next.
  3. The Importer field is where you select the code page conversion that will be done. Select Platform: z/OS.
  4. Under Data Structures, click Query. When the list has been populated, select DFHCOMMAREA and click Next. See Figure 3 following for examples.

Figure 3. The Importer dialog
The Importer Dialog
  1. On the next page, leave generation style as Default. The Project name should be EC01Web. Enter a package name (for this example, use ec01test.data). You can leave the class name as DFHCOMMAREA.
  2. Click Finish. This should have created a DFHCOMMAREA.java file in the Web project. You will use this class later to pass and receive data from CICS.

Create J2C Java Bean

Now you will use the wizard to create a bean, which means you do not have to write any code yourself to use the CCI interface to the CICS Transaction Gateway to call the program on CICS. This wizard will use the Java Data Binding you created in the previous section.

  1. Under Dynamic Web Projects, right click EC01Web and select New -> Other. In the select a Wizard dialog under J2C, select J2C Bean and click Next.
  2. The Resource Adapter selection window is where you select the Resource Adapter you are going to use. Select the J2C 1.5 ECI Resource Adapter and click Next. See Figure 4 following for an example.

Figure 4. Selecting the resource adapter
Selecting the resource adapter
  1. On the Connection Properties page you will use a managed connection.
  2. Next to JNDI lookup name click New. This will take you through a wizard that will create a Connection Factory on your WebSphere Application Server v6 Test Environment.
  3. On the Server Selection page select WebSphere Application Server v6 and click Next.
  4. On the New J2C Connection Factory page, you enter the values for the Connection Factory that will be created in WebSphere. These values will depend on your installation. The Server name should match the server you created using the Configuration tool, and a Connection URL of local: means it will use the Gateway in local mode on the local machine. For more information on these parameters consult the CICS Transaction Gateway documentation. An example is shown in Figure 5 following.

Figure 5. New Connection Factory wizard
New Connection Factory wizard

Managed vs. non-managed connections

In this example you selected a managed connection. The wizard will now make you create a Connection Factory in the Application Server that will contain all the properties necessary to connect to CICS. In the created code the J2C bean will look up this Connection Factory, and so inherit the properties set on it. This also means that WebSphere will manage connection pooling, transactions, and security for you.

If you had selected non-managed, then you would have to enter all the properties to connect to CICS here, and they would appear in the generated code. You would also have to add code to manage connection pooling, transactions, and security, as these would not be managed by WebSphere.

Non-managed connections are useful if you wish to use the J2C Java Bean outside of an Application Server environment. If you are going to be running in an Application Server, then it is recommended that you use managed connections.

For more information on managed and non-managed connections, refer to the CICS TG Programming guide.

  1. When you have filled it in, click Finish. This step will take some time, as it will start the test server, and then create a new Connection Factory on it. When this has finished it should have filled in the JNDI lookup name on the Connection Properties window. Click Next.
  2. The J2C Bean Output Properties window lets us select names for the generated classes. The Project name should be EC01Web, the Package Name ec01test.bean, the Interface Name EC01J2CBean, and it should automatically fill in the Implementation Name as EC01J2CBeanImpl. Click Next.
  3. In the Java Methods page you can add a method for each Program you want to access in CICS. Click Add.
  4. The Method Name should be callEC01. Click Next.
  5. On the next page, select the inputs and outputs for the method. These should be the data type(s) you created earlier. Next to Input type, click Browse.
  6. In the window that appears next, select the DFHCOMMAREA class you created earlier. EC01 uses the same structure for input and output, so select the Use the input type for output checkbox. Click Finish.
  7. For Function name enter EC01. This is the name of the program that will be called on CICS. Commarea length should be 20, as should Reply length under the advanced properties. The Interaction verb should be SYNC_SEND_RECIEVE because you want a synchronous call. Click Finish.
  8. This should open up the implementation class that has been created (EC01J2CBeanImpl.java).

In the wizard you selected SYNC_SEND_RECIEVE for the Interaction verb. This has resulted in the following line being added to the code: ((com.ibm.connector2.cics.ECIInteractionSpec) is).setInteractionVerb(2); This is a bug in IRAD, as an Interaction verb of 2 is actually a SYNC_RECIEVE. This will result in an error at runtime unless you change this to 1. Change this in the code, and in the comments above the method. So the callEC01 method should look like this:


Listing 1. Edited callEC01 method

/**
 * @j2c.interactionSpec class="com.ibm.connector2.cics.ECIInteractionSpec"
 * @j2c.interactionSpec-property name="functionName" value="EC01"
 * @j2c.interactionSpec-property name="commareaLength" value="20"
 * @j2c.interactionSpec-property name="replyLength" value="20"
 * @j2c.interactionSpec-property name="interactionVerb" value="1"
 * @generated
 */
public ec01test.data.DFHCOMMAREA callEC01(ec01test.data.DFHCOMMAREA arg) throws 
                                                    javax.resource.ResourceException {
    ConnectionSpec cs = getConnectionSpec();
    InteractionSpec is = interactionSpec;
	if (is == null) {
		is = new com.ibm.connector2.cics.ECIInteractionSpec();
        ((com.ibm.connector2.cics.ECIInteractionSpec) is).setFunctionName("EC01");
        ((com.ibm.connector2.cics.ECIInteractionSpec) is).setCommareaLength(20);
        ((com.ibm.connector2.cics.ECIInteractionSpec) is).setReplyLength(20);
        ((com.ibm.connector2.cics.ECIInteractionSpec) is).setInteractionVerb(1);
}
...

This Java class can now be used to call the program on CICS by invoking the callEC01 method, and using the DFHCOMMAREA Java Data Binding you created.


Create a Web service to use the J2C bean

The previous step created a bean that contains the code to call the CICS program. Now you can use the wizards to expose this as an Enterprise JavaBean™ (EJB™), a JavaServer™ Page (JSP), or as a Web service. In this example you will expose it directly as a Web Service, but the other wizards can be used in a similar way to create an EJB or JSP.

  1. Right click the EC01J2CBeanImpl.java file in the project explorer (Under EC01Web/JavaResources/JavaSource/eco01test.bean), and select New -> Other.
  2. In the select a Wizard dialog, under J2C select Web Service, Web Page, or EJB from J2C bean, and click Next.
  3. J2C Bean Implementation should be filled in with /EC01Web/JavaSource/ec01test/bean/EC01J2CBeanImpl.java. Click Next.
  4. Under J2EE Resource type, click Web Service. Click Next.
  5. On the Web Service creation page the Web Project should be EC01Web, and the EAR project should be EC01EAR. Under the Advanced properties enter a Resource Reference of CICS1Ref, and the JNDI lookup name should be CICS1. (This should match the JNDI Name you entered when creating the Connection Factory, as shown in Figure 5). Click Finish and it will generate the Web service.

Testing the Web service

Now that your Web service has been created, you want to run it, and test it to make sure that it works from end to end. IRAD provides a number of features that enables us to do this. The first is the WebSphere Application Server v6 Test Environment. This is a version of WebSphere Application Server that comes as part of IRAD, and lets you install and run your Application (EAR file). The second is the Web Services Explorer. This feature is supplied with a WSDL file, and it uses this to create a Web Services client. The client enables you to fill in the parameters, send these in a SOAP message to the endpoint, and receive in return the response from the Web service.

  1. Ensure that the CICS Transaction Server and CICS Transaction Gateway are started.
  2. Right-click the EC01EAR, and select Run -> Run on Server. This will deploy the application on the test server.
  3. Under EC01Web, expand Web Content, and wsdl and right-click EC01J2CBeanImpl.wsdl and select Web Services -> Test with Web Services Explorer, as shown in Figure 6 following.

Figure 6. Select the WSDL document
Select the WSDL document
  1. This should bring up the Web Services explorer in a Web browser. In the Explorer, expand the tree in the navigator, and then click callEC01.
  2. The action page is where you fill in the parameters for a call. You do not need to fill any in for this request, so click Go to invoke your Web service, as shown in Figure 7.

Figure 7. Invoke the Web service using the Web Services explorer
Invoke the Web service using the Web Services explorer
  1. When the invoke completes, Figure 8 illustrates how you should be able to see the Date and Time returned from CICS in the status window.

Figure 8. The result from invoking the Web service
The result from invoking the Web service

Resources

Learn

Get products and technologies

Discuss

About the author

Dan McGinnes

Dan McGinnes is an IT specialist working in the Pan-EMEA WebSphere services group, with previous experience in the CICS TS and CICS TG development teams.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational, Architecture, WebSphere
ArticleID=96211
ArticleTitle=Exposing a CICS program as a Web service using IBM Rational Application Developer
publish-date=10182005
author1-email=mcginnes@uk.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers