Path Variable처리, API식별방식 변경(DAO->STDMessageManager)
This commit is contained in:
+8
-3
@@ -235,12 +235,14 @@ public class HttpClient5AdapterServiceRest extends HttpClient5AdapterServiceSupp
|
||||
|
||||
logger.debug("HttpClientAdapterServiceRest] dataObject1 = [" + dataObject + "]");
|
||||
|
||||
// Path Variable 처리를 위해 Inbound에서 전달한 Variable Map
|
||||
Map<String, String> inboundPathVariables = (Map<String, String>) 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<String, String> 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);
|
||||
}
|
||||
|
||||
@@ -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<String, STDMsgInfoAddOnVO> getAllStdMsgInfos() throws DAOException {
|
||||
HashMap<String, STDMsgInfoAddOnVO> apiInfo = new HashMap<>();
|
||||
|
||||
EAIMessageManager eaiManager = EAIMessageManager.getInstance();
|
||||
EAIMessage eaiMsg = null;
|
||||
STDMsgInfoAddOnVO vo = null;
|
||||
try {
|
||||
List<StandardMessageInfo> 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<StandardMessageInfo> 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<StandardMessageInfo> 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"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ public class STDMessageManager implements Lifecycle {
|
||||
|
||||
private HashMap<String, StandardMessage> headers = new HashMap<>();
|
||||
private HashMap<String, StandardMessage> headersForPathVariables = new HashMap<>();
|
||||
private HashMap<String, STDMsgInfoAddOnVO> headerUrls = new HashMap<>();
|
||||
private HashMap<String, STDMsgInfoAddOnVO> 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<String, STDMsgInfoAddOnVO> 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<String, STDMsgInfoAddOnVO> entry : headerUrls.entrySet()) {
|
||||
if (StringUtils.equals(entry.getKey(), apiFullPath) ) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
String apiPathVariable = getMatchedUrlPathVariable(apiFullPath);
|
||||
for (Map.Entry<String, STDMsgInfoAddOnVO> 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<String> 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<String, STDMsgInfoAddOnVO> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user