正在显示
3 个修改的文件
包含
237 行增加
和
9 行删除
| @@ -12,6 +12,7 @@ import com.airport.dao.impl.DaoImpl; | @@ -12,6 +12,7 @@ import com.airport.dao.impl.DaoImpl; | ||
| 12 | import com.airport.util.ConfigUtils; | 12 | import com.airport.util.ConfigUtils; |
| 13 | import com.airport.util.SystemBean; | 13 | import com.airport.util.SystemBean; |
| 14 | import com.airport.util.Utils; | 14 | import com.airport.util.Utils; |
| 15 | +import com.airport.util.parse.IMFXMLMaker; | ||
| 15 | import com.airport.util.parse.XMPParse; | 16 | import com.airport.util.parse.XMPParse; |
| 16 | import com.caac.imf.api.IMFClient; | 17 | import com.caac.imf.api.IMFClient; |
| 17 | import org.apache.commons.lang.StringUtils; | 18 | import org.apache.commons.lang.StringUtils; |
| @@ -46,7 +47,7 @@ public class IMFSender extends TimerTask { | @@ -46,7 +47,7 @@ public class IMFSender extends TimerTask { | ||
| 46 | logger.info("lastFID=" + lastFID + " maxFID=" + maxFID); | 47 | logger.info("lastFID=" + lastFID + " maxFID=" + maxFID); |
| 47 | int is_ok = 0; | 48 | int is_ok = 0; |
| 48 | if (maxFID > lastFID) { | 49 | if (maxFID > lastFID) { |
| 49 | - List<MessageBak> list = this.dao.getRecordByFID(lastFID); | 50 | + List<MessageBak> list = this.dao.getRecordByFID(lastFID); //查询大于[FID]350的报文 |
| 50 | Map<Integer, XMLHeader> map = ConfigUtils.XML_HEADER_MAP; | 51 | Map<Integer, XMLHeader> map = ConfigUtils.XML_HEADER_MAP; |
| 51 | Iterator var7 = list.iterator(); | 52 | Iterator var7 = list.iterator(); |
| 52 | 53 | ||
| @@ -60,17 +61,45 @@ public class IMFSender extends TimerTask { | @@ -60,17 +61,45 @@ public class IMFSender extends TimerTask { | ||
| 60 | 61 | ||
| 61 | if (m.getContent() != null) { | 62 | if (m.getContent() != null) { |
| 62 | int times = 0; | 63 | int times = 0; |
| 63 | - | 64 | + //配置文件里面有几个sender 这里循环几次 |
| 64 | for(Iterator var10 = map.keySet().iterator(); var10.hasNext(); Thread.sleep((long)ConfigUtils.SEND_MESSAGE_INTERVAL)) { | 65 | for(Iterator var10 = map.keySet().iterator(); var10.hasNext(); Thread.sleep((long)ConfigUtils.SEND_MESSAGE_INTERVAL)) { |
| 65 | Integer key = (Integer)var10.next(); | 66 | Integer key = (Integer)var10.next(); |
| 66 | XMLHeader header = (XMLHeader)map.get(key); | 67 | XMLHeader header = (XMLHeader)map.get(key); |
| 67 | logger.info("key=" + key + " value=" + ((XMLHeader)map.get(key)).toString()); | 68 | logger.info("key=" + key + " value=" + ((XMLHeader)map.get(key)).toString()); |
| 68 | logger.info("准备发送数据 FID:" + m.getFid() + " XML.length=:" + m.getContent().length()); | 69 | logger.info("准备发送数据 FID:" + m.getFid() + " XML.length=:" + m.getContent().length()); |
| 69 | - String sendMsg = Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR"); | ||
| 70 | - sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE"); | ||
| 71 | - String stype = tranlateXML(m.getContent()); | ||
| 72 | - sendMsg = Utils.searchReplace(sendMsg, stype, "STYP"); | ||
| 73 | - sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR"); | 70 | + |
| 71 | + | ||
| 72 | + //初始化最终发布报文内容的存储器 | ||
| 73 | + String sendMsg = ""; | ||
| 74 | + String xmlStr = m.getContent(); | ||
| 75 | +//_____________________________________解析华东的报文------------------------------------------------------------------------------------------- | ||
| 76 | + if (xmlStr.contains("<MessageType>IS1</MessageType>")){ | ||
| 77 | + IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","IS1"); | ||
| 78 | + haiguanXml.setIMFContent(m.getContent()); | ||
| 79 | + sendMsg = haiguanXml.finalXmlStr(); | ||
| 80 | + }else if(xmlStr.contains("<MessageType>ES1</MessageType>") ){ | ||
| 81 | + IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","ES1"); | ||
| 82 | + haiguanXml.setIMFContent(m.getContent()); | ||
| 83 | + sendMsg = haiguanXml.finalXmlStr(); | ||
| 84 | + }else if(xmlStr.contains("<MessageType>CLR</MessageType>")){ | ||
| 85 | + IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","CLR"); | ||
| 86 | + haiguanXml.setIMFContent(m.getContent()); | ||
| 87 | + sendMsg = haiguanXml.finalXmlStr(); | ||
| 88 | + }else if(xmlStr.contains("<MessageType>RSC</MessageType>")){ | ||
| 89 | + IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","RSC"); | ||
| 90 | + haiguanXml.setIMFContent(m.getContent()); | ||
| 91 | + sendMsg = haiguanXml.finalXmlStr(); | ||
| 92 | + } else { | ||
| 93 | +//_____________________________________解析天信达的报文------------------------------------------------------------------------------------------- | ||
| 94 | + sendMsg= Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR"); | ||
| 95 | + sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE"); //替换报文主类型 | ||
| 96 | + | ||
| 97 | + String stype = tranlateXML(m.getContent()); | ||
| 98 | + sendMsg = Utils.searchReplace(sendMsg, stype, "STYP"); | ||
| 99 | + sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR"); | ||
| 100 | +//_____________________________________解析天信达的报文------------------------------------------------------------------------------------------- | ||
| 101 | + } | ||
| 102 | + | ||
| 74 | if (!"".equals(sendMsg)) { | 103 | if (!"".equals(sendMsg)) { |
| 75 | logger.info("开始发送数据 XML:" + sendMsg); | 104 | logger.info("开始发送数据 XML:" + sendMsg); |
| 76 | String is_send_ok = this.client.sendMSG(sendMsg); | 105 | String is_send_ok = this.client.sendMSG(sendMsg); |
| @@ -112,11 +112,11 @@ public class DaoImpl implements Dao { | @@ -112,11 +112,11 @@ public class DaoImpl implements Dao { | ||
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | public int getMaxFID() { | 114 | public int getMaxFID() { |
| 115 | - return this.jdbcTemplate.queryForInt("select max(FID) from MESSAGE_BAK where SNDR='CFPS' OR TYPE='CLR'"); | 115 | + return this.jdbcTemplate.queryForInt("select max(FID) from MESSAGE_BAK where SNDR='CFPS' OR TYPE='CLR' OR TYPE ='RSC' OR TYPE ='ES1' OR TYPE='IS1'"); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | public List<MessageBak> getRecordByFID(int fid) { | 118 | public List<MessageBak> getRecordByFID(int fid) { |
| 119 | - String SQL_FMT = "select FID,CONTENT from MESSAGE_BAK where (FID>%s and FID<%s+%s) and (SNDR='CFPS' OR TYPE='CLR') order by FID"; | 119 | + String SQL_FMT = "select FID,CONTENT from MESSAGE_BAK where (FID>%s and FID<%s+%s) and (SNDR='CFPS' OR TYPE='CLR' OR TYPE ='RSC' OR TYPE ='ES1' OR TYPE='IS1') order by FID"; |
| 120 | String sql = String.format(SQL_FMT, fid, fid, ConfigUtils.RECORD_COUNT); | 120 | String sql = String.format(SQL_FMT, fid, fid, ConfigUtils.RECORD_COUNT); |
| 121 | logger.info(sql); | 121 | logger.info(sql); |
| 122 | final LobHandler lobHandler = new DefaultLobHandler(); | 122 | final LobHandler lobHandler = new DefaultLobHandler(); |
| 1 | +package com.airport.util.parse; | ||
| 2 | +import org.apache.log4j.Logger; | ||
| 3 | +import org.jdom.Document; | ||
| 4 | +import org.jdom.Element; | ||
| 5 | +import org.jdom.JDOMException; | ||
| 6 | +import org.jdom.input.SAXBuilder; | ||
| 7 | +import org.jdom.output.Format; | ||
| 8 | +import org.jdom.output.XMLOutputter; | ||
| 9 | + | ||
| 10 | +import java.io.*; | ||
| 11 | +import java.text.SimpleDateFormat; | ||
| 12 | +import java.util.Date; | ||
| 13 | + | ||
| 14 | +public class IMFXMLMaker { | ||
| 15 | + private static final Logger logger = Logger.getLogger(IMFXMLMaker.class); | ||
| 16 | + private Document XmlDocument; | ||
| 17 | + private Element RootElement; | ||
| 18 | + private Element SndrElement; | ||
| 19 | + private Element RcvrElement; | ||
| 20 | + private Element SEQNElement; | ||
| 21 | + private Element TYPEElement; | ||
| 22 | + private Element STYPElement; | ||
| 23 | + | ||
| 24 | + private String XmlStr; | ||
| 25 | + private String SNDR; | ||
| 26 | + private String RCVR; | ||
| 27 | + private String SEQN; | ||
| 28 | + private String TYPE; | ||
| 29 | + private String STYP; | ||
| 30 | + private String IMFContent; | ||
| 31 | + private String IMFXml; | ||
| 32 | + | ||
| 33 | + public String getXmlStr() { | ||
| 34 | + return XmlStr; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public void setXmlStr(String xmlStr) { | ||
| 38 | + XmlStr = xmlStr; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public String getSNDR() { | ||
| 42 | + return SNDR; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public void setSNDR(String SNDR) { | ||
| 46 | + this.SNDR = SNDR; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public String getRCVR() { | ||
| 50 | + return RCVR; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public void setRCVR(String RCVR) { | ||
| 54 | + this.RCVR = RCVR; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public String getSEQN() { | ||
| 58 | + return SEQN; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setSEQN(String SEQN) { | ||
| 62 | + this.SEQN = SEQN; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public String getTYPE() { | ||
| 66 | + return TYPE; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public void setTYPE(String TYPE) { | ||
| 70 | + this.TYPE = TYPE; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public String getSTYP() { | ||
| 74 | + return STYP; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public void setSTYP(String STYP) { | ||
| 78 | + this.STYP = STYP; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public String getIMFContent() { | ||
| 82 | + return IMFContent; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public void setIMFContent(String IMFContent) { | ||
| 86 | + this.IMFContent = IMFContent; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public String getIMFXml() { | ||
| 90 | + return IMFXml; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public void setIMFXml(String IMFXml) { | ||
| 94 | + this.IMFXml = IMFXml; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + //初始化报文头部节点 | ||
| 98 | + public IMFXMLMaker(String sndr,String seqn,String type,String styp){ | ||
| 99 | + this.SNDR = sndr; | ||
| 100 | + this.SEQN = seqn; | ||
| 101 | + this.TYPE = type; | ||
| 102 | + this.STYP = styp; | ||
| 103 | + | ||
| 104 | + this.XmlDocument = new Document(); | ||
| 105 | + | ||
| 106 | + //跟节点 | ||
| 107 | + this.RootElement = new Element("MSG"); | ||
| 108 | + this.XmlDocument.addContent(this.RootElement); | ||
| 109 | + | ||
| 110 | + //meta节点 | ||
| 111 | + Element MetaElement = new Element("META"); | ||
| 112 | + this.RootElement.addContent(0,MetaElement); | ||
| 113 | + | ||
| 114 | + //meta下的子节点们 | ||
| 115 | + SndrElement = new Element("SNDR"); | ||
| 116 | + RcvrElement = new Element("RCVR"); | ||
| 117 | + SEQNElement = new Element("SEQN"); | ||
| 118 | + Element DDTMElement = new Element("DDTM"); | ||
| 119 | + TYPEElement = new Element("TYPE"); | ||
| 120 | + STYPElement = new Element("STYP"); | ||
| 121 | + | ||
| 122 | + MetaElement.addContent(0,SndrElement); | ||
| 123 | + MetaElement.addContent(1,RcvrElement); | ||
| 124 | + MetaElement.addContent(2,SEQNElement); | ||
| 125 | + MetaElement.addContent(3,DDTMElement); | ||
| 126 | + MetaElement.addContent(4,TYPEElement); | ||
| 127 | + MetaElement.addContent(5,STYPElement); | ||
| 128 | + | ||
| 129 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); | ||
| 130 | + String dateString = simpleDateFormat.format(new Date()); | ||
| 131 | + DDTMElement.setText(dateString); | ||
| 132 | + | ||
| 133 | + SndrElement.setText(this.SNDR); | ||
| 134 | + SEQNElement.setText(this.SEQN); | ||
| 135 | + TYPEElement.setText(this.TYPE); | ||
| 136 | + STYPElement.setText(this.STYP); | ||
| 137 | + | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + public String finalXmlStr(){ | ||
| 141 | + | ||
| 142 | + try{ | ||
| 143 | + Document contentDocument = string2Doc(this.IMFContent); | ||
| 144 | + this.RootElement.addContent(1,contentDocument.detachRootElement()); | ||
| 145 | + | ||
| 146 | + String backXml = doc2String(this.XmlDocument); | ||
| 147 | + return backXml; | ||
| 148 | + }catch (Exception e){ | ||
| 149 | + e.printStackTrace(); | ||
| 150 | + return this.SEQN+"error"; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + /** | ||
| 156 | + * 字符串转换为DOCUMENT | ||
| 157 | + * | ||
| 158 | + * @param xmlStr 字符串 | ||
| 159 | + * @return doc JDOM的Document | ||
| 160 | + * @throws Exception | ||
| 161 | + */ | ||
| 162 | + public static Document string2Doc(String xmlStr) throws Exception { | ||
| 163 | + java.io.Reader in = new StringReader(xmlStr); | ||
| 164 | + Document doc = (new SAXBuilder()).build(in); | ||
| 165 | + return doc; | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + /** | ||
| 169 | + * Document转换为字符串 | ||
| 170 | + * | ||
| 171 | + * @param doc DOCUMENT对象 | ||
| 172 | + * @return xmlStr 字符串 | ||
| 173 | + * @throws Exception | ||
| 174 | + */ | ||
| 175 | + public String doc2String(Document doc) throws Exception { | ||
| 176 | + Format format = Format.getPrettyFormat(); | ||
| 177 | + format.setEncoding("UTF-8");// 设置xml文件的字符为UTF-8,解决中文问题 | ||
| 178 | + XMLOutputter xmlout = new XMLOutputter(format); | ||
| 179 | + ByteArrayOutputStream bo = new ByteArrayOutputStream(); | ||
| 180 | + xmlout.output(doc, bo); | ||
| 181 | + return bo.toString(); | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + /** | ||
| 185 | + * XML转换为Document | ||
| 186 | + * | ||
| 187 | + * @param xmlFilePath XML文件路径 | ||
| 188 | + * @return doc Document对象 | ||
| 189 | + * @throws Exception | ||
| 190 | + */ | ||
| 191 | + public static Document xml2Doc(String xmlFilePath) throws Exception { | ||
| 192 | + File file = new File(xmlFilePath); | ||
| 193 | + return (new SAXBuilder()).build(file); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + public void main(String[] args) throws Exception{ | ||
| 197 | + finalXmlStr(); | ||
| 198 | + } | ||
| 199 | +} |
-
请 注册 或 登录 后发表评论