天天看點

CICS事務網關-CTG原理及操作

1.1 什麼是CTG

1.1.1 概述

CICS系統是IBM大型機上的重要的交易處理系統,并且由于大型機的特殊性,導緻CICS的已有應用程式對分布式平台開放不夠,難以重用以往的應用程式。是以,CICS與分布式系統的互動,即外界如何通路CICS傳統應用,成為一個重要的課題。

    而CTG(CICS Transaction gateway,以下簡稱為CTG),CICS交易網關,是分布式平台連接配接到CICS的首選工具,它具有高性能,高安全性,高可擴充性等特性。

    CTG與CICS的連接配接屬于直接相連的方式,幾乎不用修改CICS的已有應用,即可被外界通路。Web Services 同樣可以實作與CICS的連接配接,但是相比于Web Services,CTG有以下優勢:

    (1)沒有複雜的标準,技術相對成熟。

    (2)利用已有的應用程式接口,很少需要對CICS程式進行修改。

本文中執行個體所使用的CICS Transaction Gateway軟體為V7.2 for Windows版本。

1.1.2 CTG結構圖

CICS事務網關-CTG原理及操作

 相關概念介紹:

1. Gateway Daemon (網關守護程式):網關守護程式用于監聽遠端客戶程式的請求,并且可以管理線程和網絡連接配接,以達到優化的目的。網關守護程式中的一個重要元件是協定處理器(Protocol Handler),用于處理遠端應用程式的請求,可以支援TCP/IP和SSL協定。

2. Client Daemon (客戶機守護程式):客戶機守護程式是開放平台CTG的重要組成部分,它提供一個本地接口,客戶應用程式就通過這個接口連接配接到CICS,支援C,C++,.Net,COBOL等多種語言的應用程式。

3. IPIC driver (IPIC 驅動器):IPIC驅動器是CTG中的一個獨立元件,作用類似于客戶機守護程式,專用于IPIC方式連接配接到CICS。CICS在3.2版本中引入了IPIC(IP Intercommunication)的概念,用于CICS region之間的互連,這種連接配接是基于TCP/IP協定的,具體的IPIC概念請參考其他相關章節。從CTG V7.1版本以後,加入了對IPIC的支援。

4. CTGCFG tool(CTG configuration tool,CTG配置工具):CTG産品自帶的圖形化配置工具,用于設定ctg.ini配置檔案中的屬性,包括網關守護程式和客戶機守護程式等的相關參數。配置用戶端守護程式界面,如下圖所示:

CICS事務網關-CTG原理及操作

其中重要的幾個參數描述如下:

(1) 伺服器名稱:一個8位長的字元串,定義一個獨立于協定的伺服器名稱,用戶端應用程式發到CICS的請求都要發到這個伺服器。

(2) 協定:指定CTG所支援的各種網絡協定,本章重點介紹TCP/IP協定。

(3) 主機名或IP位址:CICS所在的主機位址,可以指定主機名或IP位址。

(4) 端口:CICS端定義的TCPIPService所指定的端口,是用戶端請求發送到CICS的接入點。

配置用戶端守護程式界面,如下圖所示:

CICS事務網關-CTG原理及操作

選中“啟用協定處理程式”就能使圖示的網關守護程式生效。

其中重要的幾個參數描述如下:

(1)綁定位址:如果在此處指定某IP或主機名,就可以将協定處理程式綁定到上面指定的值;如果需要将協定處理程式綁定到任意位址,可以把此處留白不填。

(2)端口:安裝CTG的伺服器對外開放的CTG端口,預設為2006。

1.1.3 CTG程式設計接口

由于分布式系統架構的多樣性,CTG支援一下三種連接配接方式:

1.    External Call Interface (ECI) 外部通路接口

ECI是簡單的RPC式通路接口,用來調用(LINK) CICS中的應用程式,可以使用COMMAREA或channel作為資料接口,用于客戶應用程式和CICS之間的資料交換。

    CICS将此種類型的通路看成是一種分布式程式調用(DPL : distributed program link )。用戶端發來的請求由一個鏡像交易CPMI進行處理,然後進一步調用到目标應用程式。

CICS事務網關-CTG原理及操作

2.    External Presentation Interface (EPI) 外部表現接口

EPI被用來調用基于3270終端的交易。使用這種接口時,CICS上面會自動安裝一個虛拟的終端,此終端受CTG的控制,并且CICS将用戶端發來的請求運作在這個虛拟終端上。這種接口隻支援SNA協定。

CICS事務網關-CTG原理及操作

 3.    External Security Interface (ESI) 外部安全接口

