Cics中Java调用的两种方式

原创 2013年12月05日 22:32:35

在Cics中 , Java调用分两种方式 , ECI and EPI .

External Call Interface(ECI)即是一种类似于元过程调用(RPC),CICS Client端通过ECI调用就可以把CICS Server端的交易程序叫起来运行,运行结束后再返回CICS Client
External Presentation Interface(EPI),CICS Client端模仿了一个CICS Server的终端,CICS Client程序与CICS Server程序间交换的是3270的数据流 .
这些都自己去理解, 网上关于掉用的文档都很坑爹,没代码说个飞机啊!!!
 
首先我们需要知道在java中 , cics需要支持的jar文件, ctgclient.jar ,还要知道基本的调用类.
  JavaGateway javaGateway = null;
  EPIRequest epiRequest = null;
  ECIRequest eciRequest=null;
  //字面上意思很容易理解啊
  //ECI调用: 
	/**
	 * ECI request
	 * @param para
	 * @return
	 * @throws Exception
	 */
	public static DataBean eciRequest(CicsParameter para,DataBean databean) throws Exception{
		JavaGateway javaGateway=null;
		ECIRequest eciRequest=null;
		int iReturnCode;
		CICSResult result = new CICSResult();
		//Should delete first three bytes
		//byte[] commArea=new byte[8192];	
		//INIT buffer
		for (int i=0;i<commArea.length;i++)
			commArea[i]=0;
		
		//PUT VALUES
		for (int i=0;i<databean.getSendMsg().length-3;i++)
		{
			commArea[i]=databean.getSendMsg()[3+i];
		}
		try {
			javaGateway = new JavaGateway(para.getjGateURL(), para.getjGatePort());
			eciRequest = new ECIRequest(ECIRequest.ECI_SYNC_TPN, 
					para.getServerName(), //CICS server name
					para.getUserName(),para.getPassword(), //userid & password
					para.getProgramName(), //program name
					para.getServsId(), //transaction ID
					commArea, MAXCBODBUFFLEN, //commarea data & length
		        	ECIRequest.ECI_NO_EXTEND, //extended mode
		    		ECIRequest.ECI_LUW_NEW); //LUW token
			
			eciRequest.setECITimeout((short)para.getTimeOut());
			javaGateway.flow(eciRequest);
			iReturnCode = eciRequest.getRc(); 
			switch (iReturnCode) {
	            case ECIRequest.ECI_NO_ERROR:
	            	 log.debug("ECI call  successfully..."); 	 
	            	 int iLen=(eciRequest.Commarea[8]&0xFF)*256+(eciRequest.Commarea[9]&0xFF);
	            	 if (iLen<=MAXCBODBUFFLEN)
	            		 result.setMsg(new ByteArray(eciRequest.Commarea, 0, iLen+8));
	            	 break;
	            case ECIRequest.ECI_ERR_SECURITY_ERROR:
	            	 log.error("ECI call  fail because of security reason.");
	                 break;
	            
	            case ECIRequest.ECI_ERR_REQUEST_TIMEOUT:
	            	 log.error("ECI call  fail because of Request timeout.");
	                 break;  
	            
	            case ECIRequest.ECI_ERR_RESPONSE_TIMEOUT:
	            	 log.error("ECI call  fail because of Response timeout.");
	                 break; 
	                 
	            case ECIRequest.ECI_ERR_TRANSACTION_ABEND:
	                 //Transaction 
	            	 log.error("ECI CALL fail because of the transaction abended: " + eciRequest.Abend_Code);    
	            	 break;
	
	            default:
	            	 log.error("ECI call  fail, request return code: " + eciRequest.getRcString());
	             }
	           // close
		       javaGateway.close();
		} catch (Exception ex) {
			log.error(ex);
			throw ex ;
		}finally  { 
	    	try 
	    	{ 
	    		if (javaGateway != null) 
	    		{ 
	    			javaGateway.close(); 
	    			log.debug("Successfully closed JavaGateway"); 
	    		} 
	    	} catch (Exception eClose) 
	    	{ 
	    		log.error("Exception during close : " + eClose); 
	    	} 
	    	
	    } 
		if (result.getMsg() == null){
			log.info(" ReceiveMessage rm is null.");
			return databean;
		}else
			databean.setReceiveMsg(result.getMsg().getValue());
		return databean ;
	}
