Results 1 to 5 of 5

Thread: What are best practices to generate a bad items file?

  1. #1
    Join Date
    May 2007
    Posts
    13

    Default 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. #2

    Default

    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

  3. #3
    Join Date
    Feb 2008
    Posts
    488

    Default

    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.

  4. #4
    Join Date
    Aug 2009
    Posts
    15

    Default

    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

  5. #5
    Join Date
    May 2007
    Posts
    13

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •