Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Using Web Application Models to Build Struts-Based Web Applications from CICS Programs -- Part 1: Generating a Service Proxy and Struts Middle Tier

Kevin Griffith (griffith.k@fr.ibm.com), Certified IT Specialist , IBM Paris Lab
Photo of Kevin Griffith
Kevin Griffith is an IBM Certified IT Specialist at the IBM Paris Software Lab. He specializes in IBM rapid application development tools such as VisualAge Generator Templates and Web Application Models, and helps customers worldwide improve their application development productivity. He is a graduate of the U.S. Military Academy at West Point, has a masters degree in civil engineering from Massachusetts Institute of Technology, and is a registered, but non-practicing Professional Engineer just for fun. You can reach Kevin at griffith.k@fr.ibm.com .

Summary:  This two-part article describes how to use IBM VisualAge Pacbase Web Application Models along with WebSphere Studio Application Developer Integration Edition or WebSphere Studio Enterprise Developer to develop Struts-based web applications that access existing COBOL programs running on CICS.

Date:  13 Jul 2003
Level:  Introductory

Activity:  1348 views
Comments:  

© Copyright International Business Machines Corporation 2003. All rights reserved.

Introduction

Many companies today need to bring legacy enterprise applications to the Web. Given their limited resources, rewriting legacy applications to run on the Web is out of the question. Instead, they need to leverage their deep investment in business transactions running in tried-and-true mainframe operating environments. Rather than rewrite, companies must reuse existing transactions by exposing them as Web applications while maintaining their high performance, scalability, and reliability.

Web Application Models, a component of IBM ® VisualAge® Pacbase and a plug-in to IBM WebSphere® Studio, is a tool to accelerate this process. Web Application Models can consume enterprise services built from existing CICS® or IMSTM transactions to generate the JavaTM 2 Enterprise Edition (J2EE) middle-tier components that connect to COBOL programs running in a mainframe environment through standard J2EE Connector Architecture (JCA) and the Web Services Invocation Framework (WSIF).

This two-part article describes how to use Web Application Models along with WebSphere Studio Application Developer Integration Edition or WebSphere Studio Enterprise Developer to develop Struts-based Web applications that access existing COBOL programs running on CICS. Part 1 covers:

  • Creating an enterprise service proxy for a CICS ECI program
  • Generating and testing the service proxy
  • Using the proxy with Web Application Models to generate the remaining middle-tier components
  • Testing the web application by accessing the CICS program through a JCA resource adapter

Part 2 covers customization of the Web user interface using customized Web Application Model XSL stylesheets.


Create an enterprise service proxy for a CICS ECI COBOL program

For a complete description of creating an Enterprise Service, see the online help under Enterprise Developer Information => Building Enterprise Services. There is also a helpful "Cheat Sheet" entitled Create an enterprise service for a CICS program (CICS ECI). The next section shows how to create a service from a CICS program called TRADERBL.

Generate Web Services Description Language

Import COBOL Copy Book.

  1. Open Business Integration perspective.
  2. Create a new service project called MyServiceProj.
  3. Right-click on MyServiceProj and select Import => File system.
  4. Find the directory and the COBOL program, make sure MyServiceProj is the destination folder, and then click Finish.

Launch Service built from wizard and import resource adapter.

  1. Right-click on MyServiceProj and select New => Service built from.
  2. If the CICS ECI resource adapter is not present in the workspace, you must import it. To do so, click on Import Resource Adapter.
  3. Find the connector file named <studio root>resource adapters\cicseci.rar.
  4. In the same dialog, enter a new connector project name. See Figure 1 below.
  5. Click Finish.

Figure 1. Importing a CICS ECI resource adapter into a new connector project.
Import connector

Figure 2. Choose CICS ECI adapter as shown below, then click Next.
Select CICS ECI

Enter the connection properties for:

  • Gateway address
  • Port number
  • CICS server name
  • Username
  • Password
  • TPN Name
  • Transaction name
  • JNDI lookup name

Click Next to go to the Service Binding panel of the wizard and enter an Interface file name:


Figure 3. Service Binding panel
Service binding

