我正在尝试读取EDI消息并将其转换为Java对象,但是我遇到了以下异常。


  线程“主” org.milyn.SmooksException中的异常:无法过滤
  资源。在
  org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:97)
    在
  org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:64)
    在org.milyn.Smooks._filter(Smooks.java:526)处
  org.milyn.Smooks.filterSource(Smooks.java:482)在
  org.milyn.Smooks.filterSource(Smooks.java:456)在
  org.milyn.edi.unedifact.d97a.D97AInterchangeFactory.fromUNEdifact(D97AInterchangeFactory.java:58)
    在
  org.milyn.edi.unedifact.d97a.D97AInterchangeFactory.fromUNEdifact(D97AInterchangeFactory.java:40)
    在com.ibm.gpohub.edi.common.SmooksSample.main(SmooksSample.java:18)
  引起原因:org.milyn.edisax.EDIParseException:EDI消息处理
  失败[ORDRSP] [D:97A:UN]。段[FTX]的字段4(TEXT_LITERAL),
  组件1(Free_text _-__- 1)应该包含一个值。目前
  在段号6。
  org.milyn.edisax.EDIParser.mapComponent(EDIParser.java:687)在
  org.milyn.edisax.EDIParser.mapField(EDIParser.java:636)在
  org.milyn.edisax.EDIParser.mapFields(EDIParser.java:606)在
  org.milyn.edisax.EDIParser.mapSegment(EDIParser.java:564)在
  org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:535)在
  org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:453)在
  org.milyn.edisax.EDIParser.parse(EDIParser.java:428)在
  org.milyn.edisax.EDIParser.parse(EDIParser.java:410)在
  org.milyn.edisax.unedifact.handlers.UNHHandler.process(UNHHandler.java:97)
    在
  org.milyn.edisax.unedifact.handlers.UNGHandler.process(UNGHandler.java:58)
    在
  org.milyn.edisax.unedifact.handlers.UNBHandler.process(UNBHandler.java:75)
    在
  org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:113)
    在
  org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:75)
    在org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:76)处
  org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86)
    ...另外7个


这是代码片段:

 D97AInterchangeFactory d97InterChangeFactory   = (D97AInterchangeFactory)SmooksFactoryImpl.D97A_FACTORY.getInstance();
            InputStream ediSource = new FileInputStream("C:\\EDIFACT_MSG.txt");
            UNEdifactInterchange interchange = d97InterChangeFactory.fromUNEdifact(ediSource);
        if(interchange instanceof UNEdifactInterchange41){
            List<UNEdifactMessage41>  messages =  ((UNEdifactInterchange41) interchange).getMessages();
            for(UNEdifactMessage41 msg:messages){
                System.out.println(msg.toString());
            }
        }