ESI是用來驗證并且修改CICS外部安全管理器(例如RACF)所儲存的安全資訊,并且由于CICS支援方面的原因,目前隻能通過SNA協定進行連接配接。

CICS事務網關-CTG原理及操作

1.1.4 CTG支援的網絡協定

TCP/IP:配置最簡單的方式。

SNA:必須和Communication Server搭配使用。

IPIC:CICS在3.2版本中引入了IPIC(IP Intercommunication)的概念,用于CICS region之間的互連,這種連接配接是基于TCP/IP協定的,具體的IPIC概念請參考其他相關章節。從CTG V7.1版本以後,加入了對IPIC的支援。

Namedpipe:命名管道,隻支援Windows版本的CTG。

EXCI:隻支援Z/OS版本的CTG。

1.1.5 CTG的一些注意事項

1.CTG不支援從CICS端主動發出的通路請求。這裡有個問題比較容易引起誤解,就是CTG發送請求到CICS,CICS的傳回資訊可以正常傳回給CTG,這種不是CICS主動發起的請求。

2.CTG不會做資料的轉換,這個工作需要在應用程式或CICS中處理。

1.2 兩種模式

    CTG的有兩種運作模式,這兩種模式是根據CTG以及客戶應用的拓撲結構來區分的。具體是哪種模式取決于客戶應用程式的部署位置,分别為本地模式和遠端模式。

1.本地模式(Local Mode,兩層結構)

CICS事務網關-CTG原理及操作

在本地模式下,客戶應用程式與安裝CTG的server為同一台機器。在客戶應用程式對CICS發送請求的時候,不需要經過網關守護程式,而是直接發送到CICS端,是以,整個體系架構可以看作兩層的結構。這種模式下,根本無需啟動網關守護程式,對CICS的請求直接發送到用戶端守護程式。

在客戶應用程式中的ECI請求中仍需要指定URL參數為local,即ConnectionURL = "local://" 和PortNumber = 0。

2.    遠端模式(Remote Mode,三層結構)

CICS事務網關-CTG原理及操作

在遠端模式下,客戶應用程式與安裝CTG的server為不同的機器,甚至不同的系統平台。在這種模式下,必須要配置并且啟動網關守護程式,網關守護程式介于客戶應用程式和CICS之間,整體構成三層的結構。

在客戶應用程式的ECI請求中需要指定URL參數為CTG所在機器的IP位址,即ConnectionURL = "XXX.XXX.XXX.XXX" 和PortNumber = XXX。

從另外一個角度對兩種模式的诠釋,見下圖:

CICS事務網關-CTG原理及操作

圖像 1.3 CTG連接配接到CICS執行個體

1.配置CICS region

        1. Set the SIT parameter TCPIP=YES.

        2. Install the following:

             –    CICS-supplied transient data queue CIEO, in group DFHDCTG

             –    Transaction CIEP in group DFHIPECI

             –    Program DFHIEP in group DFHIPECI

       3. Add a TCP/IP listener to CICS. Use the following CEDA command to define a TCPIPSERVICE in a group:

            –    CEDA DEF TCPIPSERVICE(service-name) GROUP(group-name)

       4. Use the following command to install the TCPIPSERVICE definition:

            –    CEDA INS TCPIPSERVICE(service-name) GROUP(group-name)

Attribute Description
POrtnumber The port on which the TCP/IP service listens.
PRotocol The protocol of the service is ECI.
TRansaction The transaction that CICS runs to handle incoming ECI requests. Set it to CIEP.
Backlog The number of TCP/IP requests that are queued before TCP/IP starts to reject incoming requests.
Ipaddress The IP address (in dotted decimal form) on which the TCPIPSERVICE listens. For configurations with more than one IP stack, specify ANY to make the TCPIPSERVICE listen on all addresses.
SOcketclose Whether CICS should wait before closing the socket after issuing a receive for incoming data on that socket. NO is recommended for ECI connections, to ensure that the connection from the Client daemon always remains open.
ATtachsec Specifies the level of attach-time security required for TCP/IP connections.

2.配置CTG

CICS事務網關-CTG原理及操作

3.測試連接配接

1.4 應用程式開發

CTG提供多種程式設計接口,包括:

(1) J2EE Connector Architecture(JCA) JAVA API,即J2EE連接配接器架構JAVA應用程式接口,這是推薦的程式設計接口。

(2)基礎的JAVA,C,COBOL,COM等程式設計接口。

1.    Java 應用程式開發

CICS事務網關-CTG原理及操作
CICS事務網關-CTG原理及操作

