This commit is contained in:
Rinjae
2025-09-05 18:57:45 +09:00
commit aacc1a389e
1229 changed files with 167963 additions and 0 deletions
@@ -0,0 +1,473 @@
package com.eactive.eai.flowcontroller;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import com.eactive.eai.adapter.AdapterGroupVO;
import com.eactive.eai.adapter.AdapterManager;
import com.eactive.eai.adapter.Keys;
import com.eactive.eai.common.EAIKeys;
import com.eactive.eai.common.EAITable;
import com.eactive.eai.common.exception.ExceptionHandler;
import com.eactive.eai.common.exception.ExceptionUtil;
import com.eactive.eai.common.message.EAIMessage;
import com.eactive.eai.common.message.EAIMessageKeys;
import com.eactive.eai.common.message.MessageType;
import com.eactive.eai.common.property.PropManager;
import com.eactive.eai.common.routing.IFRouter;
import com.eactive.eai.common.routing.Process;
import com.eactive.eai.common.routing.RouteKeys;
import com.eactive.eai.common.server.EAIServerManager;
import com.eactive.eai.common.util.Logger;
import com.eactive.eai.common.util.MessageUtil;
import com.eactive.eai.common.util.ObjectUtil;
import com.eactive.eai.common.util.ServiceUtil;
import com.eactive.eai.control.LogSender;
import com.eactive.eai.message.StandardMessage;
import com.eactive.eai.message.service.InterfaceMapper;
import com.eactive.eai.transformer.function.util.CodeConversion;
import com.ext.eai.common.stdmessage.STDMessageKeys;
public class BaseFCProcess extends Process {
public String adptrMsgPtrnCd;
public java.lang.String adapterGroupName;
public int logPssSeq;
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
public java.util.Properties callProp;
public EAIMessage resEaiMsg;
public com.eactive.eai.common.message.EAIMessage reqEaiMsg;
static Logger esbLogger = Logger.getLogger(Logger.LOGGER_ESBFW);
private int svrLogLevel;
private static ThreadLocal local = new ThreadLocal();
String guidLogPrefix = "";
static final long serialVersionUID = 1L;
public EAIMessage clientReturn() {
if (svrLogLevel >= 1) {
try {
long msgSndTm = System.currentTimeMillis();
Long threadData = (Long) local.get();
long processTm = msgSndTm - threadData.longValue();
if (esbLogger.isInfo())
esbLogger.info(
guidLogPrefix + "End... - 경과시간 : " + processTm + "(ms) - EAI Server Log Level is INFO");
} catch (Exception e) {
logger.warn("clientReturn", e);
}
}
return resEaiMsg;
}
public void callService(com.eactive.eai.common.message.EAIMessage reqEaiMsg, java.util.Properties callProp) {
this.reqEaiMsg = reqEaiMsg;
this.callProp = callProp;
if (this.reqEaiMsg == null)
return;
svrLogLevel = this.reqEaiMsg.getSvrLogLvl();
guidLogPrefix = "BaseFCProcess] GUID[" + getGuid(reqEaiMsg) + "] UUID[" + this.reqEaiMsg.getSvcOgNo() + "] ";
if (svrLogLevel >= 1) {
try {
long msgRcvTm = System.currentTimeMillis();
local.set(new Long(msgRcvTm));
if (esbLogger.isInfo())
esbLogger.info(guidLogPrefix + " started... - EAI Server Log Level is INFO");
} catch (Exception e) {
logger.warn("callService", e);
}
}
try {
flow();
} catch (Exception e) {
printExceptionMessage(e);
if (isSourceAsync()) {
logSenderCtrlSend();
callExceptionHandler();
}
return;
}
}
public void flow() throws Exception {
if (!isRealCall()) {
return;
}
// 초기화
init();
// Outbound 프로세스 호출
ifRouterProcess();
// GUID설정
setGUID();
// ASYNC-SYNC모델
if (checkServiceMsgSize()) {
// ServiceMessage설정
setCurrentService();
// 응답메시지전송
ifRouterProcessResponse();
}
}
public void ifRouterProcess() throws Exception {
try {
// this.resEaiMsg = IFRouter.process(this.reqEaiMsg, this.callProp);
EAIMessage reqMsg = (EAIMessage) ObjectUtil.deepCopy(this.reqEaiMsg);
this.resEaiMsg = IFRouter.process(reqMsg, this.callProp);
} catch (Exception e) {
String[] msgArgs = new String[1];
msgArgs[0] = this.reqEaiMsg.getEAISvcCd();
String rspErrorCode = "RECEAIFBF001";
String rspErrorMsg = ExceptionUtil.make(e, rspErrorCode, msgArgs);
if (logger.isError())
logger.error(guidLogPrefix + rspErrorMsg, e);
// this.resEaiMsg.setRspErrCd(rspErrorCode);
// this.resEaiMsg.setRspErrMsg(rspErrorMsg);
this.resEaiMsg.setRspErr(rspErrorCode,rspErrorMsg);
throw new Exception(rspErrorCode);
}
// ----------------------------------------------------
// 기동시스템이 Async 거래의 OUtbound에서 오류가 발생할 경우
// ExceptionHandler를 통해 응답메시지를 전송한다.
// ----------------------------------------------------
if (EAIMessageKeys.ASYNC_SVC.equals(this.reqEaiMsg.getSvcTsmtUsgTp())) {
if (!MessageUtil.checkRspErrCd(this.resEaiMsg.getRspErrCd())) {
try {
String bizData = this.reqEaiMsg.getStandardMessage().getBizData();
String inboundCharset = callProp.getProperty(com.eactive.eai.adapter.Keys.CHARSET_KEY_IN);
this.resEaiMsg.getStandardMessage().setBizData(bizData, inboundCharset);
ExceptionHandler.handle(this.resEaiMsg);
} catch (Exception e) {
if (logger.isError())
logger.error(guidLogPrefix + "ExceptionHandler Call Error :" + e.getMessage());
}
}
}
}
public void ifRouterProcessResponse() throws Exception {
try {
// 20220405
// AS거래에서 처리결과수신서비스ID를 서비스ID로 넣어준다.
String returnServiceId = this.resEaiMsg.getMapper().getReturnServiceId(this.resEaiMsg.getStandardMessage());
this.resEaiMsg.getMapper().setServiceId(this.resEaiMsg.getStandardMessage(), returnServiceId);
this.resEaiMsg = IFRouter.process(this.resEaiMsg, this.callProp);
} catch (Exception e) {
String[] msgArgs = new String[1];
msgArgs[0] = this.reqEaiMsg.getEAISvcCd();
String rspErrorCode = "RECEAIFBF100";
String orgErrorCode = ExceptionUtil.getErrorCode(e, rspErrorCode);
String rspErrorMsg = ExceptionUtil.make(rspErrorCode, orgErrorCode, msgArgs);
if (logger.isError())
logger.error(guidLogPrefix + rspErrorMsg);
// this.resEaiMsg.setRspErrCd(rspErrorCode);
// this.resEaiMsg.setRspErrMsg(rspErrorMsg);
this.resEaiMsg.setRspErr(rspErrorCode,rspErrorMsg);
this.logPssSeq = 400;
LogSender.send(this.logPssSeq, this.resEaiMsg, null);
}
}
public void logSenderCtrlSend() {
String telgmDmndDstcd = reqEaiMsg.getMapper().getSendRecvDivision(reqEaiMsg.getStandardMessage());
if (STDMessageKeys.SEND_RECV_CD_RECV.equals(telgmDmndDstcd)) {
this.logPssSeq = 400;
} else {
this.logPssSeq = 200;
}
try {
LogSender.send(this.logPssSeq, this.resEaiMsg, null);
} catch (Exception e) {
if (logger.isError())
logger.error(guidLogPrefix + "AA Exception Logging Error :" + e.getMessage());
}
}
public boolean checkServiceMsgSize() {
// Outbound Error일 경우
if (MessageUtil.checkRspErrCd(this.resEaiMsg.getRspErrCd()) && reqEaiMsg.getSvcMsgs().size() > 1) {
return true;
} else {
return false;
}
}
public void setCurrentService() throws Exception {
if (logger.isDebug())
logger.debug(guidLogPrefix + "ASYNC-SYNC CALLED");
// ---------------------------------------------------------------
// AS의 경우 다음 서비스메시지(AS 응답)에 키관리메시지내용을 복사한다.
// ---------------------------------------------------------------
String keyMgtMsgVl = resEaiMsg.getCurrentSvcMsg().getKeyMgtMsgVl();
if (logger.isDebug())
logger.debug(guidLogPrefix + "AS 응답 keyMgtMsgVl[" + keyMgtMsgVl + "]");
resEaiMsg.setSvcPssSeq(resEaiMsg.getSvcPssSeq() + 1);
resEaiMsg.getCurrentSvcMsg().setKeyMgtMsgVl(keyMgtMsgVl);
// ---------------------------------------------------------------
// 기동이 표준인 경우만
if (com.eactive.eai.adapter.Keys.IF_STANDARD.equals(this.reqEaiMsg.getStdMsgUsgCls())) {
// resEaiMsg = ExtMessageConverter.setAsyncSyncResponseForStandard(guidLogPrefix, reqEaiMsg, resEaiMsg);
setReturnType(resEaiMsg, STDMessageKeys.SEND_RECV_CD_RECV);
}
}
public boolean isOutboundCall() {
return true;
}
public void init() throws Exception {
// -------------------------------------------
// eLink 내부에서는 GUID 진행번호를 분리
// ExtMessage 에서는 분리
// STDMessage 에서는 사이트에 맞게 변경처리
// -------------------------------------------
InterfaceMapper mapper = this.reqEaiMsg.getMapper();
StandardMessage standardMessage = this.reqEaiMsg.getStandardMessage();
String guid = mapper.getGuid(standardMessage);
String guidseq = mapper.getGuidSeq(standardMessage);
if (logger.isDebug())
logger.debug(guidLogPrefix + " REQ Current GUID [" + guid + "][" + guidseq + "]");
mapper.nextGuidSeq(standardMessage);
guidseq = mapper.getGuidSeq(standardMessage);
if (logger.isDebug())
logger.debug(guidLogPrefix + " REQ ADD PATHSEQ GUID [" + guid + "][" + guidseq + "]");
this.resEaiMsg = this.reqEaiMsg;
this.adapterGroupName = reqEaiMsg.getCurrentSvcMsg().getPsvSysItfTp();
EAIServerManager eaiServerManager = EAIServerManager.getInstance();
AdapterManager adapterManager = AdapterManager.getInstance();
AdapterGroupVO adptGrpVO = adapterManager.getAdapterGroupVO(this.adapterGroupName);
// 등록된 어댑터가 실제 존재하지 않는 경우 : 2009.04.03
if (adptGrpVO == null) {
String[] msgArgs = new String[1];
msgArgs[0] = this.reqEaiMsg.getEAISvcCd();
String rspErrorCode = "RECEAIFBF003";
String rspErrorMsg = ExceptionUtil.make(rspErrorCode, msgArgs) + "(어댑터그룹 미등록/미사용 - "
+ this.adapterGroupName + ")";
if (logger.isError())
logger.error(guidLogPrefix + rspErrorMsg);
// this.resEaiMsg.setRspErrCd(rspErrorCode);
// this.resEaiMsg.setRspErrMsg(rspErrorMsg);
this.resEaiMsg.setRspErr(rspErrorCode,rspErrorMsg);
throw new Exception(rspErrorCode);
}
String adapterType = adptGrpVO.getType();
if (eaiServerManager.isTASEnabledEAIServer() && EAIMessageKeys.TRANTYPE_TAS.equals(reqEaiMsg.getTranType())
// RESTAdapter는 교체하지 않는다
&& !StringUtils.equals(adapterType, "RST")) {
// this.adptrMsgPtrnCd = com.eactive.eai.adapter.Keys.IF_NONSTANDARD;
// adapterType = Keys.TYPE_NET2;
PropManager manager = PropManager.getInstance();
Properties prop = manager.getProperties(RouteKeys.SIM);
if (reqEaiMsg.getCurrentSvcMsg().isSyncItfTp()) {
this.adapterGroupName = prop.getProperty(RouteKeys.SIM_ADAPTER_SYNC, "_SIM_OU_HTT_SyC");
} else {
this.adapterGroupName = prop.getProperty(RouteKeys.SIM_ADAPTER_ASYNC, "_SIM_OU_HTT_AsC");
}
} else {
// AdapterManager adapterManager = AdapterManager.getInstance();
// AdapterGroupVO adptGrpVO = adapterManager.getAdapterGroupVO(this.adapterGroupName);
// failover 사용시에는 제거 되어야됨
// if(adptGrpVO.nextAdapterVO() == null) {
// String[] msgArgs = new String[1];
// msgArgs[0] = this.reqEaiMsg.getEAISvcCd();
// String rspErrorCode = "RECEAIFBF002";
// String rspErrorMsg = ExceptionUtil.make(rspErrorCode, msgArgs)
// + ","+this.adapterGroupName;
// if (logger.isError()) logger.error( guidLogPrefix + rspErrorMsg);
// this.resEaiMsg.setRspErrCd(rspErrorCode);
// this.resEaiMsg.setRspErrMsg(rspErrorMsg);
// throw new Exception(rspErrorCode);
// }
this.adptrMsgPtrnCd = adptGrpVO.getAdptrMsgPtrnCd();
adapterType = adptGrpVO.getType();
}
String svcTsmtUsgTp = ""; // 기동 호출방식
String psvItfTp = ""; // 수동 호출방식
// 2009.03.11
// AA가 아니고 기동이 표준이 아닌 경우
// Adapter의 timeout값을 설정한다.
try {
svcTsmtUsgTp = this.reqEaiMsg.getSvcTsmtUsgTp(); // 기동 호출방식
psvItfTp = this.reqEaiMsg.getCurrentSvcMsg().getPsvItfTp(); // 수동 호출방식
if (!(EAIMessageKeys.ASYNC_SVC.equals(svcTsmtUsgTp) && EAIMessageKeys.ASYNC_SVC.equals(psvItfTp))
&& !(com.eactive.eai.adapter.Keys.IF_STANDARD.equals(this.reqEaiMsg.getStdMsgUsgCls()))) {
// SA 또는 SNA Adapter일 경우에 는 SA Timeout값을 설정
if ((EAIMessageKeys.SYNC_SVC.equals(svcTsmtUsgTp) && EAIMessageKeys.ASYNC_SVC.equals(psvItfTp))
|| Keys.TYPE_SNA.equals(adapterType)) {
int saTimeoutSec = this.reqEaiMsg.getCurrentSvcMsg().getTmoVl();
if (logger.isDebug())
logger.debug(guidLogPrefix + " SA TimeoutValue [" + saTimeoutSec + "]");
// this.reqEaiMsg.getKbMsg().getKBHeader().setGnrzToutCrtcNmvl(""+saTimeoutSec);
this.reqEaiMsg.getMapper().setTimeout(this.reqEaiMsg.getStandardMessage(), "" + saTimeoutSec);
} else {
int timeout = ServiceUtil.getTimeoutValue(adapterGroupName);
if (logger.isDebug())
logger.debug(guidLogPrefix + " Target Adapter TimeoutValue [" + timeout + "]");
if (timeout > 0) {
if (logger.isDebug())
logger.debug(guidLogPrefix + "Set Adapter TimeoutValue [" + timeout + "] to STDMessage");
// this.reqEaiMsg.getKbMsg().getKBHeader().setGnrzToutCrtcNmvl(""+timeout);
this.reqEaiMsg.getMapper().setTimeout(this.reqEaiMsg.getStandardMessage(), "" + timeout);
}
}
}
} catch (Exception e) {
if (logger.isWarn()) {
logger.warn(guidLogPrefix + "Get Adapter TimeoutValue Error - " + e.getMessage(), e);
}
}
// -----------------------------------------------------
// TheK 요건 : SNA송신 비동기 응답거래시 수신거래코드를 EAI에서 매핑함 (20190522)
String srcAdapterGroupName = reqEaiMsg.getSngSysItfTp();
// AdapterManager adapterManager = AdapterManager.getInstance();
AdapterGroupVO inAdptGrpVO = adapterManager.getAdapterGroupVO(srcAdapterGroupName);
String inAdapterMsgType = MessageType.ASC;
if (eaiServerManager.isTASEnabledEAIServer() && EAIMessageKeys.TRANTYPE_FROMTAS.equals(reqEaiMsg.getTranType())
&& inAdptGrpVO == null) {
logger.info(guidLogPrefix + "- TAS 기동거래 [" + srcAdapterGroupName + "] = " + MessageType.ASC);
} else {
if (inAdptGrpVO == null) {
String[] msgArgs = new String[1];
msgArgs[0] = this.reqEaiMsg.getEAISvcCd();
String rspErrorCode = "RECEAIFBF003";
String rspErrorMsg = ExceptionUtil.make(rspErrorCode, msgArgs) + "(어댑터그룹 미등록/미사용 - "
+ srcAdapterGroupName + ")";
if (logger.isError())
logger.error(guidLogPrefix + rspErrorMsg);
// this.resEaiMsg.setRspErrCd(rspErrorCode);
// this.resEaiMsg.setRspErrMsg(rspErrorMsg);
this.resEaiMsg.setRspErr(rspErrorCode,rspErrorMsg);
throw new Exception(rspErrorCode);
}
inAdapterMsgType = inAdptGrpVO.getMessageType();
}
}
public void printExceptionMessage(Exception e) {
// Exception e = this.context.getExceptionInfo().getException();
if (logger.isError())
logger.error(guidLogPrefix + "ExceptionPath : " + e.getMessage(), e);
}
public boolean isSourceAsync() {
if (EAIMessageKeys.ASYNC_SVC.equals(this.reqEaiMsg.getSvcTsmtUsgTp())) {
return true;
} else {
return false;
}
}
public void callExceptionHandler() {
try {
AdapterManager adapterManager = AdapterManager.getInstance();
AdapterGroupVO inAdptGrpVO = adapterManager.getAdapterGroupVO(this.reqEaiMsg.getSngSysItfTp());
String inAdapterMsgType = inAdptGrpVO.getMessageType();
if (EAITable.EBCDIC_TYPE.equals(inAdapterMsgType)) {
String bizData = this.reqEaiMsg.getStandardMessage().getBizData();
byte[] asc = CodeConversion.meToMixedAsc(bizData.getBytes());
try {
String inboundCharset = callProp.getProperty(com.eactive.eai.adapter.Keys.CHARSET_KEY_IN);
this.reqEaiMsg.getStandardMessage().setBizData(new String(asc), inboundCharset);
} catch (Exception e) {
logger.error("setBizData error", e);
}
}
ExceptionHandler.handle(this.reqEaiMsg);
} catch (Exception e) {
if (logger.isError())
logger.error(guidLogPrefix + "ExceptionHandler Call Error", e);
}
}
public boolean isRealCall() {
if (this.callProp != null) {
String mode = this.callProp.getProperty(EAIKeys.CALL_MODE_KEY);
if (mode != null && EAIKeys.CALL_MODE_WARMUP.equals(mode)) {
logger.warn(guidLogPrefix + "Warming Up Called");
return false;
} else {
return true;
}
} else {
return true;
}
}
public void setGUID() throws Exception {
InterfaceMapper mapper = this.resEaiMsg.getMapper();
StandardMessage standardMessage = this.resEaiMsg.getStandardMessage();
String guid = mapper.getGuid(standardMessage);
String guidseq = mapper.getGuidSeq(standardMessage);
if (logger.isDebug())
logger.debug(guidLogPrefix + " REQ Current GUID [" + guid + "][" + guidseq + "]");
mapper.nextGuidSeq(standardMessage);
guidseq = mapper.getGuidSeq(standardMessage);
if (logger.isDebug())
logger.debug(guidLogPrefix + " REQ ADD PATHSEQ GUID [" + guid + "][" + guidseq + "]");
String svcTsmtUsgTp = this.reqEaiMsg.getSvcTsmtUsgTp(); // 기동 호출방식
String psvItfTp = this.reqEaiMsg.getCurrentSvcMsg().getPsvItfTp(); // 수동 호출방식
if ((!(com.eactive.eai.adapter.Keys.IF_STANDARD.equals(this.adptrMsgPtrnCd))
&& !(EAIMessageKeys.ASYNC_SVC.equals(svcTsmtUsgTp) && EAIMessageKeys.ASYNC_SVC.equals(psvItfTp)))
|| ((com.eactive.eai.adapter.Keys.IF_STANDARD.equals(this.adptrMsgPtrnCd))
&& (EAIMessageKeys.ASYNC_SVC.equals(svcTsmtUsgTp)
&& EAIMessageKeys.SYNC_SVC.equals(psvItfTp)))) {
String prcssRtdTranCd = mapper.getReturnServiceId(standardMessage);
if (prcssRtdTranCd != null && prcssRtdTranCd.length() >= 14) {
// String cicsTrncd = prcssRtdTranCd.substring(0, 4);
String telgmRecvTranCd = prcssRtdTranCd.substring(4, 14);
mapper.setServiceId(standardMessage, telgmRecvTranCd);
} else {
if (logger.isInfo()) {
logger.info(guidLogPrefix + "- PrcssRtdTranCd Length < 14 [" + prcssRtdTranCd + "]");
}
}
}
if (!(EAIMessageKeys.ASYNC_SVC.equals(svcTsmtUsgTp) && EAIMessageKeys.ASYNC_SVC.equals(psvItfTp))
&& (com.eactive.eai.adapter.Keys.IF_STANDARD.equals(this.reqEaiMsg.getStdMsgUsgCls()))
&& (STDMessageKeys.RECOVER_YN_YES
.equals(this.reqEaiMsg.getMapper().getRecoverYn(this.reqEaiMsg.getStandardMessage())))) {
String reqOgtranGuIdNo = this.reqEaiMsg.getMapper().getOrgGuid(this.reqEaiMsg.getStandardMessage());
mapper.setOrgGuid(standardMessage, reqOgtranGuIdNo);
if (logger.isInfo()) {
logger.info(guidLogPrefix + " OgtranGuIdNo 복원 " + this.reqEaiMsg.getSvcOgNo() + " OgtranGuIdNo ["
+ mapper.getOrgGuid(standardMessage) + "]");
}
}
}
}