diff --git a/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java b/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java index 9d8a195..4ee9b4c 100644 --- a/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java +++ b/src/main/java/com/eactive/eai/adapter/http/client/impl/HttpClient5AdapterServiceRest.java @@ -235,12 +235,14 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp logger.debug("HttpClientAdapterServiceRest] dataObject1 = [" + dataObject + "]"); + // Path Variable 처리를 위해 Inbound에서 전달한 Variable Map + Map inboundPathVariables = (Map) tempProp.get(HttpAdapterServiceKey.INBOUND_PATH_VARIABLES); // interface 에 설정된게 우선한다. String uri = null; if (dataObject == null) { - uri = changeUrl(messageType, vo.getUrl(), restOptionData, sendData); + uri = changeUrl(messageType, vo.getUrl(), restOptionData, sendData, inboundPathVariables); } else { - uri = changeUrl(messageType, vo.getUrl(), restOptionData, dataObject); + uri = changeUrl(messageType, vo.getUrl(), restOptionData, dataObject, inboundPathVariables); } logger.debug("HttpClientAdapterServiceRest] dataObject2 = [" + dataObject + "]"); @@ -1468,7 +1470,7 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp } @SuppressWarnings("deprecation") - private String changeUrl(String messageType, String url, String restOption, Object sendData) { + private String changeUrl(String messageType, String url, String restOption, Object sendData, Map inboundPathVariables) { if ((MessageType.JSON.equals(messageType) || MessageType.XML.equals(messageType))) { try { if (StringUtils.isBlank(restOption)) { @@ -1501,6 +1503,9 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp for (Object tempObject : uriVariables) { String urlVaribleId = (String) tempObject; String uriVariable = (String) jsonObject.get(urlVaribleId); + if (StringUtils.isBlank(uriVariable) && inboundPathVariables.containsKey(urlVaribleId)) { + uriVariable = inboundPathVariables.get(urlVaribleId); + } urlVariableList.add(uriVariable); jsonObject.remove(urlVaribleId); } diff --git a/src/main/java/com/eactive/eai/common/stdmessage/STDMessageDAO.java b/src/main/java/com/eactive/eai/common/stdmessage/STDMessageDAO.java index 447fe75..307845c 100644 --- a/src/main/java/com/eactive/eai/common/stdmessage/STDMessageDAO.java +++ b/src/main/java/com/eactive/eai/common/stdmessage/STDMessageDAO.java @@ -12,9 +12,13 @@ import org.springframework.transaction.annotation.Transactional; import com.eactive.eai.common.dao.BaseDAO; import com.eactive.eai.common.dao.DAOException; import com.eactive.eai.common.exception.ExceptionUtil; +import com.eactive.eai.common.message.EAIMessage; +import com.eactive.eai.common.message.EAIMessageDAO; +import com.eactive.eai.common.message.EAIMessageManager; import com.eactive.eai.common.stdmessage.loader.StandardMessageInfoLoader; import com.eactive.eai.common.stdmessage.loader.StandardMessageRestoreService; import com.eactive.eai.common.util.Logger; +import com.eactive.eai.data.entity.onl.message.EAIMessageEntity; import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageInfo; import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageItem; import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageRestore; @@ -231,5 +235,64 @@ public class STDMessageDAO extends BaseDAO { return optional.orElseThrow(() -> new DAOException("해당 full path의 TSEAIHS04 에 데이터가 없습니다.")); } + // Path Variable 처리를 위한 Method/FullURL 베이스 처리. + public HashMap getAllStdMsgInfos() throws DAOException { + HashMap apiInfo = new HashMap<>(); + + EAIMessageManager eaiManager = EAIMessageManager.getInstance(); + EAIMessage eaiMsg = null; + STDMsgInfoAddOnVO vo = null; + try { + List list = standardMessageInfoLoader.findAll(); + for (StandardMessageInfo info : list) { + eaiMsg = eaiManager.getEAIMessage(info.getEaisvcname()); + vo = new STDMsgInfoAddOnVO(); + vo.setBzwksvckeyname(info.getBzwksvckeyname()); + vo.setEaiSvcCd(info.getEaisvcname()); + vo.setApiFullPath(info.getApifullpath()); + vo.setAdapterGroupName(eaiMsg.getSngSysItfTp()); + apiInfo.put(vo.getApiFullPath(), vo); + } + return apiInfo; + } catch (Exception e) { + throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICKE102"), e); + } + } + public STDMsgInfoAddOnVO getUrlStdMsgInfo(String apiFullPath) throws DAOException { + EAIMessageManager eaiManager = EAIMessageManager.getInstance(); + EAIMessage eaiMsg = null; + STDMsgInfoAddOnVO vo = null; + try { + Optional optional = standardMessageInfoLoader.findByApiFullPath(apiFullPath); + if (optional.isPresent()) { + StandardMessageInfo info = optional.get(); + eaiMsg = eaiManager.getEAIMessage(info.getEaisvcname()); + vo.setBzwksvckeyname(info.getBzwksvckeyname()); + vo.setEaiSvcCd(info.getEaisvcname()); + vo.setApiFullPath(info.getApifullpath()); + vo.setAdapterGroupName(eaiMsg.getSngSysItfTp()); + } + return vo; + } catch (Exception e) { + throw new DAOException("RECEAICKE110"); + } + } + + public String getApiFullPath(String serviceKey) throws DAOException { + try { + Optional optional = standardMessageInfoLoader.findById(serviceKey); + if (optional.isPresent()) { + StandardMessageInfo info = optional.get(); + return info.getApifullpath(); + } else { + throw new DAOException("RECEAICKE110"); + } + } catch (DAOException e) { + throw e; + } catch(Exception e) { + throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICKE111")); + } + } + } diff --git a/src/main/java/com/eactive/eai/common/stdmessage/STDMessageManager.java b/src/main/java/com/eactive/eai/common/stdmessage/STDMessageManager.java index 08d440d..ed14e24 100644 --- a/src/main/java/com/eactive/eai/common/stdmessage/STDMessageManager.java +++ b/src/main/java/com/eactive/eai/common/stdmessage/STDMessageManager.java @@ -30,6 +30,8 @@ public class STDMessageManager implements Lifecycle { private HashMap headers = new HashMap<>(); private HashMap headersForPathVariables = new HashMap<>(); + private HashMap headerUrls = new HashMap<>(); + private HashMap headerUrlsForPathVariables = new HashMap<>(); private boolean started; private LifecycleSupport lifecycle = new LifecycleSupport(this); @@ -60,6 +62,14 @@ public class STDMessageManager implements Lifecycle { headersForPathVariables.put(entry.getKey(), entry.getValue()); } } + // url base로 처리 추가. + headerUrls = sTDMessageDAO.getAllStdMsgInfos(); + headerUrlsForPathVariables.clear(); + for (Map.Entry entry : headerUrls.entrySet()) { + if (isPathVariable(entry.getKey())) { + headerUrlsForPathVariables.put(entry.getKey(), entry.getValue()); + } + } } public static boolean isPathVariable(String key) { @@ -86,6 +96,17 @@ public class STDMessageManager implements Lifecycle { } else { throw new Exception("STDMessage not found in Database : key[" + keyName + "]"); } + // url base로 처리 추가. + String apiFullPath = sTDMessageDAO.getApiFullPath(keyName); + STDMsgInfoAddOnVO msgUrl = sTDMessageDAO.getUrlStdMsgInfo(apiFullPath); + if (msgUrl != null) { + headerUrls.put(apiFullPath, msgUrl); + if (isPathVariable(apiFullPath)) { + headerUrlsForPathVariables.put(apiFullPath, msgUrl); + } + } else { + throw new Exception("STDMessage not found in Database : key[" + apiFullPath + "]"); + } } public void stop() throws LifecycleException { @@ -145,6 +166,41 @@ public class STDMessageManager implements Lifecycle { return null; } + // apiFullPath 기준 Path Variable 조회 + public StandardMessage getSTDMessageForUrlPathVariable(String apiFullPath) { + String matchedKey = getMatchedUrlPathVariable(apiFullPath); + if (matchedKey != null) { + return getSTDMessage(matchedKey); + } else { + return null; + } + } + + public String getMatchedUrlPathVariable(String apiFullPath) { + AntPathMatcher matcher = new AntPathMatcher(); + for (String key : headerUrlsForPathVariables.keySet()) { + if (matcher.match(key, apiFullPath)) { + return key; + } + } + return null; + } + + public STDMsgInfoAddOnVO getStdMsgInfoAddOn(String apiFullPath) { + for (Map.Entry entry : headerUrls.entrySet()) { + if (StringUtils.equals(entry.getKey(), apiFullPath) ) { + return entry.getValue(); + } + } + String apiPathVariable = getMatchedUrlPathVariable(apiFullPath); + for (Map.Entry entry : headerUrlsForPathVariables.entrySet()) { + if (StringUtils.equals(entry.getKey(), apiPathVariable) ) { + return entry.getValue(); + } + } + return null; + } + public String[] getAllSTDMessageKeys() { String[] ks = new String[this.headers.size()]; Iterator it = this.headers.keySet().iterator(); @@ -163,6 +219,19 @@ public class STDMessageManager implements Lifecycle { } return al; } + + // 업무서비스키로 기 동록된 apiFullPath 가져오기. + public String getApiFullPath(String serviceKey) { + String apiFullPath = ""; + for (Map.Entry entry : headerUrls.entrySet()) { + STDMsgInfoAddOnVO msgVO = entry.getValue(); + if (StringUtils.equals(serviceKey, msgVO.getBzwksvckeyname())) { + apiFullPath = msgVO.getApiFullPath(); + return apiFullPath; + } + } + return null; + } public void addSTDMessage(StandardMessage msg) { this.headers.put(msg.getServiceKey(), msg); @@ -175,5 +244,9 @@ public class STDMessageManager implements Lifecycle { public synchronized void removeSTDMessage(String bwkSvcKey) { this.headers.remove(bwkSvcKey); this.headersForPathVariables.remove(bwkSvcKey); + // apiFullPath 기준 등록정보 삭제. + String apiFullPath = getApiFullPath(bwkSvcKey); + this.headerUrls.remove(apiFullPath); + this.headerUrlsForPathVariables.remove(apiFullPath); } } diff --git a/src/main/java/com/eactive/eai/common/stdmessage/STDMsgInfoAddOnVO.java b/src/main/java/com/eactive/eai/common/stdmessage/STDMsgInfoAddOnVO.java new file mode 100644 index 0000000..cf9aa5a --- /dev/null +++ b/src/main/java/com/eactive/eai/common/stdmessage/STDMsgInfoAddOnVO.java @@ -0,0 +1,40 @@ +package com.eactive.eai.common.stdmessage; + +import org.json.simple.JSONObject; + +public class STDMsgInfoAddOnVO { + + private String bzwksvckeyname = null;// 업무서비스키 + private String eaiSvcCd = null;// EAI서비스코드 + private String apiFullPath = null;// Method/Url + private String adapterGroupName = null;// 인바운드 어댑터그룹 + + public String getBzwksvckeyname() { + return bzwksvckeyname; + } + public void setBzwksvckeyname(String bzwksvckeyname) { + this.bzwksvckeyname = bzwksvckeyname; + } + + public String getEaiSvcCd() { + return eaiSvcCd; + } + public void setEaiSvcCd(String eaiSvcCd) { + this.eaiSvcCd = eaiSvcCd; + } + + public String getApiFullPath() { + return apiFullPath; + } + public void setApiFullPath(String apiFullPath) { + this.apiFullPath = apiFullPath; + } + + public String gAdapterGroupName() { + return adapterGroupName; + } + public void setAdapterGroupName(String adapterGroupName) { + this.adapterGroupName = adapterGroupName; + } + +}