apache-cameltalendedismooks

camel-smooks returns null in body


I am using talend-ESB and want to parse EDI message to XML using smooks & I am getting null in body. The code looks as below.

from(
"file://D:/cimt/InvoiceEDI_Mapping/" + "?noop=true"
    + "&autoCreate=true" + "&flatten=false"
    + "&fileName=InDev_EDI_Msg.txt" + "&bufferSize=128")
.routeId("TestSmooksConfig_cFile_1")
.log(org.apache.camel.LoggingLevel.WARN,
"TestSmooksConfig.cLog_1", "${body}")

.id("TestSmooksConfig_cLog_1")

.to("smooks://EDI_Config.xml")
.to("log:TestSmooksConfig.cLog_2" + "?level=WARN")

.id("TestSmooksConfig_cLog_2");
    }

My Talend route looks as below.

enter image description here

I used following set of external dependencies. milyn-commons-1.7.0.jar milyn-smooks-camel-1.7.0.jar milyn-smooks-edi-1.7.0.jar milyn-smooks-core-1.7.0.jar jaxen-1.1.6.jar milyn-edisax-parser-1.4.jar

Also, I see a strange behavior that, upon execution, I still see "starting" prior to cJavaDSLProcessor, which initially made me wonder if at all it gets executed. But later, when I intentionally made a mistake in EDI-Mapping, then the route was throwing errors, which kind of convinced me that it does parse the EDI message.

I did also search before posting this question here, and found a similar problem in this link

And I tried to lower my revision of org.milyn.* jars to 1.4.0, and got an exception that the route could not register smooks component. So I continued using 1.7.0 version of org.milyn.* jars.


Solution

  • For the benefit of others who might bump into similar issue, I 'assume' that the output of the smooks gets written into an Object of type StringResult.class. However, in my initial implementation, there was no such option and hence the output body was null.

    Later, I tried alternative approach from http://smooks.org/guide where they used processor endpoint.Actually they had even made a statement that the data could be retrieved through exports element. The below code snippet helped to fix issue.

    Smooks smooks = new Smooks("edi-to-xml-smooks-config.xml");
    ExecutionContext context = smooks.createExecutionContext();
    smooks.setExports(new Exports(StringResult.class));
    SmooksProcessor processor = new SmooksProcessor(smooks, context);
    from("file://input?noop=true")
    .process(processor)
    .to("mock:result");