init
This commit is contained in:
@@ -0,0 +1,303 @@
|
||||
package com.eactive.eai.inbound.processor;
|
||||
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
import com.eactive.eai.adapter.AdapterManager;
|
||||
import com.eactive.eai.adapter.AdapterPropManager;
|
||||
import com.eactive.eai.adapter.AdapterVO;
|
||||
import com.eactive.eai.adapter.Keys;
|
||||
import com.eactive.eai.adapter.http.client.HttpClientAdapterServiceKey;
|
||||
import com.eactive.eai.common.routing.GWRemoteProxyClient;
|
||||
import com.eactive.eai.common.routing.RouteKeys;
|
||||
import com.eactive.eai.common.server.EAIServerManager;
|
||||
import com.eactive.eai.common.server.EAIServerVO;
|
||||
import com.eactive.eai.common.util.CommonLib;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.control.HttpSender;
|
||||
import com.eactive.eai.control.SocketSender;
|
||||
|
||||
public class GWRequestProcessor extends RequestProcessorSupport {
|
||||
|
||||
static final String OUTBOUND_ADAPTER_GROUP_NAME = "OUTBOUND_ADAPTER_GROUP_NAME";
|
||||
static final String PAIR_ADAPTER = "PAIR_ADAPTER";
|
||||
static final String PAIR_ADAPTER_HEADER_PREFIX = "PA_";
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_SIFT);
|
||||
|
||||
protected Object hookup(Object message, Properties prop, long msgRcvTm) throws Exception {
|
||||
|
||||
String inboundAdapterGroupName = prop.getProperty(Processor.ADAPTER_GROUP_NAME);
|
||||
logger.debug("GWRequestProcessor] inboundAdapterGroupName: {}", inboundAdapterGroupName);
|
||||
|
||||
AdapterManager adapterManager = AdapterManager.getInstance();
|
||||
AdapterGroupVO inboundAdptGrpVO = adapterManager.getAdapterGroupVO(inboundAdapterGroupName);
|
||||
|
||||
String inboundAdapterName = prop.getProperty(Processor.ADAPTER_NAME);
|
||||
AdapterVO inboundAdapterVO = inboundAdptGrpVO.getAdapterVO(inboundAdapterName);
|
||||
|
||||
MDC.put(Logger.DISCRIMINATOR, inboundAdapterGroupName);
|
||||
logger.info("<RECV> " + getLogMessage(message));
|
||||
logger.debug(CommonLib.getDumpMessage(message));
|
||||
MDC.remove(Logger.DISCRIMINATOR);
|
||||
|
||||
AdapterPropManager adapterPropManager = AdapterPropManager.getInstance();
|
||||
Properties inboundProp = adapterPropManager.getProperties(inboundAdapterVO.getPropGroupName());
|
||||
|
||||
String transactionId = null;
|
||||
String instanceId = EAIServerManager.getInstance().getLocalServerName();
|
||||
|
||||
//set pair adapter
|
||||
String pairAdapter = inboundProp.getProperty(PAIR_ADAPTER);
|
||||
if (StringUtils.isNotBlank(inboundAdptGrpVO.getPairAdapterYn()) && "1".equals(inboundAdptGrpVO.getPairAdapterYn())
|
||||
&& StringUtils.isNoneBlank(pairAdapter)) {
|
||||
transactionId = PAIR_ADAPTER_HEADER_PREFIX + UUID.randomUUID().toString().substring(0, 7);
|
||||
GWSessionManager.getInstance().adapterIn(transactionId, pairAdapter);
|
||||
logger.debug("GWRequestProcessor] transactionId|pairAdapter: {}, {}", transactionId, pairAdapter);
|
||||
}
|
||||
|
||||
//set use same session
|
||||
String sessionId = prop.getProperty("SESSION_ID");
|
||||
if (StringUtils.isNotBlank(sessionId)) {
|
||||
transactionId = sessionId;
|
||||
logger.debug("GWRequestProcessor] transactionId|sessionId: {}", sessionId);
|
||||
}
|
||||
|
||||
//get Outbound Adapter Group
|
||||
Object resObject = null;
|
||||
String outboundAdapterGroupName = inboundAdptGrpVO.getLinkedAdapterGroup();
|
||||
AdapterGroupVO outboundAdptGrpVO = adapterManager.getAdapterGroupVO(outboundAdapterGroupName);
|
||||
String outboundAdapterType = outboundAdptGrpVO.getType(); //HTT, HTC, NET
|
||||
|
||||
//response header
|
||||
String responseTransactionId = prop.getProperty(HttpClientAdapterServiceKey.TRANSACTION_ID);
|
||||
String responseInstanceId = prop.getProperty(HttpClientAdapterServiceKey.INSTANCE_ID);
|
||||
if (StringUtils.isNotBlank(responseTransactionId) && StringUtils.isNotBlank(responseInstanceId)) {
|
||||
if (!responseInstanceId.equals(instanceId)) {
|
||||
logger.warn("GWRequestProcessor] intanceId not matched.[{}<{}>], call Remote Proxy", outboundAdapterGroupName, responseTransactionId);
|
||||
resObject = callRemoteProxy(message, outboundAdapterGroupName, responseTransactionId, responseInstanceId);
|
||||
|
||||
return resObject;
|
||||
}
|
||||
|
||||
if (!GWSessionManager.getInstance().isExists(responseTransactionId)) {
|
||||
logger.error("GWRequestProcessor] No matched transactionId[{}], at {}", responseTransactionId, responseInstanceId);
|
||||
throw new Exception("No matched transactionId.[" + responseTransactionId + "]");
|
||||
}
|
||||
|
||||
logger.debug("GWRequestProcessor] responseTransactionId: {}", responseTransactionId);
|
||||
}
|
||||
|
||||
AdapterVO adptVO = outboundAdptGrpVO.nextAdapterVO();
|
||||
// 가용 Adapter가 없는 경우
|
||||
if (adptVO == null) {
|
||||
// throw new Exception("No adapters available.[" + outboundAdapterGroupName + "]");
|
||||
logger.warn("GWRequestProcessor] No adapters available.[{}], call Remote Proxy", outboundAdapterGroupName);
|
||||
resObject = callRemoteProxy(message, outboundAdapterGroupName);
|
||||
} else {
|
||||
Properties outboundProp = adapterPropManager.getProperties(adptVO.getPropGroupName());
|
||||
|
||||
Properties tempProp = new Properties();
|
||||
tempProp.setProperty(com.eactive.eai.adapter.Keys.CHARSET_KEY_OUT,
|
||||
StringUtils.defaultIfBlank(outboundAdptGrpVO.getMessageEncode(), Charset.defaultCharset().name()));
|
||||
|
||||
MDC.put(Logger.DISCRIMINATOR, outboundAdapterGroupName);
|
||||
logger.info("<SEND> " + getLogMessage(message));
|
||||
logger.debug(CommonLib.getDumpMessage(message));
|
||||
MDC.remove(Logger.DISCRIMINATOR);
|
||||
|
||||
try {
|
||||
if (outboundAdapterType.equals(Keys.TYPE_HTTP) || outboundAdapterType.equals(Keys.TYPE_HTTP_CUSTOM)) {
|
||||
tempProp.setProperty(HttpClientAdapterServiceKey.ADAPTER_GROUP_NAME, outboundAdapterGroupName);
|
||||
|
||||
//set header
|
||||
if (StringUtils.isNotBlank(pairAdapter) || StringUtils.isNotBlank(sessionId)) {
|
||||
String adapterHeader = "{ \"" + HttpClientAdapterServiceKey.TRANSACTION_ID + "\", \"" + transactionId + "\" },"
|
||||
+ "{ \"" + HttpClientAdapterServiceKey.INSTANCE_ID + "\", \"" + instanceId + "\" }";
|
||||
outboundProp.put(HttpClientAdapterServiceKey.ADAPTER_HEADER, adapterHeader);
|
||||
}
|
||||
|
||||
//set pair adapter
|
||||
if (StringUtils.isNotBlank(responseTransactionId) && responseTransactionId.startsWith(PAIR_ADAPTER_HEADER_PREFIX)) {
|
||||
tempProp.setProperty(HttpClientAdapterServiceKey.ADAPTER_NAME, GWSessionManager.getInstance().getAdapter(responseTransactionId));
|
||||
GWSessionManager.getInstance().adapterOut(responseTransactionId);;
|
||||
} else {
|
||||
tempProp.setProperty(HttpClientAdapterServiceKey.ADAPTER_NAME, adptVO.getName());
|
||||
}
|
||||
|
||||
resObject = HttpSender.callService(outboundAdapterGroupName, outboundProp, message, tempProp);
|
||||
} else if (outboundAdapterType.equals(Keys.TYPE_NET2)) {
|
||||
tempProp.setProperty(Keys.OUT_ADAPTER_GROUP_NAME, outboundAdapterGroupName);
|
||||
|
||||
//set pair adapter
|
||||
if (StringUtils.isNotBlank(responseTransactionId) && responseTransactionId.startsWith(PAIR_ADAPTER_HEADER_PREFIX)) {
|
||||
tempProp.setProperty(Keys.OUT_ADAPTER_NAME, GWSessionManager.getInstance().getAdapter(responseTransactionId));
|
||||
GWSessionManager.getInstance().adapterOut(responseTransactionId);;
|
||||
} else {
|
||||
tempProp.setProperty(Keys.OUT_ADAPTER_NAME, adptVO.getName());
|
||||
//set session
|
||||
if (StringUtils.isNotBlank(responseTransactionId)) {
|
||||
tempProp.setProperty(HttpClientAdapterServiceKey.TRANSACTION_ID, responseTransactionId);
|
||||
}
|
||||
}
|
||||
|
||||
resObject = SocketSender.callService(outboundAdapterGroupName, outboundProp, message, tempProp);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
logger.warn("GW.Sender] callService " + e.getMessage(), e);
|
||||
logger.warn("call Remote Proxy");
|
||||
// resObject = e.getMessage();
|
||||
resObject = callRemoteProxy(message, outboundAdapterGroupName);
|
||||
}
|
||||
|
||||
if (resObject != null) {
|
||||
MDC.put(Logger.DISCRIMINATOR, outboundAdapterGroupName);
|
||||
logger.info("<RECV> " + getLogMessage(resObject));
|
||||
logger.debug(CommonLib.getDumpMessage(resObject));
|
||||
MDC.remove(Logger.DISCRIMINATOR);
|
||||
}
|
||||
}
|
||||
|
||||
if (resObject != null) {
|
||||
MDC.put(Logger.DISCRIMINATOR, inboundAdapterGroupName);
|
||||
logger.info("<SEND> " + getLogMessage(resObject));
|
||||
logger.debug(CommonLib.getDumpMessage(resObject));
|
||||
MDC.remove(Logger.DISCRIMINATOR);
|
||||
}
|
||||
|
||||
return resObject;
|
||||
}
|
||||
|
||||
public static Object callService(Object message, Properties callProp) throws Exception {
|
||||
String outboundAdapterGroupName = callProp.getProperty(OUTBOUND_ADAPTER_GROUP_NAME);
|
||||
String transactionId = callProp.getProperty(HttpClientAdapterServiceKey.TRANSACTION_ID);
|
||||
logger.debug("GWRequestProcessor.callService] transactionId: {}", transactionId);
|
||||
|
||||
AdapterManager adapterManager = AdapterManager.getInstance();
|
||||
AdapterGroupVO outboundAdptGrpVO = adapterManager.getAdapterGroupVO(outboundAdapterGroupName);
|
||||
String outboundAdapterType = outboundAdptGrpVO.getType(); //HTT, HTC, NET
|
||||
|
||||
AdapterVO adptVO = outboundAdptGrpVO.nextAdapterVO();
|
||||
// 가용 Adapter가 없는 경우
|
||||
if (adptVO == null) {
|
||||
throw new Exception("GWRequestProcessor] No adapters available.[" + outboundAdapterGroupName + "]");
|
||||
}
|
||||
|
||||
Object resObject = null;
|
||||
AdapterPropManager manager = AdapterPropManager.getInstance();
|
||||
Properties outboundProp = manager.getProperties(adptVO.getPropGroupName());
|
||||
Properties tempProp = new Properties();
|
||||
tempProp.setProperty(com.eactive.eai.adapter.Keys.CHARSET_KEY_OUT,
|
||||
StringUtils.defaultIfBlank(outboundAdptGrpVO.getMessageEncode(), Charset.defaultCharset().name()));
|
||||
|
||||
MDC.put(Logger.DISCRIMINATOR, outboundAdapterGroupName);
|
||||
logger.info("<SEND> " + getLogMessage(message));
|
||||
logger.debug(CommonLib.getDumpMessage(message));
|
||||
MDC.remove(Logger.DISCRIMINATOR);
|
||||
|
||||
if (outboundAdapterType.equals(Keys.TYPE_HTTP) || outboundAdapterType.equals(Keys.TYPE_HTTP_CUSTOM)) {
|
||||
tempProp.setProperty(HttpClientAdapterServiceKey.ADAPTER_GROUP_NAME, outboundAdapterGroupName);
|
||||
|
||||
//set pair adapter
|
||||
if (StringUtils.isNotBlank(transactionId) && transactionId.startsWith(PAIR_ADAPTER_HEADER_PREFIX)) {
|
||||
tempProp.setProperty(HttpClientAdapterServiceKey.ADAPTER_NAME, GWSessionManager.getInstance().getAdapter(transactionId));
|
||||
GWSessionManager.getInstance().adapterOut(transactionId);;
|
||||
} else {
|
||||
tempProp.setProperty(HttpClientAdapterServiceKey.ADAPTER_NAME, adptVO.getName());
|
||||
}
|
||||
|
||||
resObject = HttpSender.callService(outboundAdapterGroupName, outboundProp, message, tempProp);
|
||||
} else if (outboundAdapterType.equals(Keys.TYPE_NET2)) {
|
||||
tempProp.setProperty(Keys.OUT_ADAPTER_GROUP_NAME, outboundAdapterGroupName);
|
||||
|
||||
//set pair adapter
|
||||
if (StringUtils.isNotBlank(transactionId) && transactionId.startsWith(PAIR_ADAPTER_HEADER_PREFIX)) {
|
||||
tempProp.setProperty(Keys.OUT_ADAPTER_NAME, GWSessionManager.getInstance().getAdapter(transactionId));
|
||||
GWSessionManager.getInstance().adapterOut(transactionId);;
|
||||
} else {
|
||||
tempProp.setProperty(Keys.OUT_ADAPTER_NAME, adptVO.getName());
|
||||
//set session
|
||||
if (StringUtils.isNotBlank(transactionId)) {
|
||||
tempProp.setProperty(HttpClientAdapterServiceKey.TRANSACTION_ID, transactionId);
|
||||
}
|
||||
}
|
||||
|
||||
resObject = SocketSender.callService(outboundAdapterGroupName, outboundProp, message, tempProp);
|
||||
}
|
||||
|
||||
if (resObject != null) {
|
||||
MDC.put(Logger.DISCRIMINATOR, outboundAdapterGroupName);
|
||||
logger.info("<RECV> " + getLogMessage(resObject));
|
||||
logger.debug(CommonLib.getDumpMessage(resObject));
|
||||
MDC.remove(Logger.DISCRIMINATOR);
|
||||
}
|
||||
|
||||
return resObject;
|
||||
}
|
||||
|
||||
public static String getLogMessage(Object obj) {
|
||||
String message = null;
|
||||
int size = 0;
|
||||
if(obj instanceof byte[]) {
|
||||
message = new String((byte[]) obj);
|
||||
size = ((byte[]) obj).length;
|
||||
}
|
||||
else if(obj instanceof String) {
|
||||
message = (String) obj;
|
||||
// size = (((String) obj).getBytes()).length;
|
||||
size = ((String) obj).length();
|
||||
}
|
||||
|
||||
StringBuffer logMessage = new StringBuffer();
|
||||
logMessage.append("size[" + size + "], message[" + message + "]");
|
||||
|
||||
return logMessage.toString();
|
||||
}
|
||||
|
||||
public String getRemoteCallUrl(String instanceId) {
|
||||
EAIServerManager mgr = EAIServerManager.getInstance();
|
||||
EAIServerVO server, backupSvr = null;
|
||||
if (instanceId == null) {
|
||||
server = mgr.getEAIServer(mgr.getLocalServerName());
|
||||
backupSvr = mgr.getEAIServer(server.getFailoverSvr());
|
||||
} else {
|
||||
backupSvr = mgr.getEAIServer(instanceId);
|
||||
}
|
||||
|
||||
|
||||
StringBuffer urlBuf = new StringBuffer();
|
||||
urlBuf.append(EAIServerVO.IIOP_PROTOCOL).append("://");
|
||||
urlBuf.append(backupSvr.getAddress()).append(":");
|
||||
urlBuf.append(backupSvr.getRmiPort());
|
||||
|
||||
return urlBuf.toString();
|
||||
}
|
||||
|
||||
public Object callRemoteProxy(Object message, String outboundAdapterGroupName) {
|
||||
return callRemoteProxy(message, outboundAdapterGroupName, null, null);
|
||||
}
|
||||
|
||||
private Object callRemoteProxy(Object message, String outboundAdapterGroupName, String responseTransactionId, String responseInstanceId) {
|
||||
Properties callProp = new Properties();
|
||||
callProp.setProperty(RouteKeys.REMOTE_CALL_URL, getRemoteCallUrl(responseInstanceId));
|
||||
callProp.setProperty(OUTBOUND_ADAPTER_GROUP_NAME, outboundAdapterGroupName);
|
||||
if (responseTransactionId != null)
|
||||
callProp.setProperty(HttpClientAdapterServiceKey.TRANSACTION_ID, responseTransactionId);
|
||||
|
||||
Object resObject = null;
|
||||
|
||||
try {
|
||||
resObject = GWRemoteProxyClient.callProxyBean(message, callProp);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return resObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.eactive.eai.inbound.processor;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.mina.common.IoSession;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
|
||||
public class GWSessionManager {
|
||||
private static final Logger logger = Logger.getLogger(Logger.LOGGER_SIFT);
|
||||
|
||||
private static volatile GWSessionManager instance;
|
||||
private final ConcurrentHashMap<String, IoSession> sessionMap;
|
||||
private final ConcurrentHashMap<String, String> adapterMap;
|
||||
|
||||
private GWSessionManager() {
|
||||
this.sessionMap = new ConcurrentHashMap<>();
|
||||
this.adapterMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public static GWSessionManager getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (GWSessionManager.class) {
|
||||
if (instance == null) {
|
||||
instance = new GWSessionManager();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, IoSession> getSessionList() {
|
||||
return sessionMap;
|
||||
}
|
||||
|
||||
public synchronized void sessionIn(String sessionId, IoSession session) throws Exception {
|
||||
logger.info("GWSessionManager ] sessionIn - [{}, {}]", sessionId, (session != null) ? session.toString() : "null");
|
||||
if (sessionId != null && session != null) {
|
||||
sessionMap.put(sessionId, session);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void sessionOut(String sessionId) {
|
||||
logger.info("GWSessionManager ] sessionOut - [{}]", sessionId);
|
||||
if (sessionId != null && sessionMap.containsKey(sessionId)) {
|
||||
sessionMap.remove(sessionId);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized IoSession getSession(String sessionId) {
|
||||
if (sessionId != null) {
|
||||
IoSession session = sessionMap.get(sessionId);
|
||||
logger.info("GWSessionManager ] getSession - [{}, {}]", sessionId, (session != null) ? session.toString() : "null");
|
||||
return session;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, String> getAdapterList() {
|
||||
return adapterMap;
|
||||
}
|
||||
|
||||
public synchronized void adapterIn(String adapterId, String adapterName) throws Exception {
|
||||
logger.info("GWSessionManager ] adapterIn - [{}, {}]", adapterId, adapterName);
|
||||
if (adapterId != null && adapterName != null) {
|
||||
adapterMap.put(adapterId, adapterName);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void adapterOut(String adapterId) {
|
||||
logger.info("GWSessionManager ] adapterOut - [{}]", adapterId);
|
||||
if (adapterId != null && adapterMap.containsKey(adapterId)) {
|
||||
adapterMap.remove(adapterId);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized String getAdapter(String adapterId) {
|
||||
if (adapterId != null) {
|
||||
String adapterName = adapterMap.get(adapterId);
|
||||
logger.info("GWSessionManager ] getAdapter - [{}, {}]", adapterId, adapterName);
|
||||
return adapterName;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isExists(String transactionId) {
|
||||
if (getSession(transactionId) != null || getAdapter(transactionId) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
package com.eactive.eai.inbound.processor;
|
||||
|
||||
import com.eactive.eai.common.message.EAIMessageKeys;
|
||||
|
||||
/**
|
||||
* request process 에서 사용하기 위한 vo
|
||||
*
|
||||
* 추후에는 전역 Context용도로 쓰일수 있음
|
||||
*
|
||||
* @author short11
|
||||
*
|
||||
*/
|
||||
public class ProcessVO
|
||||
{
|
||||
//unknow 메시지정보 시작
|
||||
private String uuid = null;//
|
||||
private String adapterGroupName = null;//
|
||||
private String adapterName = null;//
|
||||
|
||||
private String eaiSvcCd = null;//
|
||||
private boolean isTasStarted = false;//
|
||||
private long errTm = 0;//
|
||||
private String errTypeCode = null;//
|
||||
//에러정보
|
||||
private String rspErrorCode = EAIMessageKeys.EAI_DEFAULT_CODE;
|
||||
private String rspErrorMsg = null;
|
||||
|
||||
//server정보
|
||||
private String serverName = null;//
|
||||
|
||||
private String selectedKey = null;
|
||||
//unknow 메시지정보 종료
|
||||
|
||||
|
||||
//프라퍼티정보
|
||||
private String actionName = null;//
|
||||
private String stdMsgTypeCode = null;// // [K, N] 값을 가짐 : Standard, Non-Standard
|
||||
|
||||
//어댑터정보
|
||||
private String adptrMsgType = null;//
|
||||
private String inAdapterOsidInstiNo = null;//
|
||||
private String testMasterYn = null;//
|
||||
private String bidInterface = null;//
|
||||
private String inAdapterUserEmpid = null;//
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
public String getAdapterGroupName() {
|
||||
return adapterGroupName;
|
||||
}
|
||||
public void setAdapterGroupName(String adapterGroupName) {
|
||||
this.adapterGroupName = adapterGroupName;
|
||||
}
|
||||
public String getAdapterName() {
|
||||
return adapterName;
|
||||
}
|
||||
public void setAdapterName(String adapterName) {
|
||||
this.adapterName = adapterName;
|
||||
}
|
||||
public String getEaiSvcCd() {
|
||||
return eaiSvcCd;
|
||||
}
|
||||
public void setEaiSvcCd(String eaiSvcCd) {
|
||||
this.eaiSvcCd = eaiSvcCd;
|
||||
}
|
||||
public boolean isTasStarted() {
|
||||
return isTasStarted;
|
||||
}
|
||||
public void setTasStarted(boolean isTasStarted) {
|
||||
this.isTasStarted = isTasStarted;
|
||||
}
|
||||
public long getErrTm() {
|
||||
return errTm;
|
||||
}
|
||||
public void setErrTm(long errTm) {
|
||||
this.errTm = errTm;
|
||||
}
|
||||
|
||||
public String getErrTypeCode() {
|
||||
return errTypeCode;
|
||||
}
|
||||
public void setErrTypeCode(String errTypeCode) {
|
||||
this.errTypeCode = errTypeCode;
|
||||
}
|
||||
public String getActionName() {
|
||||
return actionName;
|
||||
}
|
||||
public void setActionName(String actionName) {
|
||||
this.actionName = actionName;
|
||||
}
|
||||
public String getStdMsgTypeCode() {
|
||||
return stdMsgTypeCode;
|
||||
}
|
||||
public void setStdMsgTypeCode(String stdMsgTypeCode) {
|
||||
this.stdMsgTypeCode = stdMsgTypeCode;
|
||||
}
|
||||
public String getAdptrMsgType() {
|
||||
return adptrMsgType;
|
||||
}
|
||||
public void setAdptrMsgType(String adptrMsgType) {
|
||||
this.adptrMsgType = adptrMsgType;
|
||||
}
|
||||
public String getInAdapterOsidInstiNo() {
|
||||
return inAdapterOsidInstiNo;
|
||||
}
|
||||
public void setInAdapterOsidInstiNo(String inAdapterOsidInstiNo) {
|
||||
this.inAdapterOsidInstiNo = inAdapterOsidInstiNo;
|
||||
}
|
||||
public String getRspErrorCode() {
|
||||
return rspErrorCode;
|
||||
}
|
||||
public void setRspErrorCode(String rspErrorCode) {
|
||||
this.rspErrorCode = rspErrorCode;
|
||||
}
|
||||
public String getRspErrorMsg() {
|
||||
return rspErrorMsg;
|
||||
}
|
||||
public void setRspErrorMsg(String rspErrorMsg) {
|
||||
this.rspErrorMsg = rspErrorMsg;
|
||||
}
|
||||
|
||||
public String getTestMasterYn() {
|
||||
return testMasterYn;
|
||||
}
|
||||
public void setTestMasterYn(String testMasterYn) {
|
||||
this.testMasterYn = testMasterYn;
|
||||
}
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
public void setServerName(String serverName) {
|
||||
this.serverName = serverName;
|
||||
}
|
||||
public String getBidInterface() {
|
||||
return bidInterface;
|
||||
}
|
||||
public void setBidInterface(String bidInterface) {
|
||||
this.bidInterface = bidInterface;
|
||||
}
|
||||
public String getSelectedKey() {
|
||||
return selectedKey;
|
||||
}
|
||||
public void setSelectedKey(String selectedKey) {
|
||||
this.selectedKey = selectedKey;
|
||||
}
|
||||
public String getInAdapterUserEmpid() {
|
||||
return inAdapterUserEmpid;
|
||||
}
|
||||
public void setInAdapterUserEmpid(String inAdapterUserEmpid) {
|
||||
this.inAdapterUserEmpid = inAdapterUserEmpid;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.eactive.eai.inbound.processor;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public interface Processor
|
||||
{
|
||||
public static final String ADAPTER_GROUP_NAME = "ADAPTER_GROUP_NAME";
|
||||
public static final String ADAPTER_NAME = "ADAPTER_NAME";
|
||||
|
||||
public static final String STD_MESSAGE = "STD_MESSAGE";
|
||||
public static final String REQUEST_ACTION = "REQUEST_ACTION";
|
||||
|
||||
public static final String MESSAGE_TYPE = "MESSAGE_TYPE";
|
||||
|
||||
public static final String TAS_ADAPTER_GROUP_NAME = "TAS_ADAPTER_GROUP_NAME";
|
||||
|
||||
public Object execute(Object message, Properties prop) throws Exception;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.eactive.eai.inbound.processor;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.eactive.eai.common.server.Keys;
|
||||
import com.eactive.eai.message.StandardMessageUtil;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ProcessorFactory
|
||||
{
|
||||
private static Processor processor ;
|
||||
static{
|
||||
Class<Processor> processorClass = null;
|
||||
try {
|
||||
if (Keys.EAI_SYSTEM_TYPE_GW.equals(System.getProperty(Keys.EAI_SYSTEM_TYPE))) {
|
||||
processorClass = (Class<Processor>) Class.forName("com.eactive.eai.inbound.processor.GWRequestProcessor");
|
||||
} else if (StringUtils.isBlank(StandardMessageUtil.requestProcessorClass)) {
|
||||
processorClass = (Class<Processor>) Class.forName("com.eactive.eai.inbound.processor.RequestProcessor");
|
||||
} else {
|
||||
processorClass = (Class<Processor>) Class.forName(StandardMessageUtil.requestProcessorClass);
|
||||
}
|
||||
|
||||
processor = processorClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private ProcessorFactory() {
|
||||
}
|
||||
|
||||
public static Processor newInstance() {
|
||||
return processor;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
package com.eactive.eai.inbound.processor;
|
||||
|
||||
public class RequestProcessorException extends Exception
|
||||
{
|
||||
public RequestProcessorException() {
|
||||
super("RequestProcessorException is occured.");
|
||||
}
|
||||
|
||||
public RequestProcessorException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,556 @@
|
||||
package com.eactive.eai.inbound.processor;
|
||||
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
import com.eactive.eai.adapter.AdapterManager;
|
||||
import com.eactive.eai.adapter.http.HttpStatusException;
|
||||
import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthException;
|
||||
import com.eactive.eai.common.exception.ExceptionHandler;
|
||||
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.util.DatetimeUtil;
|
||||
import com.eactive.eai.common.util.InboundErrorLogger;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.common.util.MessageUtil;
|
||||
import com.eactive.eai.inbound.error.InboundErrorInfoVO;
|
||||
import com.eactive.eai.inbound.error.InboundErrorKeys;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.manager.StandardMessageManager;
|
||||
import com.eactive.eai.message.mapper.MessageMapper;
|
||||
import com.eactive.eai.transformer.util.IConv;
|
||||
|
||||
/**
|
||||
* 1. 기능 : Inbound Adapter를 통해 전달 받은 메시지를 EAIMessage로 변환하고
|
||||
* FlowControl로 전달하는 기능을 제공한다.
|
||||
* 2. 처리 개요 :
|
||||
* - STDMessage 생성
|
||||
* - EAIMessage 생성
|
||||
* - 요청 거래로깅
|
||||
* - FlowControl 호출
|
||||
* - 응답 거래로깅
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @author :
|
||||
* @version : v 1.0.0
|
||||
* @see :
|
||||
* @since :
|
||||
* :
|
||||
*/
|
||||
|
||||
public abstract class RequestProcessorSupport implements Processor
|
||||
{
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
protected static final String SERVICE_FLAG_MESSAGE = "SERVICE BLOCKED BY EAI SYSTEM";
|
||||
protected static final String STARTING_SERVICE_KEY = "ESBFW";
|
||||
|
||||
// 장애전문송신용 EAI 수신 가상어댑터 명
|
||||
protected static final String FAIL_MSG_RECEIVER = "FAIL_MSG_RECEIVER";
|
||||
|
||||
private static int rcvCount;
|
||||
private static int errCount;
|
||||
|
||||
private static boolean EAI_SERVICE_FLAG = true;
|
||||
|
||||
static Logger esbLogger = Logger.getLogger(Logger.LOGGER_ESBFW);
|
||||
protected int svrLogLevel;
|
||||
private static ThreadLocal local = new ThreadLocal(); //경과시간 동기화를 위한 ThreadLocal
|
||||
|
||||
public RequestProcessorSupport() {
|
||||
}
|
||||
|
||||
public boolean isEAIServiceFlag() {
|
||||
return EAI_SERVICE_FLAG;
|
||||
}
|
||||
|
||||
public void setEAIServiceFlag(boolean serviceFlag) {
|
||||
EAI_SERVICE_FLAG = serviceFlag;
|
||||
}
|
||||
|
||||
public static int rcvCount() {
|
||||
return rcvCount;
|
||||
}
|
||||
|
||||
public static int errCount() {
|
||||
return errCount;
|
||||
}
|
||||
|
||||
public synchronized static void resetCount() {
|
||||
rcvCount = 0;
|
||||
errCount = 0;
|
||||
}
|
||||
|
||||
private synchronized void increaseRcvCount() {
|
||||
rcvCount++;
|
||||
}
|
||||
|
||||
public synchronized void increaseErrCount() {
|
||||
errCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 기능 : RequestDispatcher에서 호출하기 위한 메소드로 내부의 hookup을 호출한다
|
||||
* 2. 처리 개요 :
|
||||
* - 메시지수신시각설정
|
||||
* - hookup 호출
|
||||
* - 요청 거래로깅
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param message Object 타입의 요청메시지
|
||||
* @param prop 호출시 전달할 Property 값(추후 확장을 위해)
|
||||
* @return Object
|
||||
* @throws JwtAuthException
|
||||
* @exception
|
||||
**/
|
||||
public Object execute(Object message, Properties prop) throws HttpStatusException
|
||||
{
|
||||
long msgRcvTm = System.currentTimeMillis();
|
||||
increaseRcvCount();
|
||||
local.set(new Long(msgRcvTm));
|
||||
|
||||
if (logger.isDebug()) logger.debug("RequestProcessor] starting - "+prop);
|
||||
Object result = null;
|
||||
String encode = "euc-kr";
|
||||
String messageType = "";
|
||||
try {
|
||||
messageType = prop.getProperty(Processor.MESSAGE_TYPE);
|
||||
encode = prop.getProperty(com.eactive.eai.adapter.Keys.CHARSET_KEY_IN);
|
||||
result = hookup(message, prop, msgRcvTm);
|
||||
return result;
|
||||
//return message;
|
||||
} catch(HttpStatusException e) {
|
||||
throw e;
|
||||
} catch(Exception e) {
|
||||
increaseErrCount();
|
||||
esbLogger.error("execute error", e);
|
||||
String msg = "";
|
||||
if (StringUtils.equalsAny(messageType, MessageType.JSON, MessageType.XML)) {
|
||||
throw new HttpStatusException(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value());
|
||||
} else {
|
||||
msg = ExceptionHandler.handle(e.getMessage());
|
||||
}
|
||||
|
||||
if(message instanceof byte[]) {
|
||||
byte[] response = null;
|
||||
// if(MessageUtil.isUTF8(messageType)) {
|
||||
// encode = "utf-8";
|
||||
// }
|
||||
try {
|
||||
response = msg.getBytes(encode);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
return msg.getBytes();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
else {
|
||||
return msg;
|
||||
}
|
||||
} finally {
|
||||
long msgSndTm = System.currentTimeMillis();
|
||||
if (logger.isDebug()) logger.debug("RequestProcessor] EAI 처리시각["+(msgSndTm-msgRcvTm)+" msec] - "+prop);
|
||||
if(svrLogLevel >= 1) {
|
||||
try{
|
||||
Long threadData = (Long)local.get();
|
||||
long processTm = msgSndTm - threadData.longValue();
|
||||
if (esbLogger.isInfo()) esbLogger.info("RequestProcessor] End... - 경과시간 : " + processTm + "(ms) - EAI Server Log Level is INFO");
|
||||
}catch (Exception e){
|
||||
logger.warn("execute", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 기능 : 미확인 메시지에 대한 로그
|
||||
* 2. 처리 개요 :
|
||||
* - Inbound Adapter를 통해 수신된 메시지에 대한 Rule을 확인할 수 없는 경우 로그출력
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param uuid EAI서비스일련번호
|
||||
* @param adapterGroupName Inbound Adapter 그룹명
|
||||
* @param adapterName Inbound Adapter 명
|
||||
* @param errCode 에러코드
|
||||
* @param errMsg 에러내용
|
||||
* @param errTm 에러발생시각
|
||||
* @param svcInstNm EAI서버인스턴스명
|
||||
* @param message Inbound Adapter가 수신받은 메시지 Object
|
||||
* @exception
|
||||
**/
|
||||
protected void logUnknownMessage(String uuid, String adapterGroupName, String
|
||||
adapterName, String bzwkSvcKeyName, String eaiSvcCd, boolean isTasStarted,
|
||||
String errCode, String errMsg, long errTm, String svcInstNm,String errDstCd, Object message) {
|
||||
String msg = null;
|
||||
|
||||
if(errDstCd == null || errDstCd.length() ==0) {
|
||||
errDstCd = "ND";
|
||||
}
|
||||
|
||||
if(isTasStarted) {
|
||||
errDstCd = InboundErrorKeys.TAS_START;
|
||||
}
|
||||
|
||||
InboundErrorInfoVO errorInfoVO = new InboundErrorInfoVO();
|
||||
errorInfoVO.setEaiSvcSno(uuid); // EAI서비스일련번호
|
||||
errorInfoVO.setAdptBwkGrpNm(adapterGroupName); // 어댑터업무그룹명
|
||||
errorInfoVO.setEaiSvcCd(eaiSvcCd);
|
||||
errorInfoVO.setErrCd(errCode); // 에러코드
|
||||
errorInfoVO.setErrTxt(errMsg); // 에러내용
|
||||
errorInfoVO.setErrTm(DatetimeUtil.getCurrentTime(errTm)); // 에러발생시각
|
||||
errorInfoVO.setErrDstcd(errDstCd);
|
||||
errorInfoVO.setBzwkSvcKeyName(bzwkSvcKeyName);
|
||||
|
||||
if(message == null) {
|
||||
msg = "null";
|
||||
}
|
||||
else {
|
||||
if(message instanceof byte[]) {
|
||||
AdapterManager adapterManager = AdapterManager.getInstance();
|
||||
AdapterGroupVO srcAdapterGrpVO = adapterManager.getAdapterGroupVO(adapterGroupName);
|
||||
|
||||
// TAS 거래일 경우 NULL일 수 있음
|
||||
if(srcAdapterGrpVO == null) {
|
||||
msg = new String((byte[])message);
|
||||
}
|
||||
else {
|
||||
// String srcAdapterMsgType = srcAdapterGrpVO.getMessageType();
|
||||
// if( MessageUtil.isUTF8(srcAdapterMsgType) ) {
|
||||
// try {
|
||||
// msg = new String((byte[])message, UJSONMessage.encode);
|
||||
// } catch (UnsupportedEncodingException e) {
|
||||
// logger.warn("msg encode error", e);
|
||||
// msg = new String((byte[])message); }
|
||||
// }
|
||||
// else {
|
||||
// msg = new String((byte[])message);
|
||||
// }
|
||||
|
||||
String charset = StringUtils.defaultIfBlank(srcAdapterGrpVO.getMessageEncode(), Charset.defaultCharset().name());
|
||||
try {
|
||||
msg = new String((byte[])message, charset);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.warn("msg encode error", e);
|
||||
msg = new String((byte[])message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else if(message instanceof String) {
|
||||
msg = (String)message;
|
||||
}
|
||||
else {
|
||||
msg = "invaild message ["+message.getClass().getName()+"] "+message.toString();
|
||||
}
|
||||
}
|
||||
|
||||
errorInfoVO.setBwkDataTxt(msg); // 업무데이터내용
|
||||
errorInfoVO.setEaiSvrInstNm(svcInstNm); // EAI서버인스턴스명
|
||||
|
||||
InboundErrorLogger.error(errorInfoVO);
|
||||
|
||||
if (logger.isError()) {
|
||||
logger.error("======================================================================" );
|
||||
logger.error(" RequestDispatcher] GET UNKNOWN MESSAGE");
|
||||
logger.error(" ADAPTER GROUP NAME [" + adapterGroupName + "]");
|
||||
logger.error(" EAISVCNAME [" + eaiSvcCd + "]");
|
||||
logger.error(" ADAPTER NAME [" + adapterName + "]");
|
||||
logger.error("======================================================================" );
|
||||
// logger.error("<< MESSAGE DUMP >>");
|
||||
// String[] dump = CommonLib.makeDumpFormat( msg.getBytes() );
|
||||
// for(int i=0; i< dump.length; i++) {
|
||||
// logger.error(dump[i]);
|
||||
// }
|
||||
// logger.error("======================================================================" );
|
||||
}
|
||||
|
||||
}
|
||||
protected void logUnknownMessage(ProcessVO vo, Object orgMessage) {
|
||||
if(MessageType.EBC.equals(vo.getAdptrMsgType())) {
|
||||
logUnknownMessage(vo.getUuid(), vo.getAdapterGroupName(), vo.getAdapterName(), vo.getSelectedKey(), vo.getEaiSvcCd(), vo.isTasStarted(),
|
||||
vo.getRspErrorCode(), vo.getRspErrorMsg(), vo.getErrTm(), vo.getServerName(),vo.getErrTypeCode(), IConv.ebcdicToASCII((byte[])orgMessage));
|
||||
}else{
|
||||
logUnknownMessage(vo.getUuid(), vo.getAdapterGroupName(), vo.getAdapterName(), vo.getSelectedKey(), vo.getEaiSvcCd(), vo.isTasStarted(),
|
||||
vo.getRspErrorCode(), vo.getRspErrorMsg(), vo.getErrTm(), vo.getServerName(),vo.getErrTypeCode(), orgMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 1. 기능 : ServiceFlag의 설정에 대한 경고메시지를 생성하여 리턴한다.
|
||||
* 2. 처리 개요 :
|
||||
* - 메시지의 유형에 따라 ServieFlag 메시지를 리턴한다.
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param inObj 요청메시지
|
||||
* @return Object
|
||||
**/
|
||||
// private Object makeServiceFlagMessage(Object inObj) {
|
||||
// Object retObject = null;
|
||||
//
|
||||
// if(inObj instanceof byte[]) {
|
||||
// retObject = SERVICE_FLAG_MESSAGE.getBytes();
|
||||
// }
|
||||
// else if(inObj instanceof byte[]) {
|
||||
// retObject = SERVICE_FLAG_MESSAGE;
|
||||
// }
|
||||
// else {
|
||||
// retObject = SERVICE_FLAG_MESSAGE;
|
||||
// }
|
||||
// return retObject;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 1. 기능 : 응답메시지 오브젝트에 따라 응답메시지를 생성하여 리턴
|
||||
* 2. 처리 개요 :
|
||||
* - Adapter메시지패턴에 따라 응답메시지를 생성하여 리턴
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param retEaiMsg 응답EAI메시지
|
||||
* @param message Object 타입의 요청메시지
|
||||
* @param retMsgObject 응답메시지오브젝트
|
||||
* @param adptrMsgPtrnCd Adapter메시지패턴 - [S, N, C] 값을 가짐 : Standard, Non-Standard, Custom
|
||||
* @param adptrMsgType Adapter 메시지 타입 - XML, ASC, FML, EBC
|
||||
* @param uuid 거래에 대한 Unique ID - 로깅을 위한 값
|
||||
* @return Object
|
||||
**/
|
||||
|
||||
public static Object getReturnObject(EAIMessage retEaiMsg, Object message, Object retMsgObject,
|
||||
String adptrMsgPtrnCd, String adptrMsgType, String uuid, String charset) {
|
||||
|
||||
if(com.eactive.eai.adapter.Keys.IF_STANDARD.equals(adptrMsgPtrnCd)) {
|
||||
StandardMessage stdMessage = retEaiMsg.getStandardMessage();
|
||||
try {
|
||||
stdMessage.setBizData(retMsgObject, charset);
|
||||
} catch (Exception e) {
|
||||
logger.error("setBizData failed.", e);
|
||||
}
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
standardManager.getMessageCoordinator().coordinateInReturnObject(stdMessage);
|
||||
/*
|
||||
|
||||
// if(MessageType.JSON.equals(adptrMsgType)
|
||||
// || MessageType.UJSON.equals(adptrMsgType)) {
|
||||
if(MessageType.JSON.equals(adptrMsgType)) {
|
||||
return stdMessage.toJson();
|
||||
}
|
||||
// else if(MessageType.XML.equals(adptrMsgType)
|
||||
// || MessageType.UXML.equals(adptrMsgType)) {
|
||||
else if(MessageType.XML.equals(adptrMsgType)) {
|
||||
return stdMessage.toXML();
|
||||
}
|
||||
else if(MessageType.ASC.equals(adptrMsgType)) {
|
||||
return stdMessage.toFixedString(charset);
|
||||
}
|
||||
else if(MessageType.EBC.equals(adptrMsgType)) {
|
||||
logger.error("Unsupported message type - " + MessageType.EBC);
|
||||
}
|
||||
// else if(MessageUtil.isUTF8(adptrMsgType)) {
|
||||
// return stdMessage.toJson();
|
||||
// }
|
||||
else {
|
||||
return retMsgObject;
|
||||
}
|
||||
return retMsgObject;
|
||||
*/
|
||||
String obj = null;
|
||||
try {
|
||||
obj = stdMessage.getDataString(adptrMsgType, charset);
|
||||
}catch(Exception e) {
|
||||
|
||||
}
|
||||
if(obj == null) return retMsgObject;
|
||||
return obj;
|
||||
}
|
||||
else if(com.eactive.eai.adapter.Keys.IF_SUBSTANDARD.equals(adptrMsgPtrnCd)) {
|
||||
StandardMessage stdMessage = retEaiMsg.getStandardMessage();
|
||||
StandardMessage subMessage = retEaiMsg.getSubMessage();
|
||||
try {
|
||||
subMessage.setBizData(retMsgObject, charset);
|
||||
} catch (Exception e) {
|
||||
logger.error("setBizData failed.", e);
|
||||
}
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
standardManager.getMessageCoordinator().coordinateInReturnObject(stdMessage);
|
||||
|
||||
if(MessageType.JSON.equals(adptrMsgType)) {
|
||||
return subMessage.toJson();
|
||||
}
|
||||
else if(MessageType.XML.equals(adptrMsgType)) {
|
||||
return subMessage.toXML();
|
||||
}
|
||||
else if(MessageType.ASC.equals(adptrMsgType)) {
|
||||
return subMessage.toFixedString(charset);
|
||||
}
|
||||
else if(MessageType.EBC.equals(adptrMsgType)) {
|
||||
logger.error("Unsupported message type - " + MessageType.EBC);
|
||||
}
|
||||
else {
|
||||
return retMsgObject;
|
||||
}
|
||||
return retMsgObject;
|
||||
}
|
||||
else {
|
||||
// 비표준 XML일 경우 XML Header Tag의 존재여부를 확인하여 없는 경우 추가해야 한다.
|
||||
// if(MessageType.XML.equals(adptrMsgType) || MessageType.UXML.equals(adptrMsgType)) {
|
||||
if(MessageType.XML.equals(adptrMsgType)) {
|
||||
// String encode = MessageType.XML_ENCODE;
|
||||
// if(MessageType.UXML.equals(adptrMsgType)) {
|
||||
// encode = MessageType.UXML_ENCODE;
|
||||
// }
|
||||
if(retMsgObject == null) {
|
||||
return "";
|
||||
}
|
||||
else if(message instanceof String) {
|
||||
String xmlString = (String)retMsgObject;
|
||||
if(xmlString.indexOf("<?") == -1 && xmlString.indexOf("?>") == -1) {
|
||||
xmlString = "<?xml version=\"1.0\" encoding=\""+ charset +"\"?>"
|
||||
+ xmlString;
|
||||
}
|
||||
return xmlString;
|
||||
}
|
||||
else if(message instanceof byte[]) {
|
||||
String xmlString = null;
|
||||
try {
|
||||
xmlString = new String( (byte[])retMsgObject, charset );
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
xmlString = new String( (byte[])retMsgObject);
|
||||
}
|
||||
if(xmlString.indexOf("<?") == -1 && xmlString.indexOf("?>") == -1) {
|
||||
xmlString = "<?xml version=\"1.0\" encoding=\""+ charset +"\"?>"
|
||||
+ xmlString;
|
||||
}
|
||||
byte[] responseBytes = null;
|
||||
try {
|
||||
responseBytes = xmlString.getBytes(charset);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
responseBytes = xmlString.getBytes();
|
||||
}
|
||||
return responseBytes;
|
||||
} else {
|
||||
return retMsgObject;
|
||||
}
|
||||
}else if(MessageType.JSON.equals(adptrMsgType)) {
|
||||
if(retMsgObject == null) {
|
||||
return "{}";
|
||||
}else if(retMsgObject instanceof byte[]) {
|
||||
byte[] bytesObject = (byte[])retMsgObject;
|
||||
if(bytesObject.length == 0) {
|
||||
return "{}";
|
||||
}
|
||||
}else if(retMsgObject instanceof String) {
|
||||
String stringObject = (String)retMsgObject;
|
||||
if(StringUtils.isBlank(stringObject)) {
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
|
||||
return retMsgObject;
|
||||
}else {
|
||||
return retMsgObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Object getRestrictedResponse(EAIMessage retEaiMsg, Object message,
|
||||
String adptrMsgPtrnCd, String adptrMsgType, String uuid, String charset) {
|
||||
if(com.eactive.eai.adapter.Keys.IF_STANDARD.equals(adptrMsgPtrnCd)) {
|
||||
return getRestrictedResponse(retEaiMsg, message, adptrMsgType, uuid, charset);
|
||||
}
|
||||
else {
|
||||
String eaiRestrictedRespose = "";
|
||||
if (StringUtils.equals(retEaiMsg.getRspErrCd(), EAIMessageKeys.EAI_INFLOW_BLOCKED_CODE)) {
|
||||
eaiRestrictedRespose = "It was not processed by flow control.[" + retEaiMsg.getEAISvcCd() + "]";
|
||||
} else {
|
||||
eaiRestrictedRespose = "It was not processed by transaction control.[" + retEaiMsg.getEAISvcCd() + "]";
|
||||
}
|
||||
if(MessageType.XML.equals(adptrMsgType)) {
|
||||
return MessageUtil.makeXmlErrorMessage(retEaiMsg.getRspErrCd(), retEaiMsg.getRspErrMsg(), charset);
|
||||
} else if (MessageType.JSON.equals(adptrMsgType)) {
|
||||
return MessageUtil.makeJsonErrorMessage(retEaiMsg.getRspErrCd(), retEaiMsg.getRspErrMsg());
|
||||
} else {
|
||||
try {
|
||||
return eaiRestrictedRespose.getBytes(charset);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return eaiRestrictedRespose.getBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getRestrictedResponse(EAIMessage retEaiMsg, Object message,
|
||||
String adptrMsgType, String uuid, String charset) {
|
||||
StandardMessage stdMessage = retEaiMsg.getStandardMessage();
|
||||
//InterfaceMapper mapper = retEaiMsg.getMapper();
|
||||
// String errorMessage = ExceptionUtil.make(retEaiMsg.getRspErrCd(), new String[]{retEaiMsg.getEAISvcCd()});
|
||||
// mapper.setErrorCode(stdMessage, STDMessageKeys.ERROR_CODE_VALUE);
|
||||
// mapper.setErrorMsg(stdMessage, errorMessage);
|
||||
//mapper.setErrorCode(stdMessage, retEaiMsg.getRspErrCd());
|
||||
//mapper.setErrorMsg(stdMessage, retEaiMsg.getRspErrMsg());
|
||||
|
||||
// 표준메시지에 BizData 셋팅할 필요 없을듯(요청 BizData 리턴)
|
||||
// try {
|
||||
// stdMessage.setBizData(errorMessage, charset);
|
||||
// } catch (Exception e) {
|
||||
// logger.error("setBizData failed.", e);
|
||||
// }
|
||||
/*
|
||||
// if(MessageType.JSON.equals(adptrMsgType)
|
||||
// || MessageType.UJSON.equals(adptrMsgType)) {
|
||||
if(MessageType.JSON.equals(adptrMsgType)) {
|
||||
return stdMessage.toJson();
|
||||
}
|
||||
// else if(MessageType.XML.equals(adptrMsgType)
|
||||
// || MessageType.UXML.equals(adptrMsgType)) {
|
||||
else if(MessageType.XML.equals(adptrMsgType)) {
|
||||
return stdMessage.toXML();
|
||||
}
|
||||
else if(MessageType.ASC.equals(adptrMsgType)) {
|
||||
return stdMessage.toFixedString(charset);
|
||||
}
|
||||
else if(MessageType.EBC.equals(adptrMsgType)) {
|
||||
logger.error("Unsupported message type - " + MessageType.EBC);
|
||||
}
|
||||
// else if(MessageUtil.isUTF8(adptrMsgType)) {
|
||||
// return stdMessage.toJson();
|
||||
// }
|
||||
else {
|
||||
return message;
|
||||
}
|
||||
return message;
|
||||
*/
|
||||
String obj = null;
|
||||
try {
|
||||
obj = stdMessage.getDataString(adptrMsgType, charset);
|
||||
}catch(Exception e) {
|
||||
|
||||
}
|
||||
if(obj==null) return message;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 기능 : Inbound Adapter를 통해 전달 받은 메시지를 EAIMessage로 변환하고
|
||||
* FlowControl로 전달하는 기능을 제공한다.
|
||||
* 2. 처리 개요 :
|
||||
* - KBMessage 생성
|
||||
* - EAIMessage 생성
|
||||
* - 요청 거래로깅
|
||||
* - FlowControl 호출
|
||||
* - 응답 거래로깅
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param message Object 타입의 요청메시지
|
||||
* @param prop 호출시 전달할 Property 값(추후 확장을 위해)
|
||||
* @param msgRcvTm 메시지 수신시각
|
||||
* @return Object
|
||||
* @exception RequestProcessorException
|
||||
**/
|
||||
abstract protected Object hookup(Object message, Properties prop, long msgRcvTm) throws RequestProcessorException, Exception ;
|
||||
}
|
||||
Reference in New Issue
Block a user