gpt4 book ai didi

edi - 吸烟问题

转载 作者:行者123 更新时间:2023-12-04 16:34:46 28 4
gpt4 key购买 nike

我目前正在评估 smooks (www.smooks.org)。它看起来就像我们需要的,但我在使用一个简单的示例时遇到了问题。

我有一个 ant 脚本,它为我下载了所有依赖项,包括 EDIFACT 消息的映射和绑定(bind) jar。

我正在尝试使用他们的 EJC 将简单的 EDIFACT APERAK 消息转换为 Java(我正在使用 JavaSE 进行这个小测试)。转换失败,异常是某些 block 不是预期的(见下文)。所以我想知道我是否缺少某些配置(注意日志输出中的前几行)。

有人使用过 Smooks 的 EJC 吗?我如何才能获得有关它提示的线路的更多信息?

所以这是代码:

    D00BInterchangeFactory factory = D00BInterchangeFactory.getInstance();
File file = new File("aperak.edi");
BufferedInputStream ediSource = new BufferedInputStream(new FileInputStream(file));
StreamResult xmlStream = new StreamResult();
StringWriter xmlWriter = new StringWriter();
xmlStream.setWriter(xmlWriter);
UNEdifactInterchange interchange = factory.fromUNEdifact(ediSource);
//System.err.println("MEssage "+xmlWriter.toString());
if(interchange instanceof UNEdifactInterchange41){
UNEdifactInterchange41 interchange41 = (UNEdifactInterchange41)interchange;
for(UNEdifactMessage41 message: interchange41.getMessages()){
Object messageObj = message.getMessage();
System.err.println("Ref Num "+message.getMessageHeader().getMessageRefNum());
if(messageObj instanceof Aperak){
Aperak aperak = (Aperak)message.getMessage();
System.err.println("Aperak "+aperak);
}
}
}

当我运行它时,我得到了这个异常

02-Nov-2011 15:58:09 org.milyn.delivery.ContentDeliveryConfigBuilder$ContentHandlerExtractionStrategy addCDU
WARNING: ContentHandlerFactory [org.milyn.delivery.JavaContentHandlerFactory] unable to create resource processing instance for resource [Target Profile: [[*]], Selector: [cdu-creator], Selector Namespace URI: [null], Resource: [org.milyn.smooks.scripting.groovy.GroovyContentHandlerFactory], Num Params: [1]]. org/codehaus/groovy/control/CompilationFailedException
02-Nov-2011 15:58:10 org.milyn.delivery.ContentDeliveryConfigBuilder$ContentHandlerExtractionStrategy addCDU
WARNING: ContentHandlerFactory [org.milyn.delivery.JavaContentHandlerFactory] unable to create resource processing instance for resource [Target Profile: [[*]], Selector: [cdu-creator], Selector Namespace URI: [null], Resource: [org.milyn.smooks.scripting.groovy.GroovyContentHandlerFactory], Num Params: [1]]. org/codehaus/groovy/control/CompilationFailedException
Exception in thread "main" org.milyn.SmooksException: Failed to filter source.
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86)
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:61)
at org.milyn.Smooks._filter(Smooks.java:516)
at org.milyn.Smooks.filterSource(Smooks.java:475)
at org.milyn.Smooks.filterSource(Smooks.java:449)
at org.milyn.edi.unedifact.d00b.D00BInterchangeFactory.fromUNEdifact(D00BInterchangeFactory.java:58)
at org.milyn.edi.unedifact.d00b.D00BInterchangeFactory.fromUNEdifact(D00BInterchangeFactory.java:40)
at EDITestReader.readFile(EDITestReader.java:37)
at EDITestReader.main(EDITestReader.java:59)
Caused by: org.xml.sax.SAXException: Unknown/Unexpected UN/EDIFACT control block segment code '
UN'.
at org.milyn.edisax.unedifact.handlers.r41.UNEdifact41ControlBlockHandlerFactory.getControlBlockHandler(UNEdifact41ControlBlockHandlerFactory.java:53)
at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:95)
at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:77)
at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:70)
at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:75)
... 8 more
enter code here

实际的 EDIFACT 消息相当简单:

UNA:+.? '
UNB+UNOC:3+IMP+XXX+20110902:1024+44090560'
UNH+440905601+APERAK:D:00B:UN:IMP10'
BGM+313++9+RE'
RFF+ACW:XXXXXXXXX1109020'
DTM+182:201109021018:203'
RFF+BM:XXXXXXXXX'
RFF+AGO:XXXXXXX1109020'
RFF+EQ:XXXXXXXX'
NAD+MS+IMP'
CTA+MS+:EDI'
COM+XXXXXXXXXXX:TE'
COM+support@XXXXX.XX:EM'
ERC+200:IMP02:DAK'
FTX+AAO+++ERR4045?: Gest.datum ist mehr als 90 Tage kleiner als das Tagesdatum+DE'
UNT+14+440905601'
UNZ+1+44090560'

当我删除前导 UNA 和 UNB 片段时,它会出现此异常:([APERAK][D:00B:UN]。必须至少有 1 个片段 [BGM] 实例)。有一段BGM所以我不确定它为什么会提示。

Caused by: org.milyn.edisax.EDIParseException: EDI message processing failed [APERAK][D:00B:UN].  Must be a minimum of 1 instances of segment [BGM].  Currently at segment number 2.
at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:460)
at org.milyn.edisax.EDIParser.mapSegments(EDIParser.java:411)
at org.milyn.edisax.EDIParser.parse(EDIParser.java:387)
at org.milyn.edisax.EDIParser.parse(EDIParser.java:371)
at org.milyn.edisax.unedifact.handlers.r41.UNHHandler.process(UNHHandler.java:80)
at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:98)
at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:77)
at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:70)

更新:当我从消息中删除回车时

UNH+440905601+APERAK:D:00B:UN:IMP10'BGM+313++9+RE'RFF+ACW:XXXXXXXXX1109020'DTM+182:201109021018:203'

它工作正常。但是我如何让 smoks 接受回车符和空格以及两个主要的 UNA/UNB 段?我可能跳过了 smooks 通常会做的消息处理的某些部分。

更新 2:发现支持 UNA/UNB 段(我的错误),但我仍然遇到回车问题。Renat 建议在 EDIParser 上使用“ignoreNewLines”选项。我试过了,但似乎没有什么不同。我也尝试用这个配置 smooks:

<?xml version="1.0" encoding="UTF-8"?>
<smooks-resource-list
xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.4.xsd">
<edi:reader mappingModel="/org/milyn/smooks/edi/xsd14/edi-to-xml-mapping.xml" ignoreNewLines="true" />
</smooks-resource-list>

再次失败。

我感觉 D00AInterchangeFactory(或您使用的每个版本)以不同方式配置其 EDIParser,忽略 ignoreNewLines。

有没有办法获取 InterchangeFactory 正在使用的 EDIParser?

最佳答案

您需要在 EDIParser 上添加启用“忽略新行”开关。您有多种方法可以做到这一点,例如您可以使用 XMLReader#setFeature()

http://download.oracle.com/javase/1.5.0/docs/api/org/xml/sax/XMLReader.html#setFeature(java.lang.String,%20boolean )

或直接通过 EDIParser 方法调用。在此处查看示例

https://gist.github.com/825845

这里

https://gist.github.com/825843

雷纳特

关于edi - 吸烟问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7983710/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com