afterFoundEaiMessage 함수에 프러퍼티 이용 헤더매핑 로직 추가
- DJB_IN_HTTHEAD_STDHEAD_MAPPING 프러퍼티 그룹 이용
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package com.eactive.eai.custom.inbound.processor;
|
package com.eactive.eai.custom.inbound.processor;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@@ -9,8 +13,13 @@ import com.eactive.eai.common.inflow.InflowTargetVO;
|
|||||||
import com.eactive.eai.common.inflow.dual.DualBucket;
|
import com.eactive.eai.common.inflow.dual.DualBucket;
|
||||||
import com.eactive.eai.common.inflow.dual.DualCustomBucket;
|
import com.eactive.eai.common.inflow.dual.DualCustomBucket;
|
||||||
import com.eactive.eai.common.message.EAIMessage;
|
import com.eactive.eai.common.message.EAIMessage;
|
||||||
|
import com.eactive.eai.common.property.PropManager;
|
||||||
|
import com.eactive.eai.common.util.Logger;
|
||||||
import com.eactive.eai.custom.inflow.ClientDualBucket;
|
import com.eactive.eai.custom.inflow.ClientDualBucket;
|
||||||
|
import com.eactive.eai.inbound.processor.ProcessVO;
|
||||||
import com.eactive.eai.inbound.processor.RequestProcessor;
|
import com.eactive.eai.inbound.processor.RequestProcessor;
|
||||||
|
import com.eactive.eai.message.StandardItem;
|
||||||
|
import com.eactive.eai.message.StandardMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 어댑터/인터페이스/클라이언트 유량제어 차단 시 어느 버킷(PER_SECOND/THRESHOLD)에서
|
* 어댑터/인터페이스/클라이언트 유량제어 차단 시 어느 버킷(PER_SECOND/THRESHOLD)에서
|
||||||
@@ -24,6 +33,81 @@ import com.eactive.eai.inbound.processor.RequestProcessor;
|
|||||||
* <p>Spring Bean 등록 후 기존 RequestProcessor 대신 이 클래스를 어댑터에 설정한다.
|
* <p>Spring Bean 등록 후 기존 RequestProcessor 대신 이 클래스를 어댑터에 설정한다.
|
||||||
*/
|
*/
|
||||||
public class DJBRequestProcessor extends RequestProcessor {
|
public class DJBRequestProcessor extends RequestProcessor {
|
||||||
|
|
||||||
|
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void afterFoundEaiMessage(EAIMessage eaiMsg, ProcessVO vo, Properties prop) {
|
||||||
|
logger.debug("DJBRequestProcessor interface found.");
|
||||||
|
try {
|
||||||
|
this.resolveStandardHeaderMapping(eaiMsg, prop);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("DJBRequestProcessor header set failed.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveStandardHeaderMapping(EAIMessage eaiMsg, Properties prop) {
|
||||||
|
StandardMessage standardMessage = eaiMsg.getStandardMessage();
|
||||||
|
HashMap<String, String> headerMapping = getPropertyMap("DJB_IN_HTTHEAD_STDHEAD_MAPPING", eaiMsg.getSngSysItfTp());
|
||||||
|
|
||||||
|
for (Entry<String, String> entry : headerMapping.entrySet()) {
|
||||||
|
String stdHeaderPath = entry.getKey();
|
||||||
|
int dotIdx = stdHeaderPath.indexOf('.');
|
||||||
|
if(dotIdx > 0) {
|
||||||
|
String firstPath = stdHeaderPath.substring(0, dotIdx);
|
||||||
|
StandardItem topLevelItem = standardMessage.findItem(firstPath);
|
||||||
|
topLevelItem.setHidden(false);
|
||||||
|
}
|
||||||
|
StandardItem item = standardMessage.findItem(entry.getKey());
|
||||||
|
|
||||||
|
String value = resolveNestedValue(prop, entry.getValue());
|
||||||
|
if (item != null && value != null)
|
||||||
|
item.setValue(value);
|
||||||
|
else
|
||||||
|
logger.debug("header mapping item not found : {} ", entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, String> getPropertyMap(String propertyGroupName, String prefix) {
|
||||||
|
Properties prop = PropManager.getInstance().getProperties(propertyGroupName);
|
||||||
|
Set<String> keys = prop.stringPropertyNames();
|
||||||
|
HashMap<String, String> tmpToJsonArrayInterface = new HashMap<>();
|
||||||
|
for (String key : keys) {
|
||||||
|
if (StringUtils.startsWith(key, prefix + ".")) {
|
||||||
|
String propValue = prop.getProperty(key);
|
||||||
|
String replacedKey = StringUtils.replace(key, prefix + ".", "");
|
||||||
|
tmpToJsonArrayInterface.put(replacedKey, propValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tmpToJsonArrayInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveNestedValue(Map<?, ?> map, String keyPath) {
|
||||||
|
int dotIdx = keyPath.indexOf('.');
|
||||||
|
if (dotIdx < 0) {
|
||||||
|
Object val = map.get(keyPath);
|
||||||
|
if (val == null)
|
||||||
|
return null;
|
||||||
|
if (val instanceof String)
|
||||||
|
return (String) val;
|
||||||
|
return val.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
String first = keyPath.substring(0, dotIdx);
|
||||||
|
String rest = keyPath.substring(dotIdx + 1);
|
||||||
|
Object val = map.get(first);
|
||||||
|
if (val instanceof Map) {
|
||||||
|
return resolveNestedValue((Map<?, ?>) val, rest);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 폴백: 전체 keyPath를 단일 키로 조회
|
||||||
|
Object direct = map.get(keyPath);
|
||||||
|
if (direct == null)
|
||||||
|
return null;
|
||||||
|
if (direct instanceof String)
|
||||||
|
return (String) direct;
|
||||||
|
return direct.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String checkCustomInflow(Bucket bucket, EAIMessage eaiMsg, Properties prop) {
|
protected String checkCustomInflow(Bucket bucket, EAIMessage eaiMsg, Properties prop) {
|
||||||
|
|||||||
Reference in New Issue
Block a user