smooks / smooks-dfdl-cartridge Goto Github PK
View Code? Open in Web Editor NEWSmooks cartridge leveraging Apache Daffodil to parse files and unparse XML
Home Page: https://www.smooks.org
License: Other
Smooks cartridge leveraging Apache Daffodil to parse files and unparse XML
Home Page: https://www.smooks.org
License: Other
Unlike previously thought, dfdl:parser doesn't stream the input even though no data is kept in the org.apache.daffodil.japi.infoset.InfosetOutputter Smooks implementation. Streaming infosets are in Daffodil's roadmap but we shouldn't expect them any time soon. While we wait, a workaround to full streaming is to consume the stream in chunks. In practice, this means writing a DFDL schema such that a "chunk" is the root element with a given terminator (e.g., %NL;). As long as each chunk fits in memory, we can be sure that no OOM errors will happen because dfdl:parser incrementally consumes each chunk.
Describe the bug
See discussion thread https://groups.google.com/g/smooks-user/c/-XrBoBtgXCU
To Reproduce
Use the EDIFACT reader and set the syntax version in the EDIFACT document to an unsupported one. For example:
UNB+KECA:1+QW:KL+FT:KL+240216:1347+20240216134624'UNH+1+APERAK:D:00A:UN'BGM+294+cgch++1'DTM+137:202402161346:203'DOC+938:::VATDEC'RFF+ACE:cgch'RFF+wd:1'RFF+ws:E'NAD+MS+we'NAD+MR+wd'ERC+ER:E'FTX+AAP+++cgch:(30¿.():'UNT+12+1'UNZ+1+20240216134624'
Expected behavior
The fatal error should cause the DFDL parser to give up instead of retrying to process the input.
Environment
As here reported there are some blocking problems at converting an IFTMIN message to XML. I've encounter the same problem working with IFTMAN messages.
See this thread on the mailinglist: https://groups.google.com/g/smooks-user/c/BKnqqGUyX3Y
Used following dependencies:
<dependency>
<groupId>org.smooks.cartridges.edi</groupId>
<artifactId>smooks-edifact-cartridge</artifactId>
<version>2.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.smooks.cartridges.edi</groupId>
<artifactId>d96a-edifact-binding</artifactId>
<version>2.0.0-M3</version>
</dependency>
<dependency>
<groupId>org.smooks.cartridges.edi</groupId>
<artifactId>edifact-schemas</artifactId>
<version>2.0.0-M3</version>
<classifier>d96a</classifier>
</dependency>
Created following method to parse DELJIT messages:
public String parseDelJit(String message) {
final Smooks smooks = new Smooks();
smooks.setReaderConfig(new EdifactReaderConfigurator("/d96a/EDIFACT-Messages.dfdl.xsd").setMessageTypes(Arrays.asList("DELJIT")));
final StringWriter writer = new StringWriter();
smooks.filterSource(new StringSource(message), new StreamResult(writer));
return writer.toString();
}
Tried to call it with several different messages (both from our test environment which matches production, so the messages seem to be correct):
@Test
public void DelJitTest() throws IOException, SAXException {
//String message = "UNH DELJIT D96AUNA10010BGM 3020212241720458870DTM137202106031720 203NAD SEE521J 92NAD BY737 92LOC 11086 LOC159086 SEQ 34570156DTM194202105280814 203GIR 4665023107 FYYV4162UM2M2617547 VI1 LILIN30753320 MNQTY131+000000000001DTM 2202106021720 203UNT 12 \n";
String message = "UNH+1+DELJIT:D:96A:UN:A10010\n" +
"BGM+30+202106200650\n" +
"DTM+011:202106181529:203\n" +
"NAD+SE+BS8CB::92\n" +
"NAD+BY+BS8CA::92\n" +
"NAD+CN+BS8CA::92\n" +
"LOC+11+086\n" +
"SEQ+3+1\n" +
"DTM+002:202106181529:203\n" +
"GIR+4+0001:AW+4580613:AN+1:LI+T0:AT\n" +
"GIR+7+AA00:AV\n" +
"LIN+++1285323:IN\n" +
"GIR+1+T21C7444425:BN\n" +
"GIR+7+BB00:AV+VB1:ML\n" +
"QTY+131:1\n" +
"LIN+++6906533:IN\n" +
"GIR+1+T4172883:BN\n" +
"GIR+7+BB00:AV+MO1:ML\n" +
"QTY+131:1\n" +
"LIN+++32249466:IN\n" +
"GIR+1+T7965124:BN\n" +
"GIR+7+BB00:AV+PT1:ML\n" +
"QTY+131:1\n" +
"LIN+++32260849:IN\n" +
"GIR+1+T1262667053:BN\n" +
"GIR+7+BB00:AV+ACC:ML\n" +
"QTY+131:1";
String parsed = edifactTasks.parseDelJit(message);
}
Gives me this stacktrace:
org.smooks.api.SmooksException: Failed to filter source
...
Caused by: org.apache.daffodil.exceptions.Abort: Invariant broken. Runtime.scala - Leaked exception: java.lang.NullPointerException
java.lang.NullPointerException
at org.apache.daffodil.io.BucketingInputSource.fillBucketsToIndex(InputSource.scala:261)
at org.apache.daffodil.io.BucketingInputSource.areBytesAvailable(InputSource.scala:329)
...
at org.smooks.cartridges.dfdl.parser.DfdlParser.parse(DfdlParser.java:183)
at org.smooks.engine.delivery.sax.ng.SaxNgParser.parse(SaxNgParser.java:86)
Full stacktrace in attached file, we use Serenity-BDD with Cucumber to run the tests.
stack.txt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.