问题描述
我正在尝试创建带有页眉和页脚记录以及json有效内容作为主体的文件。 页眉和页脚属性值将基于时间戳和记录总数而动态变化 (目前,我正计划使用属性的静态值来实现)。 我正在使用FixedLengthDataFormat实现此目的。 但是,页眉和页脚记录未添加到文件中,该文件仅具有json有效内容作为主体。 有人可以帮助我实现这一目标吗?
我已经复制了下面的所有课程文件。
@Component
public class EmployeePackageRoute extends RouteBuilder {
@Autowired
private Header header;
private Trailer footer;
@SuppressWarnings("deprecation")
@Override
public final void configure() {
System.out.println("fetching employee details from employee api");
try {
from("jetty://http://localhost:8084/employee-package/getEmployee")
.unmarshal().json(JsonLibrary.Jackson,RecurringPaymentResults.class)
.process(
ex -> {
System.out.println("+++++++++++++++++ "+ex.getIn().getBody());
RecurringPaymentResults result = ex.getIn().getBody(RecurringPaymentResults.class);
List<RecurringPaymentsDeduct> employee = result.getResults();
ex.getOut().setBody(employee);
System.out.println("**** Header ** "+header);
})
.to("seda:employeeFeed");
final DataFormat bindy = new BindyFixedLengthDataFormat(RecurringPaymentsDeduct.class);
footer = new Trailer("TRAILER",3);
Map<String,Object> headerObjMap = new HashMap<String,Object>();
headerObjMap.put(Header.class.getName(),header);
Map<String,Object> footerObjMap = new HashMap<String,Object>();
footerObjMap.put(Trailer.class.getName(),footer);
from("seda:employeeFeed")
.log("process csv")
.marshal(bindy)
.log("csv processed")
.process(
ex -> {
System.out.println("******************** "+ex.getIn().getBody());
//ex.getOut().setHeader("header",header);
ex.getOut().setHeader(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_HEADER,headerObjMap);
ex.getOut().setBody(ex.getIn().getBody());
ex.getOut().setHeader(BindyFixedLengthDataFormat.CAMEL_BINDY_FIXED_LENGTH_FOOTER,footerObjMap);
}).to("file://C:\Users\testfolder?fileName=test.txt")
.end();
} catch(Exception e) {
System.out.println("Error occurred while processing employee data: "+e.getMessage());
e.printStackTrace();
}
}
}
@Data
@Section(number = 2)
@FixedLengthRecord(header = Header.class,footer = Trailer.class)
public class RecurringPaymentsDeduct implements Serializable {
private static final long serialVersionUID = 1L;
@DataField(pos = 1,length = 10)
public String RECTY;
@DataField(pos = 2,length = 10)
public String CLIID;
@DataField(pos = 3,length = 10)
public String INTCA;
@DataField(pos = 4,length = 10)
public String ORDNO;
@DataField(pos = 5,length = 10)
public String IOPER;
@DataField(pos = 6,length = 10)
public String INFTY;
@DataField(pos = 7,length = 10)
public String SUBTY;
@DataField(pos = 8,length = 10)
public String BEGDA;
@DataField(pos = 9,length = 10)
public String ENDDA;
@DataField(pos = 10,length = 10)
public String OBJPS;
}
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties("test")
@Data
@Section(number = 1)
@FixedLengthRecord()
public class Header implements Serializable {
private static final long serialVersionUID = 1L;
@DataField(pos = 1,length = 5)
private String header1;
@DataField(pos = 2,length = 5)
private String header2;
@DataField(pos = 3,length = 15)
private String header3;
@DataField(pos = 4,length = 60)
private String header4;
@DataField(pos = 5,length = 15)
private String header5;
@DataField(pos = 6,length = 30)
private String header6;
@DataField(pos = 7,length = 30)
private String header7;
@DataField(pos = 8,length = 8,pattern = "YYYYMMDD")
private String header8;
@DataField(pos = 9,length = 6)
private String header9;
@DataField(pos = 10,length = 1)
private String header10;
@DataField(pos = 11,length = 2)
private String header11;
@DataField(pos = 12,length = 10)
private String header12;
@DataField(pos = 13,length = 10)
private String header13;
@DataField(pos = 14,length = 10)
private String header14;
}
@Section(number = 3)
@FixedLengthRecord
public class Trailer implements Serializable {
private static final long serialVersionUID = 1L;
@DataField(pos = 1,length = 7)
private String trailer;
@DataField(pos = 2,length = 2)
private int count;
public String getTrailer() {
return trailer;
}
public void setTrailer(String trailer) {
this.trailer = trailer;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)