EDIMessage:


  UNA:+。
  UNB + UNOC:3 + 662424795TEST:16 + IBMEDIID:ZZ + 160330:1416 + IG-62779496
  UNG + ORDRSP + 662424795测试:16 + IBMEDIID:ZZ + 160330:1420 + FG-34160863 + UN + D:97A
  UNH + 80534414 + ORDRSP:D:97A:UN BGM + 231 + 20160330 + 4
  DTM + 69:20150501150000UTC?+12:304 FTX + SSR +++:空白FTX + AAR ++ ST
  FTX + COI +++ CLW FTX + PRI ++ 8 FTX + DEL ++ 06 FTX + CUR +++将所有项目打包成一个
  FTX + DIN +++盒请在交货前致电客户
  FTX + PRD +++ 1:1:PC01 FTX + AAP +++ 900:接受RFF + PC:20AMS67000
  RFF + SE:PC01K33E RFF + SZ:ND RFF + ABO:Y RFF + CO:IBM1234501
  DTM + 4:20150501010101UTC?+12:304 RFF + ACW:CASE_12345 RFF + ADG:Y RFF + ACH:Y
  RFF + ZOD:order_desk01 RFF + ZSD:IBM RFF + ZPD:30006672 RFF + ZCS:空白
  RFF + ZZZ NAD + SE + 30001234 ++ IBM NAD + BY + US00000001 ++可口可乐:CA + 9 / F:841
  WEBSTER ST:压力3:空白+旧金山+94117+美国CTA + PD +:约旦
  Surzyn [email protected]:EM COM + 6508624654:TE NAD + OY + US00000001 ++ IBM
  现场服务:CA + 9 / F:900 WEBSTER ST:应力3:空白+ SAN
  FRANCISCO ++ 94117 +美国CTA + CR +:Will Smith [email protected]:EM
  COM + 6508624654:TE LIN + 10 PIA + 5 + 04X6076 IMD + F ++ ::: KEYBOARD NetVista
  键盘(USB)数量+21:1:EA DTM + 69:20160610120000UTC?+12:304
  FTX + OSI +++ INW FTX + LIN +++ ZSP1 FTX + AAP +++ 900:接受来自FTX + ZCT +++ STO
  DC至FSL RFF + ZSB:01 RFF + ZRO:Y RFF + ZOR:KEYBOARD状况良好
  RFF + ZST:SOFT UNS + S UNT + 50 + 80534414 UNE + 1 + FG-34160863 UNZ + 1 + IG-62779496


谁能指导我,我在哪里做错了?
提前致谢。

最佳答案

这是因为EDIFACT消息格式不正确。收到正确的EDIFACT消息后即可解决此问题,如下所示。希望任何面临类似问题的人都能对此有所帮助。 - 谢谢


  UNA:+。 '
  UNB + UNOC:3 + IBM:ZZZ + 662424795TEST:16 + 160330:1416 + 00000016086706 ++++++'
  UNG + ORDRSP + IBM:ZZZ + 662424795TEST:16 + 160330:1420 + 00000000160867 + UN + D:97A'
  UNH + 1 + ORDRSP:D:97A:UN'BGM + 231 + 20160330 + 4'
  DTM + 69:20160501150000UTC?+12:304'FTX + AAR ++ ER'FTX + SSR +++ N:AM'
  FTX + COI +++ CLW'FTX + PRI ++ 8'FTX + DEL ++ 04'FTX + CUR +++将所有物品包装到
  一箱“ FTX + DIN +++交货前致电客户”
  FTX + PRD +++ IBMDECK001 :: PC01'FTX + AAP +++ 900:accept'RFF + PC:20AMS67000'
  RFF + SE:PC01K33E'RFF + SZ:ND'RFF + ABO:N'RFF + CO:IBM1234501'
  RFF + ACW:IBMCASE12301'DTM + 4:20150501000000UTC?+12:304'
  NAD + SE + 30006672 ++ 3100001'NAD + BY + US00000001 ++ CA:NEC个人
  电脑有限公司+ 9 / F:841 WEBSTER ST:应力3 + SAN
  FRANCISCO ++ 941171717 + US'CTA + PD +:Jordan Surzyn'[email protected]:EM'
  COM + 6508624654:TE'NAD + OY + US00000001 ++ CA:NEC个人计算机,
  Ltd. + 9 / F:841 WEBSTER ST:应力3+旧金山+ 941171717 + US'
  CTA + CR +:Jordan Surzyn'[email protected]:EM'COM + 6508624654:TE'
  LIN + 20 +++ 1:10'PIA + 5 + 04X6076'IMD + F ++ ::: KEYBOARD NetVista键盘
  (USB)'QTY + 21:1:EA'DTM + 69:20160610120000UTC?+12:304'FTX + LIN +++ ZSP1'
  FTX + AAP +++ 900:Accpet'FTX + OSI +++ INW'FTX + BSC +++键盘良好
  条件'RFF + SE:Y'NAD + OY + 01 + SOFT'UNS + S'UNT + 41 + 1'
  UNE + 1 + 00000000160867'UNZ + 1 + 00000016086706'

10-08 00:45