Java 使用apache camel、smooks和flatpack
我正在使用camel和smooks编写一个路由,producer作为JPA存储库,生成JPA对象列表,我需要将其作为固定宽度的文件发送到sftp服务器 我认为这是实现这一目标所必需的Java 使用apache camel、smooks和flatpack,java,apache-camel,smooks,flatpack,Java,Apache Camel,Smooks,Flatpack,我正在使用camel和smooks编写一个路由,producer作为JPA存储库,生成JPA对象列表,我需要将其作为固定宽度的文件发送到sftp服务器 我认为这是实现这一目标所必需的 使用JPA生成对象列表的存储库(我有这个) smooks到flatpack映射,它采用上述列表的xml版本,并将其转换为固定宽度的文件 以存储库开始,以通过sftp发送的文件结束的驼峰路由: 以下是我的代码: public class RetirementRoute extends RouteBuilder {
public class RetirementRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
onException(Throwable.class)
.maximumRedeliveries(3)
.useExponentialBackOff()
.backOffMultiplier(4)
.logRetryAttempted(true)
.handled(true)
.log(LoggingLevel.ERROR, "Error transmitting file to miliman")
.to("log:org.fuwt?level=ERROR&showAll=true");
//define the fixed width mapping
FlatpackDataFormat df = new FlatpackDataFormat();
df.setDefinition(new ClassPathResource("META-INF/smooks/fuintegration/retirement-fixed-width-mapping.xml"));
df.setFixed(true);
df.setIgnoreFirstRecord(false);
from("bean:retirementRepository?method=getRetirementMembers")
.to("log:org.fuwt?level=INFO")
.transacted("CRM_PROPAGATION_REQUIRED")
.routeId("retirement_member_exchange")
.aggregate(property("CamelCreatedTimestamp"), new RetirementAggregationStrategy()).completionFromBatchConsumer()
.marshal(df).log("log:org.fuwt?level=ERROR&showAll=true")
.to("file://Users/smohamed/tests/?fileName=marshal.test.txt");
}
}
但是,当我运行单元测试时,会出现以下错误:
ArrayList cannot be converted to RetirementMember
我认为这意味着flatpack不知道如何处理列表,需要在每个对象的基础上工作
因此,我要寻找的是一个类似于freemaker模板的smooks映射,但不是freemaker模板,我想使用flatpack的列定义:
<?xml version='1.0'?>
<!DOCTYPE PZMAP SYSTEM "flatpack.dtd" >
<PZMAP>
<COLUMN name="ssn" length="11" />
<COLUMN name="lastName" length="20" />
<COLUMN name="firstName" length="15" />
</PZMAP>
最好的办法是什么?没有太多可用的文档,我已经搜索了好几个星期了
谢谢
Sam事实证明,Flatpack数据格式不需要java ArrayList对象,而是需要List>对象,其中映射包含ZMAP-XML映射文件中每个列的定义名称,以及它所代表的对象,因此字段firstname(例如)将作为
Map.put(“firstname”,“Sam”)
出现在映射中
我通过下载apachecamel源代码并查看Flatpack的单元测试发现了这一点,之后我就可以开始工作了