URL과 header 값 라우팅 기능 통합 action 개발
This commit is contained in:
+106
@@ -0,0 +1,106 @@
|
||||
package com.eactive.eai.custom.inbound.action;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
import com.eactive.eai.adapter.AdapterManager;
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
||||
import com.eactive.eai.adapter.http.dynamic.impl.HttpAdapterServiceRest;
|
||||
import com.eactive.eai.common.messagekey.MessageKeyFldVO;
|
||||
import com.eactive.eai.common.messagekey.MessageKeyGroupVO;
|
||||
import com.eactive.eai.common.messagekey.MessageKeyManager;
|
||||
import com.eactive.eai.common.messagekey.MessageKeyVO;
|
||||
import com.eactive.eai.inbound.action.ActionException;
|
||||
import com.eactive.eai.inbound.action.RequestActionSupport;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class DJBRestAdapterMethodHeaderRequestAction extends RequestActionSupport {
|
||||
public static final String STEMSG_METHOD_DELIMITER = ":";
|
||||
|
||||
public static final String STEMSG_SERVICE_URL_DELIMITER = "|";
|
||||
|
||||
public static final String STEMSG_SERVICE_HEADER_DELIMITER = "^";
|
||||
|
||||
public static final String STEMSG_HEADER_SEPARATOR = ";";
|
||||
|
||||
/**
|
||||
* 1. 기능 : Inbound Adapter를 통해 전달받은 비표준메시지에서 표준메시지를 생성하기 위한 키값을 추출
|
||||
* 2. 처리 개요 :
|
||||
* - MessageKeyExtractor를 통해 Adapter별 추출 Rule에 따라 메시지를 구분할 수 있는 키값을 추출한다.
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param message Object 타입의 요청메시지
|
||||
* @return String 비표준메시지의 메시지키값
|
||||
* @exception
|
||||
**/
|
||||
public String[] perform(Object message) throws ActionException {
|
||||
|
||||
AdapterManager adapterManager = AdapterManager.getInstance();
|
||||
AdapterGroupVO adptGrpVO = adapterManager.getAdapterGroupVO(adapterGroupName);
|
||||
String adptGrpName = adptGrpVO.getName();
|
||||
|
||||
String requestMethod = prop.getProperty(HttpAdapterServiceRest.PROPERTIES_NAME_HTTP_REQUEST_METHOD);
|
||||
|
||||
// /api/v1/public/getUserInfo.svc
|
||||
String inboundUri = prop.getProperty(HttpAdapterServiceKey.INBOUND_EXTURI);
|
||||
// /api/v1/public
|
||||
String apiPath = prop.getProperty(HttpAdapterServiceKey.API_PATH);
|
||||
|
||||
// /getUserInfo.svc
|
||||
String apiUri = org.apache.commons.lang.StringUtils.removeStart(inboundUri, apiPath);
|
||||
// _TST_IN_RST_SyS|POST:getUserInfo.svc
|
||||
String baseMessageKey = adptGrpName + STEMSG_METHOD_DELIMITER + requestMethod + "|" + StringUtils.removeStart(apiUri, "/");
|
||||
|
||||
// String baseMessageKey = adptGrpName + STEMSG_METHOD_DELIMITER + requestMethod + STEMSG_SERVICE_HEADER_DELIMITER;
|
||||
String keyCode = adptGrpName + "I";
|
||||
if (logger.isInfo()) {
|
||||
logger.info("MessageKeyExtractor] CURRENT RULE [{}]", keyCode);
|
||||
}
|
||||
|
||||
MessageKeyManager manager = MessageKeyManager.getInstance();
|
||||
MessageKeyVO msgKey = manager.getMessageKey(keyCode);
|
||||
|
||||
if(msgKey == null)
|
||||
return new String[] { baseMessageKey };
|
||||
|
||||
List<MessageKeyGroupVO> alMsgGroups = msgKey.getAlMsgGroups();
|
||||
if(alMsgGroups == null)
|
||||
return new String[] { baseMessageKey };
|
||||
|
||||
int groupSize = alMsgGroups.size();
|
||||
|
||||
if(groupSize == 0)
|
||||
return new String[] { baseMessageKey };
|
||||
|
||||
Properties inboundheader = (Properties) prop.get(HttpAdapterServiceKey.INBOUND_HEADER);
|
||||
String[] keys = new String[groupSize];
|
||||
|
||||
for (int g = 0; g < groupSize; g++) {
|
||||
MessageKeyGroupVO groupVo = msgKey.getMessageKeyGroup(g);
|
||||
int fldSize = groupVo.getMessageKeyFldLength();
|
||||
String[] keyBuffer = new String[fldSize];
|
||||
|
||||
for (int i = 0; i < fldSize; i++) {
|
||||
MessageKeyFldVO keyFld = groupVo.getMessageKeyFld(i);
|
||||
String tmpKey = inboundheader.getProperty(keyFld.getBwkColNm().toLowerCase(),"");
|
||||
if(tmpKey == null)
|
||||
tmpKey = "";
|
||||
|
||||
keyBuffer[i] = tmpKey;
|
||||
}
|
||||
String currentKey = baseMessageKey + STEMSG_SERVICE_HEADER_DELIMITER + String.join(STEMSG_HEADER_SEPARATOR, keyBuffer);
|
||||
keys[g] = currentKey;
|
||||
if (logger.isInfo()) {
|
||||
logger.info("MessageKeyExtractor] CURRENT RULE[{}] KEY [{}]", keyCode,currentKey);
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
package com.eactive.eai.custom.inbound.action;
|
||||
|
||||
import com.eactive.eai.adapter.AdapterGroupVO;
|
||||
import com.eactive.eai.adapter.AdapterManager;
|
||||
import com.eactive.eai.adapter.Keys;
|
||||
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
|
||||
import com.eactive.eai.adapter.http.dynamic.impl.HttpAdapterServiceRest;
|
||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
import com.eactive.eai.common.util.MessageKeyExtractor;
|
||||
import com.eactive.eai.inbound.action.ActionException;
|
||||
import com.eactive.eai.inbound.action.RequestActionSupport;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class DJBRestAdapterMethodUrlRequestAction extends RequestActionSupport {
|
||||
|
||||
/**
|
||||
* 1. 기능 : Inbound Adapter를 통해 전달받은 비표준메시지에서 표준메시지를 생성하기 위한 키값을 추출
|
||||
* 2. 처리 개요 :
|
||||
* - MessageKeyExtractor를 통해 Adapter별 추출 Rule에 따라 메시지를 구분할 수 있는 키값을 추출한다.
|
||||
* 3. 주의사항
|
||||
*
|
||||
* @param message Object 타입의 요청메시지
|
||||
* @return String 비표준메시지의 메시지키값
|
||||
* @exception
|
||||
**/
|
||||
public String[] perform(Object message) throws ActionException {
|
||||
String[] key = null;
|
||||
|
||||
AdapterManager adapterManager = AdapterManager.getInstance();
|
||||
AdapterGroupVO adptGrpVO = adapterManager.getAdapterGroupVO(adapterGroupName);
|
||||
String adptGrpName = adptGrpVO.getName();
|
||||
|
||||
if (StringUtils.equals(adptGrpVO.getType(), Keys.TYPE_HTTP_CUSTOM)
|
||||
|| StringUtils.equals(adptGrpVO.getType(), Keys.TYPE_REST)) {
|
||||
try {
|
||||
String requestMethod = prop
|
||||
.getProperty(HttpAdapterServiceRest.PROPERTIES_NAME_HTTP_REQUEST_METHOD);
|
||||
|
||||
// /api/v1/public/getUserInfo.svc
|
||||
String inboundUri = prop.getProperty(HttpAdapterServiceKey.INBOUND_EXTURI);
|
||||
// /api/v1/public
|
||||
String apiPath = prop.getProperty(HttpAdapterServiceKey.API_PATH);
|
||||
|
||||
// /getUserInfo.svc
|
||||
String apiUri = org.apache.commons.lang.StringUtils.removeStart(inboundUri, apiPath);
|
||||
// _TST_IN_RST_SyS|POST:getUserInfo.svc
|
||||
String apiKey = adptGrpName + ":" + requestMethod + "|" + StringUtils.removeStart(apiUri, "/");
|
||||
|
||||
return new String[] { apiKey };
|
||||
} catch (Exception e) {
|
||||
throw new ActionException(ExceptionUtil.getErrorCode(e, "RECEAIIRA001"));
|
||||
}
|
||||
}
|
||||
|
||||
if (message instanceof byte[]) {
|
||||
try {
|
||||
key = MessageKeyExtractor.getMessageKeyValueForRest(this.adapterGroupName, message, prop, "url", true);
|
||||
} catch (Exception e) {
|
||||
throw new ActionException(ExceptionUtil.getErrorCode(e, "RECEAIIRA001"));
|
||||
}
|
||||
if (logger.isDebug())
|
||||
logger.debug(adapterName + "] received data >> [" + new String((byte[]) message) + "]");
|
||||
} else {
|
||||
try {
|
||||
key = MessageKeyExtractor.getMessageKeyValueForRest(this.adapterGroupName, message, prop, "url", true);
|
||||
} catch (Exception e) {
|
||||
throw new ActionException(ExceptionUtil.getErrorCode(e, "RECEAIIRA001"));
|
||||
}
|
||||
if (logger.isDebug())
|
||||
logger.debug(adapterName + "] received data >> [" + message + "]");
|
||||
}
|
||||
|
||||
for (int i = 0; i < key.length; i++) {
|
||||
key[i] = adptGrpName.trim() + key[i];
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user