2.    JCA 應用程式開發

        JCA(J2EE Connector Architecture) defines a standard architecture for connecting the Java 2 Platform Enterprise Edition (J2EE) platform to heterogeneous Enterprise Information Systems (EIS). Examples of an EIS include transaction processing systems (such as the CICS TS) and Enterprise Resource Planning systems (such as SAP).

        A resource adapter is a middle-tier between a Java application and an EIS, which enables the Java application to connect to the EIS. A resource adapter plugs into application servers supporting the JCA.

        JNDI: The Java Naming and Directory Interface (JNDI) is part of the Java platform, providing applications based on Java technology with a unified interface to multiple naming and directory services.

        J2C Connection Factory: The connection factory provides connections to the Enterprise Information System (EIS). It operates the connection management of JCA.

        Common Client Interface (CCI) : The CCI defines a common API for interacting with resource adapters. It is independent of a specific EIS. A Java application interfaces with the resource adapter using this API.

        System contracts: A set of system-level contracts between an application server and an EIS. These extend the application server to provide the following features: (Connection management, Transaction management, Security management). These system contracts are transparent to the application developer. That is, they do not implement these services themselves.

        Resource adapter deployment and packaging: A resource adapter provider includes a set of Java interfaces/classes as part of the resource adapter implementation. These Java interfaces/classes are packaged together with a deployment descriptor to create a Resource Adapter Archive (represented by a file with an extension of rar). This Resource Adapter Archive is used to deploy the resource adapter into the application server.

CICS事務網關-CTG原理及操作

        1. Look up a ConnectionFactory for the ECI resource adapter.

        2. Create a Connection object using this ConnectionFactory. A Connection is a handle to the underlying network connection to the EIS. Specific connection properties, such as a user name and password, can be passed using an ECIConnectionSpec object.

        3. Create an Interaction from the Connection. Specific interaction properties such as the transaction identifier can be passed using an ECIInteractionSpec object. The call to the EIS is initiated by invoking the execute() method on the interaction, passing data as input and output records.

        4. After the required interactions have been processed, the interaction and connection should be closed.

1.5 應用舉例

1.5.1 簡單Java應用

public class CTGdemo {

         ... Java code ...

         // Program name

         String strProgram = "EC01";

         // Port number

         int iPort = 2006;

         eciRequestObject =

         new ECIRequest(ECIRequest.ECI_SYNC,      //ECI call type

                        strChosenServer,          //CICS server

                        null,                     //CICS userid

                        null,                     //CICS password

                        strProgram,               //CICS program to be run

                        null,                     //CICS transid to be run

                        abytCommarea,             //Byte array containing the

                                                  // COMMAREA

                        iCommareaSize,            //COMMAREA length

                        ECIRequest.ECI_NO_EXTEND, //ECI extend mode

                        0);                       //ECI LUW token

... Java code ...

}

          ... COBOL code ...

     * Initialize commarea

          MOVE SPACES TO DFHCOMMAREA.

     * Invoke api to get system time

          EXEC CICS

              ASKTIME ABSTIME(WS-RAWTIME)

          END-EXEC.

     * Format

          EXEC CICS

              FORMATTIME ABSTIME(WS-RAWTIME)

                         DDMMYY(LK-DATE-OUT)

                         DATESEP('/')

                         TIME(LK-TIME-OUT)

                         TIMESEP(':')

          END-EXEC.

          ... COBOL code ...

     *end of program

1.5.2 JCA應用

        Lab3 implements a simple internet banking.

        Users can query/save/withdraw their money from the web application.

CICS事務網關-CTG原理及操作

 1. Web client

    (1)Operation Page s

          Operation Types: Query,Save,Withdraw

    (2)Return Page

        Result: Name, Gender, Balance

2. DATA FORMAT -- COMMAREA

    (1)SNNNNNNNNNNXXXXXXXXXX

    (2)S= 0,1,2(0-Query, 1-Save, 2-Withdraw)

    (3) NNNNNNNNNN --- UserName

         XXXXXXXXXX   ---  Money

struct CTGINPUT{            

    char signal;            

    char username??(10??);  

    char money??(10??);     

    char success;           

    char name??(12??);      

    char gender??(12??);    

    char balance??(12??);   

};

CICS事務網關-CTG原理及操作
CICS事務網關-CTG原理及操作

3. CICS Program – VSAM1

    (1)three operations

          (Query,Save,Withdraw)

    (2) Operate the VSAM files

4. CICS DATA – VSAM files

    (1)VSAM file1--USERINFO

     (Username:10), (Account:6)

     (Name:12), (Gender:6)

    (2)VSAM file2--ACCOUNT

     (Account:6), (Balance:10)

CICS事務網關-CTG原理及操作

出處:https://www.ibm.com/developerworks/mydeveloperworks/blogs/cicschina/entry/cics_transaction_gateway69?lang=zh