作者 朱兆平

init

正在显示 108 个修改的文件 包含 634 行增加0 行删除
/target/
!.mvn/wrapper/maven-wrapper.jar
/logs/
/out/
.mvn
/xmlFromImf/
kakoRevice/
/errorLogs/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/build/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
... ...
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
不能预览此文件类型
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tianbo</groupId>
<artifactId>imfClient</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- LOG -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<!--添加本地IMF包-->
<dependency>
<groupId>com.caac</groupId>
<artifactId>imf</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/IMFClient.1.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>imfmessage</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/imfmsg.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>process</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/ProcessService.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>apiconfig</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/apiConfig.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>upload</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/UploadService.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>heartbeat</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/HeartbeatService.jar</systemPath>
</dependency>
<dependency>
<groupId>com.caac.imf</groupId>
<artifactId>returnxml</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/returnXml.jar</systemPath>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hyperic/sigar -->
<dependency>
<groupId>org.hyperic</groupId>
<artifactId>sigar</artifactId>
<version>1.6.4</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/sigar.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>cxf</artifactId>
<version>2.3.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-2.3.2.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>xjc</artifactId>
<version>2.3.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-xjc-bug671-2.3.2.jar</systemPath>
</dependency>
<dependency>
<groupId>maven.org.apache</groupId>
<artifactId>cxf</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-manifest.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.cxf.xjc</groupId>
<artifactId>dv</artifactId>
<version>2.3.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-xjc-dv-2.3.2.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.cxf.xjc</groupId>
<artifactId>ts</artifactId>
<version>2.3.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/cxf-xjc-ts-2.3.2.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.xml</groupId>
<artifactId>xmlsec</artifactId>
<version>1.4.4</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/xmlsec-1.4.4.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.disthub2.impl</groupId>
<artifactId>cl3e</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/CL3Export.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.disthub2.impl</groupId>
<artifactId>cl3ne</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/CL3Nonexport.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>axis2</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.axis2.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>commonservices</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.commonservices.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>defaultconfig</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.defaultconfig.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>fta</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.fta.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>headers</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.headers.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mq</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>jmqi</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.jmqi.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>jms.nojndi</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.jms.Nojndi.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>pcf</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.pcf.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>postcard</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.postcard.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>soap</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.soap.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>tools.ras</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mq.tools.ras.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>etclient</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mqetclient.jar</systemPath>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>mqjms</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com.ibm.mqjms.jar</systemPath>
<!-- https://mvnrepository.com/artifact/javax.resource/connector -->
</dependency>
<dependency>
<groupId>javax.resource</groupId>
<artifactId>connector</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/connector.jar</systemPath>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.2.0.BUILD-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.tianbo.imfClient;
import com.caac.imf.api.IMFClient;
import com.tianbo.imfClient.handle.imfClient.handle.imfClient.IMFSaveHandle;
import org.apache.log4j.Logger;
public class IMF_Reader extends Thread{
protected static final Logger logger = Logger.getLogger(IMF_Reader.class);
private IMFClient client;
public static boolean isrunning;
public IMF_Reader(IMFClient client) {
this.client = client;
}
@Override
public void run() {
try{
isrunning =true;
while(true) {
if (IMF_Task.LOGIN_OK) {
String message = this.client.getMSG();
if (message != null) {
com.tianbo.imfClient.handle.imfClient.IMFSaveHandle imfSaveHandle = new com.tianbo.imfClient.handle.imfClient.IMFSaveHandle();
imfSaveHandle.handle(message);
}
} else {
//logger.info("***");
}
try {
Thread.sleep(500L);
} catch (InterruptedException var3) {
var3.printStackTrace();
}
}
}catch (Exception e){
e.printStackTrace();
}
isrunning=false;
logger.info("****************读取线程不在了****************");
}
}
... ...
package com.tianbo.imfClient;
import com.caac.imf.api.IMFClient;
import com.tianbo.warehouse.imf.schedul.IMF_Task;
import com.tianbo.warehouse.util.Date.DateUtil;
import com.tianbo.warehouse.util.IO.FileTool;
import com.tianbo.warehouse.util.XML.MakeImfMeta;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Logger;
import java.io.File;
import java.util.Iterator;
import java.util.List;
public class IMF_Sender extends Thread{
protected static final Logger logger = Logger.getLogger(IMF_Sender.class);
public static boolean isrunning;
private IMFClient client;
private String content;
public IMF_Sender(IMFClient client) {
this.client = client;
}
public IMF_Sender(IMFClient client, String content) {
this.client = client;
this.content = content;
}
@Override
public void run(){
String sendDir = FileTool.readProperties("readDirectory");
String SNDR = FileTool.readProperties("loginname");
String TYPE = FileTool.readProperties("TYPE");
String STYP = FileTool.readProperties("STYP");
String RCVR = FileTool.readProperties("RCVR");
String DDTM = DateUtil.getDDTM();
String SEQN = DDTM;
if (this.client == null) {
logger.info("IMFClient has been closed");
return;
}
isrunning=true;
if(IMF_Task.isSuc){
if(IMF_Task.LOGIN_OK){
while (true){
//发送报文
List<File> files = FileTool.readDirectoryFiles(new File(sendDir));
String sendMsg = "";
Iterator<File> it = files.iterator();
while(it.hasNext()){
File file = it.next();
try {
sendMsg = MakeImfMeta.makeImfDocument(SNDR,RCVR,TYPE,STYP,DDTM,SEQN,file);
String returnMsg = this.client.sendMSG(sendMsg);
if(returnMsg.indexOf("<CODE>9</CODE>")>=0){
FileUtils.forceDelete(file);
}
}catch (Exception e){
e.printStackTrace();
}
}
try {
Thread.sleep(500L);
} catch (InterruptedException var3) {
var3.printStackTrace();
}
}
}else{
logger.info("<<<<<<<<<<<登陆中>>>>>>>>>>>>");
}
}
isrunning=false;
logger.info("<<<<<<<<<<<发送线程结束>>>>>>>>>>>>");
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
... ...
package com.tianbo.imfClient.handle;
import com.tianbo.warehouse.model.T_ETL_MESSAGE;
import com.tianbo.warehouse.service.T_ETL_MESSAGEService;
import com.tianbo.warehouse.util.Date.DateUtil;
import com.tianbo.warehouse.util.IO.FileTool;
import com.tianbo.warehouse.util.XML.XML2ENTITY;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.Date;
import java.util.Map;
/**
* 存储IMF过来的原始报文到数据仓库T_ELT_MESSAGE原始报文表中
*/
@Component
public class IMFSaveHandle {
@Autowired
protected T_ETL_MESSAGEService messageService;
private static IMFSaveHandle saveHandle;
protected static final Logger logger = Logger.getLogger(IMFSaveHandle.class);
@PostConstruct
public void init(){
saveHandle = this;
saveHandle.messageService = this.messageService;
}
public void handle(String xmlmessage){
try {
//有人发报文头部不按规范发
// xmlmessage = xmlmessage.replace("<Msg>","<MSG>")
// .replace("<msg>","<MSG>")
// .replace("</Msg>","</MSG>")
// .replace("</msg>","</MSG>");
Document document = DocumentHelper.parseText(xmlmessage);
XML2ENTITY xml2ENTITY =new XML2ENTITY();
Map xmlMap = xml2ENTITY.Dom2Map(document);
Map meta = (Map) xmlMap.get("META");
T_ETL_MESSAGE message = new T_ETL_MESSAGE();
String sndrm = meta.get("SNDR").toString();
String stypm = meta.get("STYP").toString();
if ("TXD".equals(sndrm)){
//读取配置文件的需要本地存储报文的节点
String saveStyp= FileTool.readProperties("saveStyp");
String[] styps = saveStyp.split(",");
for (String item: styps) {
if (item.equals(stypm)){
//存储至备份目录
FileTool.writeFileToBak(xmlmessage);
}
}
}
String typem = meta.get("TYPE").toString();
String rcvr = XML2ENTITY.getMap(meta,"RCVR").toString();
String ddtm = meta.get("DDTM").toString();
String seqn = meta.get("SEQN").toString();
message.setSndr(sndrm);
message.setRcvr(rcvr);
message.setType(typem);
message.setStyp(stypm);
message.setSeqn(seqn);
Date ddtmDate = DateUtil.formatByyyyyMMddHHmmss(ddtm);
message.setDdtm(ddtmDate);
message.setSntm(ddtmDate);
message.setOper("ALL");
message.setAppid("W");
message.setEtltim(new Date());
message.setContent(xmlmessage);
int i = saveHandle.messageService.insertSelective(message);
}catch (Exception e){
FileTool.writeFile("err",e.toString()+"\n"+xmlmessage,false);
logger.warn("*报文入库失败已存储成备份文件*");
logger.error(e);
logger.warn(e);
}
}
}
... ...
package com.tianbo.imfClient.schedul;
import com.caac.imf.api.IMFClient;
import com.caac.imf.api.IMFClientFactory;
import com.tianbo.imfClient.IMF_Reader;
import com.tianbo.imfClient.IMF_Sender;
import com.tianbo.util.IO.FileTool;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
@Component
public class IMF_Task {
protected static final Logger logger = Logger.getLogger(IMF_Task.class);
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static boolean LOGIN_OK = false;
public static boolean isSuc = true;
public static IMFClient client = null;
public static String loginname;
public static String loginpass;
public static String isNeedSend = "N";
// @Scheduled(fixedRate = 5000)
private static void start() throws Exception {
PropertyConfigurator.configure("config/log4j.properties");
client = IMFClientFactory.createInstance();
loginname= FileTool.readProperties("loginname");
loginpass= FileTool.readProperties("loginpass");
isNeedSend= FileTool.readProperties("isNeedSend");
//登录
if (!LOGIN_OK) {
loginIMF(client, loginname, loginpass, "config/imf_config.properties");
}
//启动读取线程
if (client != null) {
IMF_Reader reader = new IMF_Reader(client);
if (!IMF_Reader.isrunning) {
reader.start();
logger.info("*********读取线程已开启***********");
} else {
// logger.info("*********读取线程已开启-不再启动线程*********");
}
if("Y".equals(isNeedSend)){
IMF_Sender kako_sender = new IMF_Sender(client);
if(!IMF_Sender.isrunning) {
kako_sender.start();
}
}
}
}
public void sendMsg(String msg){
if (!msg.equals(null) && !msg.isEmpty()){
if(LOGIN_OK){
IMF_Sender sender = new IMF_Sender(client,msg);
sender.setContent(msg);
sender.start();
}
}
}
private static void loginIMF(IMFClient client, String userName, String password, String confFileName) {
if (client.initial(confFileName)) {
String message = client.login(userName, password);
logger.info("message=" + message);
if (message.indexOf("<CODE>1</CODE>") > 0) {
logger.info("登陆成功");
LOGIN_OK = true;
} else {
int times = 0;
while(times <= 3) {
logger.info("try connection...");
++times;
logger.info("message.=" + message);
if (message.indexOf("<CODE>1</CODE>") > 0) {
logger.info("登陆成功");
LOGIN_OK = true;
break;
}
logger.info("登录失败~~~~");
message = client.login(userName, password);
try {
Thread.sleep(4000L);
} catch (InterruptedException var7) {
var7.printStackTrace();
}
}
if (!LOGIN_OK) {
logger.info("多次尝试登录失败,退出登陆");
client.disconnect();
isSuc =false;
System.exit(-1);
}
}
}
}
}
... ...