Clicking Finish generates three WSDL files. The default editor for MyTradeCICSECIBinding.wsdl is automatically opened. The next step is to create a new operation for the service in the editor and define the input message for the COBOL program:

  1. Under Port type and Binding Operations, click on New to create a new operation.
  2. Enter getCompany as the operation name, then click Next.
  3. In the Operation Binding Properties, enter the Function Name TRADERBL, which is the name of the CICS program, and click Next again to define the input message.
    • Click on Import and select the COBOL program in MyServiceProj, then click Next.
    • In the COBOL Import Properties panel, select the z/OS® platform (or the platform on which CICS is running, and then click Next.
    • In the COBOL Importer panel, select COMMAREA-BUFFER as shown below, then click Finish.

    Figure 4. Select COMMAREA-BUFFER data structure.
    COMMAREA-BUFFER data structure
  4. In the Operation Binding panel, check Use input message for output, then click Finish.

Generate CICS ECI service proxy

  1. Right-click on MyServiceProj/org.tempuri/MyTradeCICSECIService.wsdl and select Enterprise Services => Generate Service Proxy.
  2. Accept defaults for the names and click Next.
  3. As shown in Figure 5, select Command Bean and the getCompany operation, and then click Finish.

Figure 5. Service proxy generation
Service proxy

The Service Project now contains the WSDL files, the generated Service proxy, and the command bean:


Figure 6. Service project files
Service project files

Unit-test service proxy

The generated proxy uses the Java API of the Web Services Invocation Framework (WSIF) to communicate with the CICS program. For the Web application, the proxy is seen as an enterprise service that it can execute. Before building the Web application that executes this service proxy, unit-test the enterprise service to make sure that the CICS program is correctly invoked and can send data back to the proxy.

Switch to the Java Perspective and open the class MyTradeProxy.java.

Go to the main() method and add code before and after the call to execute as shown below. I provide the user ID and the input parameters that the COBOL program expects: a request type = "Share_value" and a company name = "IBM". After the execute, we print out to the console some of the data returned by the COBOL program.

/** 
 * main method (for proxy unit testing) 
 * @generated 
 */ 
public static void main(String[] args) { 
	try { 
	    MyTradeProxy aProxy = new MyTradeProxy(); 
 
		// user code begin {set_inputs} 
		COMMAREABUFFER comm = new COMMAREABUFFER(); 
		comm.setUserid("F058971"); 
		comm.setRequest__type("Share_Value"); 
		comm.setCompany__name("IBM"); 
		aProxy.setCOMMAREABUFFER(comm); 
		// user code end 
 
		aProxy.execute(); 
 
		// user code begin {get_outputs} 
		COMMAREABUFFER result = aProxy.getCOMMAREABUFFER(); 
		System.out.println("1=" + result.getUnit__value__1__days()); 
		System.out.println("costbuy=" + result.getCommission__cost__buy()); 
		System.out.println("costsell=" + result.getCommission__cost__sell()); 
		// user code end 

Save the class, then from the menu select Run, Run as, Java Application. The output in the Console looks like this:

1=00163.00 
costbuy=010 
costsell=015 

Export service proxy as a JAR file

Select the project MyServiceProj, right click and then Export. Export as a JAR File and choose a destination directory on the file system.


Generate the Struts-based middle tier

To generate the JSPs, Java classes, and configuration files that make up the middle tier we use Web Application Models. The procedure consists of:

  1. launching the wizard and selecting a pattern
  2. selecting the data from the Service proxy that we want to use
  3. selecting some basic display properties
  4. selecting generation parameters and generation
  5. configure WebSphere Test Environment (WTE) and test

Launch and select pattern

To launch the wizard, go to File, New, Other, Web, Model-based Web Application. As in the image below you have to choose an application name. The application name is used to identify resources that will be generated from this model.

Select the technology identified as WSIF proxy. If you choose Relational Database technology, the wizard will ask you to connect to a relational database where you can select tables that will be used to create the Web pages. The VisualAge Pacbase technology consumes VisualAge Pacbase proxies that can access numerous back-end systems.


Figure 7. Enter application name and select a technology
Select technology

After clicking Next, the Select Patterns panel in Figure 8 is displayed. Browse the available patterns to get an idea of the different configurations. In this example, the COBOL program which we want to call displays a detail view of stock shares for a company.


Figure 8. Browse available patterns and their variations
Select pattern

Select service proxy

The second step in the wizard is to configure the data from the Service proxy that will be used with the pattern.

  1. As shown in Figure 9, browse for and select the proxy JAR that was exported.
  2. Then under Input parameters, select the proxy and the COMMAREABUFFER class.
  3. Move the two input parameters that the COBOL program requires to do a read action, Request_type and Company_name from the left list to the right.
  4. For this program the input and the output parameters are in the same class. Select output parameter fields and move them to the right list also. The fields you select here can be displayed to the end user.
  5. You also have to configure the Update and Delete panels, even though in this case the read-only COBOL program can not do anything with the input.
  6. Click Next to go to the Define Layouts panel of the wizard.

Figure 9. Selecting the proxy and configuring the input and output fields
Enter parameters

Configure display

In the Define Layouts panel shown below you can select a cascading stylesheet, select/de-select fields and actions, and modify field and action properties. You can also get a preview of the Web page by clicking on the button with the eye image. Static HTML is generated on the fly to give you an idea of how the Web page will look. Click Next to go to the last page of the wizard.


Figure 10. Define layout properties for the Web page
Define layout

Generate the application

The image below shows the generation page where you configure generation parameters:

  1. Change the name of the destination project to Company.
  2. You can also change the name of the Java packages into which you will generate.
  3. In the tree view you can change the names of the pages, views, and the data set. You can directly edit the default names by clicking on the name. As you change the names of these components, the file names in the list are also changed.
  4. When you are ready to generate, click on the Finish button.

Figure 11. Generate the Web application components.
Generate panel

Browse generated components

Generated Java classes

In this section we will give you a brief description of the generated components, starting with the common Java classes.

Figure 12. Generated Java classes
Java classes
  • common.dab
    • CommonLog defines Logging functions. It uses Jakarta LoggingFactory.
    • The DataException class is used to handle errors.
  • common.list
    • MultipleSelectionListForm - this class manages the delete checkbox on each line of a list.
    • SelectionListForm - this class manages the link on each line of a list to initiate navigation to a detail view.
    • SelectionList - stores information in HTTP session: list paging information and keys for each row to allow navigation (zoom) to a detail page.
    • SessionObject - used to store information about the detail page in the HTTP session
  • common.logic
    • AdditionalFieldChecks - this class performs some common field checks.
    • CloseSession - closes the session and forwards to the SessionExpired page.
    • CommonAction - a class where you can put logic to be executed on each call to an action; checks for a valid session.
    • CommonFormatter - lets you set date and time formats.
    • OpenSession - used to establish an HTTP session.
  • wam.data
    • DataSetDataAccessBean - this class calls the operations available for the data set and catches data exceptions.
    • DataSetExtractObject - getters and setters for the extract criteria.
    • DataSetSessionObject - contains key fields to be stored in HTTP session.
    • DataSetValueObject - stores fields in the data set with their appropriate type
  • wam.logic.sample
    • CompanyDetail*Action - the Delete, Read, and Update classes invoke the action in CICS program.
    • CompanyDetailForm - this class has attributes of the form plus a validate method.
    • CompanyRefreshAction - this class refreshes the JSPs with data.
  • Application resources
    • ApplicationResources.properties - contains common labels and messages;
    • ApplicationResources-sample.properties - contains model specific labels and messages.

Web content
Figure 13. Web content
Web Content
  • common - Here you find a JSP that handles paging buttons and a SessionExpired HTML page.
  • doc - Technical documentation in HTML form along with Web, sequence and class diagrams which are generated for each model.
  • models - Models are generated and stored in XMI files.
    • jca_sample - the result of the imported description of the proxy in the form of XMI files.
    • DataSet.dsxmi - This XMI file contains the data set information that was configured in the wizard. The data set can be re-used with another pattern.
    • sample.icxmi - This XMI file stores the model information - the pages, the content of the page views, their actions, the navigation links, and the data set that is presented. This file allows you to replay the wizard scenario.
  • sample - JSP resources specific to the sample model.
  • theme - cascading style sheets.
  • WEB-INF - deployment descriptor, configuration files and binaries. Explained in more detail below.
  • XML - files and stylesheets used in Extensible Stylesheet Language Transformations which will be discussed in Part 2 of this article.
  • index.html - The test page and technical documentation entry point.

WEB-INF
Figure 14. WEB-INF
WEB-INF sub-directory
  • classes sub-directory - the compiled Java binaries.
  • lib sub-directory - jars for Struts 1.1, Web Services Invocation Framework, and the proxy jar.
  • tag libraries have the .tld extension.
  • document type descriptions have the .dtd extension.
  • There are two Struts configuration files - struts-config.xml and struts-sample-config.xml where the following are declared.
    • actions and their forward paths
    • form beans
    • a global forward to the sessionExpired.html file.
    • this model's message resource file named ApplicationResources-sample.properties.
    • the struts validator plug-in along with the files that contain the validation rules.
  • The struts validator framework where common validation rules and validation specific to the sample model are found. You can add new rules to these files.
    • validator-rules-wam.xml - This file has common validation rules like decimal and timestamp checks. If you have other common checks that are shared across models this is a good place to put them.
    • validation-sample.xml - This is where the checks specific to the sample model are found. Included are max field length and format checks. If your rules are too complex to program in XML you can implement them with Java code in generated Form classes in the validate() method.
  • web.xml - the Web deployment descriptor.

Test the Web application

Configure server

  1. Open a Server perspective,
  2. create a new server project,
  3. create a new server and WebSphere version 5.0 server configuration. If you have an existing server project go ahead and put the new server and server configuration in the existing project.
  4. Ensure the resource adapter is declared in the server configuration by opening the server configuration file and going to the J2C tab of the default editor as is shown in the figure below.
  5. Click on the Add button and select the CICS ECI resource adapter that was imported into the workspace earlier.
  6. Close and save the server configuration file.

Figure 15. J2C options
J2C options

Run on server

  1. Select the Company Web Project, bring up the contextual menu and click on Run on Server.
  2. In the dialog box that displays, click on the Advanced button to select the new server that is now properly configured with the CICS ECI resource adapter.
  3. Clicking Finish will Publish the Web application to the application server, then start the application server and the application. The Web browser will be launched and the test page displayed as shown in the figure below.

Figure 16. Test page.
Test page

Browse documentation


Figure 17. Browse the generated technical documentation
Browse documentation

Execute the application

From the test page click on the link that launches the application and the detail page as shown below.


Figure 18. Launching the application opens a session and displays the input fields.
Open session
  1. Enter the input parameters Share_Value and IBM.
  2. Click the Read button to call the servlet and the CICS program.
  3. The CICS program sends back the information in the figure below.

Figure 19. Results returned from the CICS program
Read action

Conclusion

Part 1 of this article took you through the steps to create a Struts-based Web application that connects to an existing CICS program using a Java Connection Architecture resource adapter. First we used wizards in Application Developer to create an enterprise service. We imported the data description from a COBOL program to create the Web Services Description Language (WSDL). After configuring the connection parameters, we used the WSDL to generate a Java proxy and tested it to ensure we can send and receive data from the CICS program.

We packaged the proxy in a jar and used the jar as an input to the Web Application Models wizard. In the wizard we selected the fields to display and configured some basic presentation properties before generating the Struts Java classes and JSPs that communicate with the CICS proxy. We then configured the server and deployed, launched and tested the application.

The generated application conforms to the J2EE standard and can be deployed to an application server which can provide the reliability, scalability, and required performance. And although it has basic validation, error handling, accesses and displays data and takes care of other such mundane but necessary functions, it doesn't do a whole lot. What about more complex validation? What about business rules? What about integration with other Web pages? Security considerations? Where in the generated code do all of these specifics get implemented? The application doesn't look particularly attractive either.

Part of the answer to these questions is provided by generated code that is clear, well-documented, easily understandable and meant to be modified to handle the above functions. Web Application Models is not meant to produce out-of-the- box, ready-to-run applications, but rather, produce the basic building blocks which you can rearrange and use to construct real- world deployable applications.

Part 2 of this article addresses the task of providing a user interface that is ready for deployment. I will show you how Web Application Models uses Extensible Stylesheet Language Transformations (XSLT) at development time to incorporate common look and feel into the application.


Resources

About the author

Photo of Kevin Griffith

Kevin Griffith is an IBM Certified IT Specialist at the IBM Paris Software Lab. He specializes in IBM rapid application development tools such as VisualAge Generator Templates and Web Application Models, and helps customers worldwide improve their application development productivity. He is a graduate of the U.S. Military Academy at West Point, has a masters degree in civil engineering from Massachusetts Institute of Technology, and is a registered, but non-practicing Professional Engineer just for fun. You can reach Kevin at griffith.k@fr.ibm.com .

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

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=WebSphere
ArticleID=13247
ArticleTitle=Using Web Application Models to Build Struts-Based Web Applications from CICS Programs -- Part 1: Generating a Service Proxy and Struts Middle Tier
publish-date=07132003
author1-email=griffith.k@fr.ibm.com
author1-email-cc=

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.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

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).

Try IBM PureSystems. No charge.

Special offers