SimpleFrameworkFilter 수정사항
기존 동작 그대로, 추가적으로 프로퍼티값으로 동적으로 헤더키 추가 조작할수 있게끔, AllHeaderFilter 추가 inboundHeader에서 들어오는 모든 헤더 넘기는 처리. 표준에서 사용하는 헤더(Content-Length..)들 그대로 넘기면 위험하니까 blackList 프로퍼티로 관리기능 추가.
This commit is contained in:
+122
@@ -0,0 +1,122 @@
|
||||
package com.eactive.eai.custom.kjb.adapter.http.client.filter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceSupport;
|
||||
import com.eactive.eai.common.TransactionContextKeys;
|
||||
import com.eactive.eai.common.property.PropManager;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
|
||||
public class AllHeaderFilter implements HttpClientAdapterFilter, HttpAdapterServiceKey {
|
||||
protected static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
|
||||
|
||||
public static final String PROPERTIES_GROUP_NAME = "HttpHeaderFilter";
|
||||
public static final String HEADER_KEY_NAMES = "AllHeaderFilter.blackList";
|
||||
|
||||
|
||||
String[] HttpHeaderRelayBlackList = {
|
||||
"Transfer-Encoding",
|
||||
"Host",
|
||||
"Authorization",
|
||||
"Accept",
|
||||
"Host",
|
||||
"Cookie",
|
||||
"Connection",
|
||||
"Keep-Alive",
|
||||
"Proxy-Authenticate",
|
||||
"Proxy-Authorization",
|
||||
"TE",
|
||||
"Trailer",
|
||||
"Transfer-Encoding",
|
||||
"Upgrade",
|
||||
"Content-Type",
|
||||
"Content-Encoding",
|
||||
"Content-Language",
|
||||
"Content-Location",
|
||||
"Content-MD5",
|
||||
"Expect",
|
||||
};
|
||||
|
||||
@Override
|
||||
public Object doPreFilter(String adptGrpName, String adptName, Properties prop, Object message, Properties tempProp)
|
||||
throws Exception {
|
||||
|
||||
logger.debug("doPreFilter Processing Start.");
|
||||
|
||||
Properties filterHeaders = (Properties) tempProp.get("FILTERHEADER");
|
||||
if (filterHeaders == null) {
|
||||
filterHeaders = new Properties();
|
||||
tempProp.put("FILTERHEADER", filterHeaders);
|
||||
}
|
||||
|
||||
Map<String, String> inboundHeaderMap = getInboundHeaderProp(tempProp);
|
||||
|
||||
String propValue = PropManager.getInstance().getProperty(PROPERTIES_GROUP_NAME, HEADER_KEY_NAMES, "").trim();
|
||||
|
||||
String[] userSettingBlackList = propValue.split(",");
|
||||
|
||||
if( userSettingBlackList.length > 0 ) {
|
||||
HttpHeaderRelayBlackList = Stream
|
||||
.concat(Arrays.stream(HttpHeaderRelayBlackList), Arrays.stream(userSettingBlackList))
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
|
||||
|
||||
for(String keyName : inboundHeaderMap.keySet() ) {
|
||||
|
||||
if( StringUtils.equalsAnyIgnoreCase( keyName, HttpHeaderRelayBlackList ) ) {
|
||||
logger.debug("Skip Processing Key ["+keyName+"], value ["+inboundHeaderMap.get(keyName)+"] in HttpHeaderRelayBlackList");
|
||||
continue;
|
||||
}
|
||||
|
||||
filterHeaders.put(keyName, inboundHeaderMap.get(keyName));
|
||||
logger.debug("Processing Key ["+keyName+"], value ["+inboundHeaderMap.get(keyName)+"]");
|
||||
}
|
||||
|
||||
logger.debug("doPreFilter Processing End.");
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public Map<String, String> getInboundHeaderProp(Properties prop) {
|
||||
Properties header = new Properties();
|
||||
Map<String, String> inboundHeaderMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||
try {
|
||||
Object headerObj = prop.get(HttpAdapterServiceKey.INBOUND_HEADER);
|
||||
if (headerObj instanceof Properties) { //tomcat
|
||||
header = (Properties) headerObj;
|
||||
for (String name : header.stringPropertyNames()) {
|
||||
inboundHeaderMap.put(name, header.getProperty(name));
|
||||
}
|
||||
} else if (headerObj instanceof String) { //weblogic
|
||||
String str = (String) headerObj;
|
||||
str = str.substring(1, str.length() - 1);
|
||||
// key=value 쌍 분리
|
||||
String[] entries = str.split(",");
|
||||
for (String entry : entries) {
|
||||
String[] kv = entry.split("=", 2);
|
||||
if (kv.length == 2) {
|
||||
inboundHeaderMap.put(kv[0].trim(), kv[1].trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return inboundHeaderMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object doPostFilter(String adptGrpName, String adptName, Properties prop, Object message,
|
||||
Properties tempProp) throws Exception {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-1
@@ -50,7 +50,10 @@ public class HttpClient5AdapterFilterFactory {
|
||||
break;
|
||||
case ASYNCRESPONSE:
|
||||
filter = new AsyncReponseFilter();
|
||||
break;
|
||||
break;
|
||||
case ALLHEADER:
|
||||
filter = new AllHeaderFilter();
|
||||
break;
|
||||
default:
|
||||
filter = classForName(type);
|
||||
if (filter == null) {
|
||||
|
||||
+1
@@ -11,6 +11,7 @@ public enum HttpClient5AdapterFilterType {
|
||||
NICECREDIT,
|
||||
TOSSBANK,
|
||||
ASYNCRESPONSE,
|
||||
ALLHEADER,
|
||||
UNKNOWN;
|
||||
|
||||
public static HttpClient5AdapterFilterType getValue(String type) {
|
||||
|
||||
+34
-36
@@ -7,18 +7,14 @@ import java.util.TreeMap;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceSupport;
|
||||
import com.eactive.eai.common.TransactionContextKeys;
|
||||
import com.eactive.eai.common.property.PropManager;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
|
||||
public class SimpleFrameworkFilter implements HttpClientAdapterFilter, HttpAdapterServiceKey {
|
||||
protected static Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);
|
||||
|
||||
public static final String CLIENTID = "clientId";
|
||||
public static final String TRACEID = "traceId";
|
||||
public static final String GUID = "guid";
|
||||
public static final String RECEIVEDTIMESTAMP = "receivedTimestamp";
|
||||
public static final String PARTNER_TRACE_ID = "partnerTraceId";
|
||||
public static final String PROPERTIES_GROUP_NAME = "HttpHeaderFilter";
|
||||
public static final String HEADER_KEY_NAMES = "SimpleFrameworkFilter";
|
||||
|
||||
@Override
|
||||
public Object doPreFilter(String adptGrpName, String adptName, Properties prop, Object message, Properties tempProp)
|
||||
@@ -32,38 +28,40 @@ public class SimpleFrameworkFilter implements HttpClientAdapterFilter, HttpAdapt
|
||||
tempProp.put("FILTERHEADER", filterHeaders);
|
||||
}
|
||||
|
||||
Map<String, String> inboundHeaderMap = getInboundHeaderProp(tempProp);
|
||||
String propValue = PropManager.getInstance().getProperty(PROPERTIES_GROUP_NAME, HEADER_KEY_NAMES, "").trim();
|
||||
|
||||
String[] headerKeyNames = propValue.split(",");
|
||||
|
||||
if( StringUtils.isAnyBlank(headerKeyNames) ) {
|
||||
headerKeyNames = new String[]{"clientId", "TRANSACTION_UUID", "GUID","INBOUND_REQUESTED_TIME","receivedTimestamp","partnerTraceId","X-LOAN-TOKEN"};
|
||||
}
|
||||
|
||||
for(String headerKeyName : headerKeyNames) {
|
||||
headerKeyName = headerKeyName.trim();
|
||||
}
|
||||
|
||||
Map<String, String> inboundHeaderMap = getInboundHeaderProp(tempProp);
|
||||
|
||||
try {
|
||||
/* 업체정보 */
|
||||
String clientId = tempProp.getProperty(HttpAdapterServiceSupport.PROPERTIES_NAME_CLIENT_ID);
|
||||
if (StringUtils.isEmpty(clientId)) clientId = "";
|
||||
filterHeaders.put(CLIENTID, clientId);
|
||||
logger.debug("SimpleFrameworkFilter] Processing Key ["+CLIENTID+"], value ["+clientId+"]");
|
||||
|
||||
/* APIM 거래추적자 */
|
||||
String uuid = tempProp.getProperty(TransactionContextKeys.TRANSACTION_UUID, "");
|
||||
filterHeaders.put(TRACEID, uuid);
|
||||
logger.debug("SimpleFrameworkFilter] Processing Key ["+TRACEID+"], value ["+uuid+"]");
|
||||
|
||||
/* GUID */
|
||||
String guid = tempProp.getProperty(TransactionContextKeys.GUID, "");
|
||||
filterHeaders.put(GUID, guid);
|
||||
logger.debug("SimpleFrameworkFilter] Processing Key ["+GUID+"], value ["+guid+"]");
|
||||
|
||||
/* 최초요청시간 */
|
||||
String receivedTimestamp = tempProp.getProperty(HttpAdapterServiceKey.INBOUND_REQUESTED_TIME, "");
|
||||
filterHeaders.put(RECEIVEDTIMESTAMP, receivedTimestamp);
|
||||
logger.debug("SimpleFrameworkFilter] Processing Key ["+RECEIVEDTIMESTAMP+"], value ["+receivedTimestamp+"]");
|
||||
for ( Object key : tempProp.keySet() ) {
|
||||
String keyName = (String) key;
|
||||
|
||||
if( StringUtils.equalsAnyIgnoreCase(keyName, headerKeyNames) ) {
|
||||
String value = (String) tempProp.get(keyName);
|
||||
filterHeaders.put(keyName, value);
|
||||
logger.debug("SimpleFrameworkFilter] Processing Key ["+keyName+"], value ["+value+"]");
|
||||
}
|
||||
}
|
||||
|
||||
String partnerTraceId = inboundHeaderMap.getOrDefault(PARTNER_TRACE_ID, "");
|
||||
filterHeaders.put(PARTNER_TRACE_ID, partnerTraceId);
|
||||
logger.debug("SimpleFrameworkFilter] Processing Key ["+PARTNER_TRACE_ID+"], value ["+partnerTraceId+"]");
|
||||
|
||||
String x_loan_token = inboundHeaderMap.getOrDefault(TransactionContextKeys.X_LOAN_TOKEN, "");
|
||||
filterHeaders.put(TransactionContextKeys.X_LOAN_TOKEN, x_loan_token);
|
||||
logger.debug("SimpleFrameworkFilter] Processing Key ["+TransactionContextKeys.X_LOAN_TOKEN+"], value ["+x_loan_token+"]");
|
||||
|
||||
for( String keyName : inboundHeaderMap.keySet() ) {
|
||||
|
||||
if( StringUtils.equalsAnyIgnoreCase(keyName, headerKeyNames) ) {
|
||||
String value = inboundHeaderMap.get(keyName);
|
||||
filterHeaders.put(keyName, value);
|
||||
logger.debug("SimpleFrameworkFilter] Processing Key ["+keyName+"], value ["+value+"]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user