Announcement Announcement Module
Collapse
No announcement yet.
What are best practices to generate a bad items file? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • What are best practices to generate a bad items file?

    Hello,

    What are best practices to generate a bad items file? I have several Jobs, that read a file (FlatFileItemReader) then these items may be processed and finally written in other file, on a data base, etc.

    Then problem is I need to generate a .bad file with all the records with problems. That problems can be originated on the read, process o write part. And this file must contain the original flat record

    I successful extract the original flat record when the problem is originated in the reader, using a skipListener and the FlatFileParseException. But when the problem isn't in the reader, but in the process or in the writer i don't know how to get the original flat record. I'm only have the object.

    What is the best approach to resolve this problem? maybe implementing a custom FlatFileItemReader and put the original line in the StepContext? Or there is other trick?

    Thanks a lot

  • #2
    easiest way would be to map the line to a single String Value and use a processor to map the values

    with this you can access the actual line on every point in the batch

    Comment


    • #3
      I usually do something similar. I use my FieldSetMapper to generate two types of objects "records" and "errors". I let Spring Batch treat both types as "items", passing them to the processor and writer. Then i have a custom-coded composite writer that supports writing to two files. I use the composite writer to check whether the item is a "record" or an "error" and write it to the appropriate place.

      Comment


      • #4
        Can you please give more details, how to generate two types of obejects in fieldsetmapper
        and also from there pass two types of objects to processor and writer

        Comment


        • #5
          Hi,

          Finally, i used a custom skip listener class (extending from SkipListenerSupport). This custom class use a normal FlatFileItemWriter to write the errors file.

          Also, i made that all my custom VO (generated in the reader) extendes from an abstract class with some attributes to hold original readed line and error detail.

          For write the processed item file, i used a composite writer.

          Sorry for my bad english.

          Comment

          Working...
          X