|
|
//
|
|
|
// Source code recreated from a .class file by IntelliJ IDEA
|
|
|
// (powered by Fernflower decompiler)
|
|
|
//
|
|
|
|
|
|
package com.airport.core;
|
|
|
|
|
|
import com.airport.bean.MessageBak;
|
|
|
import com.airport.bean.XMLHeader;
|
|
|
import com.airport.dao.Dao;
|
|
|
import com.airport.dao.impl.DaoImpl;
|
|
|
import com.airport.util.ConfigUtils;
|
|
|
import com.airport.util.SystemBean;
|
|
|
import com.airport.util.Utils;
|
|
|
import com.airport.util.parse.IMFXMLMaker;
|
|
|
import com.airport.util.parse.XMPParse;
|
|
|
import com.caac.imf.api.IMFClient;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.TimerTask;
|
|
|
|
|
|
public class IMFSender extends TimerTask {
|
|
|
private static final Logger logger = Logger.getLogger(IMFSender.class);
|
|
|
private Dao dao = (DaoImpl)SystemBean.getBean("dao");
|
|
|
private IMFClient client;
|
|
|
private String indexFileName; //记录发送数据的节点
|
|
|
|
|
|
public IMFSender(IMFClient client, String fileName) {
|
|
|
this.indexFileName = fileName;
|
|
|
this.client = client;
|
|
|
}
|
|
|
|
|
|
public void run() {
|
|
|
try {
|
|
|
if (this.client == null) {
|
|
|
logger.info("IMFClient has been closed");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
logger.info("job start:");
|
|
|
int lastFID = Utils.readFIDIndex(this.indexFileName);
|
|
|
int maxFID = this.dao.getMaxFID();
|
|
|
logger.info("lastFID=" + lastFID + " maxFID=" + maxFID);
|
|
|
int is_ok = 0;
|
|
|
|
|
|
if (maxFID > lastFID) {
|
|
|
List<MessageBak> list = this.dao.getRecordByFID(lastFID); //查询大于[FID]350的报文
|
|
|
Map<Integer, XMLHeader> map = ConfigUtils.XML_HEADER_MAP;
|
|
|
Iterator var7 = list.iterator();
|
|
|
|
|
|
while(true) {
|
|
|
while(var7.hasNext()) {
|
|
|
MessageBak m = (MessageBak)var7.next();
|
|
|
if (is_ok != 0) {
|
|
|
logger.error("记录FID时发生异常,发送消息任务被迫中断");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (m.getContent() != null) {
|
|
|
int times = 0;
|
|
|
//配置文件里面有几个sender 这里循环几次
|
|
|
for(Iterator var10 = map.keySet().iterator(); var10.hasNext(); Thread.sleep((long)ConfigUtils.SEND_MESSAGE_INTERVAL)) {
|
|
|
Integer key = (Integer)var10.next();
|
|
|
XMLHeader header = (XMLHeader)map.get(key);
|
|
|
logger.info("key=" + key + " value=" + ((XMLHeader)map.get(key)).toString());
|
|
|
logger.info("准备发送数据 FID:" + m.getFid() + " XML.length=:" + m.getContent().length());
|
|
|
|
|
|
|
|
|
//初始化最终发布报文内容的存储器
|
|
|
String sendMsg = "";
|
|
|
String xmlStr = m.getContent();
|
|
|
//_____________________________________解析华东的报文-------------------------------------------------------------------------------------------
|
|
|
if (xmlStr.contains("<MessageType>IS1</MessageType>")){
|
|
|
IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","IS1");
|
|
|
haiguanXml.setIMFContent(m.getContent());
|
|
|
sendMsg = haiguanXml.finalXmlStr();
|
|
|
}else if(xmlStr.contains("<MessageType>ES1</MessageType>") ){
|
|
|
IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","ES1");
|
|
|
haiguanXml.setIMFContent(m.getContent());
|
|
|
sendMsg = haiguanXml.finalXmlStr();
|
|
|
}else if(xmlStr.contains("<MessageType>CLR</MessageType>")){
|
|
|
IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","CLR");
|
|
|
haiguanXml.setIMFContent(m.getContent());
|
|
|
sendMsg = haiguanXml.finalXmlStr();
|
|
|
}else if(xmlStr.contains("<MessageType>RSC</MessageType>")){
|
|
|
IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","RSC");
|
|
|
haiguanXml.setIMFContent(m.getContent());
|
|
|
sendMsg = haiguanXml.finalXmlStr();
|
|
|
} else {
|
|
|
//_____________________________________解析天信达的报文,读取配置文件,替换相关参数-------------------------------------------------------------------------------------------
|
|
|
sendMsg= Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR");
|
|
|
sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE"); //替换报文主类型
|
|
|
|
|
|
String stype = tranlateXML(m.getContent());
|
|
|
sendMsg = Utils.searchReplace(sendMsg, stype, "STYP");
|
|
|
sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR");
|
|
|
}
|
|
|
//_____________________________________给多式联运的航空报文,读取配置文件,生成新的META,并把最原始的报文封装到新报文的content里面--------------------------------------------------------------------
|
|
|
// String sndr = header.getSndr();
|
|
|
// String type = header.getType();
|
|
|
// String styp = header.getStype();
|
|
|
//
|
|
|
// IMFXMLMaker newXml = new IMFXMLMaker(sndr,Integer.toString(m.getFid()),type,styp);
|
|
|
// newXml.setIMFContent(m.getContent());
|
|
|
// sendMsg = newXml.finalXmlStr();
|
|
|
|
|
|
if (!"".equals(sendMsg)) {
|
|
|
logger.info("开始发送数据 XML:" + sendMsg);
|
|
|
String is_send_ok = this.client.sendMSG(sendMsg);
|
|
|
logger.info("is_send_ok=" + is_send_ok);
|
|
|
is_ok = Utils.writeFIDIndex(this.indexFileName, m.getRownum_()); //发送成功写入节点文件
|
|
|
logger.debug("FID:" + m.getFid() + " 缓存成功");
|
|
|
++times;
|
|
|
} else {
|
|
|
logger.error("查找替换节点数据出现异常,可能找不到这个节点,原始XML=" + m.getContent());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// this.dao.update(m.getFid(), times);
|
|
|
} else {
|
|
|
logger.info("FID=" + m.getFid() + "XML is null ");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
} else {
|
|
|
logger.info("lastFID=" + lastFID + ">= maxFID=" + maxFID + " 忽略发送数据");
|
|
|
}
|
|
|
} catch (Exception var14) {
|
|
|
var14.printStackTrace();
|
|
|
logger.info(var14.getMessage());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private static String tranlateXML(String xml) throws Exception {
|
|
|
String stype = XMPParse.getNodeValueFromXmlString(xml, "/MSG/META/STYP");
|
|
|
if (!StringUtils.isBlank(stype)) {
|
|
|
if (ConfigUtils.XTYPE_MAP.containsKey(stype)) {
|
|
|
stype = (String)ConfigUtils.XTYPE_MAP.get(stype);
|
|
|
} else {
|
|
|
logger.info("stype=" + stype + " 在对应关系里找不到这个KEY");
|
|
|
}
|
|
|
} else {
|
|
|
logger.info(" 在XML找不到STYPE这个节点");
|
|
|
stype = "";
|
|
|
}
|
|
|
|
|
|
return stype;
|
|
|
}
|
|
|
} |