Monday 3 January 2011

Mainframe Transaction Simulation with JAVA

This is a simple example for converting programs from mainframe to JAVA - UNIX machines.

The simple example below is a full prototype of realizing mainframe transaction logic
with JAVA and uNIX systems. The transaction table processing is omitted to make things simple but it is self explanatory to add it to the right place.

A mainframe program works in a CICS like environment. In order to simulate this I will use Tomcat application server and start a JAVA program from a JSP. JSP will simulate CICS screen where you enter the transaction id.

The JSP will call the simple utility lib ARSlib which has the function to invoke the
program that corresponds to this transaction. The program itself is pur into the same place in the same jar as the utility lib. In reality it can be in another jar,
presumably a transaction-program library or even lib structure.

The simple example below is done with NetBeans 6.9.1 and JDK1.6.
It works fine as you will notice from the outputs.






web.xml
-------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Transaction Call Simulation</display-name>

<welcome-file-list>
<welcome-file>transactionCall.jsp</welcome-file>
</welcome-file-list>

</web-app>



transactionCall.jsp
-------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="testPackage.*" %>

<%
ARSlibrary lib = new ARSlibrary();
lib.invokeProgram("testPackage.testClass");
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>



ARSlibrary.java
---------------

package testPackage;

public class ARSlibrary {
public ARSlibrary() {
System.out.println("ARSlibrary's constructor");
}

public void invokeProgram(String name) throws Exception {
Class<? extends ARSprogram> np = (Class<? extends ARSprogram>) Class.forName(name);
if (np == null) {
throw new Exception("Program " + name + " not in this library");
}
ARSprogram a = (ARSprogram) np.newInstance();
a.main();

}
}



ARSprogram.java
---------------
package testPackage;

public class ARSprogram {
public void main() {
System.out.println("ARSprogram's constructor");
}
}



testClass.java
--------------

package testPackage;

public class testClass extends ARSprogram {
public testClass(){
System.out.println("testClassS constructor");
}
public void main(){
System.out.println("Transaction testClass has worked!");
}
}