如何将未整理的数据处理为原始数据?

时间:2019-04-19 15:11:40

标签: apache-camel spring-camel

我正在用骆驼实现一些应用程序。

我的情况就像打击。

1)收集输入目录中的文件。

2)解封具有特定数据格式(fixedLengthFormat)的文件。

3)如果在解组期间文件异常,则会生成一些异常。

4)如果发生异常,骆驼将原始文件移动到异常目录。

我发现了如下异常。

 org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: C:\home\WRK\PRC\WLNE\IPTVKR\KRLPPM10\FATAL\SLPNPM_FGIDRO01_ID0006_T20190312050500.DAT
at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:354) ~[camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:305) ~[camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:169) ~[camel-core-2.23.1.jar:2.23.1]
at org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:80) ~[camel-core-2.23.1.jar:2.23.1]
    ....

这是由错误的正文解析引起的错误。 因此,我在标签之前添加了String类型的标签。 我做到了,没有错误。 但是,移动的文件具有要解组的数据格式,而不是原始数据。

我应该如何处理一些代码以获得原始数据?

  • 解组的数据格式(KRFixedFormat.java)

    @FixedLengthRecord(length=3005, header=KRHeader.class, footer=KRTailer.class)
    public class KRFixedFormat implements Serializable {
     private static final long serialVersionUID = 1L;
    
    @DataField(pos=1, length=1,trim=true)
    private String sType;
    
    @DataField(pos=2, length=7, trim=true, align="L")
    private String sRecordSeq;
    
    @DataField(pos=9, length=1, trim=true, defaultValue="2")
    private char sServiceType;
    
    ...
    
  • 骆驼语境

    <doTry id="_CheckException">
        <camel:convertBodyTo charset="ISO-8859-1"
                        id="_ConvertEncoding" type="java.lang.String"/>
        <camel:unmarshal id="_FileParsing">
           <camel:bindy
                  classType="com.ktds.openmzn.dao.KRFixedFormat"
                            locale="korea" type="Fixed"/>
        </camel:unmarshal>
        <doCatch id="_ParsingException">
           <exception>org.apache.camel.component.bean.MethodNotFoundException</exception>
           <exception>org.apache.camel.NoTypeConversionAvailableException</exception>
           <convertBodyTo charset="ISO-8859-1"
                        id="_ConvertEncoding" type="java.lang.String"/>
           <toD id="_MoveErrorFile" uri="file:${header.CamelFileParent}/FATAL"/>
        </doCatch>
    </doTry>
    ...
    
  • 原始文件

    H20190312050500GIDRO01LPNPM  
    R0000001269056802668      D201903 ....
    T000000120190312050500000000003091
    
  • 输出文件

    KRFixedFormat [sType=R, sRecordSeq=0000001, sServiceType=2, sChrgId=69056802668, ....
    

0 个答案:

没有答案