正在显示
21 个修改的文件
包含
1556 行增加
和
0 行删除
src/java/com/airport/Main.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport; | ||
7 | + | ||
8 | +import com.airport.core.IMFReader; | ||
9 | +import com.airport.core.SendMessageTask; | ||
10 | +import com.airport.util.ConfigUtils; | ||
11 | +import com.airport.util.SystemBean; | ||
12 | +import com.caac.imf.api.IMFClient; | ||
13 | +import com.caac.imf.api.IMFClientFactory; | ||
14 | +import java.util.Timer; | ||
15 | +import org.apache.log4j.Logger; | ||
16 | +import org.apache.log4j.PropertyConfigurator; | ||
17 | + | ||
18 | +public class Main { | ||
19 | + private static final Logger logger = Logger.getLogger(Main.class); | ||
20 | + public static boolean LOGIN_OK = false; | ||
21 | + public static IMFClient client = null; | ||
22 | + | ||
23 | + public Main() { | ||
24 | + } | ||
25 | + | ||
26 | + private static void start() throws Exception { | ||
27 | + PropertyConfigurator.configure("config/log4j.properties"); | ||
28 | + SystemBean.createInstance("config/ApplicationContext.xml"); | ||
29 | + ConfigUtils conf = new ConfigUtils(); | ||
30 | + conf.Initialize(); | ||
31 | + client = IMFClientFactory.createInstance(); | ||
32 | + if ("R".equalsIgnoreCase(ConfigUtils.ROLE)) { | ||
33 | + if (client != null) { | ||
34 | + IMFReader reader = new IMFReader(client); | ||
35 | + reader.start(); | ||
36 | + } | ||
37 | + | ||
38 | + loginIMF(client, ConfigUtils.IMF_USERNAME, ConfigUtils.IMF_PASSWORD, "config/imf_config.properties"); | ||
39 | + } else if ("S".equalsIgnoreCase(ConfigUtils.ROLE)) { | ||
40 | + loginIMF(client, ConfigUtils.IMF_USERNAME, ConfigUtils.IMF_PASSWORD, "config/imf_config.properties"); | ||
41 | + if (LOGIN_OK && client != null) { | ||
42 | + logger.info("start run Timer,client hasocde=" + client.hashCode()); | ||
43 | + Timer timer = new Timer(); | ||
44 | + SendMessageTask sender = new SendMessageTask(client, "data/fid_index.txt"); | ||
45 | + timer.schedule(sender, 30000L, 1200000L); | ||
46 | + } | ||
47 | + } | ||
48 | + | ||
49 | + } | ||
50 | + | ||
51 | + private static void loginIMF(IMFClient client, String userName, String password, String confFileName) { | ||
52 | + if (client.initial(confFileName)) { | ||
53 | + String message = client.login(userName, password); | ||
54 | + logger.info("message=" + message); | ||
55 | + if (message.indexOf("<CODE>1</CODE>") > 0) { | ||
56 | + logger.info("登陆成功"); | ||
57 | + LOGIN_OK = true; | ||
58 | + } else { | ||
59 | + int times = 0; | ||
60 | + | ||
61 | + while(times <= 3) { | ||
62 | + logger.info("try connection..."); | ||
63 | + ++times; | ||
64 | + logger.info("message.=" + message); | ||
65 | + if (message.indexOf("<CODE>1</CODE>") > 0) { | ||
66 | + logger.info("登陆成功"); | ||
67 | + LOGIN_OK = true; | ||
68 | + break; | ||
69 | + } | ||
70 | + | ||
71 | + logger.info("登录失败~~~~"); | ||
72 | + message = client.login(userName, password); | ||
73 | + | ||
74 | + try { | ||
75 | + Thread.sleep(4000L); | ||
76 | + } catch (InterruptedException var7) { | ||
77 | + var7.printStackTrace(); | ||
78 | + } | ||
79 | + } | ||
80 | + | ||
81 | + if (!LOGIN_OK) { | ||
82 | + logger.info("多次尝试登录失败,退出登陆"); | ||
83 | + client.disconnect(); | ||
84 | + System.exit(-1); | ||
85 | + } | ||
86 | + } | ||
87 | + } | ||
88 | + | ||
89 | + } | ||
90 | + | ||
91 | + public static void main(String[] args) throws Exception { | ||
92 | + start(); | ||
93 | + } | ||
94 | +} |
src/java/com/airport/bean/MessageBak.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.bean; | ||
7 | + | ||
8 | +public class MessageBak { | ||
9 | + private int fid; | ||
10 | + private String content; | ||
11 | + | ||
12 | + public MessageBak(int fid, String content) { | ||
13 | + this.fid = fid; | ||
14 | + this.content = content; | ||
15 | + } | ||
16 | + | ||
17 | + public String toString() { | ||
18 | + return this.fid + " " + this.content; | ||
19 | + } | ||
20 | + | ||
21 | + public int getFid() { | ||
22 | + return this.fid; | ||
23 | + } | ||
24 | + | ||
25 | + public void setFid(int fid) { | ||
26 | + this.fid = fid; | ||
27 | + } | ||
28 | + | ||
29 | + public String getContent() { | ||
30 | + return this.content; | ||
31 | + } | ||
32 | + | ||
33 | + public void setContent(String content) { | ||
34 | + this.content = content; | ||
35 | + } | ||
36 | +} |
src/java/com/airport/bean/XMLHeader.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.bean; | ||
7 | + | ||
8 | +public class XMLHeader { | ||
9 | + private String sndr; | ||
10 | + private String rcvr; | ||
11 | + private String type; | ||
12 | + private String stype; | ||
13 | + | ||
14 | + public XMLHeader() { | ||
15 | + } | ||
16 | + | ||
17 | + public String toString() { | ||
18 | + return "sndr=[" + this.sndr + "]\t rcvr=[" + this.rcvr + "]\t type=[" + this.type + "]\t stype=[" + this.stype + "]"; | ||
19 | + } | ||
20 | + | ||
21 | + public String getSndr() { | ||
22 | + return this.sndr; | ||
23 | + } | ||
24 | + | ||
25 | + public void setSndr(String sndr) { | ||
26 | + this.sndr = sndr; | ||
27 | + } | ||
28 | + | ||
29 | + public String getRcvr() { | ||
30 | + return this.rcvr; | ||
31 | + } | ||
32 | + | ||
33 | + public void setRcvr(String rcvr) { | ||
34 | + this.rcvr = rcvr; | ||
35 | + } | ||
36 | + | ||
37 | + public String getType() { | ||
38 | + return this.type; | ||
39 | + } | ||
40 | + | ||
41 | + public void setType(String type) { | ||
42 | + this.type = type; | ||
43 | + } | ||
44 | + | ||
45 | + public String getStype() { | ||
46 | + return this.stype; | ||
47 | + } | ||
48 | + | ||
49 | + public void setStype(String stype) { | ||
50 | + this.stype = stype; | ||
51 | + } | ||
52 | +} |
src/java/com/airport/core/IMFReader.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.core; | ||
7 | + | ||
8 | +import com.airport.Main; | ||
9 | +import com.airport.dao.impl.DaoImpl; | ||
10 | +import com.airport.util.SystemBean; | ||
11 | +import com.airport.util.Utils; | ||
12 | +import com.airport.util.parse.XMPParse; | ||
13 | +import com.caac.imf.api.IMFClient; | ||
14 | +import java.util.Date; | ||
15 | +import org.apache.log4j.Logger; | ||
16 | + | ||
17 | +public class IMFReader extends Thread { | ||
18 | + private static final Logger logger = Logger.getLogger(IMFReader.class); | ||
19 | + private static final String stype = "/MSG/META/STYP"; | ||
20 | + private IMFClient client; | ||
21 | + | ||
22 | + public IMFReader(IMFClient client) { | ||
23 | + this.client = client; | ||
24 | + } | ||
25 | + | ||
26 | + public void run() { | ||
27 | + while(true) { | ||
28 | + if (Main.LOGIN_OK) { | ||
29 | + synchronized(this) { | ||
30 | + String message = this.client.getMSG(); | ||
31 | + if (message != null) { | ||
32 | + this.save(message); | ||
33 | + } | ||
34 | + } | ||
35 | + } else { | ||
36 | + logger.info("***"); | ||
37 | + } | ||
38 | + | ||
39 | + try { | ||
40 | + Thread.sleep(100L); | ||
41 | + } catch (InterruptedException var3) { | ||
42 | + var3.printStackTrace(); | ||
43 | + } | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | + private void save(String message) { | ||
48 | + Date dt = new Date(); | ||
49 | + DaoImpl dao = (DaoImpl)SystemBean.getBean("dao"); | ||
50 | + String path = "data/" + Utils.dateToStr(dt, "yyyy-MM-dd") + "/"; | ||
51 | + if (Utils.createDir(path)) { | ||
52 | + String fileName = ""; | ||
53 | + | ||
54 | + try { | ||
55 | + String stype_value = XMPParse.getNodeValueFromXmlString(message, "/MSG/META/STYP"); | ||
56 | + fileName = path + stype_value + "_" + Utils.dateToStr(dt, "yyyyMMddhhmmssSSS") + ".xml"; | ||
57 | + Utils.saveFile(fileName, message); | ||
58 | + dao.saveRecord("ALL", "FIMS", message); | ||
59 | + logger.info("created " + fileName + " ok"); | ||
60 | + } catch (Exception var7) { | ||
61 | + fileName = path + Utils.dateToStr(dt, "yyyyMMddhhmmssSSS") + ".txt"; | ||
62 | + Utils.saveFile(fileName, message); | ||
63 | + logger.warn("created " + fileName + " ok"); | ||
64 | + } | ||
65 | + } else { | ||
66 | + logger.info("创建目录失败."); | ||
67 | + logger.info(message); | ||
68 | + } | ||
69 | + | ||
70 | + } | ||
71 | +} |
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.core; | ||
7 | + | ||
8 | +import com.airport.bean.MessageBak; | ||
9 | +import com.airport.bean.XMLHeader; | ||
10 | +import com.airport.dao.Dao; | ||
11 | +import com.airport.dao.impl.DaoImpl; | ||
12 | +import com.airport.util.ConfigUtils; | ||
13 | +import com.airport.util.SystemBean; | ||
14 | +import com.airport.util.Utils; | ||
15 | +import com.caac.imf.api.IMFClient; | ||
16 | +import java.util.Iterator; | ||
17 | +import java.util.List; | ||
18 | +import java.util.Map; | ||
19 | +import java.util.TimerTask; | ||
20 | +import org.apache.log4j.Logger; | ||
21 | + | ||
22 | +public class SendMessageTask extends TimerTask { | ||
23 | + private static final Logger logger = Logger.getLogger(SendMessageTask.class); | ||
24 | + private Dao dao = (DaoImpl)SystemBean.getBean("dao"); | ||
25 | + private IMFClient client; | ||
26 | + private String indexFileName; | ||
27 | + | ||
28 | + public SendMessageTask(IMFClient client, String fileName) { | ||
29 | + this.indexFileName = fileName; | ||
30 | + this.client = client; | ||
31 | + } | ||
32 | + | ||
33 | + public void run() { | ||
34 | + try { | ||
35 | + if (this.client == null) { | ||
36 | + logger.info("IMFClient has been closed"); | ||
37 | + return; | ||
38 | + } | ||
39 | + | ||
40 | + logger.info("job start:"); | ||
41 | + int lastFID = Utils.readFIDIndex(this.indexFileName); | ||
42 | + int maxFID = this.dao.getMaxFID(); | ||
43 | + logger.info("lastFID=" + lastFID + " maxFID=" + maxFID); | ||
44 | + int is_ok = 0; | ||
45 | + if (maxFID > lastFID) { | ||
46 | + List<MessageBak> list = this.dao.getRecordByFID(lastFID); | ||
47 | + Map<Integer, XMLHeader> map = ConfigUtils.XML_HEADER_MAP; | ||
48 | + Iterator var7 = list.iterator(); | ||
49 | + | ||
50 | + while(true) { | ||
51 | + while(var7.hasNext()) { | ||
52 | + MessageBak m = (MessageBak)var7.next(); | ||
53 | + if (is_ok != 0) { | ||
54 | + logger.error("记录FID时发生异常,发送消息任务被迫中断"); | ||
55 | + return; | ||
56 | + } | ||
57 | + | ||
58 | + if (m.getContent() != null) { | ||
59 | + int times = 0; | ||
60 | + | ||
61 | + for(Iterator var10 = map.keySet().iterator(); var10.hasNext(); Thread.sleep((long)ConfigUtils.SEND_MESSAGE_INTERVAL)) { | ||
62 | + Integer key = (Integer)var10.next(); | ||
63 | + XMLHeader header = (XMLHeader)map.get(key); | ||
64 | + logger.info("key=" + key + " value=" + ((XMLHeader)map.get(key)).toString()); | ||
65 | + logger.info("准备发送数据 FID:" + m.getFid() + " XML.length=:" + m.getContent().length()); | ||
66 | + String sendMsg = Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR"); | ||
67 | + sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE"); | ||
68 | + sendMsg = Utils.searchReplace(sendMsg, header.getStype(), "STYP"); | ||
69 | + sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR"); | ||
70 | + if (!"".equals(sendMsg)) { | ||
71 | + logger.info("开始发送数据 XML:" + sendMsg); | ||
72 | + String is_send_ok = this.client.sendMSG(sendMsg); | ||
73 | + logger.info("is_send_ok=" + is_send_ok); | ||
74 | + is_ok = Utils.writeFIDIndex(this.indexFileName, m.getFid()); | ||
75 | + logger.debug("FID:" + m.getFid() + " 缓存成功"); | ||
76 | + ++times; | ||
77 | + } else { | ||
78 | + logger.error("查找替换节点数据出现异常,可能找不到这个节点,原始XML=" + m.getContent()); | ||
79 | + } | ||
80 | + } | ||
81 | + | ||
82 | + this.dao.update(m.getFid(), times); | ||
83 | + } else { | ||
84 | + logger.info("FID=" + m.getFid() + "XML is null "); | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + return; | ||
89 | + } | ||
90 | + } else { | ||
91 | + logger.info("lastFID=" + lastFID + ">= maxFID=" + maxFID + " 忽略发送数据"); | ||
92 | + } | ||
93 | + } catch (Exception var14) { | ||
94 | + var14.printStackTrace(); | ||
95 | + logger.info(var14.getMessage()); | ||
96 | + } | ||
97 | + | ||
98 | + } | ||
99 | +} |
src/java/com/airport/dao/Dao.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.dao; | ||
7 | + | ||
8 | +import com.airport.bean.MessageBak; | ||
9 | +import java.util.List; | ||
10 | + | ||
11 | +public interface Dao { | ||
12 | + int insertRecord(String var1, String var2); | ||
13 | + | ||
14 | + void saveRecord(String var1, String var2, String var3) throws Exception; | ||
15 | + | ||
16 | + void delete(int var1); | ||
17 | + | ||
18 | + List<MessageBak> getRecordByFID(int var1); | ||
19 | + | ||
20 | + int getRecordCount(); | ||
21 | + | ||
22 | + int getMaxFID(); | ||
23 | + | ||
24 | + void update(int var1, int var2); | ||
25 | +} |
src/java/com/airport/dao/impl/DaoImpl.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.dao.impl; | ||
7 | + | ||
8 | +import com.airport.bean.MessageBak; | ||
9 | +import com.airport.dao.Dao; | ||
10 | +import com.airport.util.ConfigUtils; | ||
11 | +import java.io.IOException; | ||
12 | +import java.io.Writer; | ||
13 | +import java.sql.Connection; | ||
14 | +import java.sql.PreparedStatement; | ||
15 | +import java.sql.ResultSet; | ||
16 | +import java.sql.SQLException; | ||
17 | +import java.sql.Statement; | ||
18 | +import java.util.ArrayList; | ||
19 | +import java.util.List; | ||
20 | +import oracle.sql.CLOB; | ||
21 | +import org.apache.log4j.Logger; | ||
22 | +import org.springframework.dao.DataAccessException; | ||
23 | +import org.springframework.dao.EmptyResultDataAccessException; | ||
24 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
25 | +import org.springframework.jdbc.core.PreparedStatementCreator; | ||
26 | +import org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor; | ||
27 | +import org.springframework.jdbc.support.GeneratedKeyHolder; | ||
28 | +import org.springframework.jdbc.support.KeyHolder; | ||
29 | +import org.springframework.jdbc.support.lob.DefaultLobHandler; | ||
30 | +import org.springframework.jdbc.support.lob.LobHandler; | ||
31 | + | ||
32 | +public class DaoImpl implements Dao { | ||
33 | + private static final Logger logger = Logger.getLogger(DaoImpl.class); | ||
34 | + private JdbcTemplate jdbcTemplate; | ||
35 | + | ||
36 | + public DaoImpl() { | ||
37 | + } | ||
38 | + | ||
39 | + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { | ||
40 | + this.jdbcTemplate = jdbcTemplate; | ||
41 | + } | ||
42 | + | ||
43 | + public int insertRecord(final String oper, final String sndr) { | ||
44 | + KeyHolder keyHolder = new GeneratedKeyHolder(); | ||
45 | + this.jdbcTemplate.update(new PreparedStatementCreator() { | ||
46 | + public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { | ||
47 | + DaoImpl.logger.info("oper=" + oper + " sndr=" + sndr); | ||
48 | + String sql = "insert into T_ETL_MESSAGE(OPER,SNDR,SNTM,content) values(?,?,sysdate,empty_clob())"; | ||
49 | + PreparedStatement ps = connection.prepareStatement(sql, new String[]{"FID"}); | ||
50 | + ps.setString(1, oper); | ||
51 | + ps.setString(2, sndr); | ||
52 | + return ps; | ||
53 | + } | ||
54 | + }, keyHolder); | ||
55 | + int generatedId = keyHolder.getKey().intValue(); | ||
56 | + return generatedId; | ||
57 | + } | ||
58 | + | ||
59 | + public void saveRecord(String messaegType, String sndr, String xmlContent) throws Exception { | ||
60 | + Connection conn = null; | ||
61 | + Statement stmt = null; | ||
62 | + ResultSet rs = null; | ||
63 | + int fid = -100; | ||
64 | + | ||
65 | + try { | ||
66 | + fid = this.insertRecord(messaegType, sndr); | ||
67 | + conn = this.jdbcTemplate.getDataSource().getConnection(); | ||
68 | + conn.setAutoCommit(false); | ||
69 | + stmt = conn.createStatement(); | ||
70 | + String SQL = "select CONTENT from T_ETL_MESSAGE where FID=" + fid + " and SNDR='FIMS' for update"; | ||
71 | + rs = stmt.executeQuery(SQL); | ||
72 | + | ||
73 | + while(rs.next()) { | ||
74 | + CLOB clob = (CLOB)rs.getClob(1); | ||
75 | + Writer os = clob.getCharacterOutputStream(); | ||
76 | + os.write(xmlContent); | ||
77 | + os.flush(); | ||
78 | + os.close(); | ||
79 | + } | ||
80 | + | ||
81 | + conn.commit(); | ||
82 | + } catch (SQLException var14) { | ||
83 | + if (fid > 0) { | ||
84 | + this.delete(fid); | ||
85 | + } | ||
86 | + | ||
87 | + var14.printStackTrace(); | ||
88 | + conn.rollback(); | ||
89 | + } finally { | ||
90 | + if (conn != null) { | ||
91 | + conn.setAutoCommit(true); | ||
92 | + } | ||
93 | + | ||
94 | + if (rs != null) { | ||
95 | + rs.close(); | ||
96 | + } | ||
97 | + | ||
98 | + if (stmt != null) { | ||
99 | + stmt.close(); | ||
100 | + } | ||
101 | + | ||
102 | + if (conn != null) { | ||
103 | + conn.close(); | ||
104 | + } | ||
105 | + | ||
106 | + } | ||
107 | + | ||
108 | + } | ||
109 | + | ||
110 | + public void delete(int fid) { | ||
111 | + this.jdbcTemplate.update("delete from T_ETL_MESSAGE where fid=" + fid); | ||
112 | + } | ||
113 | + | ||
114 | + public int getMaxFID() { | ||
115 | + return this.jdbcTemplate.queryForInt("select max(FID) from T_ETL_MESSAGE where SNDR='FIMS'"); | ||
116 | + } | ||
117 | + | ||
118 | + public List<MessageBak> getRecordByFID(int fid) { | ||
119 | + String SQL_FMT = "select FID,CONTENT from T_ETL_MESSAGE where (FID>%s and FID<%s+%s) and SNDR='FIMS' order by FID"; | ||
120 | + String sql = String.format(SQL_FMT, fid, fid, ConfigUtils.RECORD_COUNT); | ||
121 | + logger.info(sql); | ||
122 | + final LobHandler lobHandler = new DefaultLobHandler(); | ||
123 | + final ArrayList xmlList = new ArrayList(); | ||
124 | + | ||
125 | + try { | ||
126 | + this.jdbcTemplate.query(sql, new AbstractLobStreamingResultSetExtractor() { | ||
127 | + protected void streamData(ResultSet rs) throws SQLException, IOException, DataAccessException { | ||
128 | + String content = ""; | ||
129 | + | ||
130 | + while(rs.next()) { | ||
131 | + int fid = rs.getInt(1); | ||
132 | + content = lobHandler.getClobAsString(rs, "CONTENT"); | ||
133 | + if (content != null) { | ||
134 | + MessageBak obj = new MessageBak(fid, content); | ||
135 | + xmlList.add(obj); | ||
136 | + } else { | ||
137 | + DaoImpl.logger.error("FID=" + fid + " content is NULL"); | ||
138 | + } | ||
139 | + } | ||
140 | + | ||
141 | + } | ||
142 | + }); | ||
143 | + } catch (EmptyResultDataAccessException var7) { | ||
144 | + var7.printStackTrace(); | ||
145 | + } | ||
146 | + | ||
147 | + return xmlList; | ||
148 | + } | ||
149 | + | ||
150 | + public int getRecordCount() { | ||
151 | + return this.jdbcTemplate.queryForInt("select count(*) from T_ETL_MESSAGE where SNDR='FIMS' "); | ||
152 | + } | ||
153 | + | ||
154 | + public void update(int fid, int times) { | ||
155 | + String sql = String.format("update T_ETL_MESSAGE set OUTFLAG=%s ,OUTTM=sysdate where FID=%s", times, fid); | ||
156 | + logger.info("sql=" + sql); | ||
157 | + this.jdbcTemplate.update(sql); | ||
158 | + } | ||
159 | +} |
src/java/com/airport/util/ConfigUtils.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util; | ||
7 | + | ||
8 | +import com.airport.bean.XMLHeader; | ||
9 | +import java.io.File; | ||
10 | +import java.util.HashMap; | ||
11 | +import java.util.Map; | ||
12 | +import org.apache.commons.lang.StringUtils; | ||
13 | +import org.apache.log4j.Logger; | ||
14 | + | ||
15 | +public class ConfigUtils { | ||
16 | + private static final Logger logger = Logger.getLogger(ConfigUtils.class); | ||
17 | + public static String ROLE; | ||
18 | + public static String IMF_USERNAME; | ||
19 | + public static String IMF_PASSWORD; | ||
20 | + public static final String IFM_CONSUMER = "config/imf_config.properties"; | ||
21 | + public static final String IMF_PRUDUCER = "config/imf_config.properties"; | ||
22 | + public static final String INDEX_FILE_NAME = "data/fid_index.txt"; | ||
23 | + public static int SEND_MESSAGE_INTERVAL = 1; | ||
24 | + public static int RECORD_COUNT = 1000; | ||
25 | + public static String XML_HEADER_SNDR = ""; | ||
26 | + public static String XML_HEADER_TYPE = ""; | ||
27 | + public static String XML_HEADER_STYPE = ""; | ||
28 | + public static String XML_HEADER_RCVR = ""; | ||
29 | + public static Map<Integer, XMLHeader> XML_HEADER_MAP = new HashMap(); | ||
30 | + | ||
31 | + public ConfigUtils() { | ||
32 | + } | ||
33 | + | ||
34 | + public void Initialize() throws LteException { | ||
35 | + logger.debug("Loading all the config parameters..."); | ||
36 | + this.loadParameter(); | ||
37 | + } | ||
38 | + | ||
39 | + private final void loadParameter() throws LteException { | ||
40 | + boolean ok = false; | ||
41 | + logger.info("================Initialize system parameter ================="); | ||
42 | + Configuration config = (Configuration)SystemBean.getBean("configurationBean"); | ||
43 | + ROLE = config.getProperty("role").trim(); | ||
44 | + IMF_USERNAME = config.getProperty("imf_username").trim(); | ||
45 | + IMF_PASSWORD = config.getProperty("imf_password").trim(); | ||
46 | + String interval = config.getProperty("interval").trim(); | ||
47 | + String record_count = config.getProperty("record_count").trim(); | ||
48 | + logger.info(String.format("role=%s", ROLE)); | ||
49 | + logger.info(String.format("imf_username=%s", IMF_USERNAME)); | ||
50 | + logger.info(String.format("imf_password=%s", IMF_PASSWORD)); | ||
51 | + logger.info(String.format("interval=%s", interval)); | ||
52 | + if (StringUtils.isBlank(ROLE)) { | ||
53 | + logger.error("role 参数错误"); | ||
54 | + ok = true; | ||
55 | + } else if ("R".equalsIgnoreCase(ROLE)) { | ||
56 | + if (!isFileExists("config/imf_config.properties")) { | ||
57 | + logger.error("如果要从IMF接收数据,需要在config/imf_config.properties 配置IMF参数"); | ||
58 | + ok = true; | ||
59 | + } | ||
60 | + } else if ("S".equalsIgnoreCase(ROLE)) { | ||
61 | + if (!isFileExists("config/imf_config.properties")) { | ||
62 | + logger.error("如果向IMF发送数据,需要在config/imf_config.properties 配置IMF参数"); | ||
63 | + ok = true; | ||
64 | + } | ||
65 | + } else { | ||
66 | + logger.error("role 参数错误,必须是S(从IMF接收消息) 或者 R(发送消息到IMF)"); | ||
67 | + } | ||
68 | + | ||
69 | + int int_total_group; | ||
70 | + if ("S".equalsIgnoreCase(ROLE)) { | ||
71 | + String total_group = config.getProperty("total_group").trim(); | ||
72 | + int_total_group = 0; | ||
73 | + logger.info(String.format("record_count=%s", record_count)); | ||
74 | + logger.info(String.format("total_group=%s", total_group)); | ||
75 | + if (StringUtils.isBlank(total_group)) { | ||
76 | + logger.error("total_group 参数错误"); | ||
77 | + ok = true; | ||
78 | + } else { | ||
79 | + int_total_group = Integer.parseInt(total_group); | ||
80 | + if (int_total_group <= 10 && int_total_group >= 1) { | ||
81 | + this.loadXMLHeaderParameter(config, int_total_group); | ||
82 | + } else { | ||
83 | + logger.error("total_group 参数设置错误,范围在1--10之间"); | ||
84 | + ok = true; | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + int x; | ||
89 | + if (StringUtils.isBlank(record_count)) { | ||
90 | + logger.error("record_count 参数错误"); | ||
91 | + ok = true; | ||
92 | + } else { | ||
93 | + x = Integer.parseInt(record_count); | ||
94 | + if (x <= 10000 && x >= 100) { | ||
95 | + RECORD_COUNT = x; | ||
96 | + } else { | ||
97 | + logger.error("record_count 参数设置错误,范围在100--10000之间"); | ||
98 | + ok = true; | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + if (StringUtils.isBlank(interval)) { | ||
103 | + logger.error("interval 参数错误"); | ||
104 | + ok = true; | ||
105 | + } else { | ||
106 | + x = Integer.parseInt(interval); | ||
107 | + if (x <= 60 && x >= 1) { | ||
108 | + SEND_MESSAGE_INTERVAL = x * 1000; | ||
109 | + } else { | ||
110 | + logger.error("interval 参数设置错误,范围在1---60之间"); | ||
111 | + ok = true; | ||
112 | + } | ||
113 | + } | ||
114 | + } | ||
115 | + | ||
116 | + if (!isFileExists("data/")) { | ||
117 | + File f = new File("data"); | ||
118 | + f.mkdir(); | ||
119 | + Utils.writeFIDIndex("data/fid_index.txt", 0); | ||
120 | + int_total_group = Utils.readFIDIndex("data/fid_index.txt"); | ||
121 | + logger.info("FID=" + int_total_group); | ||
122 | + } else { | ||
123 | + logger.info("data/fid_index.txt exists"); | ||
124 | + } | ||
125 | + | ||
126 | + boolean hasError = false; | ||
127 | + hasError = this.validate(IMF_USERNAME, "imf_username 参数错误"); | ||
128 | + hasError = this.validate(IMF_PASSWORD, "imf_password 参数错误"); | ||
129 | + if (ok && !hasError) { | ||
130 | + logger.error("参数错误 启动程序失败。"); | ||
131 | + System.exit(-1); | ||
132 | + } | ||
133 | + | ||
134 | + } | ||
135 | + | ||
136 | + private void loadXMLHeaderParameter(Configuration config, int total) throws LteException { | ||
137 | + String sndr = ""; | ||
138 | + String rcvr = ""; | ||
139 | + String type = ""; | ||
140 | + String stype = ""; | ||
141 | + | ||
142 | + for(int i = 1; i <= total; ++i) { | ||
143 | + logger.info(String.format("group %d--------------------------", i)); | ||
144 | + sndr = config.getProperty("sndr_" + i).trim(); | ||
145 | + rcvr = config.getProperty("rcvr_" + i).trim(); | ||
146 | + type = config.getProperty("type_" + i).trim(); | ||
147 | + stype = config.getProperty("stype_" + i).trim(); | ||
148 | + logger.info(String.format("SNDR_%d=%s", i, sndr)); | ||
149 | + logger.info(String.format("RCVR_%d=%s", i, rcvr)); | ||
150 | + logger.info(String.format("TYPE_%d=%s", i, type)); | ||
151 | + logger.info(String.format("STYPE_%d=%s", i, stype)); | ||
152 | + XMLHeader header = new XMLHeader(); | ||
153 | + header.setSndr(sndr); | ||
154 | + header.setRcvr(rcvr); | ||
155 | + header.setType(type); | ||
156 | + header.setStype(stype); | ||
157 | + logger.info("group[" + i + "]\t" + header.toString()); | ||
158 | + XML_HEADER_MAP.put(i, header); | ||
159 | + } | ||
160 | + | ||
161 | + } | ||
162 | + | ||
163 | + private boolean validate(String paraValue, String tipText) { | ||
164 | + if (StringUtils.isBlank(paraValue)) { | ||
165 | + logger.error(tipText); | ||
166 | + return false; | ||
167 | + } else { | ||
168 | + return true; | ||
169 | + } | ||
170 | + } | ||
171 | + | ||
172 | + private static boolean isFileExists(String filename) { | ||
173 | + File f = new File(filename); | ||
174 | + return f.exists(); | ||
175 | + } | ||
176 | + | ||
177 | + public static void main(String[] argc) { | ||
178 | + File f = new File("config/producer_imf_config.properties"); | ||
179 | + if (f.exists()) { | ||
180 | + System.out.println("file exists"); | ||
181 | + } else { | ||
182 | + System.out.println("file not exists"); | ||
183 | + } | ||
184 | + | ||
185 | + } | ||
186 | +} |
src/java/com/airport/util/Configuration.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util; | ||
7 | + | ||
8 | +import java.io.IOException; | ||
9 | +import java.io.InputStream; | ||
10 | +import java.util.HashMap; | ||
11 | +import java.util.Iterator; | ||
12 | +import java.util.Map; | ||
13 | +import java.util.Properties; | ||
14 | +import org.apache.commons.lang.StringUtils; | ||
15 | +import org.apache.log4j.Level; | ||
16 | +import org.apache.log4j.Logger; | ||
17 | +import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; | ||
18 | +import org.springframework.core.io.Resource; | ||
19 | +import org.springframework.util.DefaultPropertiesPersister; | ||
20 | +import org.springframework.util.PropertiesPersister; | ||
21 | + | ||
22 | +public class Configuration extends PropertyPlaceholderConfigurer { | ||
23 | + private static final Logger logger = Logger.getLogger(Configuration.class); | ||
24 | + private static final Map<String, String> parameterMap = new HashMap(); | ||
25 | + private Resource location; | ||
26 | + | ||
27 | + public void setLocation(Resource location) { | ||
28 | + this.location = location; | ||
29 | + } | ||
30 | + | ||
31 | + public void loadProperties(Properties props) throws IOException { | ||
32 | + PropertiesPersister propertiesPersister = new DefaultPropertiesPersister(); | ||
33 | + InputStream is = null; | ||
34 | + | ||
35 | + try { | ||
36 | + Resource location = this.location; | ||
37 | + is = location.getInputStream(); | ||
38 | + propertiesPersister.load(props, is); | ||
39 | + Iterator var6 = props.keySet().iterator(); | ||
40 | + | ||
41 | + while(var6.hasNext()) { | ||
42 | + Object key = var6.next(); | ||
43 | + String code = props.getProperty((String)key).trim(); | ||
44 | + parameterMap.put((String)key, code); | ||
45 | + } | ||
46 | + } catch (Exception var11) { | ||
47 | + logger.error("initialization error", var11); | ||
48 | + var11.printStackTrace(); | ||
49 | + } finally { | ||
50 | + if (is != null) { | ||
51 | + is.close(); | ||
52 | + } | ||
53 | + | ||
54 | + } | ||
55 | + | ||
56 | + } | ||
57 | + | ||
58 | + public Configuration() { | ||
59 | + logger.setLevel(Level.INFO); | ||
60 | + } | ||
61 | + | ||
62 | + public String getProperty(String name) throws LteException { | ||
63 | + String str = (String)parameterMap.get(name); | ||
64 | + if (str == null) { | ||
65 | + String errMsg = String.format("config.properties key Error, can not find key [%s]", name); | ||
66 | + logger.error(errMsg); | ||
67 | + throw new LteException(errMsg); | ||
68 | + } else { | ||
69 | + return str.trim(); | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | + public String getPropertyMaybeNull(String name) throws LteException { | ||
74 | + String str = (String)parameterMap.get(name); | ||
75 | + if (StringUtils.isBlank(str)) { | ||
76 | + str = ""; | ||
77 | + } | ||
78 | + | ||
79 | + return str.trim(); | ||
80 | + } | ||
81 | +} |
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util; | ||
7 | + | ||
8 | +import java.io.PrintWriter; | ||
9 | +import java.io.StringWriter; | ||
10 | + | ||
11 | +public class ExceptionUtils { | ||
12 | + public ExceptionUtils() { | ||
13 | + } | ||
14 | + | ||
15 | + public static String outputExceptionDetailsInfo(String label, String msg, Throwable t) { | ||
16 | + StringBuffer sb = new StringBuffer(); | ||
17 | + StackTraceElement[] messages = t.getStackTrace(); | ||
18 | + int length = messages.length; | ||
19 | + sb.append("\n"); | ||
20 | + sb.append("\n"); | ||
21 | + sb.append("\t"); | ||
22 | + sb.append("["); | ||
23 | + sb.append(label + " component exception super class name"); | ||
24 | + sb.append(":"); | ||
25 | + sb.append(msg); | ||
26 | + sb.append("]"); | ||
27 | + sb.append("\n"); | ||
28 | + sb.append("\t********Exception Detail List Begin********"); | ||
29 | + sb.append("\n\t" + t + "\n"); | ||
30 | + | ||
31 | + for(int i = 0; i < length; ++i) { | ||
32 | + sb.append("\t" + messages[i].toString() + "\n"); | ||
33 | + } | ||
34 | + | ||
35 | + sb.append("\t********Exception Detail List End********"); | ||
36 | + return sb.toString(); | ||
37 | + } | ||
38 | + | ||
39 | + public static String getStackTrace(Throwable t) { | ||
40 | + StringWriter sw = new StringWriter(); | ||
41 | + PrintWriter pw = new PrintWriter(sw); | ||
42 | + | ||
43 | + String var4; | ||
44 | + try { | ||
45 | + t.printStackTrace(pw); | ||
46 | + var4 = sw.toString(); | ||
47 | + } finally { | ||
48 | + pw.close(); | ||
49 | + } | ||
50 | + | ||
51 | + return var4; | ||
52 | + } | ||
53 | +} |
src/java/com/airport/util/LteException.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util; | ||
7 | + | ||
8 | +import org.apache.log4j.Logger; | ||
9 | + | ||
10 | +public class LteException extends Exception { | ||
11 | + private static final Logger logger = Logger.getLogger(LteException.class); | ||
12 | + private static final long serialVersionUID = -3047721096749400047L; | ||
13 | + private int errorCode = -1; | ||
14 | + | ||
15 | + public LteException() { | ||
16 | + } | ||
17 | + | ||
18 | + public LteException(String s) { | ||
19 | + super(s); | ||
20 | + } | ||
21 | + | ||
22 | + public LteException(int errorCode, String errmsg) { | ||
23 | + super(errmsg); | ||
24 | + this.errorCode = errorCode; | ||
25 | + if (errorCode > 0) { | ||
26 | + logger.debug("ErrorCode: " + errorCode + " " + errmsg); | ||
27 | + } | ||
28 | + | ||
29 | + } | ||
30 | + | ||
31 | + public int getErrorCode() { | ||
32 | + return this.errorCode; | ||
33 | + } | ||
34 | + | ||
35 | + public LteException(String s, Throwable cause) { | ||
36 | + super(s, cause); | ||
37 | + } | ||
38 | +} |
src/java/com/airport/util/SystemBean.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util; | ||
7 | + | ||
8 | +import org.apache.log4j.Logger; | ||
9 | +import org.springframework.beans.BeansException; | ||
10 | +import org.springframework.context.support.FileSystemXmlApplicationContext; | ||
11 | + | ||
12 | +public class SystemBean { | ||
13 | + private static Logger logger = Logger.getLogger(SystemBean.class); | ||
14 | + private static SystemBean inistance; | ||
15 | + private static FileSystemXmlApplicationContext fileSystemXmlApplicationContext; | ||
16 | + private static Object lock = new Object(); | ||
17 | + | ||
18 | + public SystemBean() { | ||
19 | + } | ||
20 | + | ||
21 | + public static final synchronized void createInstance(String path) throws LteException { | ||
22 | + if (inistance == null) { | ||
23 | + Object var1 = lock; | ||
24 | + synchronized(lock) { | ||
25 | + if (inistance == null) { | ||
26 | + inistance = new SystemBean(); | ||
27 | + | ||
28 | + String err; | ||
29 | + try { | ||
30 | + logger.info("Initialization ApplicationContext "); | ||
31 | + fileSystemXmlApplicationContext = new FileSystemXmlApplicationContext(path); | ||
32 | + fileSystemXmlApplicationContext.registerShutdownHook(); | ||
33 | + } catch (BeansException var4) { | ||
34 | + err = ExceptionUtils.getStackTrace(var4); | ||
35 | + throw new LteException("Initialization ApplicationContext error:" + err); | ||
36 | + } catch (Exception var5) { | ||
37 | + err = ExceptionUtils.getStackTrace(var5); | ||
38 | + throw new LteException("Initialization ApplicationContext error:" + err); | ||
39 | + } | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | + | ||
44 | + } | ||
45 | + | ||
46 | + public static final Object getBean(String beanName) { | ||
47 | + return fileSystemXmlApplicationContext.getBean(beanName); | ||
48 | + } | ||
49 | + | ||
50 | + public static final void destroy() { | ||
51 | + fileSystemXmlApplicationContext.getBeanFactory().destroySingletons(); | ||
52 | + } | ||
53 | +} |
src/java/com/airport/util/Utils.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util; | ||
7 | + | ||
8 | +import java.io.BufferedReader; | ||
9 | +import java.io.BufferedWriter; | ||
10 | +import java.io.File; | ||
11 | +import java.io.FileNotFoundException; | ||
12 | +import java.io.FileOutputStream; | ||
13 | +import java.io.FileReader; | ||
14 | +import java.io.IOException; | ||
15 | +import java.io.OutputStreamWriter; | ||
16 | +import java.io.PrintStream; | ||
17 | +import java.io.PrintWriter; | ||
18 | +import java.text.ParseException; | ||
19 | +import java.text.SimpleDateFormat; | ||
20 | +import java.util.Date; | ||
21 | +import java.util.regex.Matcher; | ||
22 | +import java.util.regex.Pattern; | ||
23 | +import org.apache.commons.lang.StringUtils; | ||
24 | +import org.apache.log4j.Logger; | ||
25 | + | ||
26 | +public class Utils { | ||
27 | + private static Logger logger = Logger.getLogger(SystemBean.class); | ||
28 | + | ||
29 | + public Utils() { | ||
30 | + } | ||
31 | + | ||
32 | + public static final Date iso8601DateStrToDate(String dateStr) { | ||
33 | + Date dt = null; | ||
34 | + String str_ = dateStr.replace("T", " "); | ||
35 | + str_ = str_.substring(0, 19); | ||
36 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
37 | + | ||
38 | + try { | ||
39 | + dt = format.parse(str_); | ||
40 | + } catch (ParseException var5) { | ||
41 | + var5.printStackTrace(); | ||
42 | + } | ||
43 | + | ||
44 | + return dt; | ||
45 | + } | ||
46 | + | ||
47 | + public static String dateToStr(Date date) { | ||
48 | + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | ||
49 | + String str = format.format(date); | ||
50 | + return str; | ||
51 | + } | ||
52 | + | ||
53 | + public static String dateToStr(Date date, String dateFmt) { | ||
54 | + SimpleDateFormat format = new SimpleDateFormat(dateFmt); | ||
55 | + String str = format.format(date); | ||
56 | + return str; | ||
57 | + } | ||
58 | + | ||
59 | + public static boolean createDir(String destDirName) { | ||
60 | + File dir = new File(destDirName); | ||
61 | + if (dir.exists()) { | ||
62 | + return true; | ||
63 | + } else { | ||
64 | + if (!destDirName.endsWith(File.separator)) { | ||
65 | + destDirName = destDirName + File.separator; | ||
66 | + } | ||
67 | + | ||
68 | + if (dir.mkdirs()) { | ||
69 | + return true; | ||
70 | + } else { | ||
71 | + logger.info("创建目录失败! 目录名称:" + destDirName); | ||
72 | + return false; | ||
73 | + } | ||
74 | + } | ||
75 | + } | ||
76 | + | ||
77 | + public static void saveFile(String fileName, String content) { | ||
78 | + try { | ||
79 | + PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))); | ||
80 | + out.write(content); | ||
81 | + out.flush(); | ||
82 | + out.close(); | ||
83 | + } catch (IOException var3) { | ||
84 | + var3.printStackTrace(); | ||
85 | + logger.error(var3.getMessage()); | ||
86 | + } | ||
87 | + | ||
88 | + } | ||
89 | + | ||
90 | + public static int writeFIDIndex(String fileName, int fid) { | ||
91 | + PrintStream ps = null; | ||
92 | + byte is_ok = 1; | ||
93 | + | ||
94 | + try { | ||
95 | + File file = new File(fileName); | ||
96 | + ps = new PrintStream(new FileOutputStream(file)); | ||
97 | + ps.println(fid); | ||
98 | + is_ok = 0; | ||
99 | + } catch (IOException var8) { | ||
100 | + var8.printStackTrace(); | ||
101 | + logger.error(var8.getMessage()); | ||
102 | + } finally { | ||
103 | + ps.close(); | ||
104 | + } | ||
105 | + | ||
106 | + return is_ok; | ||
107 | + } | ||
108 | + | ||
109 | + public static int readFIDIndex(String fileName) { | ||
110 | + FileReader reader = null; | ||
111 | + BufferedReader br = null; | ||
112 | + int index = 0; | ||
113 | + | ||
114 | + try { | ||
115 | + reader = new FileReader(fileName); | ||
116 | + br = new BufferedReader(reader); | ||
117 | + String str = br.readLine(); | ||
118 | + index = Integer.parseInt(str); | ||
119 | + } catch (FileNotFoundException var15) { | ||
120 | + var15.printStackTrace(); | ||
121 | + } catch (IOException var16) { | ||
122 | + var16.printStackTrace(); | ||
123 | + } finally { | ||
124 | + try { | ||
125 | + br.close(); | ||
126 | + reader.close(); | ||
127 | + } catch (IOException var14) { | ||
128 | + var14.printStackTrace(); | ||
129 | + } | ||
130 | + | ||
131 | + } | ||
132 | + | ||
133 | + return index; | ||
134 | + } | ||
135 | + | ||
136 | + public static String searchReplace(String xml, String replacement, String nodeName) { | ||
137 | + String pStr = String.format("(?<=<%s>).*(?=</%s>)", nodeName, nodeName); | ||
138 | + Pattern pat = Pattern.compile(pStr); | ||
139 | + Matcher matcher = pat.matcher(xml); | ||
140 | + if (matcher.find()) { | ||
141 | + if (!StringUtils.isBlank(replacement)) { | ||
142 | + return xml.replace(matcher.group(), replacement); | ||
143 | + } | ||
144 | + } else { | ||
145 | + logger.error("can not find " + nodeName + " in " + xml); | ||
146 | + } | ||
147 | + | ||
148 | + return xml; | ||
149 | + } | ||
150 | + | ||
151 | + public static String searchReplaceSingle(String xml, String replacement, String nodeName) { | ||
152 | + String pStr = String.format("(<%s/>)", nodeName); | ||
153 | + String rep = String.format("<%s>%s</%s>", nodeName, replacement, nodeName); | ||
154 | + Pattern pat = Pattern.compile(pStr); | ||
155 | + Matcher mat = pat.matcher(xml); | ||
156 | + return mat.find() && !StringUtils.isBlank(replacement) ? xml.replace(mat.group(), rep) : xml; | ||
157 | + } | ||
158 | +} |
src/java/com/airport/util/parse/SubNode.java
0 → 100644
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util.parse; | ||
7 | + | ||
8 | +import org.jdom.Element; | ||
9 | + | ||
10 | +public class SubNode { | ||
11 | + private Element element; | ||
12 | + | ||
13 | + public SubNode(Element element) { | ||
14 | + this.element = element; | ||
15 | + } | ||
16 | + | ||
17 | + public Element getElement() { | ||
18 | + return this.element; | ||
19 | + } | ||
20 | + | ||
21 | + public void setElement(Element element) { | ||
22 | + this.element = element; | ||
23 | + } | ||
24 | +} |
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util.parse; | ||
7 | + | ||
8 | +import com.airport.util.Utils; | ||
9 | +import java.io.IOException; | ||
10 | +import java.io.StringReader; | ||
11 | +import java.util.Date; | ||
12 | +import java.util.LinkedList; | ||
13 | +import java.util.List; | ||
14 | +import org.jdom.Document; | ||
15 | +import org.jdom.Element; | ||
16 | +import org.jdom.JDOMException; | ||
17 | +import org.jdom.input.SAXBuilder; | ||
18 | +import org.xml.sax.InputSource; | ||
19 | + | ||
20 | +public class XMPParse { | ||
21 | + public XMPParse() { | ||
22 | + } | ||
23 | + | ||
24 | + public static final Date nodeValue2Date(String xmlFile, String xmlNodePath) { | ||
25 | + String str = getNodeValue(xmlFile, xmlNodePath); | ||
26 | + return !"".equals(str) ? Utils.iso8601DateStrToDate(str) : null; | ||
27 | + } | ||
28 | + | ||
29 | + public static final Date nodeValue2Date(String xmlFile, String xmlNodePath, Date date) { | ||
30 | + String str = getNodeValue(xmlFile, xmlNodePath); | ||
31 | + return !"".equals(str) ? Utils.iso8601DateStrToDate(str) : date; | ||
32 | + } | ||
33 | + | ||
34 | + public static final Date nodeAttribute2Date(String xmlFile, String xmlNodePath, String attributeName, Date date) { | ||
35 | + String str = getNodeAttribute(xmlFile, xmlNodePath, attributeName, ""); | ||
36 | + return !"".equals(str) ? Utils.iso8601DateStrToDate(str) : date; | ||
37 | + } | ||
38 | + | ||
39 | + public static final String getNodeValue(String xmlFile, String xmlNodePath) { | ||
40 | + String[] nodes = xmlNodePath.split("/"); | ||
41 | + new Document(); | ||
42 | + SAXBuilder builder = new SAXBuilder(); | ||
43 | + Element root = null; | ||
44 | + LinkedList<SubNode> listNode = new LinkedList(); | ||
45 | + String value = ""; | ||
46 | + | ||
47 | + Document document; | ||
48 | + try { | ||
49 | + document = builder.build(xmlFile); | ||
50 | + | ||
51 | + for(int i = 1; i < nodes.length; ++i) { | ||
52 | + SubNode snode; | ||
53 | + if (i > 1) { | ||
54 | + snode = (SubNode)listNode.getLast(); | ||
55 | + List<Element> eList = snode.getElement().getChildren(nodes[i]); | ||
56 | + if (eList != null && eList.size() > 0) { | ||
57 | + SubNode s1 = new SubNode((Element)eList.get(0)); | ||
58 | + listNode.add(s1); | ||
59 | + } | ||
60 | + } else if (1 == i) { | ||
61 | + root = document.getRootElement(); | ||
62 | + snode = new SubNode(root); | ||
63 | + listNode.add(snode); | ||
64 | + } | ||
65 | + } | ||
66 | + | ||
67 | + SubNode n = (SubNode)listNode.getLast(); | ||
68 | + value = n.getElement().getText(); | ||
69 | + n = null; | ||
70 | + } catch (Exception var15) { | ||
71 | + var15.printStackTrace(); | ||
72 | + } finally { | ||
73 | + listNode.clear(); | ||
74 | + document = null; | ||
75 | + root = null; | ||
76 | + builder = null; | ||
77 | + nodes = null; | ||
78 | + } | ||
79 | + | ||
80 | + System.out.println("key=" + xmlNodePath + " value=" + value); | ||
81 | + return value; | ||
82 | + } | ||
83 | + | ||
84 | + public static final String getNodeValueFromXmlString(String xmlString, String xmlNodePath) throws Exception { | ||
85 | + String[] nodes = xmlNodePath.split("/"); | ||
86 | + new Document(); | ||
87 | + SAXBuilder builder = new SAXBuilder(); | ||
88 | + Element root = null; | ||
89 | + LinkedList<SubNode> listNode = new LinkedList(); | ||
90 | + String value = ""; | ||
91 | + | ||
92 | + Document document; | ||
93 | + try { | ||
94 | + StringReader xmlReader = new StringReader(xmlString); | ||
95 | + InputSource xmlSource = new InputSource(xmlReader); | ||
96 | + document = builder.build(xmlSource); | ||
97 | + | ||
98 | + for(int i = 1; i < nodes.length; ++i) { | ||
99 | + SubNode snode; | ||
100 | + if (i > 1) { | ||
101 | + snode = (SubNode)listNode.getLast(); | ||
102 | + List<Element> eList = snode.getElement().getChildren(nodes[i]); | ||
103 | + if (eList != null && eList.size() > 0) { | ||
104 | + SubNode s1 = new SubNode((Element)eList.get(0)); | ||
105 | + listNode.add(s1); | ||
106 | + } | ||
107 | + } else if (1 == i) { | ||
108 | + root = document.getRootElement(); | ||
109 | + snode = new SubNode(root); | ||
110 | + listNode.add(snode); | ||
111 | + } | ||
112 | + } | ||
113 | + | ||
114 | + SubNode n = (SubNode)listNode.getLast(); | ||
115 | + value = n.getElement().getText(); | ||
116 | + n = null; | ||
117 | + return value; | ||
118 | + } catch (Exception var17) { | ||
119 | + var17.printStackTrace(); | ||
120 | + throw var17; | ||
121 | + } finally { | ||
122 | + listNode.clear(); | ||
123 | + document = null; | ||
124 | + root = null; | ||
125 | + builder = null; | ||
126 | + nodes = null; | ||
127 | + } | ||
128 | + } | ||
129 | + | ||
130 | + public static final String getNodeAttribute(String xmlFile, String xmlNodePath, String attributeName, String defaultValue) { | ||
131 | + String[] nodes = xmlNodePath.split("/"); | ||
132 | + new Document(); | ||
133 | + SAXBuilder builder = new SAXBuilder(); | ||
134 | + Element root = null; | ||
135 | + LinkedList<SubNode> listNode = new LinkedList(); | ||
136 | + String value = ""; | ||
137 | + | ||
138 | + Document document; | ||
139 | + try { | ||
140 | + document = builder.build(xmlFile); | ||
141 | + | ||
142 | + for(int i = 1; i < nodes.length; ++i) { | ||
143 | + SubNode snode; | ||
144 | + if (i > 1) { | ||
145 | + snode = (SubNode)listNode.getLast(); | ||
146 | + List<Element> eList = snode.getElement().getChildren(nodes[i]); | ||
147 | + if (eList != null && eList.size() > 0) { | ||
148 | + SubNode s1 = new SubNode((Element)eList.get(0)); | ||
149 | + listNode.add(s1); | ||
150 | + } | ||
151 | + } else if (1 == i) { | ||
152 | + root = document.getRootElement(); | ||
153 | + snode = new SubNode(root); | ||
154 | + listNode.add(snode); | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + SubNode n = (SubNode)listNode.getLast(); | ||
159 | + value = n.getElement().getAttributeValue(attributeName, defaultValue); | ||
160 | + n = null; | ||
161 | + } catch (JDOMException var18) { | ||
162 | + var18.printStackTrace(); | ||
163 | + } catch (IOException var19) { | ||
164 | + var19.printStackTrace(); | ||
165 | + } finally { | ||
166 | + listNode.clear(); | ||
167 | + document = null; | ||
168 | + root = null; | ||
169 | + builder = null; | ||
170 | + nodes = null; | ||
171 | + } | ||
172 | + | ||
173 | + System.out.println("key=" + xmlNodePath + " node attrivte value=" + value); | ||
174 | + return value; | ||
175 | + } | ||
176 | +} |
1 | +// | ||
2 | +// Source code recreated from a .class file by IntelliJ IDEA | ||
3 | +// (powered by Fernflower decompiler) | ||
4 | +// | ||
5 | + | ||
6 | +package com.airport.util.parse; | ||
7 | + | ||
8 | +import java.io.IOException; | ||
9 | +import java.util.LinkedList; | ||
10 | +import java.util.List; | ||
11 | +import org.jdom.Document; | ||
12 | +import org.jdom.Element; | ||
13 | +import org.jdom.JDOMException; | ||
14 | +import org.jdom.input.SAXBuilder; | ||
15 | + | ||
16 | +public class XmlDocument { | ||
17 | + private Document document = null; | ||
18 | + private SAXBuilder builder = null; | ||
19 | + private Element root = null; | ||
20 | + private String xmlFile; | ||
21 | + | ||
22 | + public XmlDocument(String xmlFileName) { | ||
23 | + this.xmlFile = xmlFileName; | ||
24 | + | ||
25 | + try { | ||
26 | + this.builder = new SAXBuilder(); | ||
27 | + this.document = new Document(); | ||
28 | + this.document = this.builder.build(this.xmlFile); | ||
29 | + } catch (JDOMException var3) { | ||
30 | + var3.printStackTrace(); | ||
31 | + } catch (IOException var4) { | ||
32 | + var4.printStackTrace(); | ||
33 | + } | ||
34 | + | ||
35 | + } | ||
36 | + | ||
37 | + public void destory() { | ||
38 | + this.document = null; | ||
39 | + this.root = null; | ||
40 | + this.builder = null; | ||
41 | + } | ||
42 | + | ||
43 | + public String getStringFromInnerText(String xmlNodePath) { | ||
44 | + String[] nodes = xmlNodePath.split("/"); | ||
45 | + LinkedList<SubNode> listNode = new LinkedList(); | ||
46 | + String value = ""; | ||
47 | + | ||
48 | + try { | ||
49 | + for(int i = 1; i < nodes.length; ++i) { | ||
50 | + SubNode snode; | ||
51 | + if (i > 1) { | ||
52 | + snode = (SubNode)listNode.getLast(); | ||
53 | + List<Element> eList = snode.getElement().getChildren(nodes[i]); | ||
54 | + if (eList != null && eList.size() > 0) { | ||
55 | + SubNode s1 = new SubNode((Element)eList.get(0)); | ||
56 | + listNode.add(s1); | ||
57 | + } | ||
58 | + } else if (1 == i) { | ||
59 | + this.root = this.document.getRootElement(); | ||
60 | + snode = new SubNode(this.root); | ||
61 | + listNode.add(snode); | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + SubNode n = (SubNode)listNode.getLast(); | ||
66 | + value = n.getElement().getText(); | ||
67 | + n = null; | ||
68 | + } catch (Exception var12) { | ||
69 | + var12.printStackTrace(); | ||
70 | + } finally { | ||
71 | + listNode.clear(); | ||
72 | + } | ||
73 | + | ||
74 | + return value; | ||
75 | + } | ||
76 | + | ||
77 | + public String getStringFromXmlNodeAttribute(String xmlNodePath, String attributeName, String defaultValue) { | ||
78 | + String[] nodes = xmlNodePath.split("/"); | ||
79 | + LinkedList<SubNode> listNode = new LinkedList(); | ||
80 | + String value = ""; | ||
81 | + | ||
82 | + try { | ||
83 | + for(int i = 1; i < nodes.length; ++i) { | ||
84 | + SubNode snode; | ||
85 | + if (i > 1) { | ||
86 | + snode = (SubNode)listNode.getLast(); | ||
87 | + List<Element> eList = snode.getElement().getChildren(nodes[i]); | ||
88 | + if (eList != null && eList.size() > 0) { | ||
89 | + SubNode s1 = new SubNode((Element)eList.get(0)); | ||
90 | + listNode.add(s1); | ||
91 | + } | ||
92 | + } else if (1 == i) { | ||
93 | + this.root = this.document.getRootElement(); | ||
94 | + snode = new SubNode(this.root); | ||
95 | + listNode.add(snode); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + SubNode n = (SubNode)listNode.getLast(); | ||
100 | + value = n.getElement().getAttributeValue(attributeName, defaultValue); | ||
101 | + n = null; | ||
102 | + } catch (Exception var14) { | ||
103 | + var14.printStackTrace(); | ||
104 | + } finally { | ||
105 | + listNode.clear(); | ||
106 | + } | ||
107 | + | ||
108 | + return value; | ||
109 | + } | ||
110 | +} |
src/resources/META-INF/MANIFEST.MF
0 → 100644
1 | +Manifest-Version: 1.0 | ||
2 | +Class-Path: org.springframework.jdbc-3.0.0.CI-331.jar spring-jms-3.0.5 | ||
3 | + .RELEASE.jar spring-expression-3.0.5.RELEASE.jar spring-aop-3.0.5.REL | ||
4 | + EASE.jar imfmsg.jar HeartbeatService.jar c3p0-0.9.5.2.jar spring-bean | ||
5 | + s-3.0.5.RELEASE.jar mchange-commons-java-0.2.11.jar UploadService.jar | ||
6 | + spring-core-3.0.5.RELEASE.jar spring-asm-3.0.5.RELEASE.jar apiConfig | ||
7 | + .jar CL3Export.jar CL3Nonexport.jar com.ibm.mq.axis2.jar com.ibm.mq.c | ||
8 | + ommonservices.jar com.ibm.mq.defaultconfig.jar com.ibm.mq.headers.jar | ||
9 | + com.ibm.mq.jar com.ibm.mq.jmqi.jar com.ibm.mq.jms.Nojndi.jar com.ibm | ||
10 | + .mq.pcf.jar com.ibm.mq.postcard.jar com.ibm.mq.soap.jar com.ibm.mq.to | ||
11 | + ols.ras.jar com.ibm.mqetclient.jar com.ibm.mqjms.jar connector.jar dh | ||
12 | + bcore.jar fscontext.jar jms.jar jndi.jar jta.jar ldap.jar provideruti | ||
13 | + l.jar rmm.jar antlr-2.7.7.jar antlr-3.2.jar antlr-runtime-3.2.jar aop | ||
14 | + alliance-1.0.jar asm-3.3.jar bcprov-jdk15-1.45.jar commons-collection | ||
15 | + s-3.2.1.jar commons-lang-2.5.jar commons-logging-1.1.1.jar commons-po | ||
16 | + ol-1.5.5.jar cxf-2.3.2.jar cxf-xjc-boolean-2.3.2.jar cxf-xjc-bug671-2 | ||
17 | + .3.2.jar cxf-xjc-dv-2.3.2.jar cxf-xjc-ts-2.3.2.jar FastInfoset-1.2.8. | ||
18 | + jar geronimo-activation_1.1_spec-1.1.jar geronimo-annotation_1.0_spec | ||
19 | + -1.1.1.jar geronimo-javamail_1.4_spec-1.7.1.jar geronimo-jaxws_2.2_sp | ||
20 | + ec-1.0.jar geronimo-jms_1.1_spec-1.1.1.jar geronimo-servlet_3.0_spec- | ||
21 | + 1.0.jar geronimo-stax-api_1.0_spec-1.0.1.jar geronimo-ws-metadata_2.0 | ||
22 | + _spec-1.1.3.jar jaxb-api-2.2.1.jar jaxb-impl-2.2.1.1.jar jettison-1.2 | ||
23 | + .jar jetty-continuation-7.2.2.v20101205.jar jetty-http-7.2.2.v2010120 | ||
24 | + 5.jar jetty-io-7.2.2.v20101205.jar jetty-server-7.2.2.v20101205.jar j | ||
25 | + etty-util-7.2.2.v20101205.jar jra-1.0-alpha-4.jar js-1.7R2.jar jsr173 | ||
26 | + _1.0_api.jar jsr311-api-1.1.1.jar neethi-2.0.4.jar oro-2.0.8.jar reso | ||
27 | + lver.jar saaj-api-1.3.jar saaj-impl-1.3.2.jar serializer-2.7.1.jar si | ||
28 | + gar.jar slf4j-api-1.6.1.jar slf4j-jdk14-1.6.1.jar stax2-api-3.0.2.jar | ||
29 | + stringtemplate-3.2.jar velocity-1.6.4.jar woodstox-core-asl-4.0.8.ja | ||
30 | + r wsdl4j-1.6.2.jar wss4j-1.5.11.jar xalan-2.7.1.jar xbean_xpath.jar x | ||
31 | + bean.jar xml-resolver-1.2.jar xmlbeans-2.4.0.jar xmlbeans-qname.jar x | ||
32 | + mlpublic.jar XmlSchema-1.4.7.jar xmlsec-1.4.4.jar com.ibm.mq.fta.jar | ||
33 | + log4j-1.2.16.jar jaxb-xjc-2.2.1.1.jar spring-tx-3.0.5.RELEASE.jar ojd | ||
34 | + bc6.jar jdom-1.1.3.jar IMFClient.1.0.0.jar spring-web-3.0.5.RELEASE.j | ||
35 | + ar spring-context-3.0.5.RELEASE.jar returnXml.jar ProcessService.jar | ||
36 | +Main-Class: com.airport.Main | ||
37 | + |
src/resources/config/ApplicationContext.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<beans xmlns="http://www.springframework.org/schema/beans" | ||
3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee" | ||
4 | + xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxws="http://cxf.apache.org/jaxws" | ||
5 | + xmlns:context="http://www.springframework.org/schema/context" | ||
6 | + xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
7 | + http://www.springframework.org/schema/beans/spring-beans-2.5.xsd | ||
8 | + http://www.springframework.org/schema/tx | ||
9 | + http://www.springframework.org/schema/tx/spring-tx-2.5.xsd | ||
10 | + http://www.springframework.org/schema/jee | ||
11 | + http://www.springframework.org/schema/jee/spring-jee-2.5.xsd | ||
12 | + http://www.springframework.org/schema/context | ||
13 | + http://www.springframework.org/schema/context/spring-context-2.5.xsd | ||
14 | + http://cxf.apache.org/jaxws | ||
15 | + http://cxf.apache.org/schemas/jaxws.xsd" | ||
16 | + default-lazy-init="false"> | ||
17 | + <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> | ||
18 | + <property name="driverClass" value="${db_driver}" /> | ||
19 | + <property name="jdbcUrl" value="${db_url}" /> | ||
20 | + <property name="user" value="${db_user}" /> | ||
21 | + <property name="password" value="${db_pass}" /> | ||
22 | + <property name="minPoolSize" value="1" /> | ||
23 | + <property name="maxPoolSize" value="1" /> | ||
24 | + <property name="initialPoolSize" value="1" /> | ||
25 | + <property name="maxIdleTime" value="1800" /> | ||
26 | + <property name="acquireIncrement" value="1" /> | ||
27 | + <property name="idleConnectionTestPeriod" value="10000" /> | ||
28 | + <property name="acquireRetryAttempts" value="30" /> | ||
29 | + <property name="testConnectionOnCheckin" value="true" /> | ||
30 | + <property name="acquireRetryDelay" value="1000"/> | ||
31 | + <property name="automaticTestTable" value="c3p0TestTable_jwe"/> | ||
32 | + <property name="checkoutTimeout" value="60000"/> | ||
33 | + <property name="numHelperThreads" value="5"/> | ||
34 | +</bean> | ||
35 | + | ||
36 | +<bean id='configurationBean' class="com.airport.util.Configuration" > | ||
37 | +<property name="location" value="file:config/config.properties"/> | ||
38 | +</bean> | ||
39 | + | ||
40 | +<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> | ||
41 | +<property name="dataSource" ref="dataSource"/> | ||
42 | +</bean> | ||
43 | + | ||
44 | +<bean id="dao" class="com.airport.dao.impl.DaoImpl"> | ||
45 | +<property name="jdbcTemplate" ref="jdbcTemplate" /> | ||
46 | +</bean> | ||
47 | + | ||
48 | + | ||
49 | +</beans> |
src/resources/config/config.properties
0 → 100644
1 | + | ||
2 | +######################################################### | ||
3 | +db_driver=oracle.jdbc.driver.OracleDriver | ||
4 | +db_url=jdbc:oracle:thin:@10.50.3.68:1521:CGODW | ||
5 | +db_user=cgoetl | ||
6 | +db_pass=1q2w3e4r | ||
7 | + | ||
8 | +######################################################### | ||
9 | +#R:receiver S:sender, | ||
10 | +role=S | ||
11 | +imf_username=DLCF | ||
12 | +imf_password=DLCF_P | ||
13 | + | ||
14 | +######################################################### | ||
15 | +interval=5 | ||
16 | +record_count=350 | ||
17 | +total_group=1 | ||
18 | + | ||
19 | +######################################################### | ||
20 | +sndr_1=DLCF | ||
21 | +rcvr_1= | ||
22 | +type_1=HYXX | ||
23 | +stype_1=DLCF | ||
24 | + | ||
25 | +######################################################### | ||
26 | +sndr_2=SJCK | ||
27 | +rcvr_2= | ||
28 | +type_2=HYXX | ||
29 | +stype_2=CKSY |
src/resources/config/imf_config.properties
0 → 100644
src/resources/config/log4j.properties
0 → 100644
1 | +########Log4j configuration##################################### | ||
2 | +log4j.rootLogger=INFO, stdout, fileout | ||
3 | + | ||
4 | + | ||
5 | +log4j.logger.com.fiscal = INFO | ||
6 | +#******************************* | ||
7 | +log4j.logger.com.system = INFO | ||
8 | +#******************************* | ||
9 | +log4j.appender.stdout=org.apache.log4j.ConsoleAppender | ||
10 | +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | ||
11 | +log4j.appender.stdout.layout.ConversionPattern=%d{MM-dd HH:mm:ss,SSSS}[%p] %m%n | ||
12 | + | ||
13 | +#yyyy-MM-dd HH:mm:ss | ||
14 | + | ||
15 | + | ||
16 | +log4j.appender.fileout=org.apache.log4j.RollingFileAppender | ||
17 | +log4j.appender.fileout.File=logs/imf.log | ||
18 | +log4j.appender.fileout.MaxFileSize=50MB | ||
19 | +log4j.appender.fileout.MaxBackupIndex=10 | ||
20 | +log4j.appender.fileout.layout=org.apache.log4j.PatternLayout | ||
21 | +log4j.appender.fileout.layout.ConversionPattern=%d{MM-dd HH:mm:ss,SSSS}[%p] %m%n |
-
请 注册 或 登录 后发表评论