首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

经过XML入库操作 EsbmMessageProcessor 01

2012-11-10 
通过XML入库操作 EsbmMessageProcessor 01import java.util.Dateimport java.util.Hashtableimport java

通过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));
        }
    }

热点排行