init
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package com.eactive.eai.message;
|
||||
|
||||
public class EncodingVar {
|
||||
//FlatReader String -<-> bytes encoding
|
||||
public static String flatEncoding ="euc-kr";
|
||||
|
||||
//StandardItem XML encoding
|
||||
public static String xmlEncoding ="utf-8";
|
||||
public static String jsonEncoding ="utf-8";
|
||||
|
||||
// performance를 위해 static으로 변경 후 commented
|
||||
//
|
||||
// private static EncodingVar instance;
|
||||
//
|
||||
// public static EncodingVar getInstance() {
|
||||
// if(instance == null) {
|
||||
// synchronized(EncodingVar.class) {
|
||||
// if(instance == null) {
|
||||
// instance = new EncodingVar();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return instance;
|
||||
// }
|
||||
|
||||
// public String getFlatEncoding() {
|
||||
// return flatEncoding;
|
||||
// }
|
||||
// public void setFlatEncoding(String flatEncoding) {
|
||||
// EncodingVar.flatEncoding = flatEncoding;
|
||||
// }
|
||||
// public String getValueEncoding() {
|
||||
// return valueEncoding;
|
||||
// }
|
||||
// public void setValueEncoding(String valueEncoding) {
|
||||
// EncodingVar.valueEncoding = valueEncoding;
|
||||
// }
|
||||
// public String getXmlEncoding() {
|
||||
// return xmlEncoding;
|
||||
// }
|
||||
// public void setXmlEncoding(String xmlEncoding) {
|
||||
// EncodingVar.xmlEncoding = xmlEncoding;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.eactive.eai.message;
|
||||
|
||||
public interface StandardDataType {
|
||||
public final int STRING = 1;
|
||||
public final int NUMBER = 2;
|
||||
public final int ZZ_STRING = 11;
|
||||
public final int LL_NUMBER = 12;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.eactive.eai.message;
|
||||
|
||||
public interface StandardFieldType {
|
||||
public final int ELEMENT = 1;
|
||||
public final int ATTRIBUTE = 2;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
||||
package com.eactive.eai.message;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class StandardLogItem implements Serializable, Cloneable {
|
||||
String name;
|
||||
int level; // 0 : root ~ n
|
||||
int type; // 0: Message, 1: Field, 2:Group, 3 : Grid, 4 : Field Array, 9 : BIZ DATA
|
||||
int size; // array size
|
||||
int fieldType; // 0: ELEMENT, 1: ATTRIBUTE,
|
||||
int length;
|
||||
int dataType; // 0: String, 1: Number, 10: ZZ String, 11: Length Number
|
||||
String refPath;
|
||||
String refValue;
|
||||
String value;
|
||||
String desc = "";
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
public void setSize(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
public int getFieldType() {
|
||||
return fieldType;
|
||||
}
|
||||
public void setFieldType(int fieldType) {
|
||||
this.fieldType = fieldType;
|
||||
}
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
public int getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
public void setDataType(int dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
public String getRefPath() {
|
||||
return refPath;
|
||||
}
|
||||
public void setRefPath(String refPath) {
|
||||
this.refPath = refPath;
|
||||
}
|
||||
public String getRefValue() {
|
||||
return refValue;
|
||||
}
|
||||
public void setRefValue(String refValue) {
|
||||
this.refValue = refValue;
|
||||
}
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
public void setDesc(String desc) {
|
||||
this.desc = desc;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StandardLogItem [name=" + name + ", level=" + level + ", type=" + type + ", size=" + size
|
||||
+ ", fieldType=" + fieldType + ", length=" + length + ", dataType=" + dataType + ", refPath=" + refPath
|
||||
+ ", refValue=" + refValue + ", value=" + value + ", desc=" + desc + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
package com.eactive.eai.message;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.eactive.eai.common.message.MessageType;
|
||||
import com.eactive.eai.message.filter.MessageFilter;
|
||||
|
||||
public class StandardMessage extends StandardItem {
|
||||
private static final long serialVersionUID = 8250470942348479859L;
|
||||
static Logger logger = LoggerFactory.getLogger(StandardMessage.class);
|
||||
int readPosition = 0;
|
||||
|
||||
private String serviceKey = null;
|
||||
|
||||
private String bizDataCharset = null;
|
||||
|
||||
private String bizDataPath = null;
|
||||
private String llDataPath = null;
|
||||
private String zzDataPath = null;
|
||||
|
||||
private MessageFilter flatFilter = null;
|
||||
|
||||
public String getBizDataCharset() {
|
||||
return bizDataCharset;
|
||||
}
|
||||
|
||||
public void setBizDataCharset(String bizDataCharset) {
|
||||
this.bizDataCharset = bizDataCharset;
|
||||
}
|
||||
|
||||
public MessageFilter getFlatFilter() {
|
||||
return flatFilter;
|
||||
}
|
||||
|
||||
public void setFlatFilter(MessageFilter flatFilter) {
|
||||
this.flatFilter = flatFilter;
|
||||
}
|
||||
|
||||
public String getServiceKey() {
|
||||
return serviceKey;
|
||||
}
|
||||
|
||||
public void setServiceKey(String serviceKey) {
|
||||
this.serviceKey = serviceKey;
|
||||
}
|
||||
|
||||
public String getBizDataPath() {
|
||||
return bizDataPath;
|
||||
}
|
||||
|
||||
public void setBizDataPath(String bizDataPath) {
|
||||
this.bizDataPath = bizDataPath;
|
||||
}
|
||||
|
||||
|
||||
public String getLlDataPath() {
|
||||
return llDataPath;
|
||||
}
|
||||
|
||||
public void setLlDataPath(String llDataPath) {
|
||||
this.llDataPath = llDataPath;
|
||||
}
|
||||
|
||||
public String getZzDataPath() {
|
||||
return zzDataPath;
|
||||
}
|
||||
|
||||
public void setZzDataPath(String zzDataPath) {
|
||||
this.zzDataPath = zzDataPath;
|
||||
}
|
||||
|
||||
public String getBizData() throws Exception {
|
||||
if(bizDataPath == null) {
|
||||
throw new Exception("bizDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(bizDataPath);
|
||||
if(item == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return item.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getBizDataBytes() throws Exception {
|
||||
if(StringUtils.isEmpty(this.bizDataCharset)) {
|
||||
throw new Exception("bizData Charset not defined or bizData not set yet.");
|
||||
}
|
||||
return getBizDataBytes(this.bizDataCharset);
|
||||
}
|
||||
|
||||
public byte[] getBizDataBytes(String charset) throws Exception {
|
||||
if(bizDataPath == null) {
|
||||
throw new Exception("bizDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(bizDataPath);
|
||||
if(item == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
byte[] bizBytes = item.getBytesValue(charset);
|
||||
if(StringUtils.isNotEmpty(bizDataCharset) && bizBytes != null &&
|
||||
bizDataCharset.equalsIgnoreCase(charset)){
|
||||
return bizBytes;
|
||||
}
|
||||
else {
|
||||
String bizData = item.getValue();
|
||||
if(bizData != null) {
|
||||
bizDataCharset = charset;
|
||||
bizBytes = bizData.getBytes(charset);
|
||||
item.setBytesValue(bizBytes);
|
||||
return bizBytes;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBizData(byte[] data, String charset) throws Exception {
|
||||
if(bizDataPath == null) {
|
||||
throw new Exception("bizDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(bizDataPath);
|
||||
if(item != null) {
|
||||
if (data == null){
|
||||
item.setValue(null);
|
||||
item.setBytesValue(null);
|
||||
}
|
||||
else{
|
||||
item.setBytesValue(data);
|
||||
item.setValue(new String(data, charset));
|
||||
}
|
||||
setBizDataCharset(charset);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBizData(String data, String charset) throws Exception {
|
||||
if(bizDataPath == null) {
|
||||
throw new Exception("bizDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(bizDataPath);
|
||||
if(item != null) {
|
||||
if (data == null){
|
||||
item.setValue(null);
|
||||
item.setBytesValue(null);
|
||||
}
|
||||
else{
|
||||
item.setValue(data);
|
||||
item.setBytesValue(data.getBytes(charset));
|
||||
}
|
||||
setBizDataCharset(charset);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBizData(Object data, String charset) throws Exception {
|
||||
if(bizDataPath == null) {
|
||||
throw new Exception("bizDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(bizDataPath);
|
||||
if(item != null) {
|
||||
if (data == null){
|
||||
item.setValue(null);
|
||||
item.setBytesValue(null);
|
||||
setBizDataCharset(charset);
|
||||
}else if (data instanceof String){
|
||||
setBizData((String)data, charset);
|
||||
}else if (data instanceof byte[]){
|
||||
setBizData((byte[])data, charset);
|
||||
}else {
|
||||
throw new Exception("invalid data object. -" + data.getClass());
|
||||
}
|
||||
setBizDataCharset(charset);
|
||||
}
|
||||
}
|
||||
|
||||
// use only FlatReader
|
||||
public void cutBizData(int zzSize) throws Exception {
|
||||
if(bizDataPath == null) {
|
||||
throw new Exception("bizDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(bizDataPath);
|
||||
if(item != null) {
|
||||
byte[] bizDataBytes = item.getBytesValue(this.bizDataCharset);
|
||||
int finalSize = bizDataBytes.length - zzSize;
|
||||
|
||||
if(finalSize > 0) {
|
||||
byte[] fbizDataBytes = new byte[finalSize];
|
||||
for(int i=0; i<finalSize; i++) {
|
||||
fbizDataBytes[i] = bizDataBytes[i];
|
||||
}
|
||||
item.setBytesValue(fbizDataBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getLlData() throws Exception {
|
||||
if(llDataPath == null) {
|
||||
throw new Exception("llDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(llDataPath);
|
||||
if(item == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return item.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void setLlData(String llData) throws Exception {
|
||||
if(llDataPath == null) {
|
||||
throw new Exception("llDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(llDataPath);
|
||||
if(item != null) {
|
||||
item.setValue(llData);
|
||||
}
|
||||
}
|
||||
public void setLlData(int llDataSize) throws Exception {
|
||||
if(llDataPath == null) {
|
||||
throw new Exception("llDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem bizItem = findItem(llDataPath);
|
||||
if(bizItem != null) {
|
||||
bizItem.setValue(Integer.toString(llDataSize));
|
||||
}
|
||||
}
|
||||
|
||||
public String getZzData() throws Exception {
|
||||
if(zzDataPath == null) {
|
||||
throw new Exception("zzDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(zzDataPath);
|
||||
if(item == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return item.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void setZzData(String zzData) throws Exception {
|
||||
if(zzDataPath == null) {
|
||||
throw new Exception("zzDataPath path not configured, check layout definition.");
|
||||
}
|
||||
StandardItem item = findItem(zzDataPath);
|
||||
if(item != null) {
|
||||
item.setValue(zzData);
|
||||
}
|
||||
}
|
||||
|
||||
public StandardMessage() {
|
||||
this.name = "StandardRoot"; // XML 일 경우 Root name으로 사용 ?
|
||||
this.type = 1;
|
||||
}
|
||||
|
||||
public int getReadPosition() {
|
||||
return readPosition;
|
||||
}
|
||||
public void setReadPosition(int readPosition) {
|
||||
this.readPosition = readPosition;
|
||||
}
|
||||
|
||||
public StandardItem findItem(String path) {
|
||||
return findItem(path, '.', true, false);
|
||||
}
|
||||
|
||||
private String[] split(String source, char spliter) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
CharSequence chars = source;
|
||||
int start = 0, end = 0;
|
||||
for(int i=0; i<chars.length(); i++) {
|
||||
if(chars.charAt(i) == spliter) {
|
||||
end = i;
|
||||
list.add(chars.subSequence(start, end).toString());
|
||||
start = end+1;
|
||||
i = i+1;
|
||||
}
|
||||
}
|
||||
|
||||
if(end == 0) {
|
||||
list.add(chars.toString());
|
||||
}
|
||||
else {
|
||||
list.add(chars.subSequence(start, chars.length()).toString());
|
||||
}
|
||||
|
||||
return (String[])list.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public StandardItem findItem(String path, char pathSeparator, boolean zeroBase, boolean createNew) {
|
||||
String[] paths = split(path, pathSeparator);
|
||||
StandardItem item = null;
|
||||
|
||||
LinkedHashMap<String , StandardItem> childItems = this.getChilds();
|
||||
for(int i=0; i< paths.length; i++) {
|
||||
String itemName = paths[i];
|
||||
int arrayIndex = StandardMessageUtil.getArrayIndex(itemName);
|
||||
|
||||
if(arrayIndex >= 0) {
|
||||
itemName = StandardMessageUtil.getArrayName(itemName);
|
||||
// if XML, use 1 base index
|
||||
if( !zeroBase ) {
|
||||
arrayIndex = arrayIndex -1;
|
||||
}
|
||||
}
|
||||
try {
|
||||
item = childItems.get(itemName);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
logger.error("get Child error : this=" + itemName, ex);
|
||||
return null;
|
||||
}
|
||||
if(i< paths.length-1) {
|
||||
if(item != null && item.getType() >StandardType.FIELD) {
|
||||
if(arrayIndex >= 0) {
|
||||
childItems = item.getArrayChilds(arrayIndex, createNew);
|
||||
}
|
||||
else {
|
||||
childItems = item.getChilds();
|
||||
}
|
||||
if(childItems == null) {
|
||||
logger.warn("childItems not found : " + paths[i] +" / "+ path);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.warn("group not found : " + paths[i] +" / "+ path);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(item == null) {
|
||||
logger.warn("Item not found : " + path);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
// group1.group2.item1
|
||||
public String findItemValue(String path) {
|
||||
StandardItem item = findItem(path);
|
||||
if(item == null) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return item.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void setData(String path, String value) {
|
||||
StandardItem item = findItem(path);
|
||||
if(item == null) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
item.setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
// deprecated
|
||||
// public String toFixedString() {
|
||||
// return toFixedString(true, this.bizDataCharset);
|
||||
// }
|
||||
|
||||
public String toFixedString(String charset) {
|
||||
return toFixedString(true, charset);
|
||||
}
|
||||
|
||||
public String toFixedString(boolean withBizData) {
|
||||
return toFixedString(withBizData, this.bizDataCharset);
|
||||
}
|
||||
|
||||
public String toFixedString(boolean withBizData, String charset) {
|
||||
byte[] bytes = toByteArray(withBizData, charset);
|
||||
try {
|
||||
logger.debug("Encoding : {}", charset );
|
||||
return new String(bytes, charset);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
logger.error("encoding fail, use default.", e);
|
||||
return new String(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public String toJson(boolean withBizData) {
|
||||
return toJson(false, withBizData);
|
||||
}
|
||||
public String toPrettyJson(boolean withBizData) {
|
||||
return toJson(true, withBizData);
|
||||
}
|
||||
|
||||
public byte[] toByteArray(String charset) {
|
||||
return toByteArray(true, charset);
|
||||
}
|
||||
|
||||
// deprecated
|
||||
// public byte[] toByteArray() {
|
||||
// return toByteArray(true, this.bizDataCharset);
|
||||
// }
|
||||
|
||||
public String getDataString(String messageType, String charset) throws Exception {
|
||||
if (MessageType.JSON.equals(messageType)) {
|
||||
return toJson();
|
||||
} else if (MessageType.XML.equals(messageType)) {
|
||||
return toXML();
|
||||
} else if (MessageType.ASC.equals(messageType)) {
|
||||
return toFixedString(charset);
|
||||
} else if (MessageType.EBC.equals(messageType)) {
|
||||
logger.error("Unsupported message type - " + MessageType.EBC);
|
||||
throw new Exception("Unsupported msgType - " + messageType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] getDataBytes(String messageType, String charset) throws Exception {
|
||||
if (MessageType.JSON.equals(messageType)) {
|
||||
return toJson().getBytes(charset);
|
||||
} else if (MessageType.XML.equals(messageType)) {
|
||||
return toXML().getBytes(charset);
|
||||
} else if (MessageType.ASC.equals(messageType)) {
|
||||
return toByteArray(charset);
|
||||
} else if (MessageType.EBC.equals(messageType)) {
|
||||
logger.error("Unsupported message type - " + MessageType.EBC);
|
||||
throw new Exception("Unsupported msgType - " + messageType);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public byte[] toByteArray(boolean withBizData, String charset) {
|
||||
//if(runFilter && flatFilter != null) { // runFilter 사용여부가 아니라 withBizData 여부여서 변경하고 Filter가 null이 아니면 로직수행으로 변경
|
||||
if( flatFilter != null) {
|
||||
flatFilter.doFilter(this);
|
||||
}
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
Iterator<String> keyIter = null;
|
||||
try {
|
||||
keyIter = childs.keySet().iterator();
|
||||
while(keyIter.hasNext()) {
|
||||
String key = keyIter.next();
|
||||
StandardItem item = childs.get(key);
|
||||
bos.write(item.toByteArray(withBizData, charset));
|
||||
}
|
||||
return bos.toByteArray();
|
||||
} catch(Exception e) {
|
||||
logger.error("toByteArray failed", e);
|
||||
return new byte[0];
|
||||
}
|
||||
finally {
|
||||
if(bos != null)
|
||||
try {
|
||||
bos.close();
|
||||
} catch (IOException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getBytesDataLength() {
|
||||
return getBytesDataLength(this.bizDataCharset);
|
||||
}
|
||||
|
||||
public int getBytesDataLength(String charset) {
|
||||
Iterator<String> keyIter = null;
|
||||
int totalSize = 0;
|
||||
try {
|
||||
keyIter = childs.keySet().iterator();
|
||||
while(keyIter.hasNext()) {
|
||||
String key = keyIter.next();
|
||||
StandardItem item = childs.get(key);
|
||||
totalSize +=item.getBytesDataLength(charset);
|
||||
}
|
||||
return totalSize;
|
||||
} catch(Exception e) {
|
||||
logger.error("getBytesDataLength failed", e);
|
||||
return totalSize;
|
||||
}
|
||||
finally {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* path로 하위에 있는 byte 길이 계산
|
||||
*
|
||||
* @param path
|
||||
* @return
|
||||
*/
|
||||
public int getBytesDataLengthForPath(String path) {
|
||||
Iterator<String> keyIter = null;
|
||||
int totalSize = 0;
|
||||
try {
|
||||
StandardItem find = findItem(path);
|
||||
keyIter = find.childs.keySet().iterator();
|
||||
while (keyIter.hasNext()) {
|
||||
String key = keyIter.next();
|
||||
StandardItem item = find.childs.get(key);
|
||||
totalSize += item.getBytesDataLength(this.bizDataCharset);
|
||||
}
|
||||
return totalSize;
|
||||
} catch (Exception e) {
|
||||
logger.error("getBytesDataLength failed", e);
|
||||
return totalSize;
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getLevelTreeIndent()).append("StandardMessage [name=" + name + ", level=" + level
|
||||
+ ", type=" + type
|
||||
// +", size=" + size + ", fieldType=" + fieldType +", length=" + length + ", dataType=" + dataType
|
||||
// + ", refPath=" + refPath + ", refValue=" + refValue
|
||||
// + ", value=" + value
|
||||
+ ", desc=" + desc + "]");
|
||||
if(bizDataPath != null) sb.append(", bizDataPath=" + bizDataPath);
|
||||
if(llDataPath != null) sb.append(", llDataPath=" + llDataPath);
|
||||
if(zzDataPath != null) sb.append(", zzDataPath=" + zzDataPath);
|
||||
|
||||
|
||||
Iterator<String> keyIter = childs.keySet().iterator();
|
||||
while(keyIter.hasNext()) {
|
||||
String key = keyIter.next();
|
||||
StandardItem item = childs.get(key);
|
||||
sb.append("\n").append(item.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
StandardMessage cloned = (StandardMessage)super.clone();
|
||||
if(flatFilter != null) cloned.setFlatFilter(flatFilter);
|
||||
return cloned;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
package com.eactive.eai.message;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.eactive.eai.common.message.EAIMessage;
|
||||
import com.eactive.eai.common.stdmessage.STDMessageManager;
|
||||
import com.eactive.eai.common.util.ApplicationContextProvider;
|
||||
import com.eactive.eai.inbound.processor.ProcessVO;
|
||||
import com.eactive.eai.message.layout.CsvFileReader;
|
||||
import com.eactive.eai.message.layout.DatabaseReader;
|
||||
import com.eactive.eai.message.layout.LayoutReader;
|
||||
import com.eactive.eai.message.manager.StandardMessageManager;
|
||||
|
||||
public class StandardMessageUtil {
|
||||
static Logger logger = LoggerFactory.getLogger(StandardMessageUtil.class);
|
||||
|
||||
public static String requestProcessorClass = "com.eactive.eai.inbound.processor.RequestProcessor";
|
||||
|
||||
public static String REST_URL_ACTION1 = "com.eactive.eai.inbound.action.RestUrlAdapterGroupParseRequestAction";
|
||||
public static String REST_URL_ACTION2 = "com.eactive.eai.inbound.action.RestUrlParseRequestAction";
|
||||
|
||||
public StandardMessageUtil() {
|
||||
}
|
||||
|
||||
public static String getBizData(EAIMessage eaiMessage) throws Exception {
|
||||
// InterfaceMapper mapper = eaiMessage.getMapper();
|
||||
StandardMessage standardMessage = eaiMessage.getStandardMessage();
|
||||
return standardMessage.getBizData();
|
||||
}
|
||||
|
||||
public static void setBizData(EAIMessage eaiMessage, String bizData, String charset) throws Exception {
|
||||
// InterfaceMapper mapper = eaiMessage.getMapper();
|
||||
StandardMessage standardMessage = eaiMessage.getStandardMessage();
|
||||
standardMessage.setBizData(bizData, charset);
|
||||
}
|
||||
|
||||
public static StandardMessage getStandardMessageFromRule(Object message, ProcessVO vo, String charset, Properties prop) throws Exception {
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
StandardMessage standardMessage = standardManager.getStandardMessage();
|
||||
|
||||
STDMessageManager stdMessageManager = STDMessageManager.getInstance();
|
||||
standardMessage = stdMessageManager.getSTDMessage(vo.getSelectedKey());
|
||||
if (standardMessage == null) {
|
||||
// API 서비스일경우 PathVariable 지원 추가
|
||||
// ex) /api/account/{no}
|
||||
if (StringUtils.equalsAny(vo.getActionName(), REST_URL_ACTION1, REST_URL_ACTION2)) {
|
||||
standardMessage = stdMessageManager.getSTDMessageForPathVariable(vo.getSelectedKey());
|
||||
}
|
||||
|
||||
if (standardMessage == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
standardMessage.setBizData(message, charset);
|
||||
standardManager.getMessageCoordinator().coordinateAfterCreateMessageByRule(standardMessage, vo, prop);
|
||||
return standardMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* API 서비스에서 실제 요청된 path를 설정된 PathVariable 형태의 key를 찾는다
|
||||
* ex) /api/bank/account/12345 --> /api/bank/account/{accountNo}
|
||||
* @param key
|
||||
* @param actionName
|
||||
* @return
|
||||
*/
|
||||
public static String getMatchedKey(String key, String actionName) {
|
||||
STDMessageManager stdMessageManager = STDMessageManager.getInstance();
|
||||
String[] keys = stdMessageManager.getAllSTDMessageKeys();
|
||||
for (String keyStr : keys) {
|
||||
if (StringUtils.equals(key, keyStr)) {
|
||||
return keyStr;
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.equalsAny(actionName, REST_URL_ACTION1, REST_URL_ACTION2)) {
|
||||
return stdMessageManager.getMatchedPathVariable(key);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static StandardMessage generateMessageFromCsvFile() {
|
||||
String filePath = "./resources/standard-layout.csv";
|
||||
return generateMessageFromCsvFile(filePath);
|
||||
}
|
||||
public static StandardMessage generateMessageFromCsvFile(String filePath) {
|
||||
ArrayList<StandardItem> list = null;
|
||||
|
||||
try {
|
||||
LayoutReader reader = new CsvFileReader();
|
||||
list = reader.parse(filePath);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
StandardMessage message = null;
|
||||
try {
|
||||
message = generate(list);
|
||||
// message = generate_backup(list);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public static StandardMessage generateMessageFromDb(String layoutName) {
|
||||
ArrayList<StandardItem> list = null;
|
||||
try {
|
||||
LayoutReader reader = ApplicationContextProvider.getContext().getBean(DatabaseReader.class);
|
||||
list = reader.parse(layoutName);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
logger.error("", ex);
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
StandardMessage message = null;
|
||||
try {
|
||||
message = generate(list);
|
||||
// message = generate_backup(list);
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
// TODO : if Fixed Array, clone list item to length ?
|
||||
public static StandardMessage generate_backup(ArrayList<StandardItem> itemList) throws Exception {
|
||||
StandardMessage message = new StandardMessage();
|
||||
Stack<StandardItem> stack = new Stack<StandardItem>();
|
||||
Stack<String> stackPath = new Stack<String>();
|
||||
int pLevel = 0;
|
||||
StandardItem parent = message;
|
||||
String parentPath = null;
|
||||
// logger.debug("======================================================");
|
||||
for(int i=0; i< itemList.size(); i++) {
|
||||
StandardItem item = itemList.get(i);
|
||||
logger.debug("{} : item - {}", i, item);
|
||||
// top level
|
||||
if(item.getLevel() == 0) {
|
||||
message.setName(item.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
if(item.getLevel() == 1) {
|
||||
message.addItem(item);
|
||||
}
|
||||
else {
|
||||
// get parent & add
|
||||
int levelDiff = (item.getLevel() - pLevel);
|
||||
if( levelDiff == 0) {
|
||||
// do nothing
|
||||
}
|
||||
else if( levelDiff == 1) {
|
||||
parent = stack.peek();
|
||||
parentPath = stackPath.peek();
|
||||
// logger.debug("<< PEEK = {}", parent.getName());
|
||||
}
|
||||
else if(levelDiff < 0) {
|
||||
while(item.getLevel() > parent.getLevel()
|
||||
&& !stack.isEmpty()) {
|
||||
parent = stack.pop();
|
||||
parentPath = stackPath.pop();
|
||||
// logger.debug("<< POP = {}", parent.getName());
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Exception("item level error - "+ item.getName() +" level diff=" + levelDiff);
|
||||
}
|
||||
|
||||
if(parent.getType() == StandardType.GROUP) {
|
||||
// logger.debug("add group child item - {}", item);
|
||||
parent.addItem(item);
|
||||
}
|
||||
else if(parent.getType() == StandardType.GRID) {
|
||||
parent.addArrayItem(0, item);
|
||||
}
|
||||
else {
|
||||
throw new Exception("item parent is not GROUP/ARRAY : item - " + item);
|
||||
}
|
||||
}
|
||||
|
||||
if(item.getType() == StandardType.BIZDATA) {
|
||||
if(item.getLevel() == 1) {
|
||||
message.setBizDataPath(item.getName());
|
||||
}
|
||||
else {
|
||||
message.setBizDataPath(getFullPath(parentPath , item.getName()));
|
||||
}
|
||||
logger.debug("@@@ BIZ DATA PATH = {}", message.getBizDataPath());
|
||||
}
|
||||
|
||||
// if group/array,push to stack, pLevel
|
||||
if(item.getType() > 1) {
|
||||
logger.debug(">> PUSH = {}", item.getName());
|
||||
|
||||
if(parent.getLevel() == item.getLevel()) {
|
||||
// logger.debug(">> POP revious sibling = {}", parent.getName());
|
||||
stack.pop();
|
||||
stackPath.pop();
|
||||
}
|
||||
stackPath.push( getFullPath(parentPath , item.getName()) );
|
||||
stack.push(item);
|
||||
}
|
||||
else {
|
||||
if(item.getDataType() == StandardDataType.LL_NUMBER) {
|
||||
if(item.getLevel() == 1) {
|
||||
message.setLlDataPath(item.getName());
|
||||
}
|
||||
else {
|
||||
message.setLlDataPath(getFullPath(parentPath , item.getName()));
|
||||
}
|
||||
logger.debug("@@@ LL_NUMBER PATH = {}", message.getLlDataPath());
|
||||
|
||||
}
|
||||
else if(item.getDataType() == StandardDataType.ZZ_STRING) {
|
||||
if(item.getLevel() == 1) {
|
||||
message.setZzDataPath(item.getName());
|
||||
}
|
||||
else {
|
||||
message.setZzDataPath(getFullPath(parentPath , item.getName()));
|
||||
}
|
||||
logger.debug("@@@ ZZ_STRING PATH = {}", message.getZzDataPath());
|
||||
|
||||
}
|
||||
}
|
||||
pLevel = item.getLevel();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public static StandardMessage generate(ArrayList<StandardItem> itemList) throws Exception {
|
||||
int itemIdx = 0;
|
||||
String parentPath = "";
|
||||
|
||||
if (itemList == null || itemList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// MESSAGE 항목이 없다면 추가
|
||||
if (itemList.get(0).getType() != StandardType.MESSAGE) {
|
||||
StandardItem rootItem = new StandardItem("StandardRoot", 0, StandardType.MESSAGE, 0,
|
||||
StandardDataType.STRING, null);
|
||||
itemList.add(0, rootItem);
|
||||
}
|
||||
|
||||
StandardMessage message = new StandardMessage();
|
||||
return (StandardMessage) setRecursiveItems(message, itemList, itemIdx, parentPath);
|
||||
}
|
||||
|
||||
private static StandardItem setRecursiveItems(StandardMessage message, ArrayList<StandardItem> itemList,
|
||||
int itemIdx, String parentPath) {
|
||||
StandardItem curItem = itemList.get(itemIdx);
|
||||
if (curItem.getType() == StandardType.MESSAGE) {
|
||||
message.setName(curItem.getName());
|
||||
curItem = message;
|
||||
}
|
||||
|
||||
if (curItem.getLevel() <= 1) {
|
||||
parentPath = "";
|
||||
}
|
||||
|
||||
if (curItem.getType() == StandardType.MESSAGE || curItem.getType() == StandardType.GROUP
|
||||
|| curItem.getType() == StandardType.GRID) {
|
||||
for (int i = itemIdx + 1; i < itemList.size(); i++) { // sub item 처리
|
||||
StandardItem item = itemList.get(i);
|
||||
if (item.getLevel() <= curItem.getLevel()) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (item.getLevel() == curItem.getLevel() + 1) {
|
||||
if (curItem.getType() == StandardType.GRID) {
|
||||
curItem.addArrayItem(0,
|
||||
setRecursiveItems(message, itemList, i, getFullPath(parentPath, curItem.getName())));
|
||||
} else {
|
||||
curItem.addItem(
|
||||
setRecursiveItems(message, itemList, i, getFullPath(parentPath, curItem.getName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (curItem.getType() == StandardType.BIZDATA) {
|
||||
message.setBizDataPath(getFullPath(parentPath, curItem.getName()));
|
||||
logger.debug("@@@ BIZ DATA PATH = {}", message.getBizDataPath());
|
||||
}
|
||||
|
||||
if (curItem.getDataType() == StandardDataType.LL_NUMBER) {
|
||||
message.setLlDataPath(getFullPath(parentPath, curItem.getName()));
|
||||
logger.debug("@@@ LL_NUMBER PATH = {}", message.getLlDataPath());
|
||||
|
||||
} else if (curItem.getDataType() == StandardDataType.ZZ_STRING) {
|
||||
message.setZzDataPath(getFullPath(parentPath, curItem.getName()));
|
||||
logger.debug("@@@ ZZ_STRING PATH = {}", message.getZzDataPath());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return curItem;
|
||||
}
|
||||
|
||||
private static String getFullPath(String parentPath, String itemName) {
|
||||
if(parentPath == null || parentPath.length() == 0) {
|
||||
return itemName;
|
||||
}
|
||||
return parentPath + "." + itemName;
|
||||
}
|
||||
|
||||
public static int getArrayIndex(String path) {
|
||||
int index = -1;
|
||||
|
||||
if(path.charAt(path.length()-1) != ']') {
|
||||
return index;
|
||||
}
|
||||
int start = path.indexOf("[");
|
||||
if(start > 0) {
|
||||
String p = path.substring(start + 1, path.length()-1);
|
||||
try {
|
||||
index = Integer.parseInt(p);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
public static String getArrayName(String path) {
|
||||
if(path.charAt(path.length()-1) != ']') {
|
||||
return path;
|
||||
}
|
||||
int start = path.indexOf("[");
|
||||
if(start > 0) {
|
||||
String p = path.substring(0, start);
|
||||
return p;
|
||||
}
|
||||
else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// logger.debug("{}", getArrayIndex("group[10]"));
|
||||
// logger.debug("{}", getArrayName("group[10]"));
|
||||
// logger.debug("{}", getArrayIndex("group"));
|
||||
// logger.debug("{}", getArrayName("group"));
|
||||
|
||||
// String basePath = "D:\\Projects\\workspaces\\current_elink4.5_online_multi\\elink-online-multi\\";
|
||||
String basePath = "D:\\SOURCE\\v4.5-beta-multi\\elink-online-multi\\";
|
||||
|
||||
String filePath = basePath + "src\\main\\resources\\standard-layout.csv";
|
||||
// String filePath = basePath + "src\\main\\resources\\standard-layout-sbi.csv";
|
||||
|
||||
|
||||
StandardMessage stdmsg = generateMessageFromCsvFile(filePath);
|
||||
System.out.println("===========================================================================");
|
||||
System.out.println(stdmsg.getChilds().size());
|
||||
System.out.println(stdmsg);
|
||||
System.out.println("===========================================================================");
|
||||
System.out.println(stdmsg.getLlDataPath());
|
||||
System.out.println(stdmsg.getBizDataPath());
|
||||
System.out.println(stdmsg.getZzDataPath());
|
||||
System.out.println("===========================================================================");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.eactive.eai.message;
|
||||
|
||||
public interface StandardType {
|
||||
public final int MESSAGE = 1;
|
||||
public final int FIELD = 2;
|
||||
public final int GROUP = 3;
|
||||
public final int GRID = 4;
|
||||
public final int FARRAY = 5;
|
||||
public final int BIZDATA = 9;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.eactive.eai.message.filter;
|
||||
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
|
||||
public class FlatMessageFilter implements MessageFilter {
|
||||
|
||||
@Override
|
||||
public StandardMessage doFilter(StandardMessage message) {
|
||||
try {
|
||||
int totalSize = message.getBytesDataLength();
|
||||
message.setLlData(String.valueOf(totalSize));
|
||||
} catch (Exception e) {
|
||||
;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.eactive.eai.message.filter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
|
||||
public interface MessageFilter extends Serializable {
|
||||
public StandardMessage doFilter(StandardMessage message);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.eactive.eai.message.layout;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.StandardMessageUtil;
|
||||
|
||||
public class CsvFileReader implements LayoutReader {
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
String COMMA_DELIMITER = ",";
|
||||
String COMMENT_HEADER = "#";
|
||||
|
||||
public CsvFileReader() {
|
||||
}
|
||||
|
||||
private BufferedReader getReader(String filePath) throws Exception {
|
||||
BufferedReader reader = null;
|
||||
if(logger.isInfoEnabled()) logger.info("getReader from filepath. read file = " + filePath);
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(filePath));
|
||||
return reader;
|
||||
}
|
||||
catch(Exception ex) {
|
||||
if(logger.isWarnEnabled()) {
|
||||
// logger.warn("getReader failed. read file = " +filePath, ex);
|
||||
logger.warn("getReader failed. read file = " +filePath +", " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
try {
|
||||
if(logger.isInfoEnabled()) logger.info("getReader from classpath. read file = " + filePath);
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
reader = new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream(filePath)) );
|
||||
return reader;
|
||||
}
|
||||
catch(Exception ex) {
|
||||
if(logger.isWarnEnabled()) {
|
||||
// logger.warn("getReader failed. read classpath file = " + filePath, ex);
|
||||
logger.warn("getReader failed. read classpath file = " + filePath + ", " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
throw new Exception("file not found : " + filePath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<StandardItem> parse(String filePath) throws Exception {
|
||||
if(logger.isInfoEnabled()) logger.info("CsvFileReader read file = " + filePath);
|
||||
|
||||
ArrayList<StandardItem> list = new ArrayList<StandardItem>();
|
||||
|
||||
int lineNo = 0;
|
||||
try (BufferedReader br = getReader(filePath)) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
lineNo++;
|
||||
if(line.startsWith(COMMENT_HEADER)) {
|
||||
if(logger.isDebugEnabled()) logger.debug(String.format("SKIP comment %s : %s", lineNo, line) );
|
||||
continue;
|
||||
}
|
||||
if(logger.isDebugEnabled()) logger.debug(String.format("Parsing line %s : %s", lineNo, line) );
|
||||
String[] values = line.split(COMMA_DELIMITER, StandardItem.ITEM_COUNT);
|
||||
StandardItem item = new StandardItem(values);
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {
|
||||
throw new Exception(String.format("csv file %s parsing error lineNo=%d", filePath, lineNo), ex);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ArrayList<StandardItem> list = null;
|
||||
String filePath = "./resources/standard-layout.csv";
|
||||
try {
|
||||
LayoutReader reader = new CsvFileReader();
|
||||
list = (ArrayList<StandardItem>) reader.parse(filePath);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
StandardMessage message = null;;
|
||||
try {
|
||||
message = StandardMessageUtil.generate(list);
|
||||
logger.debug("@toCSVString\n" + message.toCSVString());
|
||||
logger.debug("@toString\n" + message.toString());
|
||||
logger.debug("@toJson\n" + message.toJson());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.eactive.eai.message.layout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.eactive.eai.common.stdmessage.loader.StandardMessageLayoutDeployLoader;
|
||||
import com.eactive.eai.common.stdmessage.loader.StandardMessageLayoutLoader;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageLayoutDeploy;
|
||||
import com.eactive.eai.data.entity.onl.stdmessage.StandardMessageLayoutItem;
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
|
||||
@Component
|
||||
@Transactional
|
||||
public class DatabaseReader implements LayoutReader {
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
@Autowired
|
||||
private StandardMessageLayoutDeployLoader standardMessageLayoutDeployLoader;
|
||||
|
||||
@Autowired
|
||||
private StandardMessageLayoutLoader standardMessageLayoutLoader;
|
||||
|
||||
@Override
|
||||
public ArrayList<StandardItem> parse(String layoutName) throws Exception {
|
||||
logger.info("DB Reader Init");
|
||||
|
||||
boolean isMaster = false;
|
||||
String targetLayoutName = null;
|
||||
if(StringUtils.isBlank(layoutName)){
|
||||
StandardMessageLayoutDeploy deploy = standardMessageLayoutDeployLoader.findFirst();
|
||||
if(deploy != null){
|
||||
targetLayoutName = deploy.getLayoutName();
|
||||
isMaster = true;
|
||||
}
|
||||
}else{
|
||||
targetLayoutName = layoutName;
|
||||
}
|
||||
|
||||
ArrayList<StandardItem> list = new ArrayList<>();
|
||||
if(StringUtils.isNotBlank(targetLayoutName)){
|
||||
//로그 적재 시 사용 될 표준전문 레아이아웃 명을 저장한다(현재 로그저장 아키텍처 개선방안이 없어 임시로 작성한 코드이다)
|
||||
// SUB 표준전문 로딩으로 로직 수정함.
|
||||
if(isMaster) {
|
||||
System.setProperty("STANDARD_LAYOUT_NAME", targetLayoutName);
|
||||
logger.info("DB Reader Target Layout Name - {}", targetLayoutName);
|
||||
}
|
||||
Collection<StandardMessageLayoutItem> entityList = standardMessageLayoutLoader.getById(targetLayoutName)
|
||||
.getStandardMessageLayoutItems();
|
||||
|
||||
for (StandardMessageLayoutItem entityItem : entityList) {
|
||||
StandardItem item = new StandardItem(entityItem);
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.eactive.eai.message.layout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
|
||||
public interface LayoutReader {
|
||||
public ArrayList<StandardItem> parse(String fileParh) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,450 @@
|
||||
package com.eactive.eai.message.manager;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.eactive.eai.common.exception.ExceptionUtil;
|
||||
import com.eactive.eai.common.lifecycle.Lifecycle;
|
||||
import com.eactive.eai.common.lifecycle.LifecycleException;
|
||||
import com.eactive.eai.common.lifecycle.LifecycleListener;
|
||||
import com.eactive.eai.common.lifecycle.LifecycleSupport;
|
||||
import com.eactive.eai.common.util.Logger;
|
||||
import com.eactive.eai.message.EncodingVar;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.StandardMessageUtil;
|
||||
import com.eactive.eai.message.filter.MessageFilter;
|
||||
import com.eactive.eai.message.mapper.MessageMapper;
|
||||
import com.eactive.eai.message.parser.StandardReader;
|
||||
import com.eactive.eai.message.service.InterfaceMapper;
|
||||
import com.eactive.eai.message.service.StandardMessageCoordinator;
|
||||
|
||||
public class StandardMessageManager implements Lifecycle {
|
||||
static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||
|
||||
private static StandardMessageManager instance;
|
||||
private boolean started;
|
||||
private LifecycleSupport lifecycle = new LifecycleSupport(this);
|
||||
|
||||
/**
|
||||
# standard-message-config.properties
|
||||
# layout : StandardMessage layout definition
|
||||
layout.file.type=CSV
|
||||
layout.file.path=./resources/standard-layout.csv
|
||||
# mapper : StandardMessage's fields getter/setter interface
|
||||
mapper.class=com.eactive.eai.message.service.DefaultInterfaceMapper
|
||||
mapper.definition=./resources/standard-message-mapping-config.properties
|
||||
# reader : parsing input data to StandardMessage
|
||||
reader.JSON=com.eactive.eai.message.parser.JsonReader
|
||||
reader.XML=com.eactive.eai.message.parser.XmlReader
|
||||
reader.FLAT=com.eactive.eai.message.parser.FlatReader
|
||||
*/
|
||||
public static String STANDARD_MESSAGE_CONFIG = "standard.message.config";
|
||||
private String DEFAULT_CONFIG_PATH = "./resources/standard-message-config.properties";
|
||||
private String DEFAULT_CONFIG_FILE = "standard-message-config.properties";
|
||||
|
||||
private String LAYOUT_FILE_TYPE = "layout.file.type";
|
||||
private String LAYOUT_FILE_PATH = "layout.file.path";
|
||||
|
||||
private String LAYOUT_FILTER = "layout.filter.FLAT";
|
||||
|
||||
private String MAPPER_CLASS = "mapper.class";
|
||||
private String MAPPER_DEFINITION = "mapper.definition";
|
||||
private String READER_PREFIX = "reader.";
|
||||
|
||||
private String ENCODE_FLAT = "encode.flat";
|
||||
private String ENCODE_XML = "encode.xml";
|
||||
private String ENCODE_JSON = "encode.json";
|
||||
|
||||
private String COORDINATOR_CLASS = "message.coordinator.class";
|
||||
private String DEFAULT_COORDINATOR_CLASS = "com.eactive.eai.message.service.DefaultStandardMessageCoordinator";
|
||||
private String REQUEST_PROCESSOR_CLASS = "requestProcessor.class";
|
||||
|
||||
private StandardMessage standardMessage = null;
|
||||
private InterfaceMapper mapper;
|
||||
private StandardMessageCoordinator messageCoordinator;
|
||||
|
||||
private ConcurrentHashMap<String, StandardReader> readerMap = null;
|
||||
|
||||
private Map<String, String> versionMap = new HashMap<>();;
|
||||
private String VERSION_LAYOUT_NAME = "version.layout.name";
|
||||
private String VERSION_LAYOUT_FILTER = "version.layout.filter.FLAT";
|
||||
private String VERSION_MAPPER = "version.mapper";
|
||||
private String VERSION_MAPPING_DEFINATION = "version.mapper.definition";
|
||||
private MessageMapper versionMapper;
|
||||
private StandardMessage versionMessage = null;
|
||||
private String versionLayoutName = null;
|
||||
|
||||
public Map<String, String> getVersionMap() {
|
||||
return versionMap;
|
||||
}
|
||||
|
||||
public void setVersionMap(Map<String, String> versionMap) {
|
||||
this.versionMap = versionMap;
|
||||
}
|
||||
|
||||
public String getVersionLayoutName() {
|
||||
return versionLayoutName;
|
||||
}
|
||||
|
||||
public void setVersionLayoutName(String versionLayoutName) {
|
||||
this.versionLayoutName = versionLayoutName;
|
||||
}
|
||||
|
||||
public synchronized StandardMessage getVersionMessage() {
|
||||
if(versionMessage == null) return null;
|
||||
try {
|
||||
return (StandardMessage) versionMessage.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return SerializationUtils.clone(standardMessage);
|
||||
}
|
||||
}
|
||||
|
||||
private StandardMessageManager() {
|
||||
readerMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public static StandardMessageManager getInstance() {
|
||||
return LazyHolder.INSTANCE;
|
||||
}
|
||||
private static class LazyHolder {
|
||||
private static final StandardMessageManager INSTANCE = new StandardMessageManager();
|
||||
}
|
||||
|
||||
public void start() throws LifecycleException {
|
||||
if (started)
|
||||
throw new LifecycleException("RECEAICMM201");
|
||||
|
||||
lifecycle.fireLifecycleEvent(STARTING_EVENT, this);
|
||||
|
||||
try {
|
||||
init();
|
||||
} catch(Exception e) {
|
||||
throw new LifecycleException(ExceptionUtil.getErrorCode(e,"RECEAICMM202"));
|
||||
}
|
||||
|
||||
started = true;
|
||||
lifecycle.fireLifecycleEvent(STARTED_EVENT, this);
|
||||
}
|
||||
|
||||
public void stop() throws LifecycleException {
|
||||
if (!started)
|
||||
throw new LifecycleException("RECEAICMM203");
|
||||
|
||||
lifecycle.fireLifecycleEvent(STOPING_EVENT, this);
|
||||
readerMap.clear();
|
||||
readerMap = null;
|
||||
started = false;
|
||||
lifecycle.fireLifecycleEvent(STOPPED_EVENT, this);
|
||||
}
|
||||
|
||||
public void addLifecycleListener(LifecycleListener listener)
|
||||
{
|
||||
lifecycle.addLifecycleListener(listener);
|
||||
}
|
||||
|
||||
public LifecycleListener[] findLifecycleListeners()
|
||||
{
|
||||
return lifecycle.findLifecycleListeners();
|
||||
}
|
||||
|
||||
public void removeLifecycleListener(LifecycleListener listener)
|
||||
{
|
||||
lifecycle.removeLifecycleListener(listener);
|
||||
}
|
||||
|
||||
public boolean isStarted() {
|
||||
return this.started;
|
||||
}
|
||||
|
||||
public synchronized StandardMessage getStandardMessage() {
|
||||
try {
|
||||
return (StandardMessage) standardMessage.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
return SerializationUtils.clone(standardMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public MessageMapper getVersionMapper() {
|
||||
return versionMapper;
|
||||
}
|
||||
|
||||
public void setVersionMapper(MessageMapper versionMapper) {
|
||||
this.versionMapper = versionMapper;
|
||||
}
|
||||
|
||||
public InterfaceMapper getMapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public void setMapper(InterfaceMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public StandardMessageCoordinator getMessageCoordinator() {
|
||||
return messageCoordinator;
|
||||
}
|
||||
|
||||
public void setMessageCoordinator(StandardMessageCoordinator messageCoordinator) {
|
||||
this.messageCoordinator = messageCoordinator;
|
||||
}
|
||||
|
||||
public synchronized void reload() throws Exception {
|
||||
if(logger.isWarn()) {
|
||||
logger.warn("StandardMessageManager] reload all started ...");
|
||||
}
|
||||
init();
|
||||
if(logger.isWarn()) {
|
||||
logger.warn("StandardMessageManager] reload all finished ...");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void initReaderFactory(Properties config) {
|
||||
Class cl = null;
|
||||
StandardReader reader = null;
|
||||
|
||||
Set<Object> keys = config.keySet();
|
||||
|
||||
for(Object key: keys) {
|
||||
String keyStr = (String)key;
|
||||
if(keyStr.startsWith(READER_PREFIX)) {
|
||||
String name = keyStr.substring(READER_PREFIX.length());
|
||||
String readerClassName = config.getProperty(keyStr);
|
||||
|
||||
try {
|
||||
cl = Class.forName(readerClassName);
|
||||
reader = (StandardReader)cl.newInstance();
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
if(logger.isWarn()) logger.warn(String.format("Invalid class path : %s %s", keyStr, readerClassName), e);
|
||||
continue;
|
||||
}
|
||||
readerMap.put(name, reader);
|
||||
if(logger.isWarn()) logger.warn(String.format("# Add reader : %s %s", keyStr, readerClassName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public StandardReader getReader(String messageType) {
|
||||
return readerMap.get(messageType);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void init() throws Exception {
|
||||
try {
|
||||
Properties config = loadConfigFile();
|
||||
logger.debug(config.toString());
|
||||
|
||||
String encodeFlat = config.getProperty(ENCODE_FLAT, "euc-kr");
|
||||
String encodeXml = config.getProperty(ENCODE_XML, "utf-8");
|
||||
String encodeJson = config.getProperty(ENCODE_JSON, encodeXml);
|
||||
String requestProcessorClass = config.getProperty(REQUEST_PROCESSOR_CLASS);
|
||||
if(logger.isDebug()) {
|
||||
logger.debug( "{} : {}", ENCODE_FLAT, encodeFlat );
|
||||
logger.debug( "{} : {}", ENCODE_XML, encodeXml );
|
||||
logger.debug( "{} : {}", ENCODE_JSON, encodeJson );
|
||||
logger.debug( "{} : {}", REQUEST_PROCESSOR_CLASS, requestProcessorClass );
|
||||
}
|
||||
EncodingVar.flatEncoding = encodeFlat;
|
||||
EncodingVar.xmlEncoding = encodeXml;
|
||||
EncodingVar.jsonEncoding = encodeJson;
|
||||
StandardMessageUtil.requestProcessorClass = requestProcessorClass;
|
||||
|
||||
String layoutFileType = config.getProperty(LAYOUT_FILE_TYPE, "CSV");
|
||||
String path = config.getProperty(LAYOUT_FILE_PATH);
|
||||
if(logger.isDebug()) {
|
||||
// logger.debug( String.format("%s : %s", LAYOUT_FILE_TYPE, layoutFileType) );
|
||||
// logger.debug( String.format("%s : %s", LAYOUT_FILE_PATH, path) );
|
||||
logger.debug( "{} : {}", LAYOUT_FILE_TYPE, layoutFileType );
|
||||
logger.debug( "{} : {}", LAYOUT_FILE_PATH, path );
|
||||
}
|
||||
|
||||
|
||||
if("CSV".contentEquals(layoutFileType.toUpperCase())) {
|
||||
standardMessage = StandardMessageUtil.generateMessageFromCsvFile(path);
|
||||
} else if(StringUtils.startsWithIgnoreCase(layoutFileType, "DB")) {
|
||||
String layout = StringUtils.substring(layoutFileType, 3);
|
||||
standardMessage = StandardMessageUtil.generateMessageFromDb(StringUtils.trimToNull(layout));
|
||||
} else {
|
||||
standardMessage = StandardMessageUtil.generateMessageFromCsvFile(path);
|
||||
}
|
||||
|
||||
if(standardMessage != null) {
|
||||
standardMessage.setReadPosition(0);
|
||||
}
|
||||
String flatFilterClass = config.getProperty(LAYOUT_FILTER);
|
||||
logger.debug("{} : {}", LAYOUT_FILTER, flatFilterClass);
|
||||
|
||||
String versionFlatFilterClass = config.getProperty(VERSION_LAYOUT_FILTER);
|
||||
logger.debug("{} : {}", VERSION_LAYOUT_FILTER, versionFlatFilterClass);
|
||||
|
||||
|
||||
if(StringUtils.isNotBlank(flatFilterClass)) {
|
||||
try {
|
||||
Class cl = Class.forName(flatFilterClass);
|
||||
MessageFilter flatFilter = (MessageFilter)cl.newInstance();
|
||||
standardMessage.setFlatFilter(flatFilter);
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
if(logger.isWarn()) logger.warn(String.format("configure %s : %s", LAYOUT_FILTER, flatFilterClass), e);
|
||||
}
|
||||
}
|
||||
|
||||
String coordinatorClass = config.getProperty(COORDINATOR_CLASS, DEFAULT_COORDINATOR_CLASS);
|
||||
logger.debug("{} : {}", COORDINATOR_CLASS, coordinatorClass);
|
||||
try {
|
||||
Class cl = Class.forName(coordinatorClass);
|
||||
this.messageCoordinator = (StandardMessageCoordinator) cl.newInstance();
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
if (logger.isWarn())
|
||||
logger.warn(String.format("configure %s : %s", COORDINATOR_CLASS,
|
||||
config.getProperty(COORDINATOR_CLASS)), e);
|
||||
}
|
||||
|
||||
String mapperClass = config.getProperty(MAPPER_CLASS);
|
||||
String mapperFilePath = config.getProperty(MAPPER_DEFINITION);
|
||||
if(logger.isDebug()) logger.debug( String.format("%s : %s", MAPPER_CLASS, mapperClass) );
|
||||
if(logger.isDebug()) logger.debug( String.format("%s : %s", MAPPER_DEFINITION, mapperFilePath) );
|
||||
|
||||
if(mapperClass == null) {
|
||||
throw new Exception("StandardMessageManager | config error, not found config : " + MAPPER_CLASS);
|
||||
}
|
||||
if(mapperFilePath == null) {
|
||||
throw new Exception("StandardMessageManager | config error, not found config : " + MAPPER_DEFINITION);
|
||||
}
|
||||
|
||||
initReaderFactory(config);
|
||||
|
||||
Class cl = null;
|
||||
try {
|
||||
cl = Class.forName(mapperClass);
|
||||
mapper = (InterfaceMapper)cl.newInstance();
|
||||
Properties mapperMapPropties = loadConfigFileProperties(mapperFilePath);
|
||||
HashMap<String, String> map = propertyToMap(mapperMapPropties);
|
||||
mapper.initPathMap(map);
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if(logger.isDebug()) logger.debug("mapperClass : {}", mapper.getClass().getCanonicalName());
|
||||
|
||||
String versionMapperClass = config.getProperty(VERSION_MAPPER);
|
||||
if(StringUtils.isEmpty(versionMapperClass)) {
|
||||
versionMapperClass = "com.eactive.eai.message.mapper.DefaultMessageMapper";
|
||||
}
|
||||
if(logger.isDebug()) logger.debug("version.mapper : {}", versionMapperClass);
|
||||
try {
|
||||
Class clazz = Class.forName(versionMapperClass);
|
||||
versionMapper = (MessageMapper)clazz.newInstance();
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if(logger.isDebug()) logger.debug("version.mapper class : {}", versionMapper.getClass().getCanonicalName());
|
||||
|
||||
String versionMapFilePath = config.getProperty(VERSION_MAPPING_DEFINATION);
|
||||
if(logger.isDebug()) logger.debug( String.format("%s : %s", VERSION_MAPPING_DEFINATION, versionMapFilePath) );
|
||||
if(versionMapFilePath != null) {
|
||||
Properties versionMapPropties = loadConfigFileProperties(versionMapFilePath);
|
||||
versionMap = propertyToMap(versionMapPropties);
|
||||
}
|
||||
if(logger.isDebug()) logger.debug("versionMap size ="+ versionMap.size() );
|
||||
|
||||
versionLayoutName = config.getProperty(VERSION_LAYOUT_NAME);
|
||||
if(logger.isDebug()) logger.debug( String.format("%s : %s", VERSION_LAYOUT_NAME, versionLayoutName) );
|
||||
if(versionLayoutName != null) {
|
||||
versionMessage = StandardMessageUtil.generateMessageFromDb(versionLayoutName);
|
||||
versionMessage.setReadPosition(0);
|
||||
|
||||
if(StringUtils.isNotBlank(versionFlatFilterClass)) {
|
||||
try {
|
||||
Class vcl = Class.forName(versionFlatFilterClass);
|
||||
MessageFilter versionFlatFilter = (MessageFilter)vcl.newInstance();
|
||||
versionMessage.setFlatFilter(versionFlatFilter);
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
|
||||
if(logger.isWarn()) logger.warn(String.format("configure %s : %s", VERSION_LAYOUT_FILTER, versionFlatFilterClass), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {
|
||||
ex.printStackTrace();
|
||||
logger.error("init failed", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, String> propertyToMap(Properties prop) {
|
||||
HashMap<String, String> retMap = new HashMap<>();
|
||||
for (Map.Entry<Object, Object> entry : prop.entrySet()) {
|
||||
retMap.put(String.valueOf(entry.getKey()).trim(), String.valueOf(entry.getValue()).trim());
|
||||
}
|
||||
return retMap;
|
||||
}
|
||||
|
||||
private Properties loadConfigFile() throws Exception {
|
||||
String configFile = getConfigFile();
|
||||
return loadConfigFileProperties(configFile);
|
||||
}
|
||||
|
||||
private Properties loadConfigFileProperties(String configFile) throws Exception {
|
||||
try {
|
||||
return loadFileProperties(configFile);
|
||||
}
|
||||
catch(Exception e) {
|
||||
// logger.warn("StandardMessageManager | loadFileProperties failed. - " + configFile, e);
|
||||
logger.warn("StandardMessageManager | loadFileProperties failed. - " + configFile +", " +e.getMessage());
|
||||
}
|
||||
// try classpath file
|
||||
return loadClassPathProperties(configFile);
|
||||
}
|
||||
|
||||
private Properties loadFileProperties(String filePath) throws Exception {
|
||||
logger.debug("configFile : ", filePath);
|
||||
Properties p = new Properties();
|
||||
try(InputStream in = new FileInputStream(filePath)) {
|
||||
p.load(in);
|
||||
return p;
|
||||
} catch(Exception e) {
|
||||
throw new Exception("StandardMessageManager | Cannot load config file. - " + filePath, e);
|
||||
}
|
||||
}
|
||||
|
||||
private Properties loadClassPathProperties(String filePath) throws Exception {
|
||||
Properties p = new Properties();
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
logger.warn("StandardMessageManager | ClassLoader : load. - "+ filePath);
|
||||
try( InputStream in = classLoader.getResourceAsStream(filePath) ) {
|
||||
p.load(in);
|
||||
return p;
|
||||
} catch(Exception e) {
|
||||
if(logger.isWarn()) {
|
||||
// logger.warn("StandardMessageManager | ClassLoader : Cannot load config file. - " + filePath, e);
|
||||
logger.warn("StandardMessageManager | ClassLoader : Cannot load config file. - " + filePath +", " +e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
logger.warn("StandardMessageManager | ClassLoader : load default - "+ DEFAULT_CONFIG_FILE);
|
||||
try( InputStream in = classLoader.getResourceAsStream(DEFAULT_CONFIG_FILE) ) {
|
||||
p.load(in);
|
||||
logger.warn("StandardMessageManager | ClassLoader : load default success - "+ DEFAULT_CONFIG_FILE);
|
||||
return p;
|
||||
} catch(Exception e) {
|
||||
logger.error("StandardMessageManager | ClassLoader : Cannot load default config file. - " + DEFAULT_CONFIG_FILE, e);
|
||||
throw new Exception("StandardMessageManager | ClassLoader : Cannot load default config file. - " + DEFAULT_CONFIG_FILE, e);
|
||||
}
|
||||
}
|
||||
private String getConfigFile() {
|
||||
String configFilePath = System.getProperty(STANDARD_MESSAGE_CONFIG);
|
||||
if (StringUtils.isEmpty(configFilePath)) {
|
||||
return DEFAULT_CONFIG_PATH;
|
||||
} else {
|
||||
return configFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.eactive.eai.message.mapper;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.layout.LayoutReader;
|
||||
import com.eactive.eai.message.manager.StandardMessageManager;
|
||||
import com.eactive.eai.message.parser.StandardReader;
|
||||
|
||||
public class DefaultMessageMapper implements MessageMapper {
|
||||
|
||||
public StandardMessage parseSub(String msgType, Object message) throws Exception {
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
StandardMessage subMessage = standardManager.getVersionMessage();
|
||||
StandardReader reader = standardManager.getReader(msgType);
|
||||
reader.parse(subMessage, message);
|
||||
return subMessage;
|
||||
}
|
||||
|
||||
public StandardMessage mapFromSub(StandardMessage subMessage, StandardMessage orgStandardMessage) throws Exception {
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
Map<String, String> mappingMap = standardManager.getVersionMap();
|
||||
StandardMessage standardMessage = null;
|
||||
|
||||
if (orgStandardMessage == null) {
|
||||
standardMessage = standardManager.getStandardMessage();
|
||||
} else {
|
||||
standardMessage = orgStandardMessage;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> entry : mappingMap.entrySet()) {
|
||||
map(subMessage, entry.getValue(), standardMessage, entry.getKey());
|
||||
}
|
||||
return standardMessage;
|
||||
}
|
||||
|
||||
// Sub request inbound(100), Sub response outbound(300)
|
||||
// parse sub -> mapping to standard
|
||||
public StandardMessage mapFromSub(String msgType, Object message, StandardMessage orgStandardMessage)
|
||||
throws Exception {
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
|
||||
StandardMessage subMessage = parseSub(msgType, message);
|
||||
|
||||
Map<String, String> mappingMap = standardManager.getVersionMap();
|
||||
StandardMessage standardMessage = null;
|
||||
|
||||
if (orgStandardMessage == null) {
|
||||
standardMessage = standardManager.getStandardMessage();
|
||||
} else {
|
||||
standardMessage = orgStandardMessage;
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> entry : mappingMap.entrySet()) {
|
||||
map(subMessage, entry.getValue(), standardMessage, entry.getKey());
|
||||
}
|
||||
return standardMessage;
|
||||
}
|
||||
|
||||
// Sub response inbound(400), Sub request outbound(200)
|
||||
public StandardMessage convertToSub(StandardMessage standardMessage) throws Exception {
|
||||
return convertToSub(standardMessage, null);
|
||||
}
|
||||
|
||||
public StandardMessage convertToSub(StandardMessage standardMessage, StandardMessage subMessage) throws Exception {
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
if (subMessage == null) {
|
||||
subMessage = standardManager.getVersionMessage();
|
||||
}
|
||||
Map<String, String> mappingMap = standardManager.getVersionMap();
|
||||
// Standard -> Sub
|
||||
for (Map.Entry<String, String> entry : mappingMap.entrySet()) {
|
||||
map(standardMessage, entry.getKey(), subMessage, entry.getValue());
|
||||
}
|
||||
return subMessage;
|
||||
}
|
||||
|
||||
// Not used until now
|
||||
public StandardMessage convertToStandard(StandardMessage subMessage, StandardMessage standardMessage)
|
||||
throws Exception {
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
Map<String, String> mappingMap = standardManager.getVersionMap();
|
||||
// Sub -> Standard
|
||||
for (Map.Entry<String, String> entry : mappingMap.entrySet()) {
|
||||
map(subMessage, entry.getValue(), standardMessage, entry.getKey());
|
||||
}
|
||||
return standardMessage;
|
||||
}
|
||||
|
||||
public void map(StandardMessage sourceMessage, String sourcePath, StandardMessage targetMessage,
|
||||
String targetPath) {
|
||||
if (sourceMessage == null || StringUtils.isBlank(sourcePath) || targetMessage == null
|
||||
|| StringUtils.isBlank(targetPath)) {
|
||||
return;
|
||||
}
|
||||
StandardItem sItem = sourceMessage.findItem(sourcePath);
|
||||
StandardItem tItem = targetMessage.findItem(targetPath);
|
||||
if (sItem != null && tItem != null) {
|
||||
tItem.setValue(sItem.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.eactive.eai.message.mapper;
|
||||
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
|
||||
public interface MessageMapper {
|
||||
public StandardMessage parseSub(String msgType, Object message) throws Exception;
|
||||
|
||||
// Sub request inbound(100), Sub response outbound(300)
|
||||
// parse sub -> mapping to standard
|
||||
public StandardMessage mapFromSub(StandardMessage subMessage, StandardMessage orgStandardMessage) throws Exception;
|
||||
|
||||
public StandardMessage mapFromSub(String msgType, Object message, StandardMessage orgStandardMessage) throws Exception;
|
||||
|
||||
// Sub response inbound(400), Sub request outbound(200)
|
||||
public StandardMessage convertToSub(StandardMessage standardMessage) throws Exception;
|
||||
public StandardMessage convertToSub(StandardMessage standardMessage, StandardMessage subMessage) throws Exception;
|
||||
|
||||
// Not used until now
|
||||
public StandardMessage convertToStandard(StandardMessage subMessage, StandardMessage standardMessage) throws Exception;
|
||||
|
||||
public void map(StandardMessage sourceMessage, String sourcePath, StandardMessage targetMessage,
|
||||
String targetPath);
|
||||
}
|
||||
@@ -0,0 +1,289 @@
|
||||
package com.eactive.eai.message.parser;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.eactive.eai.message.EncodingVar;
|
||||
import com.eactive.eai.message.StandardDataType;
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.StandardType;
|
||||
|
||||
public class FlatReader implements StandardReader {
|
||||
static Logger logger = LoggerFactory.getLogger(FlatReader.class);
|
||||
private char FIELD_SEPARATOR = '.';
|
||||
private boolean ZERO_BASE_INDEX = true;
|
||||
|
||||
public FlatReader() {
|
||||
|
||||
}
|
||||
|
||||
public StandardMessage parse(StandardMessage message, Object flatObject) throws Exception {
|
||||
ArrayList<StandardItem> list = message.toList();
|
||||
for(int i=0; i<list.size(); i++) {
|
||||
StandardItem item = list.get(i);
|
||||
logger.debug("{} Level={} Name={}", i, item.getLevel(), item.getName());
|
||||
}
|
||||
|
||||
byte[] srcbytes = null;
|
||||
String encoding = EncodingVar.flatEncoding;
|
||||
if (flatObject instanceof String) {
|
||||
try {
|
||||
logger.debug("Encoding : {}", encoding);
|
||||
srcbytes = ((String) flatObject).getBytes(encoding);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
srcbytes = ((String) flatObject).getBytes();
|
||||
}
|
||||
} else {
|
||||
srcbytes = (byte[]) flatObject;
|
||||
}
|
||||
|
||||
// make item map(path, value)
|
||||
LinkedHashMap<String, String> itemMap = new LinkedHashMap<String, String>();
|
||||
|
||||
message.setReadPosition(0);
|
||||
|
||||
traverse(message, message, srcbytes, null, itemMap);
|
||||
int remain = srcbytes.length - message.getReadPosition();
|
||||
if(remain > 0) {
|
||||
throw new Exception("flat message parsing error(overflow) remain size="+remain);
|
||||
}
|
||||
|
||||
message.setBizDataCharset(encoding);
|
||||
logger.debug("setBizDataCharset : {}", encoding);
|
||||
|
||||
// for(String key:itemMap.keySet()) {
|
||||
// logger.debug("~ itemMap : {} => {}", key, itemMap.get(key) );
|
||||
// }
|
||||
return message;
|
||||
}
|
||||
|
||||
private void traverse(StandardMessage message, StandardItem currentItem, byte[] srcbytes, String parentName
|
||||
, LinkedHashMap<String, String> itemMap){
|
||||
String fieldName = null;
|
||||
ArrayList<StandardItem> childList = null;
|
||||
StandardItem item = null;
|
||||
|
||||
int type = currentItem.getType();
|
||||
int start = message.getReadPosition();
|
||||
fieldName = genPath(parentName, currentItem.getName());
|
||||
logger.debug("<-> CALL path = " + fieldName);
|
||||
switch(type) {
|
||||
case StandardType.MESSAGE:
|
||||
childList = currentItem.getChildsList();
|
||||
for(int i=0; i<childList.size(); i++) {
|
||||
item = childList.get(i);
|
||||
logger.debug("@MESSAGE path = {}, start={}, length={}, value=[{}]", fieldName, start, item.getLength(), item.getValue());
|
||||
traverse(message, item, srcbytes, null, itemMap);
|
||||
}
|
||||
break;
|
||||
case StandardType.FIELD:
|
||||
item = currentItem; //message.findItem(fieldName, FIELD_SEPARATOR, ZERO_BASE_INDEX, true);
|
||||
//아래로직은 BIZDATA 에서 처리 하기 때문에 삭제
|
||||
// if(item.getDataType() == StandardDataType.ZZ_STRING) {
|
||||
//// start = start - item.getLength();
|
||||
// logger.debug("@FIELD path = {}, start={}, length={}, ZZ check start {}", fieldName, start, item.getLength(), item.getValue(), start);
|
||||
// // cut bizData
|
||||
// try {
|
||||
// message.cutBizData(item.getLength());
|
||||
// } catch (Exception e) {
|
||||
// logger.error("@FIELD path = {}, start={}, length={}, cutBizData Failed", fieldName, start, item.getLength(), e);
|
||||
// }
|
||||
// }
|
||||
byte[] value = cut(fieldName, srcbytes, start, item.getLength());
|
||||
item.setBytesValue(value, EncodingVar.flatEncoding);
|
||||
itemMap.put(fieldName, item.getValue());
|
||||
logger.debug("@FIELD path = {}, start={}, length={}, value=[{}]", fieldName, start, item.getLength(), item.getValue());
|
||||
start = start + item.getLength();
|
||||
message.setReadPosition(start);
|
||||
break;
|
||||
case StandardType.GROUP:
|
||||
logger.debug("@GROUP name={}, getLength={}, getRefPath={}, getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getLength(), currentItem.getRefPath(), currentItem.getRefValue());
|
||||
if( currentItem.getSize() == 0
|
||||
&& StringUtils.isNotBlank(currentItem.getRefPath())
|
||||
&& StringUtils.isNotBlank(currentItem.getRefValue()) ) {
|
||||
String refItemValue = itemMap.get(currentItem.getRefPath());
|
||||
|
||||
logger.debug("@GROUP name={}, getRefPath={}, refItemValue=[{}], getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getRefPath(), refItemValue, currentItem.getRefValue());
|
||||
|
||||
if(refItemValue != null) refItemValue = refItemValue.trim();
|
||||
|
||||
/*
|
||||
* 값의 경우의수 NR,ER,""(blank)
|
||||
* ER이 아닐경우 표현하고 싶어서 ! 를 추가했음
|
||||
* 원칙으로는 NR을 넣었을경우에는 NR 이 있을경우에만 해당됨
|
||||
* !ER일경우에는 blank와 NR일 경우에 해당됨
|
||||
*/
|
||||
String refValue = currentItem.getRefValue();
|
||||
if (refValue.startsWith("!")) { // 느낌표가 들어가면 다음에 나오는게 아닌경우
|
||||
refValue = refValue.substring(1);
|
||||
if (refValue.equals(refItemValue)) {
|
||||
logger.warn("@GROUP name={} SKIPPED.", currentItem.getName());
|
||||
currentItem.setHidden(true);
|
||||
break;
|
||||
} else {
|
||||
currentItem.setHidden(false);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!currentItem.getRefValue().equals(refItemValue)) {
|
||||
logger.warn("@GROUP name={} SKIPPED.", currentItem.getName());
|
||||
currentItem.setHidden(true);
|
||||
break;
|
||||
} else {
|
||||
currentItem.setHidden(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
childList = currentItem.getChildsList();
|
||||
for(int i=0; i<childList.size(); i++) {
|
||||
item = childList.get(i);
|
||||
logger.debug("@GROUP item={}, path = {}, start={}, length={}, value=[{}]", item.getName(), fieldName, start, item.getLength(), item.getValue());
|
||||
traverse(message, item, srcbytes, fieldName, itemMap);
|
||||
}
|
||||
if( currentItem.getSize() == 0) {
|
||||
currentItem.setSize(1);
|
||||
}
|
||||
break;
|
||||
case StandardType.GRID:
|
||||
logger.debug("@GRID name={}, getLength={}, getRefPath={}, getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getLength(), currentItem.getRefPath(), currentItem.getRefValue());
|
||||
if( currentItem.getSize() == 0
|
||||
&& (StringUtils.isNotBlank(currentItem.getRefPath())
|
||||
|| StringUtils.isNotBlank(currentItem.getRefValue())) ) {
|
||||
String refItemValue = "";
|
||||
if (StringUtils.isNotBlank(currentItem.getRefPath())) {
|
||||
refItemValue = itemMap.get(currentItem.getRefPath());
|
||||
currentItem.setRefValue(refItemValue);
|
||||
} else {
|
||||
refItemValue = currentItem.getRefValue();
|
||||
}
|
||||
currentItem.setSize(NumberUtils.toInt(StringUtils.trim(refItemValue)));
|
||||
|
||||
logger.debug("@GRID name={}, getRefPath={}, refItemValue=[{}], getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getRefPath(), refItemValue, currentItem.getRefValue());
|
||||
|
||||
if( !currentItem.getRefValue().equals(refItemValue) ) {
|
||||
logger.warn("@GRID name={} SKIPPED.", currentItem.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
int arraySize = currentItem.getSize();
|
||||
for(int ai = 0; ai<arraySize; ai++) {
|
||||
LinkedHashMap<String, StandardItem> map = currentItem.getArrayChilds(ai, true);
|
||||
if(map == null) {
|
||||
logger.warn("Array create failed item path = {}", fieldName +"[" + ai +"]");
|
||||
continue;
|
||||
}
|
||||
childList = new ArrayList<StandardItem>(map.values());
|
||||
for(int i=0; i<childList.size(); i++) {
|
||||
item = childList.get(i);
|
||||
logger.debug("@ARRAY parent path = {}, item={}, start={}, length={}, current value=[{}]", fieldName+"[" + ai +"]", item.getName(), start, item.getLength(), item.getValue());
|
||||
traverse(message, item, srcbytes, fieldName +"[" + ai +"]", itemMap);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case StandardType.FARRAY:
|
||||
logger.debug("@FARRAY name={}, getLength={}, getRefPath={}, getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getLength(), currentItem.getRefPath(), currentItem.getRefValue());
|
||||
|
||||
int farraySize = currentItem.getSize();
|
||||
item = currentItem; //message.findItem(fieldName, FIELD_SEPARATOR, ZERO_BASE_INDEX, true);
|
||||
for(int ai = 0; ai<farraySize; ai++) {
|
||||
//아래로직은 BIZDATA 에서 처리 하기 때문에 삭제
|
||||
// if(item.getDataType() == StandardDataType.ZZ_STRING) {
|
||||
// start = start - item.getLength();
|
||||
// logger.debug("@FARRAY path = {}, start={}, length={}, ZZ check start {}", fieldName, start, item.getLength(), item.getValue(), start);
|
||||
// // cut bizData
|
||||
// try {
|
||||
// message.cutBizData(item.getLength());
|
||||
// } catch (Exception e) {
|
||||
// logger.error("@FARRAY path = {}, start={}, length={}, cutBizData Failed", fieldName, start, item.getLength(), e);
|
||||
// }
|
||||
// }
|
||||
value = cut(fieldName, srcbytes, start, item.getLength());
|
||||
item.addBytesValue(value);
|
||||
|
||||
itemMap.put(fieldName, item.getValue());
|
||||
logger.debug("@FARRAY path = {}, start={}, length={}, value=[{}]", fieldName, start, item.getLength(), item.getValue());
|
||||
start = start + item.getLength();
|
||||
message.setReadPosition(start);
|
||||
}
|
||||
break;
|
||||
case StandardType.BIZDATA:
|
||||
// FIX-ME : how to calculate bzi data size ?
|
||||
// current : bizData is last item in layout items (variable size)
|
||||
item = message.findItem(fieldName, FIELD_SEPARATOR, ZERO_BASE_INDEX, true);
|
||||
int bizDataSize = item.getLength();
|
||||
int zzLength = 0;
|
||||
String zzDataPath = message.getZzDataPath();
|
||||
if(StringUtils.isNotEmpty(zzDataPath)) {
|
||||
try {
|
||||
StandardItem zzItem = message.findItem(zzDataPath);
|
||||
if(zzItem != null) {
|
||||
zzLength = zzItem.getLength();
|
||||
}
|
||||
}
|
||||
catch(Exception ex) {
|
||||
logger.warn("ZzData check error", ex);
|
||||
}
|
||||
}
|
||||
if(bizDataSize == 0) {
|
||||
bizDataSize = srcbytes.length - start - zzLength;
|
||||
}
|
||||
byte[] bizDataBytes = cut(fieldName, srcbytes, start, bizDataSize);
|
||||
|
||||
item.setBytesValue(bizDataBytes, EncodingVar.flatEncoding);
|
||||
|
||||
itemMap.put(fieldName, item.getValue());
|
||||
logger.debug("@BIZDATA path = {}, start={}, length={}, value=[{}]", fieldName, start, item.getLength(), item.getValue());
|
||||
start = start + bizDataSize;
|
||||
message.setReadPosition(start);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private String genPath(String parent, String nodeName) {
|
||||
if(parent == null || parent.length() < 1) {
|
||||
return nodeName;
|
||||
}
|
||||
return parent + FIELD_SEPARATOR + nodeName;
|
||||
}
|
||||
|
||||
private static byte[] cut(String fieldName, byte[] srcBytes, int start, int length) {
|
||||
if (srcBytes == null) {
|
||||
return null;
|
||||
}
|
||||
if (srcBytes.length < (start+length)) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("item="+ fieldName);
|
||||
sb.append(", cut failed(underflow) - start index=" + start);
|
||||
sb.append(", item length=" + length);
|
||||
sb.append(", total size=" + srcBytes.length);
|
||||
throw new RuntimeException(sb.toString());
|
||||
}
|
||||
|
||||
byte[] result = new byte[length];
|
||||
int end = start + length;
|
||||
int p=0;
|
||||
for (int i = start; i < end; i++) {
|
||||
result[p] = srcBytes[i];
|
||||
p++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// public static void main(String[] args) {
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
package com.eactive.eai.message.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.eactive.eai.message.EncodingVar;
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.StandardType;
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeType;
|
||||
|
||||
public class JsonReader implements StandardReader {
|
||||
static Logger logger = LoggerFactory.getLogger(JsonReader.class);
|
||||
private char FIELD_SEPARATOR = '.';
|
||||
private boolean ZERO_BASE_INDEX = true;
|
||||
|
||||
public JsonReader() {
|
||||
|
||||
}
|
||||
|
||||
public StandardMessage parse(StandardMessage message, Object obj) throws Exception {
|
||||
String jsonString;
|
||||
if (obj instanceof byte[]) {
|
||||
jsonString = new String((byte[]) obj, EncodingVar.jsonEncoding);
|
||||
} else {
|
||||
jsonString = (String) obj;
|
||||
}
|
||||
|
||||
JsonNode jsonNode = null;
|
||||
ObjectMapper mapper = null;
|
||||
JsonFactory factory = null;
|
||||
JsonParser parser = null;
|
||||
mapper = new ObjectMapper();
|
||||
mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
|
||||
factory = mapper.getFactory();
|
||||
try {
|
||||
parser = factory.createParser(jsonString);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
try {
|
||||
jsonNode = mapper.readTree(parser);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
|
||||
// ArrayList<StandardItem> list = message.toList();
|
||||
// for(int i=0; i<list.size(); i++) {
|
||||
// StandardItem item = list.get(i);
|
||||
// logger.debug( i + " - "+ item.getLevel() + " : " +item.getName());
|
||||
// }
|
||||
// ArrayList<StandardItem> childList = message.getChildsList();
|
||||
// int i=0;
|
||||
// for(StandardItem item:childList) {
|
||||
// logger.debug( i++ + " - "+ item.getLevel() + " : " +item.getName());
|
||||
// jsonNode.get(item.getName());
|
||||
// }
|
||||
|
||||
// make json map(path, value)
|
||||
LinkedHashMap<String, String> itemMap = new LinkedHashMap<String, String>();
|
||||
traverse(message, jsonNode, null, itemMap);
|
||||
|
||||
// for(String key:itemMap.keySet()) {
|
||||
// logger.debug("~ itemMap : " + key + " => " + itemMap.get(key));
|
||||
// }
|
||||
return message;
|
||||
}
|
||||
|
||||
private void traverse(StandardMessage message, JsonNode currentNode, String parentName, LinkedHashMap<String, String> itemMap){
|
||||
StandardItem currentItem = null;
|
||||
String fieldName = null;
|
||||
if(parentName != null) {
|
||||
if(logger.isDebugEnabled()) logger.debug("$ findItem :: findItem="+ parentName);
|
||||
currentItem = message.findItem(parentName, FIELD_SEPARATOR, ZERO_BASE_INDEX, true);
|
||||
if(currentItem == null) {
|
||||
if(logger.isDebugEnabled()) logger.debug("$ SKIP :: undefined path in StandardMessage node name="+ parentName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(currentNode == null) {
|
||||
if(logger.isDebugEnabled()) logger.debug("$ SKIP :: node is NULL name="+ parentName);
|
||||
return;
|
||||
}
|
||||
|
||||
if( currentItem!=null && currentItem.getType() == StandardType.BIZDATA) {
|
||||
String bizData = null;
|
||||
if(currentNode.getNodeType() == JsonNodeType.STRING) {
|
||||
bizData = currentNode.asText();
|
||||
}
|
||||
else {
|
||||
bizData = currentNode.toString();
|
||||
}
|
||||
itemMap.put(parentName , bizData);
|
||||
currentItem.setValue(bizData);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(currentNode.getNodeType()) {
|
||||
case OBJECT:
|
||||
if( currentItem != null && currentItem.getSize() == 0
|
||||
&& StringUtils.isNotBlank(currentItem.getRefPath())
|
||||
&& StringUtils.isNotBlank(currentItem.getRefValue()) ) {
|
||||
String refItemValue = itemMap.get(currentItem.getRefPath());
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("@GROUP name={}, getRefPath={}, refItemValue=[{}], getRefValue=[{}]",
|
||||
currentItem.getName(), currentItem.getRefPath(), refItemValue,
|
||||
currentItem.getRefValue());
|
||||
|
||||
if (refItemValue != null) refItemValue = refItemValue.trim();
|
||||
String refValue = currentItem.getRefValue();
|
||||
if (refValue.startsWith("!")) { // 느낌표가 들어가면 다음에 나오는게 아닌경우
|
||||
refValue = refValue.substring(1);
|
||||
if (refValue.equals(refItemValue)) {
|
||||
logger.warn("@GROUP name={} SKIPPED.", currentItem.getName());
|
||||
currentItem.setHidden(true);
|
||||
break;
|
||||
} else {
|
||||
currentItem.setHidden(false);
|
||||
}
|
||||
} else {
|
||||
if (!currentItem.getRefValue().equals(refItemValue)) {
|
||||
if (logger.isDebugEnabled())
|
||||
logger.warn("@GROUP name={} SKIPPED.", currentItem.getName());
|
||||
currentItem.setHidden(true);
|
||||
break;
|
||||
} else {
|
||||
currentItem.setHidden(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Iterator<String> fieldNames = currentNode.fieldNames();
|
||||
while(fieldNames.hasNext()) {
|
||||
fieldName = fieldNames.next();
|
||||
JsonNode fieldValue = currentNode.get(fieldName);
|
||||
fieldName = genPath(parentName, fieldName);
|
||||
traverse(message, fieldValue, fieldName, itemMap);
|
||||
}
|
||||
if(currentItem != null && currentItem.getSize() == 0) {
|
||||
currentItem.setSize(1);
|
||||
}
|
||||
break;
|
||||
case ARRAY:
|
||||
if(logger.isDebugEnabled()) logger.debug("@ARRAY name={}, getLength={}, getRefPath={}, getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getLength(), currentItem.getRefPath(), currentItem.getRefValue());
|
||||
if( currentItem != null && currentItem.getSize() == 0
|
||||
&& StringUtils.isNotBlank(currentItem.getRefPath())
|
||||
&& StringUtils.isNotBlank(currentItem.getRefValue()) ) {
|
||||
String refItemValue = itemMap.get(currentItem.getRefPath());
|
||||
|
||||
if(logger.isDebugEnabled()) logger.debug("@ARRAY name={}, getRefPath={}, refItemValue=[{}], getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getRefPath(), refItemValue, currentItem.getRefValue());
|
||||
|
||||
if( !currentItem.getRefValue().equals(refItemValue) ) {
|
||||
if(logger.isDebugEnabled()) logger.warn("@ARRAY name={} SKIPPED.", currentItem.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
ArrayNode arrayNode = (ArrayNode) currentNode;
|
||||
for(int i = 0; i < arrayNode.size(); i++) {
|
||||
JsonNode arrayElement = arrayNode.get(i);
|
||||
traverse(message, arrayElement, parentName+"["+ i+"]", itemMap);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if(logger.isDebugEnabled()) logger.debug("parsing : " + parentName + "=" +currentNode.asText());
|
||||
itemMap.put(parentName , currentNode.asText());
|
||||
if(currentItem.getType() == StandardType.FARRAY) {
|
||||
currentItem.addValue(currentNode.asText());
|
||||
}
|
||||
else {
|
||||
currentItem.setValue(currentNode.asText());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private String genPath(String parent, String nodeName) {
|
||||
if(parent == null || parent.length() < 1) {
|
||||
return nodeName;
|
||||
}
|
||||
return parent +FIELD_SEPARATOR + nodeName;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.eactive.eai.message.parser;
|
||||
|
||||
public interface ReaderType {
|
||||
public final String FLAT = "FLAT";
|
||||
public final String ASC = "ASC";
|
||||
public final String XML = "XML";
|
||||
public final String UXML = "UXL";
|
||||
public final String JSON = "JSN";
|
||||
public final String UJSON = "UJN";
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.eactive.eai.message.parser;
|
||||
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
|
||||
public interface StandardReader {
|
||||
public StandardMessage parse(StandardMessage message, Object data) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package com.eactive.eai.message.parser;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dom4j.Attribute;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Node;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.eactive.eai.message.EncodingVar;
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.StandardType;
|
||||
|
||||
public class XmlReader implements StandardReader {
|
||||
static Logger logger = LoggerFactory.getLogger(XmlReader.class);
|
||||
private char FIELD_SEPARATOR = '/'; // XML use /
|
||||
private boolean ZERO_BASE_INDEX = false; // 1 base
|
||||
|
||||
private boolean BIZDATA_NAME_INCLUDE = true;
|
||||
|
||||
public XmlReader() {
|
||||
|
||||
}
|
||||
|
||||
public StandardMessage parse(StandardMessage message, Object obj) throws Exception {
|
||||
String xmlString;
|
||||
if (obj instanceof byte[]) {
|
||||
xmlString = new String((byte[]) obj, EncodingVar.xmlEncoding);
|
||||
} else {
|
||||
xmlString = (String) obj;
|
||||
}
|
||||
|
||||
org.dom4j.io.SAXReader saxReader = new org.dom4j.io.SAXReader();
|
||||
org.dom4j.Document document = null;
|
||||
try {
|
||||
document = saxReader.read(new StringReader(xmlString));
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
org.dom4j.Element root = document.getRootElement();
|
||||
// ArrayList<StandardItem> list = message.toList();
|
||||
// for(int i=0; i<list.size(); i++) {
|
||||
// StandardItem item = list.get(i);
|
||||
// logger.debug( i + " - "+ item.getLevel() + " : " +item.getName());
|
||||
// }
|
||||
|
||||
|
||||
// ArrayList<StandardItem> childList = message.getChildsList();
|
||||
// int i=0;
|
||||
// for(StandardItem item:childList) {
|
||||
// logger.debug( i++ + " - "+ item.getLevel() + " : " +item.getName());
|
||||
// jsonNode.get(item.getName());
|
||||
// }
|
||||
|
||||
// make json map(path, value)
|
||||
LinkedHashMap<String, String> itemMap = new LinkedHashMap<String, String>();
|
||||
String rootName = root.getName();
|
||||
message.setName(rootName);
|
||||
traverse(message, root, null, itemMap);
|
||||
// for(String key:itemMap.keySet()) {
|
||||
// logger.debug("~ itemMap : " + key + " => " + itemMap.get(key));
|
||||
// }
|
||||
return message;
|
||||
}
|
||||
|
||||
private String getContent(org.dom4j.Element element) {
|
||||
if (element.isTextOnly())
|
||||
return element.getText();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Element currElement = null;
|
||||
Iterator<org.dom4j.Element> iterator = element.elementIterator();
|
||||
while( iterator.hasNext() ) {
|
||||
currElement = iterator.next();
|
||||
sb.append(currElement.asXML());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private void traverse(StandardMessage message, org.dom4j.Element currentNode, String parentName, LinkedHashMap<String, String> itemMap){
|
||||
StandardItem currentItem = null;
|
||||
String fullPath = null;
|
||||
String fieldName = null;
|
||||
if(currentNode == null) {
|
||||
if(logger.isDebugEnabled()) logger.debug("$ SKIP :: node is NULL name="+ parentName);
|
||||
return;
|
||||
}
|
||||
Iterator<org.dom4j.Element> i = currentNode.elementIterator();
|
||||
while (i.hasNext()) {
|
||||
org.dom4j.Element child = (org.dom4j.Element) i.next();
|
||||
// if necessary, uncomment below 2 lines.
|
||||
// QName qn = new QName(child.getName(),Namespace.NO_NAMESPACE);
|
||||
// child.setQName(qn);
|
||||
|
||||
fullPath = child.getUniquePath();
|
||||
fieldName = lastNodeName(fullPath);
|
||||
|
||||
fieldName = genPath(parentName, fieldName);
|
||||
currentItem = message.findItem(fieldName, FIELD_SEPARATOR, ZERO_BASE_INDEX, true);
|
||||
if(currentItem == null) continue;
|
||||
|
||||
if(currentItem.getType() == StandardType.BIZDATA) {
|
||||
String bizData = null;
|
||||
if(BIZDATA_NAME_INCLUDE)
|
||||
bizData = getContent(child);
|
||||
else
|
||||
bizData = child.asXML();
|
||||
|
||||
itemMap.put(fieldName , bizData);
|
||||
currentItem.setValue(bizData);
|
||||
// item.setBizData(bizData);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(child.getNodeType()) {
|
||||
case Node.ELEMENT_NODE:
|
||||
if(logger.isDebugEnabled()) logger.debug("$ ELEMENT_NODE name="+ fieldName + ", fullPath="+ fullPath+ ", value="+ child.getStringValue());
|
||||
if(currentItem.getType() == StandardType.FIELD) {
|
||||
itemMap.put(fieldName , child.getStringValue());
|
||||
currentItem.setValue(child.getStringValue());
|
||||
}
|
||||
else if(currentItem.getType() == StandardType.FARRAY) {
|
||||
itemMap.put(fieldName , child.getStringValue());
|
||||
currentItem.addValue(child.getStringValue());
|
||||
}
|
||||
else {
|
||||
if(logger.isDebugEnabled()) logger.debug("@GROUP name={}, getLength={}, getRefPath={}, getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getLength(), currentItem.getRefPath(), currentItem.getRefValue());
|
||||
if( currentItem.getSize() == 0
|
||||
&& StringUtils.isNotBlank(currentItem.getRefPath())
|
||||
&& StringUtils.isNotBlank(currentItem.getRefValue()) ) {
|
||||
String refItemValue = null;
|
||||
StandardItem refItem = message.findItem(currentItem.getRefPath(), '.', true, false);
|
||||
if(refItem != null) {
|
||||
refItemValue = refItem.getValue();
|
||||
}
|
||||
|
||||
if(logger.isDebugEnabled()) logger.debug("@GROUP name={}, getRefPath={}, refItemValue=[{}], getRefValue=[{}]"
|
||||
, currentItem.getName(), currentItem.getRefPath(), refItemValue, currentItem.getRefValue());
|
||||
|
||||
if( !currentItem.getRefValue().equals(refItemValue) ) {
|
||||
if(logger.isDebugEnabled()) logger.warn("@GROUP name={} SKIPPED.", currentItem.getName());
|
||||
break;
|
||||
}
|
||||
}
|
||||
int attrCnt = child.attributeCount();
|
||||
for (int ai=0; ai<attrCnt; ai++) {
|
||||
Attribute at = child.attribute(ai);
|
||||
String atPath = genPath(fieldName, at.getName());
|
||||
if(logger.isDebugEnabled()) logger.debug("@ ATTRIBUTE name="+ atPath + ", fullPath="+ at.getUniquePath()+ ", value="+ at.getStringValue());
|
||||
StandardItem attrItem = message.findItem(atPath, FIELD_SEPARATOR, ZERO_BASE_INDEX, true);
|
||||
itemMap.put(atPath, at.getStringValue());
|
||||
attrItem.setValue(at.getStringValue());
|
||||
}
|
||||
if( currentItem.getSize() == 0) {
|
||||
currentItem.setSize(1);
|
||||
}
|
||||
traverse(message, child, fieldName, itemMap);
|
||||
}
|
||||
break;
|
||||
case Node.TEXT_NODE:
|
||||
if(logger.isDebugEnabled()) logger.debug("$ TEXT_NODE value="+ child.getStringValue());
|
||||
break;
|
||||
default:
|
||||
if(logger.isDebugEnabled()) logger.debug("$ type="+ child.getNodeType() + ", name=" + fieldName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String genPath(String parent, String nodeName) {
|
||||
if(parent == null || parent.length() < 1) {
|
||||
return nodeName;
|
||||
}
|
||||
return parent + FIELD_SEPARATOR + nodeName;
|
||||
}
|
||||
|
||||
protected String lastNodeName(String xpath) {
|
||||
String itemPath = null;
|
||||
int sepPosition = xpath.lastIndexOf(FIELD_SEPARATOR);
|
||||
if(sepPosition < 0) {
|
||||
return xpath;
|
||||
}
|
||||
itemPath = xpath.substring(sepPosition+1);
|
||||
|
||||
return itemPath;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
package com.eactive.eai.message.service;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.eactive.eai.message.StandardItem;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class DefaultInterfaceMapper implements InterfaceMapper {
|
||||
static Logger logger = LoggerFactory.getLogger(DefaultInterfaceMapper.class);
|
||||
|
||||
HashMap<String, String> itemPathMap = new HashMap<String, String>();
|
||||
|
||||
public void initPathMap(HashMap<String, String> map) {
|
||||
itemPathMap = map;
|
||||
}
|
||||
|
||||
protected String getPath(String key) {
|
||||
String path = itemPathMap.get(key);
|
||||
if(StringUtils.isBlank(path)) {
|
||||
logger.warn("message-mapping not defined key = {}", key);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public DefaultInterfaceMapper() {
|
||||
|
||||
}
|
||||
|
||||
protected String getItemValue(StandardMessage standardMessage, String path) {
|
||||
if(standardMessage == null || StringUtils.isBlank(path)) return null;
|
||||
return standardMessage.findItemValue(path);
|
||||
}
|
||||
|
||||
protected void setItemValue(StandardMessage standardMessage, String path, String value) {
|
||||
if(standardMessage == null || StringUtils.isBlank(path)) {
|
||||
return;
|
||||
}
|
||||
StandardItem item = standardMessage.findItem(path);
|
||||
if(item != null) item.setValue(value);
|
||||
}
|
||||
//------------------------------------------------------------
|
||||
// 표준전문과 Mapping 되는 항목을 모두 정의해야 함.
|
||||
//------------------------------------------------------------
|
||||
@Override
|
||||
public String getEaiSvcCode(StandardMessage standardMessage) {
|
||||
String eaiSvcCode = null;
|
||||
String interfaceId = getInterfaceId(standardMessage);
|
||||
String returnType = getSendRecvDivision(standardMessage); // S | R
|
||||
String inExDivision = getInExDivision(standardMessage); // 1 | 2
|
||||
// TODO : site에 맞게 조합해야 함.
|
||||
eaiSvcCode = interfaceId + returnType + StringUtils.defaultString(inExDivision);
|
||||
return eaiSvcCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextGuidSeq(StandardMessage standardMessage) {
|
||||
String guidSeq = getGuidSeq(standardMessage);
|
||||
if(guidSeq == null) return "";
|
||||
int seq = 0;
|
||||
try {
|
||||
seq = Integer.parseInt(guidSeq) + 1;
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
seq = 1;
|
||||
}
|
||||
guidSeq = Integer.toString(seq);
|
||||
setGuidSeq(standardMessage, guidSeq);
|
||||
return guidSeq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServiceId(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(SERVICE_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setServiceId(StandardMessage standardMessage, String serviceId) {
|
||||
setItemValue(standardMessage,getPath(SERVICE_ID), serviceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReqSysCode(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(REQ_SYS_CODE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannelTypeCd(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(CHANNEL_TYPE_CD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannelDetailCd(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(CHANNEL_DETAIL_CD));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSendTime(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(SEND_TIME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuid(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(GUID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSystemType(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(SYSTEM_TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecvTime(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(RECV_TIME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReturnValue(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(RETURN_VALUE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOrgGuid(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(GUID_ORG));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGuidSeq(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(GUID_SEQ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReturnServiceId(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(RETURN_SERVICE_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInterfaceId(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(INTERFACE_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSessionId(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(SESSION_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSendRecvDivision(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(SEND_RECV_DIVISION));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInExDivision(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(IN_EX_DIVISION));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOperationEnv(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(OPERATION_ENV));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstReqIp(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(FIRST_REQ_IP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecoverYn(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(RECOVER_YN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInstCode(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(INST_CODE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTimeout(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(TIMEOUT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorCode(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(ERROR_CODE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorMsg(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(ERROR_MSG));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserId(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(USER_ID));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getResponseType(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(RESPONSE_TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyncAsyncType(StandardMessage standardMessage) {
|
||||
return getItemValue(standardMessage, getPath(SYNC_ASYNC_TYPE));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReqSysCode(StandardMessage standardMessage, String reqSysCode) {
|
||||
setItemValue(standardMessage,getPath(REQ_SYS_CODE), reqSysCode);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChannelTypeCd(StandardMessage standardMessage, String channelTypeCd) {
|
||||
setItemValue(standardMessage,getPath(CHANNEL_TYPE_CD), channelTypeCd);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setChannelDetailCd(StandardMessage standardMessage, String channelDetailCd) {
|
||||
setItemValue(standardMessage,getPath(CHANNEL_DETAIL_CD), channelDetailCd);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSendTime(StandardMessage standardMessage, String sendTime) {
|
||||
setItemValue(standardMessage,getPath(SEND_TIME), sendTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuid(StandardMessage standardMessage, String guid) {
|
||||
setItemValue(standardMessage,getPath(GUID), guid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemType(StandardMessage standardMessage, String systemType) {
|
||||
setItemValue(standardMessage,getPath(SYSTEM_TYPE), systemType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecvTime(StandardMessage standardMessage, String recvTime) {
|
||||
setItemValue(standardMessage,getPath(RECV_TIME), recvTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReturnValue(StandardMessage standardMessage, String returnValue) {
|
||||
setItemValue(standardMessage,getPath(RETURN_VALUE), returnValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrgGuid(StandardMessage standardMessage, String orgGuid) {
|
||||
setItemValue(standardMessage,getPath(GUID_ORG), orgGuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGuidSeq(StandardMessage standardMessage, String guidSeq) {
|
||||
setItemValue(standardMessage,getPath(GUID_SEQ), guidSeq);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReturnServiceId(StandardMessage standardMessage, String returnServiceId) {
|
||||
setItemValue(standardMessage,getPath(RETURN_SERVICE_ID), returnServiceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInterfaceId(StandardMessage standardMessage, String interfaceId) {
|
||||
setItemValue(standardMessage,getPath(INTERFACE_ID), interfaceId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSessionId(StandardMessage standardMessage, String sessionId) {
|
||||
setItemValue(standardMessage,getPath(SESSION_ID), sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSendRecvDivision(StandardMessage standardMessage, String sendRecvDivision) {
|
||||
setItemValue(standardMessage,getPath(SEND_RECV_DIVISION), sendRecvDivision);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInExDivision(StandardMessage standardMessage, String inExDivision) {
|
||||
setItemValue(standardMessage,getPath(IN_EX_DIVISION), inExDivision);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOperationEnv(StandardMessage standardMessage, String operationEnv) {
|
||||
setItemValue(standardMessage,getPath(OPERATION_ENV), operationEnv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFirstReqIp(StandardMessage standardMessage, String firstReqIp) {
|
||||
setItemValue(standardMessage,getPath(FIRST_REQ_IP), firstReqIp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecoverYn(StandardMessage standardMessage, String recoverYn) {
|
||||
setItemValue(standardMessage,getPath(RECOVER_YN), recoverYn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInstCode(StandardMessage standardMessage, String instCode) {
|
||||
setItemValue(standardMessage,getPath(INST_CODE), instCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeout(StandardMessage standardMessage, String timeout) {
|
||||
setItemValue(standardMessage,getPath(TIMEOUT), timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setErrorCode(StandardMessage standardMessage, String errorCode) {
|
||||
setItemValue(standardMessage,getPath(ERROR_CODE), errorCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setErrorMsg(StandardMessage standardMessage, String errorMsg) {
|
||||
setItemValue(standardMessage,getPath(ERROR_MSG), errorMsg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserId(StandardMessage standardMessage, String userId) {
|
||||
setItemValue(standardMessage,getPath(USER_ID), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResponseType(StandardMessage standardMessage, String responseType) {
|
||||
setItemValue(standardMessage,getPath(RESPONSE_TYPE), responseType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSyncAsyncType(StandardMessage standardMessage, String syncAsyncType) {
|
||||
setItemValue(standardMessage,getPath(SYNC_ASYNC_TYPE), syncAsyncType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.eactive.eai.message.service;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.eactive.eai.common.message.EAIMessage;
|
||||
import com.eactive.eai.common.server.EAIServerManager;
|
||||
import com.eactive.eai.common.util.UUIDGenerator;
|
||||
import com.eactive.eai.inbound.processor.ProcessVO;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
import com.eactive.eai.message.manager.StandardMessageManager;
|
||||
import com.ext.eai.common.stdmessage.STDMessageKeys;
|
||||
|
||||
public class DefaultStandardMessageCoordinator implements StandardMessageCoordinator {
|
||||
|
||||
@Override
|
||||
public void coordinateAfterParsing(StandardMessage standardMessage, Object paramObject, Properties prop) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void coordinateAfterCreateMessageByRule(StandardMessage standardMessage, Object paramObject, Properties prop) {
|
||||
// guid 설정
|
||||
EAIServerManager eaiServerManager = EAIServerManager.getInstance();
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
InterfaceMapper mapper = standardManager.getMapper();
|
||||
mapper.setGuid(standardMessage, UUIDGenerator.getGUID(eaiServerManager.getSystemType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void coordinateInReturnObject(StandardMessage standardMessage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void coordinateBeforeInboundErrorResponse(StandardMessage standardMessage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean coordinateSetStandardMessageError(StandardMessage standardMessage, InterfaceMapper mapper,
|
||||
String errCode, String errMsg) {
|
||||
if (errCode != null) {
|
||||
mapper.setErrorCode(standardMessage, errCode);
|
||||
}
|
||||
if (errMsg != null) {
|
||||
mapper.setErrorMsg(standardMessage, errMsg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void coordinateAfterRestored(StandardMessage restoredMessage, StandardMessage responseMessage) {
|
||||
StandardMessageManager standardManager = StandardMessageManager.getInstance();
|
||||
InterfaceMapper mapper = standardManager.getMapper();
|
||||
mapper.setSendRecvDivision(restoredMessage, STDMessageKeys.SEND_RECV_CD_RECV);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean coordinateIsWaitCheckForSync(StandardMessage responseMessage) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int coordinateForTimeoutCodeToValue(EAIMessage eaiMessage) {
|
||||
return eaiMessage.getCurrentSvcMsg().getTmoVl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean coordinateValidation(StandardMessage standardMessage, ProcessVO vo) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void coordinateAfterRecvNonStdSyncResponse(StandardMessage responseMessage) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.eactive.eai.message.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
|
||||
public interface InterfaceMapper extends Serializable {
|
||||
// define mapping
|
||||
String REQ_SYS_CODE = "REQ_SYS_CODE";
|
||||
String CHANNEL_TYPE_CD = "CHANNEL_TYPE_CD";
|
||||
String CHANNEL_DETAIL_CD = "CHANNEL_DETAIL_CD";
|
||||
String SEND_TIME = "SEND_TIME";
|
||||
String GUID = "GUID";
|
||||
String SYSTEM_TYPE = "SYSTEM_TYPE";
|
||||
String RECV_TIME = "RECV_TIME";
|
||||
String RETURN_VALUE = "RETURN_VALUE";
|
||||
String GUID_ORG = "GUID_ORG";
|
||||
String GUID_SEQ = "GUID_SEQ";
|
||||
String SERVICE_ID = "SERVICE_ID";
|
||||
String RETURN_SERVICE_ID = "RETURN_SERVICE_ID";
|
||||
String INTERFACE_ID = "INTERFACE_ID";
|
||||
String SESSION_ID = "SESSION_ID";
|
||||
String SEND_RECV_DIVISION = "SEND_RECV_DIVISION";
|
||||
String IN_EX_DIVISION = "IN_EX_DIVISION";
|
||||
String OPERATION_ENV = "OPERATION_ENV";
|
||||
String FIRST_REQ_IP = "FIRST_REQ_IP";
|
||||
String RECOVER_YN = "RECOVER_YN";
|
||||
String INST_CODE = "INST_CODE";
|
||||
String TIMEOUT = "TIMEOUT";
|
||||
String ERROR_CODE = "ERROR_CODE";
|
||||
String ERROR_MSG = "ERROR_MSG";
|
||||
String USER_ID = "USER_ID";
|
||||
String RESPONSE_TYPE = "RESPONSE_TYPE";
|
||||
String SYNC_ASYNC_TYPE = "SYNC_ASYNC_TYPE";
|
||||
|
||||
public void initPathMap(HashMap<String, String> map);
|
||||
//------------------------------------------------------------
|
||||
// 표준전문과 Mapping 되는 항목을 모두 정의해야 함.
|
||||
//------------------------------------------------------------
|
||||
public String getEaiSvcCode(StandardMessage standardMessage);
|
||||
public String nextGuidSeq(StandardMessage standardMessage);
|
||||
|
||||
public String getReqSysCode (StandardMessage standardMessage);
|
||||
public String getChannelTypeCd (StandardMessage standardMessage);
|
||||
public String getChannelDetailCd (StandardMessage standardMessage);
|
||||
public String getSendTime (StandardMessage standardMessage);
|
||||
public String getGuid (StandardMessage standardMessage);
|
||||
public String getSystemType (StandardMessage standardMessage);
|
||||
public String getRecvTime (StandardMessage standardMessage);
|
||||
public String getReturnValue (StandardMessage standardMessage);
|
||||
public String getOrgGuid (StandardMessage standardMessage);
|
||||
public String getGuidSeq (StandardMessage standardMessage);
|
||||
public String getServiceId (StandardMessage standardMessage);
|
||||
public String getReturnServiceId (StandardMessage standardMessage);
|
||||
public String getInterfaceId (StandardMessage standardMessage);
|
||||
public String getSessionId (StandardMessage standardMessage);
|
||||
public String getSendRecvDivision (StandardMessage standardMessage);
|
||||
public String getInExDivision (StandardMessage standardMessage);
|
||||
public String getOperationEnv (StandardMessage standardMessage);
|
||||
public String getFirstReqIp (StandardMessage standardMessage);
|
||||
public String getRecoverYn (StandardMessage standardMessage);
|
||||
public String getInstCode (StandardMessage standardMessage);
|
||||
public String getTimeout (StandardMessage standardMessage);
|
||||
public String getErrorCode (StandardMessage standardMessage);
|
||||
public String getErrorMsg (StandardMessage standardMessage);
|
||||
public String getUserId (StandardMessage standardMessage);
|
||||
public String getResponseType (StandardMessage standardMessage);
|
||||
public String getSyncAsyncType (StandardMessage standardMessage);
|
||||
|
||||
public void setReqSysCode (StandardMessage standardMessage, String reqSysCode );
|
||||
public void setChannelTypeCd (StandardMessage standardMessage, String channelTypeCd );
|
||||
public void setChannelDetailCd (StandardMessage standardMessage, String channelDetailCd );
|
||||
public void setSendTime (StandardMessage standardMessage, String sendTime );
|
||||
public void setGuid (StandardMessage standardMessage, String guid );
|
||||
public void setSystemType (StandardMessage standardMessage, String systemType );
|
||||
public void setRecvTime (StandardMessage standardMessage, String recvTime );
|
||||
public void setReturnValue (StandardMessage standardMessage, String returnValue );
|
||||
public void setOrgGuid (StandardMessage standardMessage, String guidOrg );
|
||||
public void setGuidSeq (StandardMessage standardMessage, String guidSeq );
|
||||
public void setServiceId (StandardMessage standardMessage, String serviceId );
|
||||
public void setReturnServiceId (StandardMessage standardMessage, String returnServiceId );
|
||||
public void setInterfaceId (StandardMessage standardMessage, String interfaceId );
|
||||
public void setSessionId (StandardMessage standardMessage, String sessionId );
|
||||
public void setSendRecvDivision (StandardMessage standardMessage, String sendRecvDivision);
|
||||
public void setInExDivision (StandardMessage standardMessage, String inExDivision );
|
||||
public void setOperationEnv (StandardMessage standardMessage, String operationEnv );
|
||||
public void setFirstReqIp (StandardMessage standardMessage, String firstReqIp );
|
||||
public void setRecoverYn (StandardMessage standardMessage, String recoverYn );
|
||||
public void setInstCode (StandardMessage standardMessage, String instCode );
|
||||
public void setTimeout (StandardMessage standardMessage, String timeout );
|
||||
public void setErrorCode (StandardMessage standardMessage, String errorCode );
|
||||
public void setErrorMsg (StandardMessage standardMessage, String errorMsg );
|
||||
public void setUserId (StandardMessage standardMessage, String userId );
|
||||
public void setResponseType (StandardMessage standardMessage, String responseType );
|
||||
public void setSyncAsyncType (StandardMessage standardMessage, String syncAsyncType );
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.eactive.eai.message.service;
|
||||
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
/*
|
||||
* Example of EAIMessage
|
||||
*/
|
||||
public class InterfaceMessage {
|
||||
private InterfaceMapper mapper;
|
||||
private StandardMessage standardMessage;
|
||||
|
||||
public InterfaceMessage() {
|
||||
}
|
||||
|
||||
public InterfaceMapper getMapper() {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public void setMapper(InterfaceMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public StandardMessage getStandardMessage() {
|
||||
return standardMessage;
|
||||
}
|
||||
|
||||
public void setStandardMessage(StandardMessage standardMessage) {
|
||||
this.standardMessage = standardMessage;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
// Service 정보에서 정의한 고정값들
|
||||
//------------------------------------------------------------
|
||||
private String interfaceCode;
|
||||
private String interfaceType;
|
||||
|
||||
public String getInterfaceCode() {
|
||||
return interfaceCode;
|
||||
}
|
||||
|
||||
public void setInterfaceCode(String interfaceCode) {
|
||||
this.interfaceCode = interfaceCode;
|
||||
}
|
||||
|
||||
public String getInterfaceType() {
|
||||
return interfaceType;
|
||||
}
|
||||
|
||||
public void setInterfaceType(String interfaceType) {
|
||||
this.interfaceType = interfaceType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.eactive.eai.message.service;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import com.eactive.eai.common.message.EAIMessage;
|
||||
import com.eactive.eai.inbound.processor.ProcessVO;
|
||||
import com.eactive.eai.message.StandardMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface StandardMessageCoordinator {
|
||||
|
||||
/**
|
||||
* 전달된 표준메시지 파싱후 후처리
|
||||
*
|
||||
* @param standardMessage
|
||||
* @param paramObject
|
||||
*/
|
||||
public void coordinateAfterParsing(StandardMessage standardMessage, Object paramObject, Properties prop);
|
||||
|
||||
/**
|
||||
* 비표준 메시지일경우 Rule정보로부터 표준메시지 생성후 후처리
|
||||
*
|
||||
* @param standardMessage
|
||||
* @param prop
|
||||
*/
|
||||
public void coordinateAfterCreateMessageByRule(StandardMessage standardMessage, Object paramObject, Properties prop);
|
||||
|
||||
/**
|
||||
* 표준 메시지일경우 ReturnObject 에서 처리
|
||||
*
|
||||
* @param standardMessage
|
||||
*/
|
||||
public void coordinateInReturnObject(StandardMessage standardMessage);
|
||||
|
||||
/**
|
||||
* 인바운드에러에서 표준전문 오류응답주기전
|
||||
*
|
||||
* @param standardMessage
|
||||
*/
|
||||
public void coordinateBeforeInboundErrorResponse(StandardMessage standardMessage);
|
||||
|
||||
/**
|
||||
* 표준전문 에러 셋팅 및
|
||||
* 응답이 true 일경우 업무데이터에 오류메시지 설정 (현재 JSON만 컨트롤)
|
||||
* 응답이 false일경우 업무데이터에 null처리
|
||||
*
|
||||
* @param standardMessage
|
||||
* @param mapper
|
||||
* @param errCode
|
||||
* @param errMsg
|
||||
* @return
|
||||
*/
|
||||
public boolean coordinateSetStandardMessageError(StandardMessage standardMessage, InterfaceMapper mapper,
|
||||
String errCode, String errMsg);
|
||||
|
||||
/**
|
||||
* 표준전문 복원후
|
||||
*
|
||||
* @param standardMessage
|
||||
* @param errCode
|
||||
* @param errMsg
|
||||
*/
|
||||
public void coordinateAfterRestored(StandardMessage restoredMessage, StandardMessage responseMessage);
|
||||
|
||||
/**
|
||||
* 표준전문 복원후
|
||||
*
|
||||
* @param standardMessage
|
||||
* @param errCode
|
||||
* @param errMsg
|
||||
* @return
|
||||
*/
|
||||
public boolean coordinateIsWaitCheckForSync(StandardMessage responseMessage);
|
||||
|
||||
/**
|
||||
* Timeout 값
|
||||
*
|
||||
* @param eaiMessage
|
||||
* @return 타임아웃값
|
||||
*/
|
||||
public int coordinateForTimeoutCodeToValue(EAIMessage eaiMessage);
|
||||
|
||||
/**
|
||||
* 표준전문 validation
|
||||
* @param standardMessage
|
||||
* @param vo
|
||||
* @return
|
||||
*/
|
||||
public boolean coordinateValidation(StandardMessage standardMessage, ProcessVO vo);
|
||||
|
||||
|
||||
/**
|
||||
* 비표준 동기 응답 수신 후 표준전문 처리
|
||||
*
|
||||
* @param responseMessage
|
||||
*/
|
||||
public void coordinateAfterRecvNonStdSyncResponse(StandardMessage responseMessage);
|
||||
}
|
||||
Reference in New Issue
Block a user