We all know that the XML is the better format to interchange data between applications. It's text based, it's structured and most of the development platforms have support for it. We should consider it as the main (and perhaps) the unique form of data integration.
But when we speak about integration, we've to consider platforms that must not support XML documents, or even that they support, the application could not be changed for some reason. I've worked in a project that must integrate platforms using EDI documents. I've used JBoss ESB as the software for the EAI broker. The JBoss ESB should receive a EDI document, transform this EDI document in XML to be sended for a Web Service endpoint. That part was very easy todo since JBoss ESB has a native smooks support for EDI reading (See the "transform_EDI2XML_Groovy_XSLT" demo for more details).
Have the document processed asynchronously by a legacy platform (the platform that received the SOAP request made by the ESB), this legacy platform notifies the ESB that the request is done sending a JMS message for the Broker. The ESB JMS gateway just deliveries the message for a internal service that makes a series of transformation on the message to prepare it for FTP delivering. Using the current resources of JBoss ESB this was not a hard task to accomplish. But the problem cames when the target endpoint (the application that was waiting for the response) asked me to send a EDI document back to it.
I'd all the data in XML format, and using JBoss ESB transformation features, I could transform this document to anything that I could imagine (CSV, Java, other XML using XSLT). But the customer requirement was delivery a message response using the EDI format, and for my surprise (and bad luck), JBoss ESB does not have support for EDI generation. And because this scenario, this post has been written. I've created a generic action that creates a EDI document from a Java regular object. To solve my problems, I'd transformed the XML response to Java (using Smooks) and from that point, I've used my custom action to generate the EDI document. I'm going to share with you this implementation, since could help you at scenarios like mine. Here we go ...
Imagine for instance, that you've the following XML document at your ESB pipeline:
Using the JBoss ESB current transformation features, we could easily transform this document to a Java instance based on the following group of classes:
At this point, we could generate our EDI document using the following ESB action declaration:
And the result of this transformation would be:
Cool isn't? with this little configuration we can generate a complex EDI document to be sent for every channel that JBoss ESB supports as outbound since it's text based. That's the code I created to support this configuration:
In the implementation above, there are a Java interface mentioned. It's used to define custom behaviors for field processing in that cases when logic are related to a specific field. For instance, suppose that you want to guarantee that a specific field must have 40 characters of length even when the value only have 20. You could write a custom handler for that field and put this logic of characters. Here's the interface code:
Hope that help anybody like me that not every time can determine the format of messages that must be delivered by the ESB. We see around ;-)