在Cics中 , Java调用分两种方式 , ECI and EPI .
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
//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 ; }
//懂不懂看个人啦, 自己慢慢看