EDIFACT EDI Connector 2.2 - Examples - Mule 4

The following examples show how to read, validate, and write EDI messages. In addition, you can send functional and interchange acknowlegments to your trading partners.

XML for EDIFACT Studio

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule app.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
  <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config">
    <http:listener-connection host="localhost" port="8081" />
  <edifact:config name="EDIFACT_EDI_Config" doc:name="EDIFACT EDI Config"
      <edifact:schema value="/edifact/d96a/ORDERS.esl"/>
      <edifact:schema value="/edifact/d99b/CUSRES.esl"/>
  <flow name="edifactmappingFlow">
     <http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/map" />
     <edifact:read doc:name="Read" config-ref="EDIFACT_EDI_Config"/>
     <ee:transform doc:name="Transform Message">
       <ee:message >
         <ee:set-payload ><![CDATA[%dw 2.0
output application/java
    Messages: {
        D96A: {
            ORDERS: payload.Messages.D96A.ORDERS
     <edifact:write doc:name="Write" config-ref="EDIFACT_EDI_Config"/>

Read and Validate EDIFACT EDI Messages

  1. To read an EDIFACT message, search the palette for EDIFACT EDI, and drag the EDIFACT Read operation into a flow.

  2. Go to the properties view, select the connector configuration you created and select the Read operation.

This reads any byte stream into the structure described by your EDIFACT schemas.

The EDIFACT module validates the message when it reads it. Message validation includes checking the syntax and content of the envelope segments UNB and UNZ as well as the actual messages within the message. Normally errors are both logged, accumulated, and reported in CONTRL acknowledgment messages and all accepted messages (whether error free or with non-fatal errors) are passed on for processing as part of the output message Map. Exceptions are thrown Errors when reading the input data.

Error data entered in the receive data map uses the EdifactError class. This is a read-only JavaBean with these properties:

Property Description


The zero-based index within the input of the segment causing the error


Flag for a fatal error. This means the associated message, group, or interchange is rejected as a result of the error.


EDIFACT syntax error code


Text description of the error

Error data is returned by the Read operation as optional lists with the Errors key at both the root level of the data structure and at the message level. For the message level, the list contains non-fatal errors encountered during the message parsing. For the root level, the list contains both interchange errors and fatal message errors.

Write EDIFACT EDI Messages

  • To write an outgoing message, search the palette for EDIFACT EDI and drag the EDIFACT Write operation into a flow.

  • Construct an outgoing EDIFACT EDI message according to the structure as defined for input to the write operation.

If no fatal errors are found in the Write operation, the normal flow continues. Otherwise, an exception is thrown that describes the error.

Send Functional Acknowledgments

Sending generated functional acknowledgments (CONTRL messages) is the same as writing any other type of EDI message except that transactions are set to the acknowledgments that were generated during the Read operation.

For example:

<edifact-edi:read config-ref="EDIFACT_EDI__Configuration" doc:name="Read EDI Doc"/>
<dw:transform-message doc:name="Create Outgoing Acks Message">
    <dw:set-payload><![CDATA[%dw 1.0
%output application/java
	FunctionalAcksToSend: payload.FunctionalAcksGenerated
<edifact-edi:write config-ref="EDIFACT_EDI__Configuration" doc:name="Send Acks"/>

The generated functional acknowledgments have interchange data set up for sending back to the sender of the original message, so it’s not required to change anything in the transactions to perform the send.