SmooksException: Failed to filter source for EDI processing class

75 views
Skip to first unread message

impend

unread,
Apr 11, 2025, 3:44:16 PMApr 11
to Smooks Users
Hi all,

I'm trying to validate and process an EDI 834 file using Smooks 2.x in a Java test automation framework.

I'm loading raw EDI content (starting with ISA*) into a String, and configuring Smooks with a smooks-config.xml file and a programmatic registration of EDIReaderConfigurator. My goal is to map EDI segments into JavaBeans and validate them after parsing.

In my EDIProcessor class, I:

  • Read the EDI file into a string

  • Initialize Smooks using new Smooks(SMOOKS_CONFIG)

  • Register a DefaultResourceConfig for "edi:reader" with the correct parameters and EDIReaderConfigurator

  • Set up a JavaResult

  • Attempt to filter using smooks.filterSource(...)

However, I'm getting this error:

org.smooks.api.SmooksException: Failed to filter source Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'I' (code 73) in prolog; expected '<'

It appears Smooks is attempting to parse the EDI file as XML. After some digging, I realized I was using StringSource, which seems intended for XML. I'm switching to StreamSource with a StringReader instead.

Can you confirm this is the correct approach for non-XML EDI input in Smooks 2.x? And is JavaResult still supported when filtering via ExecutionContext, or do I need to work directly with the BeanContext?

Thanks in advance — happy to share code snippets if helpful.

impend

unread,
Apr 11, 2025, 4:01:26 PMApr 11
to Smooks Users
Here's the code snippet of my method:

private void parseWithSmooks(String ediData) throws IOException, SAXException {
System.out.println("Initializing Smooks...");

// Use try-with-resources with Smooks directly via config path
try (Smooks smooks = new Smooks(SMOOKS_CONFIG)) {

System.out.println("Smooks loaded from: " + SMOOKS_CONFIG);

Properties ediParams = new Properties();
ediParams.setProperty("mappingModelUri", "xml mapping file path");
ediParams.setProperty("segmentSeparator", "~");
ediParams.setProperty("elementSeparator", "*");

DefaultResourceConfig ediReaderConfig = new DefaultResourceConfig(
"edi:reader",
ediParams
);

ediReaderConfig.setResource("org.smooks.cartridges.edi.reader.EDIReaderConfigurator");
smooks.addResourceConfig(ediReaderConfig);

ExecutionContext executionContext = smooks.createExecutionContext();
JavaResult result = new JavaResult();
executionContext.getBeanContext().addBean(JavaResult.class.getName(), result);

Source source = new StreamSource(new StringReader(ediData));

System.out.println("Smooks filtering started...");
smooks.filterSource(source);
System.out.println("Smooks filtering completed successfully!");

validateSegments(result);

} catch (Exception e) {
System.err.println(" ERROR: Smooks filtering failed!");
e.printStackTrace();
throw e;
}
}

Claude Mamo

unread,
Apr 15, 2025, 7:08:08 AMApr 15
to smook...@googlegroups.com
Can't see how this would work. Was this written with the help of a LLM? There are several problems with your code. We don't have a specific example of an EdiReaderConfigurator, and unfortunately documentation is sparse to say the least, but you can find how it's being used in one of the EDI cartridge tests: https://github.com/smooks/smooks-edi-cartridge/blob/v2.1.0/edi-cartridge/src/test/java/org/smooks/cartridges/edi/EdiReaderConfiguratorTestCase.java#L59


It appears Smooks is attempting to parse the EDI file as XML. After some digging, I realized I was using StringSource, which seems intended for XML. I'm switching to StreamSource with a StringReader instead.

You can use StringSource for both XML and non-XML data, however, you should have a reader configured for non-XML data.

Claude


--
You received this message because you are subscribed to the Google Groups "Smooks Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smooks-user...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/smooks-user/3b2ff05e-39a8-4e66-b8e1-ce6ceb9bfed6n%40googlegroups.com.

impend

unread,
Apr 15, 2025, 3:42:17 PMApr 15
to Smooks Users
Yes, it was. I'm trying to validate an EDI (834) file, and assumed smooks could help with setting up some basic reading of the EDI file and I could use Java to perform some schema comparisons.

Claude Mamo

unread,
Apr 16, 2025, 4:25:12 AMApr 16
to smook...@googlegroups.com
It's certainly possible to configure programmatically the EDI reader and map the ingested EDI to Java beans. It might not be exactly what you want but take a look at the EDI-to-Java example: https://github.com/smooks/smooks-examples/tree/v6/edi-to-java

Reply all
Reply to author
Forward
0 new messages