2016-02-03 63 views
2

目前,我能夠使用駱駝Bindy從POJO生成平面文件,但無法將頁眉和頁腳添加到完整文件。如何使用Camel Bindy生成包含頁眉和頁腳的平面文件

但是,當我試圖添加頁眉/頁腳到文件,它將添加到每個單個記錄,但我需要添加一個單一的頁眉/頁腳到完整的文件而不是文件中的每個記錄。

下面是代碼片斷:

from("jpa:com.PACKAGENAME.RebatePayout?consumer.namedQuery=REBATE_PAYOUT&consumer.delay=500000&consumeLockEntity=true&consumeDelete=false") 
    .routeId("rebateroute") 
    .process(new Processor() { 
     RebateOutputgenerator rop = new RebateOutputgenerator(); 
       @Override 
       public void process(Exchange exchange) throws Exception { 
        exchange.getIn().setBody(rop.processEntities((RebatePayout) exchange.getIn().getBody())); 
        log.info("the exchange value is ", exchange);       
       } 
     }) 
     .process(new FahHeaderAndFooterHelper()) 
     .log("Fixed length format marshal....") 
     .marshal(fixedLegth) 
     .log("Fixed length format data....${body}") 
     .to("file://C:/Users/vvakalap/Desktop/example/New folder?fileExist=Append&fileName=output.txt") 
     .log("Data Saved in file..."); 

Process類是

public class FahHeaderAndFooterHelper implements Processor{ 
    @Override 
    public void process(Exchange exchange) throws Exception { 
     Map<String, Object> headerObjMap = new HashMap<String,Object>(); 
     headerObjMap.put(FahRecordHeader.class.getName(), new FahRecordHeader()); 
     if(exchange.getOut().getBody() == "null") 
      exchange.getOut().setHeader(CAMEL_BINDY_FIXED_LENGTH_HEADER, headerObjMap); 
     Map<String, Object> footerObjMap = new HashMap<String,Object>(); 
     footerObjMap.put(FahRecordFooter.class.getName(), new FahRecordFooter()); 
     exchange.getOut().setHeader(CAMEL_BINDY_FIXED_LENGTH_FOOTER, footerObjMap); 
     exchange.getOut().setBody(exchange.getIn().getBody()); 
    } 

POJO類

@Data 
@Section(number=2) 
@FixedLengthRecord(header = FahRecordHeader.class, footer = FahRecordFooter.class) 
public class RebateFinalRecord implements Serializable { 

    private static final long serialVersionUID = 7375828620208233805L; 

    @DataField(pos = 1, length = 3) 
    private String transactionRecordIdentifier; 

    @DataField(pos = 4, length = 10) 
    private String transactionNumber; 

    @DataField(pos = 14, length = 5) 
    private String transactionLineNumber; 

    @DataField(pos = 19, length = 20) 
    private String transactionDistributionType; 

    @DataField(pos = 39, length = 30) 
    private String eventTypeName; 

    @DataField(pos = 69, length = 8) 
    private String transactionDate; 

    @DataField(pos = 77, length = 8) 
    private String transactionEffectiveDate; 

    @DataField(pos = 85, length = 5) 
    private String transactingEntityValue; 

    @DataField(pos = 90, length = 1) 
    private String reciprocationFlag; 

} 

Bindy類

@Data 
public class FahRecordHeader { 
    @DataField(pos = 1, length = 3) 
    private String fileRecordIdentifier = "000"; 
    @DataField(pos = 4, length = 15) 
    private String controlIdentifierOrSequenceNumber = "LSCD00000000006"; 
    @DataField(pos = 19, length = 20) 
    private String source = "LSCD"; 
} 

@Data 
public class FahRecordFooter { 

    @DataField(pos = 1, length = 70) 
    private String footer = "footervalusforfahrecord for cashrebates"; 
    /* 
    * @DataField(pos = 2, length = 9, align = "R", paddingChar = &#39;0&#39;) 
    * private int numberOfRecordsInTheFile; 
    */ 
} 
+0

你到底了嗎?如果是,你介意分享知識嗎? – theo

回答

0

您是否嘗試過將@FixedLengthRecordhasHeaderhasFooter屬性設置爲true

@FixedLengthRecord(header = FahRecordHeader.class, 
        footer = FahRecordFooter.class, 
        hasHeader = true, 
        hasFooter = true) 

請參閱https://camel.apache.org/bindy.html#Bindy-4.FixedLengthRecord

+1

hasHeader和hasFooter在最新版本的camel中不受支持。可能這是造成這個問題。即使我們無法再使用駱駝綁定的Header和Footer。 –

相關問題