4

It is seen in the smooks website that it supports EDI generation. But there is no way to specify the configuration for an edi writer (as in the case of reader defined in schema http://www.milyn.org/xsd/smooks/edi-1.1.xsd).

In some old posts in certain forums, I have seen that smooks is planning for such a writer. Is it available? Thanks in advance.

Naveed S
  • 5,106
  • 4
  • 34
  • 52

2 Answers2

4

I managed to do this using the same schema used in the unedifact:reader

Smooks-config:

<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                      xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd">
    <import file="/org/milyn/edi/unedifact/d96a/message-bindingconfig.xml" />
    <import file="/org/milyn/smooks/edi/unedifact/model/r41/bindings/unedifact-interchange.xml" />
    <core:exports>
        <core:result type="org.milyn.payload.JavaResult"/>
    </core:exports>
</smooks-resource-list>

The result is a HashMap withe the elements readed. Now that i have objets i can make any modifications and after that i use the document interchange factory: ex D96AInterchangeFactory

D96AInterchangeFactory factory = D96AInterchangeFactory.getInstance();
UNEdifactInterchange41 unEdifactInterchange = (UNEdifactInterchange41) map.get("unEdifactInterchange");
StringWriter ediOutStream = new StringWriter();
factory.toUNEdifact(unEdifactInterchange, ediOutStream);

Finally i can use toString() to get my document:

System.out.println("document: " + ediOutStream.toString());
Panchitoboy
  • 810
  • 9
  • 18
  • I am attempting to use your solution for outputting EDI, but the ediOutStream is empty. My Smooks config is like yours (except that I import D98a), so the problem is probably the way my JavaResult is populated. – morsor Jun 26 '15 at 09:04
  • You can debug your route to know if the JavaResult is populated. I think that if you use a different import there are at least theses changes: D96AInterchangeFactory, UNEdifactInterchange41 – Panchitoboy Jun 26 '15 at 11:38
  • Thanks for the reply. My full code is here -> http://stackoverflow.com/questions/31069450/smooks-outputting-edi-from-java I have a feeling that the sample Java object I create is not populated enough to be recognized as a EDI message – morsor Jun 26 '15 at 11:42
  • how to prepare the map object which you have been using to get the unEdifactInterchange object. – RCS Mar 01 '16 at 13:06
  • i used apache camel in that project. so the object it was filled by the framework. But i'm sure that you can create an instances of UNEdifactInterchange41 and add all the information that you need – Panchitoboy Mar 01 '16 at 21:47
0

According to the Smooks website:

Smooks can read and write data formats other than XML, including EDI, CSV, JSON, YAML, Java. To read non-XML data, you typically need to configure a for that data type. Writing data typically involves configuring a template that operates on the event stream produced by the (as in the case of XSLT), or on the beans in the BeanContext (as in the case of FreeMarker). You can also simply allow Smooks to serialize the event stream produced by the input reader, which will produce XML, giving an effective NNN to XML transformation by simply configuring a reader for the input source.

So, yes, there is a possibility to generate EDI with Smooks.

Vlad
  • 117
  • 1
  • 1
  • 9
  • Can you give an example, how to generate edi file from java object/xml, as i am new to smooks and lack of documentation, i am struggling to achieve this. – RCS Mar 01 '16 at 13:05
  • @RCS take a look here: http://www.smooks.org/user-guide/user-guide.html#EDI – Vlad Feb 28 '17 at 16:00