//EPI调用

 /**   * EPI request   * @param para   * @return   * @throws Exception   */  public static DataBean epiRequest(CicsParameter para,DataBean databean) throws Exception{   JavaGateway javaGateway = null;   EPIRequest epiRequest = null;   int iReturnCode =0;   CICSResult result = new CICSResult();   try {    javaGateway = new JavaGateway();    javaGateway.setURL(para.getjGateURL());    javaGateway.setPort(para.getjGatePort());    javaGateway.open();    epiRequest = EPIRequest.addTerminal(para.getServerName(), null, "vt100");    iReturnCode = javaGateway.flow(epiRequest);    if (iReturnCode != EPIRequest.EPI_NORMAL)     EpiPublic.logEpiErrorAndException("main - addTerminal - javaGateway.flow", iReturnCode);        epiRequest.startTran(para.getServsId(), databean.getSendMsg(), databean.getSendMsg().length);    iReturnCode = javaGateway.flow(epiRequest);    if (iReturnCode != EPIRequest.EPI_NORMAL)     EpiPublic.logEpiErrorAndException("main - startTran - javaGateway.flow", iReturnCode);    // wait until service end    int num = 1;    do {     epiRequest.getEvent(EPIRequest.EPI_WAIT,ByteArray.BUFFER_SIZE_MAX);     iReturnCode = javaGateway.flow(epiRequest);     ///////////////////////////////////////////////////////////////////////////////     ////exception test     ///////////////////////////////////////////////////////////////////////////////     if(iReturnCode == EPIRequest.EPI_ERR_MORE_DATA){      log.debug("epiRequest.event=EPI_ERR_MORE_DATA");      log.debug("iReturnCode=" + iReturnCode+",num="+num);      if(num>=5){       EpiPublic.logEpiErrorAndException("main - getEvent - javaGateway.flow", iReturnCode);      }      num++;      continue;     }     ///////////////////////////////////////////////////////////////////////////////     ////exception test     ///////////////////////////////////////////////////////////////////////////////     if (iReturnCode != EPIRequest.EPI_NORMAL       && iReturnCode != EPIRequest.EPI_ERR_MORE_EVENTS) {      log.debug("iReturnCode=" + iReturnCode);      EpiPublic.logEpiErrorAndException("main - getEvent - javaGateway.flow", iReturnCode);     }     switch (epiRequest.event) {     case EPIRequest.EPI_EVENT_SEND:      log.debug("epiRequest.event=EPI_EVENT_SEND");      result.setMsg(new ByteArray(epiRequest.data, 2, epiRequest.size - 2));      break;

    case EPIRequest.EPI_EVENT_END_TRAN:      log.debug(        "epiRequest.event=EPI_EVENT_END_TRAN");      break;

    default:      log.debug("epiRequest.event=?");      EpiPublic.printEpiEventData(epiRequest);      break;     }    } while (epiRequest.event != EPIRequest.EPI_EVENT_END_TRAN);

   epiRequest.delTerminal();    iReturnCode = javaGateway.flow(epiRequest);    if (iReturnCode != EPIRequest.EPI_NORMAL)     EpiPublic.logEpiErrorAndException("main - delTerminal - javaGateway.flow", iReturnCode);    // wait until terminal end    do {     epiRequest.getEvent(EPIRequest.EPI_WAIT,       ByteArray.BUFFER_SIZE_MAX);     iReturnCode = javaGateway.flow(epiRequest);     if (iReturnCode != EPIRequest.EPI_NORMAL       && iReturnCode != EPIRequest.EPI_ERR_MORE_EVENTS)      EpiPublic.logEpiErrorAndException(        "main - getEvent - javaGateway.flow", iReturnCode);

    switch (epiRequest.event) {     case EPIRequest.EPI_EVENT_END_TERM:      if (epiRequest.endReason != EPIRequest.EPI_END_SIGNOFF) // what       // we       // expected       // is       // EPI_END_SIGNOFF       EpiPublic.printEpiEventData(epiRequest);      break;

    default:      EpiPublic.printEpiEventData(epiRequest);      break;     }    } while (epiRequest.event != EPIRequest.EPI_EVENT_END_TERM);    //close    javaGateway.close();   } catch (Exception ex) {    log.debug(ex);    throw ex ;   }finally  {       try       {        if (javaGateway != null)        {         javaGateway.close();         log.debug("Successfully closed JavaGateway");        }       } catch (Exception eClose)       {        log.error("Exception during close : " + eClose);       }             }      if (result.getMsg() == null){    log.info(" ReceiveMessage rm is null.");    return null;   }else    databean.setReceiveMsg(result.getMsg().getValue());      return databean ;  }

//懂不懂看个人啦, 自己慢慢看

相关文章推荐

CICS事务网关-CTG原理及操作

1.1 什么是CTG 1.1.1 概述 CICS系统是IBM大型机上的重要的交易处理系统,并且由于大型机的特殊性,导致CICS的已有应用程序对分布式平台开放不够,难以重用以往的应用程序。因此,CI...

IBM外围系统CICS连接银行核心

接口说明 ECIRequestpublic ECIRequest(java.lang.String strServer, java.lang.String strUserid, ...

CICS通讯java应用调用服务的CTG Client配置

当一个java应用需要调用CICS Server端的服务时,它调用的过程是这样的:首先java应用汇通过JavaGateway(String ip, intport)对象去连接CICS Transac...

CICS事务网关-CTG原理及操作

1.1 什么是CTG 1.1.1 概述 CICS系统是IBM大型机上的重要的交易处理系统,并且由于大型机的特殊性,导致CICS的已有应用程序对分布式平台开放不够,难以重用以往的应用程序。因此,CICS...

CICS事务网关-CTG原理及操作

1.1 什么是CTG 1.1.1 概述 CICS系统是IBM大型机上的重要的交易处理系统,并且由于大型机的特殊性,导致CICS的已有应用程序对分布式平台开放不够,难以重用以往的应用程序。因此,CI...

Eclipse反编译工具Jad及插件JadClipse配置

Eclipse反编译工具Jad及插件JadClipse配置     Jad是一个Java的一个反编译工具,是用命令行执行,和通常JDK自带的java,javac命令是一样的。不过因为是控制台运行,所以...

java调用rest风格web服务的两种方式

java调用rest风格web service 的两种形式
  • Eric_Hxy
  • Eric_Hxy
  • 2015年04月08日 09:39
  • 33762
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Cics中Java调用的两种方式
举报原因:
原因补充:

(最多只允许输入30个字)