Skip to Content

This weblog is about how to inform the sender by mail about all wrong records he sent. Here I am going to illustrate the method with File sender adapter. The principal difference between just validating by schema and my method is that by my method you can inform the sender about all bad records, so he can correct them and send you again.I demonstrate here not appropriate length.I suppose that about more than 50 errors in file you have no need to inform(50 is enough), but you can easily increase that number by simply increasing the size of array in global variables.

The method includes the following steps:

1. Deploying a module that will add “EOF” record to your message.

2. UDF adding the error to the global array holding the errors of the message if this is not the last record (marked “EOF”) and writing the array to a file if it is.

3.Finally the file can be sent through simple File>XI>Mail scenario (Here I don’t describe it, since it has nothing to do with the method).

Note: this method was tested for “EOIO” QOS Sender. I suppose it works when the sender sends the messages parallely as well, but it wasn’t tested.

So, Lets begin:

1. Create a namespace for your interface (I will call it “http://Bad_Records“).

2. We need to create 2 simple datatypes:

image

image

image

1. Here is the “process” function of the module:

public ModuleData process(ModuleContext moduleContext,

        ModuleData inputModuleData)

        throws ModuleException {

          try {

               Object dataObject = null;

               Message xiMessage = null;

               dataObject = inputModuleData.getPrincipalData();

               xiMessage = (Message) dataObject;

               XMLPayload payloadData = xiMessage.getDocument();

               ByteArrayOutputStream outXML=null;

               String Message_Text;

               String Message_Text_With_EOF;

               int start_index_eof;

               //Getting the text to add from Module

               //Parameter(set in communication channel)

               String txt_add = moduleContext.getContextData(“parameter”);                    

               if (payloadData != null) {

                    outXML = new ByteArrayOutputStream();

                    Add_EOF obj= new  Add_EOF();

                    //Get the text of the message  

                    Message_Text = payloadData.getText();

                    //Search for the end of the records

//marked with

3. What is needed in User Defined Function is to collect all the errors to Global variable and to write them to an error file.

Defining Global Variable in your Mapping Program:

image

In your “Global variables” you declare:

String[] Global_Errors; int Global_Errors_Index;

And in “Initialization section” you write:

Global_Errors = new String[50];Global_Errors_Index = 0;

And Our UDF should look like (I add timestamp to error file, cause I suppose there are many messages pass through).

It has text_data argument of String Type.

Date my_time_stamp = new Date();

long my_time_stamp_lng = my_time_stamp.getTime();

//”eof” record?

if( ((text_data.charAt(0) == ‘e’) && (text_data.charAt(1) == ‘o’) && (text_data.charAt(2) == ‘f’)) || Global_Errors_Index  > 49))

{

  try {

        if (Global_Errors_Index > 0)

        {//Give your path for error file

          FileWriter outFile = new FileWriter (“l:
MailErrors
mail_errors” + (“” + my_time_stamp_lng));

               PrintWriter out = new PrintWriter(outFile);

               //Write out all the lines

               for(int i_lines=0; i_lines” in my case. You should simply add one record exactly according to your xml structure with “eof” value in each field.

The result: you have files including all the errors of files sent to you.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply