通过XML入库操作 EsbmMessageProcessor 01

import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.XPath;
import org.dom4j.tree.DefaultAttribute;
import org.dom4j.tree.DefaultText;
import com.huawei.ngbss.common.EncryptUtil;
import com.huawei.ngbss.esb.logprocess.util.BatchPersistent;
import com.huawei.ngbss.esb.logprocess.util.DataCache;
import com.huawei.ngbss.esb.logprocess.util.RealTimeAlarm;
import com.huawei.ngbss.esb.logprocess.util.TableName_Field;
import com.huawei.ngbss.esb.logprocess.util.Tools;

public class EsbmMessageProcessor
{
private static Logger logger = Logger.getLogger(EsbmMessageProcessor.class);

private final static String SERVICE_NAME_XPATH = "//esbMessage/service_name/text()";

private final static String LOG_SN_XPATH = "//esbMessage/log_sn/text()";

/**
* @功能说明:通过字符串实行解析esb message, 显示方法请参考process(Document doc)
*
* @param message
*/
public static void process(String inputXML)
{
if (inputXML != null)
{
// 将input message constract Document
Document documentDOM4j = Tools.string2Dom4J(inputXML);
if (documentDOM4j != null)
{
EsbmMessageProcessor.process(documentDOM4j);
}
}
}

/**
* @功能说明: 使用Document实行调用
*
* @param doc 不能为空,由调用保证
*/
private static void process(Document doc)
{
// 只是为了打日志用
long start_Process_time = 0l;
if (logger.isDebugEnabled())
{
logger.debug("start process new Message:" + doc.asXML());

}
// info 级别需要统计处理时长
if (logger.isInfoEnabled())
{
start_Process_time = System.currentTimeMillis();
}
// 使用Map中的Xpath将数据库的字段值从ESBMessage中取出
Map<String, String> propertiesValue = EsbmMessageProcessor
.getValuefromXpath(doc);
if (propertiesValue == null)
{
return;
}
// 实时告警检查
logger.debug("RealTimeAlarm.realTimecheck");
RealTimeAlarm.realTimecheck(propertiesValue);
// 将消息中解析出来的value打印到日志中
if (logger.isDebugEnabled())
{
Iterator<Map.Entry<String, String>> iterator = propertiesValue
.entrySet().iterator();
Map.Entry<String, String> entry = null;
while (iterator.hasNext())
{
entry = iterator.next();
logger.debug("Message node mapping to the Database field key is: "
+ entry.getKey() + ", and value:" + entry.getValue());
}
}
// ESB日志的数据库表
TableName_Field[] tableName_Fields = Tools.sqlList(propertiesValue,
DataCache.getEsbmTable());

// 将SQl写入线程
BatchPersistent.putSQLTosqlList(tableName_Fields);
if (logger.isInfoEnabled())
{
logger.info("End process massage process times : "
+ (System.currentTimeMillis() - start_Process_time));
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值