前言
版本:
SpringBoot 2.4
camel 3.5.0
上篇文章已经说过项目需求和主要流程,现在已经接收解析xml报文并入库生成Java对象。下一步就是处理完生成的数据生成XML报文,再返回给第三方ftp服务器了。下面看看怎么做。
1. 增加camel配置,本地监听目录和远程第三方ftp服务器URL。
# camel配置
camel:
# camel ftp服务路由地址
route:
id: XMLRoute
ftp:
server: sftp://ip:port/AAA/BBB?username=root&password=123456&passiveMode=true&move=backup&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
# server: file:e:/test?recursive=true&move=.backup&moveFailed=.error&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
file:
download:
local:
# camel 文件内容下载到本地地址(配置中文乱码)
address: file:/home/AAA/BBB/
upload:
local:
# 本地383报文生成目录
383: file:/home/AAA/BBB/send/383?move=backup&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
# 本地385报文生成目录
385: file:/home/AAA/BBB/send/385?move=backup&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
remote:
# 远程383报文接收目录
383: sftp://ip:port/AAA/CCC?username=root&password=123456&passiveMode=true&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
# 远程385报文接收目录
385: sftp://ip:port/AAA/DDD?username=root&password=123456&passiveMode=true&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
二、主要代码
1. zbus接口实现类。(相当于SpringBoot的Controller层)
package com.yorma.ex.api.impl;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.yorma.dcl.api.DecApi;
import com.yorma.dcl.entity.DecHead;
import com.yorma.entity.YmMsg;
import com.yorma.ex.api.ExApi;
import com.yorma.ex.utils.XmlUtils;
import com.yorma.util.RequestKit;
import io.zbus.rpc.annotation.Param;
import io.zbus.rpc.annotation.Route;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.Date;
import static cn.hutool.core.util.ObjectUtil.isEmpty;
import static cn.hutool.core.util.StrUtil.isBlank;
import static cn.hutool.core.util.StrUtil.isNotBlank;
import static com.yorma.ex.utils.Const.BW383;
import static com.yorma.ex.utils.Const.BW385;
/**
* @author ZHANGCHAO
* @date 2021/6/15 10:18
* @since 1.0.0
*/
@Slf4j
@Route("/dec")
@Component
public class ExApiImpl implements ExApi {
@Autowired
private DecApi decApi;
/**
* 报文上传本地目录383
*/
@Value("${camel.file.upload.local.383}")
private String uploadLocal383Path;
/**
* 报文上传本地目录385
*/
@Value("${camel.file.upload.local.385}")
priv