diff --git a/src/main/java/com/eactive/eai/custom/inbound/processor/DJBRequestProcessor.java b/src/main/java/com/eactive/eai/custom/inbound/processor/DJBRequestProcessor.java index d356c6b..34d2be3 100644 --- a/src/main/java/com/eactive/eai/custom/inbound/processor/DJBRequestProcessor.java +++ b/src/main/java/com/eactive/eai/custom/inbound/processor/DJBRequestProcessor.java @@ -1,6 +1,10 @@ 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.Set; 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.DualCustomBucket; 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.inbound.processor.ProcessVO; import com.eactive.eai.inbound.processor.RequestProcessor; +import com.eactive.eai.message.StandardItem; +import com.eactive.eai.message.StandardMessage; /** * 어댑터/인터페이스/클라이언트 유량제어 차단 시 어느 버킷(PER_SECOND/THRESHOLD)에서 @@ -24,6 +33,81 @@ import com.eactive.eai.inbound.processor.RequestProcessor; *

Spring Bean 등록 후 기존 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 headerMapping = getPropertyMap("DJB_IN_HTTHEAD_STDHEAD_MAPPING", eaiMsg.getSngSysItfTp()); + + for (Entry 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 getPropertyMap(String propertyGroupName, String prefix) { + Properties prop = PropManager.getInstance().getProperties(propertyGroupName); + Set keys = prop.stringPropertyNames(); + HashMap 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 protected String checkCustomInflow(Bucket bucket, EAIMessage eaiMsg, Properties prop) {